diff --git a/examples/main.lua b/examples/main.lua index e36ec79..219cbe6 100644 --- a/examples/main.lua +++ b/examples/main.lua @@ -63,4 +63,39 @@ function M.load_scene(self, id) end, nil, error) end +local SYSTEM_NAME = sys.get_sys_info().system_name + +function M.resize_window() + if SYSTEM_NAME ~= "Windows" and SYSTEM_NAME ~= "Darwin" and SYSTEM_NAME ~= "Linux" then + return + end + assert(defos, "`defos` is required") + + local displays = defos.get_displays() + local current_display_id = defos.get_current_display_id() + local screen_width = 1920 -- displays[current_display_id].bounds.width + local screen_height = 1080 -- displays[current_display_id].bounds.height + + local project_width = tonumber(sys.get_config("display.width", 1920)) + local project_height = tonumber(sys.get_config("display.height", 1080)) + + -- Resize the window. The code doesn't respect HiDPi screens. + local x, y, w, h = defos.get_view_size() + w = project_width + h = project_height + print("w x h -> ", w, h, screen_width, screen_height) + while screen_height * 0.95 <= h or screen_width * 0.95 <= w do + w = w * 0.75 + h = h * 0.75 + print("w x h -> ", w, h, screen_width, screen_height) + end + defos.set_view_size(x, y, w, h) + + -- Center the window + local x, y, w, h = defos.get_window_size() + x = math.floor((screen_width - w) / 2) + y = math.floor((screen_height - h) / 2) + defos.set_window_size(x, y, w, h) +end + return M \ No newline at end of file diff --git a/examples/main.script b/examples/main.script index b6413fc..21b51ef 100644 --- a/examples/main.script +++ b/examples/main.script @@ -19,6 +19,9 @@ function init(self) main.setup_error_handling() window.set_listener(main.window_callback) + -- Resize game window on desktop platforms + main.resize_window() + -- Set Pointer Lock's virtual cursor invisible by default pointer.cursor_visible = false