2022-01-13 05:24:03 +01:00
|
|
|
/// @description init
|
|
|
|
event_inherited();
|
|
|
|
|
|
|
|
#region data
|
2022-11-01 03:06:03 +01:00
|
|
|
destroy_on_click_out = false;
|
2024-08-09 13:30:09 +02:00
|
|
|
draggable = false;
|
|
|
|
mouse_init_inside = false;
|
2024-08-10 15:32:50 +02:00
|
|
|
mouse_init_r_pressed = mouse_click(mb_right);
|
2024-08-09 13:30:09 +02:00
|
|
|
selecting = -1;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-08-09 13:30:09 +02:00
|
|
|
menu_id = "";
|
|
|
|
alarm[0] = -1;
|
|
|
|
menu = 1;
|
2024-09-12 05:08:48 +02:00
|
|
|
font = f_p2;
|
2024-09-10 11:48:51 +02:00
|
|
|
hght = line_get_height(font, 10);
|
2024-08-09 13:30:09 +02:00
|
|
|
tooltips = [];
|
|
|
|
show_icon = false;
|
|
|
|
context = noone;
|
2024-09-11 11:56:41 +02:00
|
|
|
submenu = noone;
|
2024-09-13 12:29:19 +02:00
|
|
|
submenuIt = noone;
|
2023-02-19 02:13:19 +01:00
|
|
|
|
2024-09-12 05:08:48 +02:00
|
|
|
_hovering_ch = true;
|
|
|
|
init_press_l = MOUSE_POOL.lpress;
|
2024-04-08 07:13:46 +02:00
|
|
|
|
|
|
|
setFocus(self.id);
|
|
|
|
|
2024-09-11 11:56:41 +02:00
|
|
|
item_sel_submenu = noone;
|
2024-08-09 13:30:09 +02:00
|
|
|
remove_parents = true;
|
|
|
|
selecting_menu = noone;
|
|
|
|
hk_editing = noone;
|
|
|
|
|
2023-02-23 07:02:19 +01:00
|
|
|
function setMenu(_menu, align = fa_left) {
|
2024-05-27 03:41:41 +02:00
|
|
|
with(_p_dialog) { if(on_top) continue; other.depth = min(depth - 1, other.depth); }
|
|
|
|
|
2024-09-12 05:08:48 +02:00
|
|
|
title = menu_id;
|
|
|
|
menu = _menu;
|
2022-01-13 05:24:03 +01:00
|
|
|
dialog_x = x;
|
|
|
|
dialog_y = y;
|
|
|
|
|
2023-02-19 02:13:19 +01:00
|
|
|
show_icon = false;
|
2022-01-13 05:24:03 +01:00
|
|
|
dialog_w = 0;
|
|
|
|
dialog_h = 0;
|
|
|
|
|
2024-09-11 11:56:41 +02:00
|
|
|
if(submenu != noone) instance_destroy(submenu);
|
|
|
|
submenu = noone;
|
2024-09-10 11:48:51 +02:00
|
|
|
tooltips = [];
|
2022-11-01 03:06:03 +01:00
|
|
|
|
2024-08-10 07:30:41 +02:00
|
|
|
draw_set_text(font, fa_center, fa_center, COLORS._main_text);
|
2022-01-13 05:24:03 +01:00
|
|
|
for(var i = 0; i < array_length(menu); i++) {
|
2023-02-19 02:13:19 +01:00
|
|
|
var _menuItem = menu[i];
|
2024-08-10 09:12:20 +02:00
|
|
|
|
2023-02-19 02:13:19 +01:00
|
|
|
if(_menuItem == -1) {
|
2022-11-03 11:44:49 +01:00
|
|
|
dialog_h += ui(8);
|
2022-01-13 05:24:03 +01:00
|
|
|
continue;
|
|
|
|
}
|
2023-02-19 02:13:19 +01:00
|
|
|
|
2024-08-09 13:30:09 +02:00
|
|
|
if(is_string(_menuItem)) {
|
|
|
|
draw_set_font(f_p3);
|
|
|
|
dialog_w = max(dialog_w, string_width(_menuItem) + ui(24));
|
|
|
|
dialog_h += string_height(_menuItem) + ui(8);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2024-08-10 07:30:41 +02:00
|
|
|
draw_set_font(font);
|
2024-08-12 04:28:38 +02:00
|
|
|
var ww = string_width(_menuItem.name) + ui(64);
|
|
|
|
var _key = _menuItem.hotkey != noone? find_hotkey(_menuItem.hotkey[0], _menuItem.hotkey[1]) : noone;
|
|
|
|
|
|
|
|
draw_set_font(font);
|
|
|
|
var _kw = _key? string_width(key_get_name(_key.key, _key.modi)) + ui(16) : 0;
|
2023-02-19 02:13:19 +01:00
|
|
|
|
|
|
|
if(instanceof(_menuItem) == "MenuItemGroup") {
|
|
|
|
var amo = array_length(_menuItem.group);
|
2024-08-12 04:28:38 +02:00
|
|
|
ww = max(ww + _kw * 2, ui(16) + amo * (_menuItem.spacing + ui(4)));
|
2023-02-19 02:13:19 +01:00
|
|
|
dialog_h += hght;
|
|
|
|
}
|
2023-01-25 06:49:00 +01:00
|
|
|
|
2023-02-19 02:13:19 +01:00
|
|
|
if(instanceof(_menuItem) == "MenuItem") {
|
2024-08-12 04:28:38 +02:00
|
|
|
ww += _kw;
|
2024-08-10 09:12:20 +02:00
|
|
|
if(_menuItem.spr != noone || _menuItem.toggle != noone) show_icon = true;
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
2023-02-19 02:13:19 +01:00
|
|
|
dialog_w = max(dialog_w, ww);
|
2022-01-13 05:24:03 +01:00
|
|
|
dialog_h += hght;
|
|
|
|
}
|
|
|
|
|
2023-02-19 02:13:19 +01:00
|
|
|
if(show_icon)
|
|
|
|
dialog_w += ui(32);
|
|
|
|
|
2024-09-11 13:01:21 +02:00
|
|
|
var _mon = winMan_getData();
|
|
|
|
var _maxw = PREFERENCES.multi_window? _mon[6] - WIN_X : WIN_W;
|
|
|
|
var _maxh = PREFERENCES.multi_window? _mon[7] - WIN_Y : WIN_H;
|
|
|
|
|
|
|
|
dialog_y = min(dialog_y, _maxh - dialog_h - 2);
|
2023-02-23 07:02:19 +01:00
|
|
|
|
|
|
|
switch(align) {
|
2024-09-11 13:01:21 +02:00
|
|
|
case fa_left: dialog_x = round(min(dialog_x, _maxw - dialog_w - 2)); break;
|
|
|
|
case fa_center: dialog_x = round(min(dialog_x - dialog_w / 2, _maxw - dialog_w - 2)); break;
|
2023-03-28 06:58:28 +02:00
|
|
|
case fa_right: dialog_x = round(max(dialog_x - dialog_w, 2)); break;
|
2023-02-23 07:02:19 +01:00
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-08-09 13:30:09 +02:00
|
|
|
mouse_init_inside = point_in_rectangle(mouse_mx, mouse_my, dialog_x, dialog_y, dialog_x + dialog_w, dialog_y + dialog_h);
|
2022-01-13 05:24:03 +01:00
|
|
|
ready = true;
|
2024-09-11 11:56:41 +02:00
|
|
|
|
|
|
|
if(PREFERENCES.multi_window) {
|
|
|
|
var _wx = winwin_get_x_safe(WINDOW_ACTIVE) + dialog_x;
|
|
|
|
var _wy = winwin_get_y_safe(WINDOW_ACTIVE) + dialog_y;
|
|
|
|
|
2024-09-12 05:08:48 +02:00
|
|
|
if(window == noone || !winwin_exists(window)) {
|
|
|
|
var _cfg = winwin_config_ext("", winwin_kind_borderless, false, false);
|
|
|
|
window = winwin_create_ext(_wx, _wy, dialog_w, dialog_h, _cfg);
|
2024-09-11 11:56:41 +02:00
|
|
|
|
|
|
|
} else {
|
|
|
|
winwin_set_position_safe(window, _wx, _wy);
|
|
|
|
winwin_set_size_safe(window, dialog_w, dialog_h);
|
|
|
|
}
|
|
|
|
|
|
|
|
dialog_x = 0;
|
|
|
|
dialog_y = 0;
|
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
#endregion
|