- window popup stuff

This commit is contained in:
Tanasart 2024-09-12 10:08:48 +07:00
parent 3e4b61fc0b
commit f25eca1cab
20 changed files with 174 additions and 77 deletions

View file

@ -15,6 +15,7 @@
{"name":"addons","order":142,"path":"folders/addons.yy",},
{"name":"animation_curve","order":143,"path":"folders/animation_curve.yy",},
{"name":"dialog","order":144,"path":"folders/dialog.yy",},
{"name":"Extensions","order":157,"path":"folders/Extensions.yy",},
{"name":"font","order":145,"path":"folders/font.yy",},
{"name":"functions","order":146,"path":"folders/functions.yy",},
{"name":"camera","order":7,"path":"folders/functions/3d/camera.yy",},

View file

@ -50,6 +50,7 @@
{"$GMFolder":"","%Name":"inspector","folderPath":"folders/dialog/inspector.yy","name":"inspector","resourceType":"GMFolder","resourceVersion":"2.0",},
{"$GMFolder":"","%Name":"menu","folderPath":"folders/dialog/menu.yy","name":"menu","resourceType":"GMFolder","resourceVersion":"2.0",},
{"$GMFolder":"","%Name":"widget","folderPath":"folders/dialog/widget.yy","name":"widget","resourceType":"GMFolder","resourceVersion":"2.0",},
{"$GMFolder":"","%Name":"Extensions","folderPath":"folders/Extensions.yy","name":"Extensions","resourceType":"GMFolder","resourceVersion":"2.0",},
{"$GMFolder":"","%Name":"font","folderPath":"folders/font.yy","name":"font","resourceType":"GMFolder","resourceVersion":"2.0",},
{"$GMFolder":"","%Name":"functions","folderPath":"folders/functions.yy","name":"functions","resourceType":"GMFolder","resourceVersion":"2.0",},
{"$GMFolder":"","%Name":"3d","folderPath":"folders/functions/3d.yy","name":"3d","resourceType":"GMFolder","resourceVersion":"2.0",},

View file

