Pixel-Composer/scripts/contextMenu_controller/contextMenu_controller.gml

115 lines
3.4 KiB
Text
Raw Normal View History

2024-08-09 13:30:09 +02:00
#region data
2024-08-10 15:32:50 +02:00
globalvar CONTEXT_MENU_CALLBACK, FOCUS_BEFORE;
2023-05-03 21:42:17 +02:00
CONTEXT_MENU_CALLBACK = ds_map_create();
2024-08-10 15:32:50 +02:00
FOCUS_BEFORE = noone;
2024-08-09 13:30:09 +02:00
#endregion
2024-09-12 05:08:48 +02:00
function menuCall(menu_id = "", menu = [], _x = 0, _y = 0, align = fa_left) {
if(array_empty(menu)) return noone;
FOCUS_BEFORE = FOCUS;
2024-08-10 11:04:14 +02:00
_x = _x == 0? mouse_mx + ui(4) : _x;
_y = _y == 0? mouse_my + ui(4) : _y;
2024-08-09 13:30:09 +02:00
var dia = dialogCall(o_dialog_menubox, _x, _y);
2024-08-09 13:30:09 +02:00
if(menu_id != "" && ds_map_exists(CONTEXT_MENU_CALLBACK, menu_id)) {
var callbacks = CONTEXT_MENU_CALLBACK[? menu_id];
2023-05-03 21:42:17 +02:00
2024-08-09 13:30:09 +02:00
for( var i = 0, n = array_length(callbacks); i < n; i++ )
array_append(menu, callbacks[i].populate());
2023-05-03 21:42:17 +02:00
}
2023-12-20 14:02:49 +01:00
2024-09-12 05:08:48 +02:00
dia.context = self;
2024-09-10 11:48:51 +02:00
dia.menu_id = menu_id;
2024-08-09 13:30:09 +02:00
dia.setMenu(menu, align);
return dia;
}
2023-05-03 21:42:17 +02:00
2024-09-12 05:08:48 +02:00
function pieMenuCall(menu_id = "", _x = mouse_mx, _y = mouse_my, menu = []) {
2024-08-09 13:30:09 +02:00
var dia = instance_create(_x, _y, o_pie_menu);
if(menu_id != "" && ds_map_exists(CONTEXT_MENU_CALLBACK, menu_id)) {
var callbacks = CONTEXT_MENU_CALLBACK[? menu_id];
2023-05-07 20:55:13 +02:00
2024-08-09 13:30:09 +02:00
for( var i = 0, n = array_length(callbacks); i < n; i++ )
array_append(menu, callbacks[i].populate());
2023-05-03 21:42:17 +02:00
}
2024-09-12 05:08:48 +02:00
dia.context = self;
2024-08-09 13:30:09 +02:00
dia.menu_id = menu_id;
dia.setMenu(menu);
return dia;
}
2024-08-10 07:30:41 +02:00
function submenuCall(_data = undefined, menu = []) {
2024-08-10 11:04:14 +02:00
if(is_undefined(_data)) return menuCall("", menu);
2024-08-10 07:30:41 +02:00
2024-09-12 05:08:48 +02:00
var _xx = _data.x - 1;
var dia = instance_create_depth(_xx, _data.y, _data.depth - 1, o_dialog_menubox);
dia.context = _data.context;
2024-08-09 13:30:09 +02:00
dia.setMenu(menu);
2024-05-22 04:46:29 +02:00
2024-09-12 05:08:48 +02:00
if(_xx + dia.dialog_w > WIN_W - ui(2))
2024-08-09 13:30:09 +02:00
dia.dialog_x = _data._x - dia.dialog_w + ui(4);
2024-08-09 13:30:09 +02:00
return dia;
}
2023-05-03 21:42:17 +02:00
2024-08-09 13:30:09 +02:00
function fileNameCall(path, onModify, _x = mouse_mx + 8, _y = mouse_my + 8) {
var dia = dialogCall(o_dialog_file_name, _x, _y);
dia.onModify = onModify;
dia.path = string_trim_end(path, [ "\\", "/" ]) + "/";
2023-10-07 09:09:18 +02:00
2024-08-09 13:30:09 +02:00
return dia;
}
2024-08-19 06:16:12 +02:00
function menuItem( name, func, spr = noone, hotkey = noone, toggle = noone, params = noone) { return new MenuItem(name, func, spr, hotkey, toggle, params); }
function menuItemShelf(name, func, spr = noone, hotkey = noone, toggle = noone, params = noone) { return new MenuItem(name, func, spr, hotkey, toggle, params).setIsShelf(); }
2024-08-09 13:30:09 +02:00
2024-08-19 06:16:12 +02:00
function MenuItem(_name, _func, _spr = noone, _hotkey = noone, _toggle = noone, _params = noone) constructor {
2024-08-09 13:30:09 +02:00
active = true;
name = _name;
func = _func;
spr = _spr;
hotkey = _hotkey;
toggle = _toggle;
params = _params;
color = c_white;
isShelf = false;
shelfObject = noone;
shiftMenu = noone;
hoykeyObject = noone;
static deactivate = function() /*=>*/ { INLINE active = false; return self; }
static setIsShelf = function() /*=>*/ { INLINE isShelf = true; return self; }
static setActive = function(_active) /*=>*/ { INLINE active = _active; return self; }
static setColor = function(_color) /*=>*/ { INLINE color = _color; return self; }
static setShiftMenu = function(_shiftMenu) /*=>*/ { INLINE shiftMenu = _shiftMenu; return self; }
}
2024-08-10 15:32:50 +02:00
function menuItemGroup(_name, _group, _hotkey = noone) { return new MenuItemGroup(_name, _group, _hotkey); }
function MenuItemGroup(_name, _group, _hotkey = noone) constructor {
2024-08-09 13:30:09 +02:00
active = true;
name = _name;
group = _group;
2024-08-10 15:32:50 +02:00
hotkey = _hotkey;
params = {};
2024-08-09 13:30:09 +02:00
2024-08-10 15:32:50 +02:00
hoykeyObject = noone;
2024-08-09 13:30:09 +02:00
spacing = ui(36);
2024-08-10 15:32:50 +02:00
static setSpacing = function(_spacing) {
spacing = _spacing;
return self;
}
}
function menuButton(_spr, _onClick, _tooltip = "", _step = noone) constructor {
spr = _spr;
onClick = _onClick;
tooltip = _tooltip;
step = _step;
2024-08-09 13:30:09 +02:00
}