Pixel-Composer/scripts/windowManager/windowManager.gml

281 lines
6.7 KiB
Text
Raw Normal View History

2023-11-28 06:50:54 +01:00
#region defines
globalvar window_resize_padding; window_resize_padding = 6;
globalvar window_minimize_size; window_minimize_size = [ 1920, 1080 ];
globalvar window_is_maximized; window_is_maximized = false;
globalvar window_is_fullscreen; window_is_fullscreen = false;
globalvar window_drag_status; window_drag_status = 0;
globalvar window_drag_hold; window_drag_hold = 0;
globalvar window_drag_mx; window_drag_mx = 0;
globalvar window_drag_my; window_drag_my = 0;
globalvar window_drag_sx; window_drag_sx = 0;
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;
2023-11-28 06:50:54 +01:00
2024-05-02 12:16:34 +02:00
globalvar window_min_w; window_min_w = 960;
2023-11-28 06:50:54 +01:00
globalvar window_min_h; window_min_h = 600;
2023-12-18 04:40:21 +01:00
globalvar window_preminimize_rect; window_preminimize_rect = [ 0, 0, 1, 1 ];
2024-12-11 12:44:48 +01:00
globalvar __winman_to_ref; __winman_to_ref = false;
2023-12-18 04:40:21 +01:00
2024-04-30 10:49:12 +02:00
#macro DISPLAY_REFRESH CURRENT_PANEL = panelSerialize(true); display_refresh();
2023-11-28 06:50:54 +01:00
#endregion
2024-09-11 13:01:21 +02:00
function winManInit() {
2023-12-18 04:40:21 +01:00
if(OS == os_macosx) mac_window_init();
window_preminimize_rect = [ 0, 0, 1, 1 ];
2024-09-11 13:01:21 +02:00
}
2023-12-18 04:40:21 +01:00
2024-09-11 11:56:41 +02:00
function winMan_getData(curr = true) {
2023-11-28 06:50:54 +01:00
INLINE
var _monitors = display_measure_all();
2023-12-06 13:51:22 +01:00
if(!is_array(_monitors) || array_empty(_monitors))
return [ 0, 0, display_get_width(), display_get_height(),
0, 0, display_get_width(), display_get_height(), ];
2023-11-28 06:50:54 +01:00
var _x = window_get_x();
var _y = window_get_y();
for( var i = 0, n = array_length(_monitors); i < n; i++ ) {
var _monitor = _monitors[i];
if(!is_array(_monitor) || array_length(_monitor) < 8) continue;
if(point_in_rectangle(
_x + WIN_W / 2,
_y + WIN_H / 2,
_monitor[0],
_monitor[1],
_monitor[0] + _monitor[2],
_monitor[1] + _monitor[3]
)) return _monitor;
}
return _monitors[0];
2024-09-11 11:56:41 +02:00
}
2023-11-28 06:50:54 +01:00
2024-09-11 11:56:41 +02:00
function winMan_setRect(_x, _y, _w, _h) {
2023-11-28 06:50:54 +01:00
INLINE
_w = max(window_min_w, _w);
_h = max(window_min_h, _h);
window_set_rectangle(_x, _y, _w, _h);
2024-09-11 11:56:41 +02:00
}
2023-11-28 06:50:54 +01:00
2024-09-11 11:56:41 +02:00
function winMan_isMinimized() {
2023-11-28 06:50:54 +01:00
INLINE
2023-12-18 04:40:21 +01:00
if(OS == os_macosx) return false;
2023-11-28 06:50:54 +01:00
return gameframe_is_natively_minimized();
2024-09-11 11:56:41 +02:00
}
2023-11-28 06:50:54 +01:00
2024-09-11 11:56:41 +02:00
function winMan_Maximize() {
2023-11-28 06:50:54 +01:00
INLINE
if(gameframe_is_natively_minimized()) return;
window_is_maximized = true;
var _mon = winMan_getData();
winMan_setRect(_mon[4], _mon[5], _mon[6], _mon[7]);
gameframe_set_shadow(false);
2024-09-11 11:56:41 +02:00
}
2023-11-28 06:50:54 +01:00
2024-09-11 11:56:41 +02:00
function winMan_Unmaximize() {
2023-11-28 06:50:54 +01:00
INLINE
if(gameframe_is_natively_minimized()) return;
window_is_maximized = false;
var _mon = winMan_getData();
winMan_setRect(
_mon[4] + _mon[6] / 2 - window_minimize_size[0] / 2,
_mon[5] + _mon[7] / 2 - window_minimize_size[1] / 2,
window_minimize_size[0],
window_minimize_size[1]
);
gameframe_set_shadow(true);
2024-09-11 11:56:41 +02:00
}
2023-11-28 06:50:54 +01:00
2024-09-11 11:56:41 +02:00
function winMan_Minimize() {
2023-11-28 06:50:54 +01:00
INLINE
if(gameframe_is_natively_minimized()) return;
gameframe_syscommand(61472);
2024-09-11 11:56:41 +02:00
}
2023-11-28 06:50:54 +01:00
2024-09-11 11:56:41 +02:00
function winMan_initDrag(_index) {
2023-11-28 06:50:54 +01:00
window_drag_status = _index;
window_drag_hold = 0;
window_drag_mx = mouse_raw_x;
window_drag_my = mouse_raw_y;
window_drag_sx = window_get_x();
window_drag_sy = window_get_y();
window_drag_sw = window_get_width();
window_drag_sh = window_get_height();
2024-09-11 11:56:41 +02:00
}
2023-11-28 06:50:54 +01:00
2024-09-11 11:56:41 +02:00
function winMan_setFullscreen(full) {
2023-11-28 06:50:54 +01:00
if(full == window_is_fullscreen) return;
window_is_fullscreen = full;
var _mon = winMan_getData();
if(full) {
winMan_setRect(_mon[0], _mon[1], _mon[2], _mon[3]);
gameframe_set_shadow(false);
} else {
if(window_is_maximized) winMan_Maximize();
else winMan_Unmaximize();
}
2024-12-11 12:44:48 +01:00
run_in(5, function() /*=>*/ { DISPLAY_REFRESH });
2024-09-11 11:56:41 +02:00
}
2023-11-28 06:50:54 +01:00
2024-09-11 11:56:41 +02:00
function winManStep() {
2023-12-12 06:40:29 +01:00
if(OS == os_macosx) {
if(__win_to_dock) {
_window_set_showborder(window_handle(), true);
mac_minimize_to_dock(window_handle());
__win_to_dock = false;
} else {
if(_window_get_showborder(window_handle()))
_window_set_showborder(window_handle(), false);
}
}
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];
}
2023-11-28 06:50:54 +01:00
if(window_drag_status == 0) return;
var _mx = window_drag_mx;
var _my = window_drag_my;
var _sx = window_drag_sx;
var _sy = window_drag_sy;
var _sw = window_drag_sw;
var _sh = window_drag_sh;
var mx = mouse_raw_x;
var my = mouse_raw_y;
var sx = _sx;
var sy = _sy;
var sw = _sw;
var sh = _sh;
if(window_drag_status & 0b10000) {
if(window_drag_hold == 0 && window_is_maximized) {
if(point_distance(mx, my, _mx, _my) > 8)
window_drag_hold = 1;
2024-12-11 12:44:48 +01:00
2023-11-28 09:42:22 +01:00
} else {
2023-11-28 06:50:54 +01:00
if(window_is_maximized) {
winMan_Unmaximize();
window_drag_sw = window_minimize_size[0];
window_drag_sh = window_minimize_size[1];
2024-12-11 12:44:48 +01:00
__winman_to_ref = true;
2023-11-28 06:50:54 +01:00
} else {
sx = _sx + (mx - _mx);
sy = _sy + (my - _my);
winMan_setRect(sx, sy, sw, sh);
}
}
2024-12-11 12:44:48 +01:00
if(__winman_to_ref && mouse_release(mb_left)) {
__winman_to_ref = false;
DISPLAY_REFRESH
}
2023-11-28 06:50:54 +01:00
} else {
if(window_drag_status & 0b0001) {
sw = _sw + (mx - _mx);
}
if(window_drag_status & 0b0010) {
sh = max(window_min_h, _sh - (my - _my));
sy = _sy + (_sh - sh);
}
if(window_drag_status & 0b0100) {
sw = max(window_min_w, _sw - (mx - _mx));
sx = _sx + (_sw - sw);
}
if(window_drag_status & 0b1000) {
sh = _sh + (my - _my);
}
winMan_setRect(sx, sy, sw, sh);
2023-11-30 03:18:25 +01:00
2024-12-11 12:44:48 +01:00
if(mouse_release(mb_left))
2023-11-30 03:18:25 +01:00
DISPLAY_REFRESH
2023-11-28 06:50:54 +01:00
}
if(mouse_release(mb_left)) {
window_minimize_size = [ sw, sh ];
window_drag_status = 0;
}
2024-09-11 11:56:41 +02:00
}
2023-11-28 06:50:54 +01:00
2024-09-11 11:56:41 +02:00
function winManDraw() {
2023-11-28 06:50:54 +01:00
if(window_is_maximized || window_is_fullscreen) return;
var pd = window_resize_padding;
var hv = -1;
var l = mouse_mx > 0 && mouse_mx < pd && mouse_my > 0 && mouse_my < WIN_H;
var r = mouse_mx > WIN_W - pd && mouse_mx < WIN_W && mouse_my > 0 && mouse_my < WIN_H;
var u = mouse_mx > 0 && mouse_mx < WIN_W && mouse_my > 0 && mouse_my < pd;
var d = mouse_mx > 0 && mouse_mx < WIN_W && mouse_my > WIN_H - pd && mouse_my < WIN_H;
if(r) {
CURSOR = cr_size_we;
hv = 0b0001;
}
if(u) {
CURSOR = cr_size_ns;
hv = 0b0010;
}
if(l) {
CURSOR = cr_size_we;
hv = 0b0100;
}
if(d) {
CURSOR = cr_size_ns;
hv = 0b1000;
}
if(l && u) {
2024-09-10 04:50:48 +02:00
CURSOR = MAC? cr_size_all : cr_size_nwse;
2023-11-28 06:50:54 +01:00
hv = 0b0110;
}
if(r && d) {
2024-09-10 04:50:48 +02:00
CURSOR = MAC? cr_size_all : cr_size_nwse;
2023-11-28 06:50:54 +01:00
hv = 0b1001;
}
if(l && d) {
2024-09-10 04:50:48 +02:00
CURSOR = MAC? cr_size_all : cr_size_nesw;
2023-11-28 06:50:54 +01:00
hv = 0b1100;
}
if(r && u) {
2024-09-10 04:50:48 +02:00
CURSOR = MAC? cr_size_all : cr_size_nesw;
2023-11-28 06:50:54 +01:00
hv = 0b0011;
}
if(hv > -1 && mouse_press(mb_left))
winMan_initDrag(hv);
2024-09-11 11:56:41 +02:00
}