From ea1d726a4603fdd6bd4dfa6c1fa3128cfb2915c7 Mon Sep 17 00:00:00 2001 From: Marcelo Fernandez Date: Mon, 12 Feb 2018 14:17:29 -0300 Subject: Added OS::center_window to center the window precisely on desktop platforms --- core/os/os.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'core/os/os.cpp') diff --git a/core/os/os.cpp b/core/os/os.cpp index c6e5de703c..422acf95dc 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -616,6 +616,17 @@ bool OS::has_feature(const String &p_feature) { return false; } +void OS::center_window() { + + if (is_window_fullscreen()) return; + + Size2 scr = get_screen_size(get_current_screen()); + Size2 wnd = get_real_window_size(); + int x = scr.width / 2 - wnd.width / 2; + int y = scr.height / 2 - wnd.height / 2; + set_window_position(Vector2(x, y)); +} + OS::OS() { void *volatile stack_bottom; -- cgit v1.2.3