mirror of
https://github.com/tiennm99/godot.git
synced 2026-08-21 08:26:19 +00:00
Merge pull request #16648 from marcelofg55/center_window
Added OS::center_window to center the window precisely on desktop platforms
This commit is contained in:
@@ -167,6 +167,7 @@ public:
|
||||
virtual void set_window_title(const String &p_title);
|
||||
|
||||
virtual Size2 get_window_size() const;
|
||||
virtual Size2 get_real_window_size() const;
|
||||
|
||||
virtual void set_icon(const Ref<Image> &p_icon);
|
||||
|
||||
|
||||
@@ -1845,6 +1845,12 @@ Size2 OS_OSX::get_window_size() const {
|
||||
return window_size;
|
||||
};
|
||||
|
||||
Size2 OS_OSX::get_real_window_size() const {
|
||||
|
||||
NSRect frame = [window_object frame];
|
||||
return Size2(frame.size.width, frame.size.height);
|
||||
}
|
||||
|
||||
void OS_OSX::set_window_size(const Size2 p_size) {
|
||||
|
||||
Size2 size = p_size;
|
||||
|
||||
@@ -1487,6 +1487,12 @@ Size2 OS_Windows::get_window_size() const {
|
||||
GetClientRect(hWnd, &r);
|
||||
return Vector2(r.right - r.left, r.bottom - r.top);
|
||||
}
|
||||
Size2 OS_Windows::get_real_window_size() const {
|
||||
|
||||
RECT r;
|
||||
GetWindowRect(hWnd, &r);
|
||||
return Vector2(r.right - r.left, r.bottom - r.top);
|
||||
}
|
||||
void OS_Windows::set_window_size(const Size2 p_size) {
|
||||
|
||||
video_mode.width = p_size.width;
|
||||
|
||||
@@ -201,6 +201,7 @@ public:
|
||||
virtual Point2 get_window_position() const;
|
||||
virtual void set_window_position(const Point2 &p_position);
|
||||
virtual Size2 get_window_size() const;
|
||||
virtual Size2 get_real_window_size() const;
|
||||
virtual void set_window_size(const Size2 p_size);
|
||||
virtual void set_window_fullscreen(bool p_enabled);
|
||||
virtual bool is_window_fullscreen() const;
|
||||
|
||||
@@ -924,6 +924,26 @@ Size2 OS_X11::get_window_size() const {
|
||||
return Size2i(current_videomode.width, current_videomode.height);
|
||||
}
|
||||
|
||||
Size2 OS_X11::get_real_window_size() const {
|
||||
XWindowAttributes xwa;
|
||||
XSync(x11_display, False);
|
||||
XGetWindowAttributes(x11_display, x11_window, &xwa);
|
||||
int w = xwa.width;
|
||||
int h = xwa.height;
|
||||
Atom prop = XInternAtom(x11_display, "_NET_FRAME_EXTENTS", True);
|
||||
Atom type;
|
||||
int format;
|
||||
unsigned long len;
|
||||
unsigned long remaining;
|
||||
unsigned char *data = NULL;
|
||||
if (XGetWindowProperty(x11_display, x11_window, prop, 0, 4, False, AnyPropertyType, &type, &format, &len, &remaining, &data) == Success) {
|
||||
long *extents = (long *)data;
|
||||
w += extents[0] + extents[1]; // left, right
|
||||
h += extents[2] + extents[3]; // top, bottom
|
||||
}
|
||||
return Size2(w, h);
|
||||
}
|
||||
|
||||
void OS_X11::set_window_size(const Size2 p_size) {
|
||||
// If window resizable is disabled we need to update the attributes first
|
||||
if (is_window_resizable() == false) {
|
||||
|
||||
@@ -251,6 +251,7 @@ public:
|
||||
virtual Point2 get_window_position() const;
|
||||
virtual void set_window_position(const Point2 &p_position);
|
||||
virtual Size2 get_window_size() const;
|
||||
virtual Size2 get_real_window_size() const;
|
||||
virtual void set_window_size(const Size2 p_size);
|
||||
virtual void set_window_fullscreen(bool p_enabled);
|
||||
virtual bool is_window_fullscreen() const;
|
||||
|
||||
Reference in New Issue
Block a user