mirror of
https://github.com/godotengine/godot.git
synced 2026-01-05 06:11:29 +03:00
Improve window_set_current_screen and fix secondary window initial mode and positions.
This commit is contained in:
@@ -625,10 +625,10 @@ DisplayServer::WindowID DisplayServerWindows::get_window_at_screen_position(cons
|
||||
return INVALID_WINDOW_ID;
|
||||
}
|
||||
|
||||
DisplayServer::WindowID DisplayServerWindows::create_sub_window(WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Rect2i &p_rect) {
|
||||
DisplayServer::WindowID DisplayServerWindows::create_sub_window(WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Rect2i &p_rect, int p_screen) {
|
||||
_THREAD_SAFE_METHOD_
|
||||
|
||||
WindowID window_id = _create_window(p_mode, p_vsync_mode, p_flags, p_rect);
|
||||
WindowID window_id = _create_window(p_mode, p_vsync_mode, p_flags, p_rect, p_screen);
|
||||
ERR_FAIL_COND_V_MSG(window_id == INVALID_WINDOW_ID, INVALID_WINDOW_ID, "Failed to create sub window.");
|
||||
|
||||
WindowData &wd = windows[window_id];
|
||||
@@ -865,19 +865,24 @@ void DisplayServerWindows::window_set_current_screen(int p_screen, WindowID p_wi
|
||||
ERR_FAIL_COND(!windows.has(p_window));
|
||||
ERR_FAIL_INDEX(p_screen, get_screen_count());
|
||||
|
||||
if (window_get_current_screen(p_window) == p_screen) {
|
||||
return;
|
||||
}
|
||||
const WindowData &wd = windows[p_window];
|
||||
if (wd.fullscreen) {
|
||||
int cs = window_get_current_screen(p_window);
|
||||
if (cs == p_screen) {
|
||||
return;
|
||||
}
|
||||
Point2 pos = screen_get_position(p_screen);
|
||||
Size2 size = screen_get_size(p_screen);
|
||||
|
||||
MoveWindow(wd.hWnd, pos.x, pos.y, size.width, size.height, TRUE);
|
||||
} else {
|
||||
Vector2 ofs = window_get_position(p_window) - screen_get_position(window_get_current_screen(p_window));
|
||||
window_set_position(ofs + screen_get_position(p_screen), p_window);
|
||||
Rect2i srect = screen_get_usable_rect(p_screen);
|
||||
Point2i wpos = window_get_position(p_window) - screen_get_position(window_get_current_screen(p_window));
|
||||
Size2i wsize = window_get_size(p_window);
|
||||
wpos += srect.position;
|
||||
|
||||
wpos.x = CLAMP(wpos.x, srect.position.x, srect.position.x + srect.size.width - wsize.width / 3);
|
||||
wpos.y = CLAMP(wpos.y, srect.position.y, srect.position.y + srect.size.height - wsize.height / 3);
|
||||
window_set_position(wpos, p_window);
|
||||
}
|
||||
|
||||
// Don't let the mouse leave the window when resizing to a smaller resolution.
|
||||
@@ -3534,7 +3539,7 @@ void DisplayServerWindows::_update_tablet_ctx(const String &p_old_driver, const
|
||||
}
|
||||
}
|
||||
|
||||
DisplayServer::WindowID DisplayServerWindows::_create_window(WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Rect2i &p_rect) {
|
||||
DisplayServer::WindowID DisplayServerWindows::_create_window(WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Rect2i &p_rect, int p_screen) {
|
||||
DWORD dwExStyle;
|
||||
DWORD dwStyle;
|
||||
|
||||
@@ -3548,24 +3553,37 @@ DisplayServer::WindowID DisplayServerWindows::_create_window(WindowMode p_mode,
|
||||
WindowRect.bottom = p_rect.position.y + p_rect.size.y;
|
||||
|
||||
if (p_mode == WINDOW_MODE_FULLSCREEN || p_mode == WINDOW_MODE_EXCLUSIVE_FULLSCREEN) {
|
||||
Rect2i screen_rect = Rect2i(screen_get_position(p_screen), screen_get_size(p_screen));
|
||||
|
||||
WindowRect.left = screen_rect.position.x;
|
||||
WindowRect.right = screen_rect.position.x + screen_rect.size.x;
|
||||
WindowRect.top = screen_rect.position.y;
|
||||
WindowRect.bottom = screen_rect.position.y + screen_rect.size.y;
|
||||
} else {
|
||||
int nearest_area = 0;
|
||||
Rect2i screen_rect;
|
||||
int pos_screen = -1;
|
||||
for (int i = 0; i < get_screen_count(); i++) {
|
||||
Rect2i r;
|
||||
r.position = screen_get_position(i);
|
||||
r.size = screen_get_size(i);
|
||||
Rect2 inters = r.intersection(p_rect);
|
||||
int area = inters.size.width * inters.size.height;
|
||||
if (area >= nearest_area) {
|
||||
screen_rect = r;
|
||||
if (area > nearest_area) {
|
||||
pos_screen = i;
|
||||
nearest_area = area;
|
||||
}
|
||||
}
|
||||
|
||||
WindowRect.left = screen_rect.position.x;
|
||||
WindowRect.right = screen_rect.position.x + screen_rect.size.x;
|
||||
WindowRect.top = screen_rect.position.y;
|
||||
WindowRect.bottom = screen_rect.position.y + screen_rect.size.y;
|
||||
Rect2i srect = screen_get_usable_rect(p_screen);
|
||||
Point2i wpos = p_rect.position - ((pos_screen >= 0) ? screen_get_position(pos_screen) : Vector2i());
|
||||
wpos += srect.position;
|
||||
wpos.x = CLAMP(wpos.x, srect.position.x, srect.position.x + srect.size.width - p_rect.size.width / 3);
|
||||
wpos.y = CLAMP(wpos.y, srect.position.y, srect.position.y + srect.size.height - p_rect.size.height / 3);
|
||||
|
||||
WindowRect.left = wpos.x;
|
||||
WindowRect.right = wpos.x + p_rect.size.x;
|
||||
WindowRect.top = wpos.y;
|
||||
WindowRect.bottom = wpos.y + p_rect.size.y;
|
||||
}
|
||||
|
||||
AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);
|
||||
@@ -3933,7 +3951,7 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win
|
||||
window_position = *p_position;
|
||||
}
|
||||
|
||||
WindowID main_window = _create_window(p_mode, p_vsync_mode, 0, Rect2i(window_position, p_resolution));
|
||||
WindowID main_window = _create_window(p_mode, p_vsync_mode, 0, Rect2i(window_position, p_resolution), 0);
|
||||
ERR_FAIL_COND_MSG(main_window == INVALID_WINDOW_ID, "Failed to create main window.");
|
||||
|
||||
joypad = new JoypadWindows(&windows[MAIN_WINDOW_ID].hWnd);
|
||||
|
||||
Reference in New Issue
Block a user