From b8918d21fb62ea9cd9979c086ed6fd07342e1d64 Mon Sep 17 00:00:00 2001 From: Tanasart Date: Tue, 7 May 2024 13:09:38 +0700 Subject: [PATCH] - Software now remember the monitor it's closed on. --- scripts/preferences/preferences.gml | 37 +++++++++++++++++-------- scripts/windowManager/windowManager.gml | 15 ++++++++++ 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/scripts/preferences/preferences.gml b/scripts/preferences/preferences.gml index 792435362..5c5b27c44 100644 --- a/scripts/preferences/preferences.gml +++ b/scripts/preferences/preferences.gml @@ -9,7 +9,8 @@ PREFERENCES.window_width = 1600; PREFERENCES.window_height = 800; PREFERENCES.window_maximize = false; - + PREFERENCES.window_monitor = ""; + PREFERENCES.theme = "default"; PREFERENCES.local = "en"; PREFERENCES.font_overwrite = ""; @@ -99,7 +100,6 @@ PREFERENCES.collection_scale = 1; PREFERENCES.pan_mouse_key = mb_middle; - #endregion #region //////////////////////////////////////////////////////////////////////// WIDGET //////////////////////////////////////////////////////////////////////// @@ -219,6 +219,7 @@ PREFERENCES.window_maximize = window_is_maximized; PREFERENCES.window_width = max(960, window_minimize_size[0]); PREFERENCES.window_height = max(600, window_minimize_size[1]); + PREFERENCES.window_monitor = window_monitor; map.preferences = PREFERENCES; @@ -276,17 +277,31 @@ else setException(); if(OS != os_macosx && !LOADING) { - if(PREFERENCES.window_maximize) { - winMan_Maximize(); - } else { - var ww = PREFERENCES.window_width; - var hh = PREFERENCES.window_height; - window_minimize_size = [ ww, hh ]; + var _monitors = display_measure_all(); + var _monitor = noone; + + if(is_array(_monitors)) + for( var i = 0, n = array_length(_monitors); i < n; i++ ) { + var _m = _monitors[i]; + if(!is_array(_m) || array_length(_m) < 10) continue; - window_set_position(display_get_width() / 2 - ww / 2, display_get_height() / 2 - hh / 2); - window_set_size(ww, hh); - gameframe_set_shadow(true); + if(PREFERENCES.window_monitor == _m[9]) + _monitor = _m; } + + var ww = PREFERENCES.window_width; + var hh = PREFERENCES.window_height; + window_minimize_size = [ ww, hh ]; + + if(is_array(_monitor) && array_length(_monitor) >= 8) + window_set_rectangle(_monitor[0] + _monitor[2] / 2 - ww / 2, _monitor[1] + _monitor[3] / 2 - hh / 2, ww, hh); + else + window_set_rectangle(display_get_width() / 2 - ww / 2, display_get_height() / 2 - hh / 2, ww, hh); + + if(PREFERENCES.window_maximize) + winMan_Maximize(); + + gameframe_set_shadow(true); } window_refresh(); diff --git a/scripts/windowManager/windowManager.gml b/scripts/windowManager/windowManager.gml index 7964947ae..4e10cc75c 100644 --- a/scripts/windowManager/windowManager.gml +++ b/scripts/windowManager/windowManager.gml @@ -11,6 +11,7 @@ globalvar window_drag_sy; window_drag_sy = 0; globalvar window_drag_sw; window_drag_sw = 0; globalvar window_drag_sh; window_drag_sh = 0; + globalvar window_monitor; window_monitor = 0; globalvar window_min_w; window_min_w = 960; globalvar window_min_h; window_min_h = 600; @@ -138,6 +139,20 @@ function winManStep() { #region } } + window_monitor = 0; + var _monitors = display_measure_all(); + var _x = window_get_x() + WIN_W / 2; + var _y = window_get_y() + WIN_H / 2; + + if(is_array(_monitors)) + for( var i = 0, n = array_length(_monitors); i < n; i++ ) { + var _monitor = _monitors[i]; + if(!is_array(_monitor) || array_length(_monitor) < 10) continue; + + if(point_in_rectangle(_x, _y, _monitor[0], _monitor[1], _monitor[0] + _monitor[2], _monitor[1] + _monitor[3])) + window_monitor = _monitor[9]; + } + if(window_drag_status == 0) return; var _mx = window_drag_mx; var _my = window_drag_my;