@ -24,6 +24,7 @@
_dialog_h = 320;
dialog_x = 0;
dialog_y = 0;
anchor = ANCHOR.none;
title = "dialog";
window = noone;
@ -40,7 +41,6 @@
destroy_on_escape = true;
destroy_on_click_out = false;
anchor = ANCHOR.none;
init_pressing = mouse_click(mb_left);
#endregion
@ -82,15 +82,8 @@
o_main.dialog_popup_y = mouse_my;
if(mouse_release(mb_left)) {
var _wconfig = new winwin_config();
_wconfig.kind = winwin_kind_borderless;
_wconfig.caption = title;
_wconfig.topmost = true;
_wconfig.per_pixel_alpha = true;
_wconfig.resize = true;
_wconfig.owner = winwin_main;
window = winwin_create(_wx + _dx, _wy + _dy, dialog_w, dialog_h, _wconfig);
var _cfg = winwin_config_ext(title, winwin_kind_borderless, false, true);
window = winwin_create_ext(_wx + _dx, _wy + _dy, dialog_w, dialog_h, _cfg);
dialog_x = 0;
dialog_y = 0;
}
@ -334,11 +327,13 @@
function checkMouse() {
if(!active) return;
if(!DIALOG_CLICK) return;
if(init_pressing) return;
WINDOW_ACTIVE = window;
if(!init_pressing && mouse_press(mb_any)) {
if(!isTop()) return;
if(MOUSE_POOL.lpress || MOUSE_POOL.rpress) { //print($"Closing {title}");
if(!isTop()) {
// print($" > Not close, not on top.")
return;
}
for( var i = 0, n = array_length(children); i < n; i++ )
if(instance_exists(children[i])) return;

View file

@ -4,6 +4,7 @@ event_inherited();
#region data
draggable = false;
title = "Add node";
node_target_x = 0;
node_target_y = 0;
node_target_x_raw = 0;
@ -60,6 +61,8 @@ event_inherited();
category_width = maxLen + ui(56);
#endregion
function isTop() { return true; }
function trigger_favourite() {
if(node_menu_selecting == noone) return;
@ -81,7 +84,7 @@ event_inherited();
menuItem(fav? __txtx("add_node_remove_favourite", "Remove from favourite") : __txtx("add_node_add_favourite", "Add to favourite"), trigger_favourite, THEME.star)
];
menuCall("add_node_window_manu", menu, 0, 0, fa_left, node_menu_selecting);
menuCall("add_node_window_menu", menu, 0, 0, fa_left);
}
function filtered(node) {

View file

@ -6,4 +6,25 @@ event_inherited();
dialog_w = ui(440);
dialog_h = ui(140);
function resetPosition() {
if(!active) return;
dialog_x = xstart - dialog_w / 2;
dialog_y = ystart - dialog_h / 2;
dialog_x = round(clamp(dialog_x, 2, WIN_SW - dialog_w - 2));
dialog_y = round(clamp(dialog_y, 2, WIN_SH - dialog_h - 2));
if(PREFERENCES.multi_window) {
var _wx = WIN_X + dialog_x;
var _wy = WIN_Y + dialog_y;
var _cfg = winwin_config_ext("Exit", winwin_kind_borderless, false, false);
window = winwin_create_ext(_wx, _wy, dialog_w, dialog_h, _cfg);
dialog_x = 0;
dialog_y = 0;
}
}
#endregion

View file

@ -0,0 +1,2 @@
/// @description Insert description here
event_inherited();

View file

@ -16,10 +16,12 @@ if !ready exit;
}
#endregion
#region base UI
DIALOG_PREDRAW
DIALOG_WINCLEAR
var _des = false;
DIALOG_DRAW_BG
if(sFOCUS) DIALOG_DRAW_FOCUS
#endregion
#region text
var py = dialog_y + ui(16);
@ -43,7 +45,7 @@ if !ready exit;
var b = buttonInstant(THEME.button_def, bx0, by0, bw, bh, mouse_ui, sFOCUS, sHOVER);
draw_text(bx0 + bw / 2, by0 + bh / 2, __txt("Cancel"));
if(b == 2)
instance_destroy();
_des = true;
bx0 -= bw + ui(12);
var b = buttonInstant(THEME.button_def, bx0, by0, bw, bh, mouse_ui, sFOCUS, sHOVER);
@ -51,7 +53,7 @@ if !ready exit;
if(b == 2) {
if(instance_number(o_dialog_exit) == 1)
close_program();
instance_destroy();
_des = true;
}
bx0 -= bw + ui(12);
@ -60,8 +62,12 @@ if !ready exit;
if(b == 2 && SAVE(project)) {
if(instance_number(o_dialog_exit) == 1)
close_program();
instance_destroy();
_des = true;
}
dialog_h = _dialog_h;
#endregion
DIALOG_POSTDRAW
if(_des) instance_destroy();

View file

@ -4,6 +4,7 @@
"eventList":[
{"$GMEvent":"v1","%Name":"","collisionObjectId":null,"eventNum":64,"eventType":8,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"$GMEvent":"v1","%Name":"","collisionObjectId":null,"eventNum":0,"eventType":0,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
{"$GMEvent":"v1","%Name":"","collisionObjectId":null,"eventNum":0,"eventType":1,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
],
"managed":true,
"name":"o_dialog_exit",

View file

@ -11,7 +11,7 @@ event_inherited();
menu_id = "";
alarm[0] = -1;
menu = 1;
font = f_p1;
font = f_p2;
hght = line_get_height(font, 10);
tooltips = [];
show_icon = false;
@ -19,7 +19,7 @@ event_inherited();
submenu = noone;
_hovering_ch = true;
init_pressing = false;
init_press_l = MOUSE_POOL.lpress;
setFocus(self.id);
@ -31,6 +31,7 @@ event_inherited();
function setMenu(_menu, align = fa_left) {
with(_p_dialog) { if(on_top) continue; other.depth = min(depth - 1, other.depth); }
title = menu_id;
menu = _menu;
dialog_x = x;
dialog_y = y;
@ -103,18 +104,10 @@ event_inherited();
var _wx = winwin_get_x_safe(WINDOW_ACTIVE) + dialog_x;
var _wy = winwin_get_y_safe(WINDOW_ACTIVE) + dialog_y;
if(window == noone) {
var _wconfig = new winwin_config();
_wconfig.kind = winwin_kind_borderless;
_wconfig.caption = "";
_wconfig.topmost = true;
_wconfig.per_pixel_alpha = true;
_wconfig.resize = false;
_wconfig.owner = winwin_main;
_wconfig.taskbar_button = false;
_wconfig.close_button = false;
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);
window = winwin_create(_wx, _wy, dialog_w, dialog_h, _wconfig);
} else {
winwin_set_position_safe(window, _wx, _wy);
winwin_set_size_safe(window, dialog_w, dialog_h);
@ -122,9 +115,6 @@ event_inherited();
dialog_x = 0;
dialog_y = 0;
} else if(winwin_exists(window)) {
winwin_destroy(window);
}
}
#endregion

View file

@ -73,23 +73,27 @@ winwin_draw_clear(COLORS.panel_bg_clear, 1);
};
if(_menuItem.isShelf) {
FOCUS_CONTENT = context;
var _res = _menuItem.func(_dat);
if(submenu) instance_destroy(submenu);
submenu = _res;
} else if(remove_parents) {
DIALOG_POSTDRAW
FOCUS_CONTENT = context;
if(_par == noone) _menuItem.func();
else _menuItem.func(_par);
DIALOG_POSTDRAW
instance_destroy(o_dialog_menubox); // close all
exit;
} else {
DIALOG_POSTDRAW
FOCUS_CONTENT = context;
if(_par == noone) _menuItem.func();
else _menuItem.func(_par);
DIALOG_POSTDRAW
instance_destroy();
exit;
}
@ -155,7 +159,7 @@ winwin_draw_clear(COLORS.panel_bg_clear, 1);
if(is_string(_sprs)) {
_str = _sprs;
draw_set_text(f_p2, fa_center, fa_center, COLORS._main_text);
draw_set_text(font, fa_center, fa_center, COLORS._main_text);
_sw = string_width(_str) + ui(12);
_sh = string_height(_str) + ui(8);
@ -177,9 +181,9 @@ winwin_draw_clear(COLORS.panel_bg_clear, 1);
draw_sprite_stretched_ext(THEME.textbox, 1, _bx - _sw / 2, _by - _sh / 2, _sw, _sh, COLORS.dialog_menubox_highlight, 1);
if(mouse_press(mb_left, sFOCUS)) {
_submenu[1](_dat);
DIALOG_POSTDRAW
_submenu[1](_dat);
instance_destroy(o_dialog_menubox);
exit;
}
@ -232,11 +236,10 @@ winwin_draw_clear(COLORS.panel_bg_clear, 1);
if(hk_editing == _menuItem) {
draw_set_color(COLORS._main_accent);
// draw_sprite_stretched_ext(THEME.ui_panel, 1, _bx, _by, _bw, _bh, COLORS._main_text_accent, .5);
if(_ktxt == "") _ktxt = "-";
} else if(_ktxt != "") {
draw_set_color(COLORS._main_text_sub);
// draw_sprite_stretched_ext(THEME.ui_panel, 1, _bx, _by, _bw, _bh, CDEF.main_dkgrey, .5);
}
draw_text(_hx, _hy - ui(2), _ktxt);

View file

@ -7,8 +7,14 @@ if(item_sel_submenu) {
exit;
}
if(init_press_l) {
if(MOUSE_POOL.lrelease)
init_press_l = false;
exit;
}
var hov = point_in(mouse_raw_x, mouse_raw_y);
if(submenu) hov |= submenu.point_in(mouse_raw_x, mouse_raw_y);
_hovering_ch = hov;
if(!hov && mouse_press(mb_left)) instance_destroy();
if(!hov && MOUSE_POOL.lpress) instance_destroy();

View file

@ -47,6 +47,8 @@ _FILE_DROPPED = false;
#region window & mouse
//if(keyboard_check_pressed(vk_f12)) DEBUG = !DEBUG;
global_mouse_pool_init();
if(_cursor != CURSOR) {
window_set_cursor(CURSOR);
_cursor = CURSOR;

View file

@ -5,7 +5,7 @@
FOCUS_BEFORE = noone;
#endregion
function menuCall(menu_id = "", menu = [], _x = 0, _y = 0, align = fa_left, context = noone) {
function menuCall(menu_id = "", menu = [], _x = 0, _y = 0, align = fa_left) {
if(array_empty(menu)) return noone;
FOCUS_BEFORE = FOCUS;
@ -22,13 +22,13 @@ function menuCall(menu_id = "", menu = [], _x = 0, _y = 0, align = fa_left, cont
array_append(menu, callbacks[i].populate());
}
dia.context = self;
dia.menu_id = menu_id;
dia.context = context;
dia.setMenu(menu, align);
return dia;
}
function pieMenuCall(menu_id = "", _x = mouse_mx, _y = mouse_my, menu = [], context = noone) {
function pieMenuCall(menu_id = "", _x = mouse_mx, _y = mouse_my, menu = []) {
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];
@ -37,8 +37,8 @@ function pieMenuCall(menu_id = "", _x = mouse_mx, _y = mouse_my, menu = [], cont
array_append(menu, callbacks[i].populate());
}
dia.context = self;
dia.menu_id = menu_id;
dia.context = context;
dia.setMenu(menu);
return dia;
}
@ -46,11 +46,12 @@ function pieMenuCall(menu_id = "", _x = mouse_mx, _y = mouse_my, menu = [], cont
function submenuCall(_data = undefined, menu = []) {
if(is_undefined(_data)) return menuCall("", menu);
var dia = instance_create_depth(_data.x - ui(4), _data.y, _data.depth - 1, o_dialog_menubox);
var _xx = _data.x - 1;
var dia = instance_create_depth(_xx, _data.y, _data.depth - 1, o_dialog_menubox);
dia.context = _data.context;
dia.setMenu(menu);
if(_data.x - ui(4) + dia.dialog_w > WIN_W - ui(2))
if(_xx + dia.dialog_w > WIN_W - ui(2))
dia.dialog_x = _data._x - dia.dialog_w + ui(4);
return dia;

View file

@ -97,6 +97,7 @@
#macro UI_SCALE PREFERENCES.display_scaling
#macro mouse_ui [mouse_mx, mouse_my]
#macro mouse_mx (PEN_USE? PEN_X : winwin_mouse_get_x_safe(WINDOW_ACTIVE))
#macro mouse_my (PEN_USE? PEN_Y : winwin_mouse_get_y_safe(WINDOW_ACTIVE))
@ -105,7 +106,6 @@
#macro mouse_raw_x display_mouse_get_x()
#macro mouse_raw_y display_mouse_get_y()
#macro mouse_ui [device_mouse_x_to_gui(0), device_mouse_y_to_gui(0)]
#macro sFOCUS (FOCUS == self.id)
#macro sHOVER (!CURSOR_IS_LOCK && (HOVER == self.id || (WINDOW_ACTIVE != noone && winwin_mouse_is_over_safe(WINDOW_ACTIVE))))

View file

@ -1,12 +1,18 @@
#region mouse global
globalvar CURSOR, CURSOR_LOCK, CURSOR_IS_LOCK, CURSOR_LOCK_X, CURSOR_LOCK_Y;
globalvar MOUSE_WRAP, MOUSE_WRAPPING, MOUSE_BLOCK, _MOUSE_BLOCK;
globalvar MOUSE_POOL;
MOUSE_WRAP = false;
MOUSE_WRAPPING = false;
MOUSE_BLOCK = false;
_MOUSE_BLOCK = false;
PEN_RELEASED = false;
MOUSE_POOL = {
lclick: false, lpress: false, lrelease: false,
rclick: false, rpress: false, rrelease: false,
mclick: false, mpress: false, mrelease: false,
}
#macro SCROLL_SPEED PREFERENCES.mouse_wheel_speed
#macro MOUSE_MOVED (window_mouse_get_delta_x() || window_mouse_get_delta_y())
@ -23,6 +29,37 @@
}
#endregion
function global_mouse_pool_init() {
MOUSE_POOL.lclick = mouse_check_button(mb_left);
MOUSE_POOL.rclick = mouse_check_button(mb_right);
MOUSE_POOL.mclick = mouse_check_button(mb_middle);
MOUSE_POOL.lpress = mouse_check_button_pressed(mb_left);
MOUSE_POOL.rpress = mouse_check_button_pressed(mb_right);
MOUSE_POOL.mpress = mouse_check_button_pressed(mb_middle);
MOUSE_POOL.lrelease = mouse_check_button_released(mb_left);
MOUSE_POOL.rrelease = mouse_check_button_released(mb_right);
MOUSE_POOL.mrelease = mouse_check_button_released(mb_middle);
for( var i = 0, n = array_length(global.winwin_all); i < n; i++ ) {
var ww = global.winwin_all[i];
if(!__ww_valid) continue;
MOUSE_POOL.lclick |= winwin_mouse_check_button(ww, mb_left);
MOUSE_POOL.rclick |= winwin_mouse_check_button(ww, mb_right);
MOUSE_POOL.mclick |= winwin_mouse_check_button(ww, mb_middle);
MOUSE_POOL.lpress |= winwin_mouse_check_button_pressed(ww, mb_left);
MOUSE_POOL.rpress |= winwin_mouse_check_button_pressed(ww, mb_right);
MOUSE_POOL.mpress |= winwin_mouse_check_button_pressed(ww, mb_middle);
MOUSE_POOL.lrelease |= winwin_mouse_check_button_released(ww, mb_left);
MOUSE_POOL.rrelease |= winwin_mouse_check_button_released(ww, mb_right);
MOUSE_POOL.mrelease |= winwin_mouse_check_button_released(ww, mb_middle);
}
}
function mouse_click(mouse, focus = true) {
INLINE
if(MOUSE_BLOCK) return false;

View file

@ -309,9 +309,11 @@
function create_preview_window(node) {
if(node == noone) return;
var win = new Panel_Preview_Window();
win.node_target = node;
win.preview_channel = node.preview_channel;
var dia = dialogPanelCall(win, mouse_mx, mouse_my);
dia.destroy_on_click_out = false;
}

View file

@ -963,7 +963,6 @@ function PanelContent() constructor {
if(pFOCUS) FOCUS_CONTENT = self;
}
drawContent(panel);
}

View file

@ -811,7 +811,7 @@ function Panel_Inspector() : PanelContent() constructor {
if(mouse_press(mb_left, pFOCUS))
jun[@ 1] = !coll;
if(mouse_press(mb_right, pFOCUS))
menuCall("inspector_group_menu", group_menu, 0, 0, fa_left, _inspecting);
menuCall("inspector_group_menu", group_menu, 0, 0, fa_left);
} else
draw_sprite_stretched_ext(THEME.s_box_r5_clr, 0, lbx, yy, lbw, lbh, COLORS.panel_inspector_group_bg, 1);

View file

@ -170,7 +170,8 @@ function Panel_Preview_Window() : PanelContent() constructor {
array_push(_menu, menuItem(o.name, function(_dat) { changeChannel(_dat.index); }, noone, noone, noone, { index: _chan }));
_chan++;
}
menuCall("preview_window_menu", _menu, 0, 0, fa_left, node_target);
menuCall("preview_window_menu", _menu, 0, 0, fa_left);
}
}
}

View file

@ -1,9 +1,23 @@
global.__winwin_map = ds_map_create();
global.winwin_all = [];
function winwin(_ptr) constructor {
__ptr__ = _ptr;
}
function winwin_config_ext(caption = "", kind = winwin_kind_normal, topmost = false, resize = false, owner = winwin_main) {
var cnf = new winwin_config();
cnf.caption = caption;
cnf.kind = kind;
cnf.topmost = topmost;
cnf.resize = resize;
cnf.owner = owner;
cnf.per_pixel_alpha = true;
return cnf;
}
function winwin_config() constructor {
static caption = "Window";
static kind = winwin_kind_normal;
@ -22,6 +36,18 @@ function winwin_config() constructor {
#macro __ww_valid (ww != noone && winwin_exists(ww))
function winwin_create_ext(_x, _y, _w, _h, _conf) {
var window = winwin_create(_x, _y, _w, _h, _conf);
array_push(global.winwin_all, window);
return window;
}
function winwin_destroy_ext(ww) {
if(__ww_valid) winwin_destroy(_ww);
array_remove(global.winwin_all, window);
}
function winwin_get_x_safe(ww) { return __ww_valid? winwin_get_x(ww) : window_get_x(); }
function winwin_get_y_safe(ww) { return __ww_valid? winwin_get_y(ww) : window_get_y(); }