Pixel-Composer/scripts/panel_data/panel_data.gml

940 lines
24 KiB
Plaintext
Raw Normal View History

2022-01-13 05:24:03 +01:00
enum ANCHOR {
none = 0,
top = 1,
bottom = 2,
left = 4,
right = 8
}
function Panel(_parent, _x, _y, _w, _h) constructor {
parent = _parent;
if(parent) ds_list_add(parent.childs, self);
2023-06-10 13:59:45 +02:00
padding = THEME_VALUE.panel_margin;
2023-03-19 09:17:39 +01:00
content = [];
content_index = 0;
childs = ds_list_create();
anchor = ANCHOR.none;
2022-01-13 05:24:03 +01:00
x = _x;
y = _y;
w = _w;
h = _h;
2023-03-19 09:17:39 +01:00
tx = x;
ty = y;
tw = w;
th = h;
2023-03-11 06:40:34 +01:00
split = "";
2022-01-13 05:24:03 +01:00
2023-03-19 09:17:39 +01:00
tab_width = 0;
2023-06-13 14:42:06 +02:00
tab_height = ui(24);
2023-03-19 09:17:39 +01:00
tab_x = 0;
tab_x_to = 0;
tab_surface = noone;
2023-03-13 10:45:56 +01:00
min_w = ui(40);
min_h = ui(40);
2022-01-13 05:24:03 +01:00
dragging = -1;
drag_sval = 0;
drag_sm = 0;
2023-03-11 01:40:17 +01:00
mouse_active = true;
2022-01-13 05:24:03 +01:00
2022-11-01 03:06:03 +01:00
content_surface = surface_create_valid(w, h);
mask_surface = surface_create_valid(w, h);
2022-01-13 05:24:03 +01:00
2023-03-19 09:17:39 +01:00
tab_holding = noone;
tab_hold_state = 0;
tab_holding_mx = 0;
tab_holding_my = 0;
tab_holding_sx = 0;
tab_holding_sy = 0;
tab_cover = noone;
2023-03-19 09:17:39 +01:00
border_rb_close = menuItem(__txt("Close"), function() { #region
2023-07-06 19:49:16 +02:00
var con = getContent();
if(con == noone) return;
con.close();
}, THEME.cross); #endregion
2023-03-21 03:01:53 +01:00
border_rb_menu = [ #region
2023-06-04 18:28:29 +02:00
menuItem(__txt("Move"), function() {
2023-03-21 03:01:53 +01:00
extract();
panel_mouse = 1;
}),
2023-06-04 18:28:29 +02:00
menuItem(__txtx("panel_pop_out", "Pop out"), function() { popWindow(); }, THEME.node_goto),
2023-03-21 03:01:53 +01:00
border_rb_close
]; #endregion
2023-03-21 03:01:53 +01:00
2023-03-19 09:17:39 +01:00
static getContent = function() { return array_safe_get(content, content_index, noone, ARRAY_OVERFLOW._default); }
static hasContent = function() { return bool(array_length(content)); }
function resetMask() { #region
2023-03-19 09:17:39 +01:00
var tab = array_length(content) > 1;
tx = x; ty = y + tab * ui(tab_height);
tw = w; th = h - tab * ui(tab_height);
content_surface = surface_verify(content_surface, tw, th);
mask_surface = surface_verify(mask_surface, tw, th);
2022-01-13 05:24:03 +01:00
surface_set_target(mask_surface);
draw_clear(c_black);
gpu_set_blendmode(bm_subtract);
2023-03-19 09:17:39 +01:00
draw_sprite_stretched(THEME.ui_panel_bg, 0, padding, padding, tw - padding * 2, th - padding * 2);
2022-01-13 05:24:03 +01:00
gpu_set_blendmode(bm_normal);
surface_reset_target();
} resetMask(); #endregion
2022-01-13 05:24:03 +01:00
function setPadding(padding) { #region
2023-02-23 07:02:19 +01:00
self.padding = padding;
2023-03-19 09:17:39 +01:00
refresh();
} #endregion
2023-02-23 07:02:19 +01:00
function refresh() { #region
2022-01-13 05:24:03 +01:00
resetMask();
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(content); i < n; i++ )
2023-03-19 09:17:39 +01:00
content[i].refresh();
2022-01-13 05:24:03 +01:00
2023-03-11 01:40:17 +01:00
for( var i = 0; i < ds_list_size(childs); i++ )
2022-01-13 05:24:03 +01:00
childs[| i].refresh();
} #endregion
2022-01-13 05:24:03 +01:00
function move(dx, dy) { #region
2022-01-13 05:24:03 +01:00
x += dx;
y += dy;
for(var i = 0; i < ds_list_size(childs); i++) {
var _panel = childs[| i];
_panel.move(dx, dy);
}
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(content); i < n; i++ ) {
2023-03-19 09:17:39 +01:00
content[i].x = x;
content[i].y = y;
2022-01-13 05:24:03 +01:00
}
} #endregion
2022-01-13 05:24:03 +01:00
function resizable(dw, dh, oppose = ANCHOR.left) { #region
2023-03-19 09:17:39 +01:00
var tab = array_length(content) > 1;
tx = x; ty = y + tab * ui(tab_height);
tw = w; th = h - tab * ui(tab_height);
2022-01-13 05:24:03 +01:00
2023-03-13 10:45:56 +01:00
var hori = oppose == ANCHOR.left || oppose == ANCHOR.right;
2023-03-19 09:17:39 +01:00
if(hasContent()) {
var res = true;
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(content); i < n; i++ )
2023-03-19 09:17:39 +01:00
res &= hori? tw + dw > content[i].min_w : th + dh > content[i].min_h;
return res;
}
2023-03-13 10:45:56 +01:00
var ind = hori? childs[| 1].w > childs[| 0].w : childs[| 1].h > childs[| 0].h;
return childs[| ind].resizable(dw, dh, oppose);
} #endregion
2022-01-13 05:24:03 +01:00
function refreshSize(recur = true) { #region //refresh content surface after resize
2023-03-11 06:40:34 +01:00
//__debug_counter("refresh size");
2023-03-19 09:17:39 +01:00
var tab = array_length(content) > 1;
tx = x; ty = y + tab * ui(tab_height);
tw = w; th = h - tab * ui(tab_height);
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(content); i < n; i++ ) {
2023-03-19 09:17:39 +01:00
content[i].w = max(tw, content[i].min_w);
content[i].h = max(th, content[i].min_h);
content[i].onResize();
}
if(ds_list_size(childs) == 2) {
2023-03-11 06:40:34 +01:00
//print("=== Refreshing (" + string(w) + ", " + string(h) + ") " + string(split) + " ===");
2023-03-11 01:40:17 +01:00
2023-03-19 09:17:39 +01:00
var _tw = childs[| 0].w + childs[| 1].w;
var _th = childs[| 0].h + childs[| 1].h;
2023-03-11 01:40:17 +01:00
2023-03-11 06:40:34 +01:00
var fixChild = split == "h"? childs[| 1].x < childs[| 0].x : childs[| 1].y < childs[| 0].y;
2023-03-11 01:40:17 +01:00
childs[| fixChild].x = x;
childs[| fixChild].y = y;
2023-03-11 06:40:34 +01:00
if(split == "h") {
2023-03-19 09:17:39 +01:00
childs[| fixChild].w = round(childs[| fixChild].w / _tw * w);
2023-03-13 10:45:56 +01:00
childs[| fixChild].h = round(h);
2023-03-11 01:40:17 +01:00
childs[| !fixChild].x = x + childs[| fixChild].w;
childs[| !fixChild].y = y;
2023-03-13 10:45:56 +01:00
childs[| !fixChild].w = round(w - childs[| fixChild].w);
childs[| !fixChild].h = round(h);
2023-03-11 06:40:34 +01:00
childs[| fixChild].anchor = ANCHOR.left;
childs[| !fixChild].anchor = ANCHOR.right;
} else if(split == "v") {
2023-03-13 10:45:56 +01:00
childs[| fixChild].w = round(w);
2023-03-19 09:17:39 +01:00
childs[| fixChild].h = round(childs[| fixChild].h / _th * h);
2023-03-11 01:40:17 +01:00
childs[| !fixChild].x = x;
childs[| !fixChild].y = y + childs[| fixChild].h;
2023-03-13 10:45:56 +01:00
childs[| !fixChild].w = round(w);
childs[| !fixChild].h = round(h - childs[| fixChild].h);
2023-03-11 06:40:34 +01:00
childs[| fixChild].anchor = ANCHOR.top;
childs[| !fixChild].anchor = ANCHOR.bottom;
2023-03-11 01:40:17 +01:00
}
2023-03-11 06:40:34 +01:00
if(recur)
2023-03-19 09:17:39 +01:00
for(var i = 0; i < ds_list_size(childs); i++)
2023-03-11 01:40:17 +01:00
childs[| i].refreshSize();
2022-12-27 04:00:50 +01:00
}
2023-03-11 01:40:17 +01:00
refresh();
} #endregion
2022-12-27 04:00:50 +01:00
function resize(dw, dh, oppose = ANCHOR.left) { #region
2022-01-13 05:24:03 +01:00
if(dw == 0 && dh == 0) return;
2023-03-13 10:45:56 +01:00
if(ds_list_size(childs) == 2) {
var hori = oppose == ANCHOR.left || oppose == ANCHOR.right;
var ind = hori? childs[| 1].w > childs[| 0].w : childs[| 1].h > childs[| 0].h;
childs[| ind].resize(dw, dh, oppose);
2022-01-13 05:24:03 +01:00
}
2023-03-13 10:45:56 +01:00
w = max(round(w + dw), min_w);
h = max(round(h + dh), min_h);
2022-01-13 05:24:03 +01:00
2023-03-11 06:40:34 +01:00
refreshSize(false);
} #endregion
2022-01-13 05:24:03 +01:00
function setContent(_content = noone, _switch = false) { #region
2023-03-19 09:17:39 +01:00
if(is_array(_content))
content = array_append(content, _content);
else
array_push(content, _content);
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(content); i < n; i++ )
2023-03-19 09:17:39 +01:00
content[i].onSetPanel(self);
2023-07-06 19:49:16 +02:00
if(_switch) setTab(array_find(content, _content));
2023-03-19 09:17:39 +01:00
refresh();
} #endregion
2022-01-13 05:24:03 +01:00
function switchContent(_content) { #region
var _ind = array_find(content, _content);
if(_ind == -1) return;
setTab(_ind);
} #endregion
function split_h(_w) { #region
2023-03-11 06:40:34 +01:00
if(abs(_w) > w) {
print("Error: Split panel larger than size w (" + string(_w) + " > " + string(w) + ")");
return noone;
}
2022-11-01 03:06:03 +01:00
2022-01-13 05:24:03 +01:00
if(_w < 0) _w = w + _w;
var _panelParent = new Panel(parent, x, y, w, h);
_panelParent.anchor = anchor;
2023-03-11 06:40:34 +01:00
_panelParent.split = "h";
2022-01-13 05:24:03 +01:00
var _panelL = self;
ds_list_add(_panelParent.childs, _panelL);
var _panelR = new Panel(_panelParent, x + _w, y, w - _w, h);
_panelR.anchor = ANCHOR.right;
var prev_w = w;
w = _w;
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(content); i < n; i++ ) {
2023-03-19 09:17:39 +01:00
content[i].w = w;
content[i].onResize();
2022-01-13 05:24:03 +01:00
}
2023-03-19 09:17:39 +01:00
if(parent == noone)
PANEL_MAIN = _panelParent;
else
2022-01-13 05:24:03 +01:00
ds_list_delete(parent.childs, ds_list_find_index(parent.childs, self));
2023-03-19 09:17:39 +01:00
parent = _panelParent;
anchor = ANCHOR.left;
content = [];
2022-01-13 05:24:03 +01:00
return [ _panelL, _panelR ];
} #endregion
2022-01-13 05:24:03 +01:00
function split_v(_h) { #region
2023-03-11 06:40:34 +01:00
if(abs(_h) > h) {
print("Error: Split panel larger than size h (" + string(_h) + " > " + string(h) + ")");
return noone;
}
2022-11-01 03:06:03 +01:00
2022-01-13 05:24:03 +01:00
if(_h < 0) _h = h + _h;
var _panelParent = new Panel(parent, x, y, w, h);
_panelParent.anchor = anchor;
2023-03-11 06:40:34 +01:00
_panelParent.split = "v";
2022-01-13 05:24:03 +01:00
var _panelT = self;
ds_list_add(_panelParent.childs, _panelT);
var _panelB = new Panel(_panelParent, x, y + _h, w, h - _h);
_panelB.anchor = ANCHOR.bottom;
var prev_h = h;
h = _h;
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(content); i < n; i++ ) {
2023-03-19 09:17:39 +01:00
content[i].h = h;
content[i].onResize();
2022-01-13 05:24:03 +01:00
}
2023-03-19 09:17:39 +01:00
if(parent == noone)
PANEL_MAIN = _panelParent;
else
2022-01-13 05:24:03 +01:00
ds_list_delete(parent.childs, ds_list_find_index(parent.childs, self));
2023-03-19 09:17:39 +01:00
parent = _panelParent;
anchor = ANCHOR.top;
content = [];
2022-01-13 05:24:03 +01:00
return [_panelT, _panelB];
} #endregion
2022-01-13 05:24:03 +01:00
function stepBegin() { #region
2023-03-19 09:17:39 +01:00
var con = getContent();
if(con) con.panelStepBegin(self);
2022-01-13 05:24:03 +01:00
2023-03-11 01:40:17 +01:00
if(o_main.panel_dragging != noone) dragging = -1;
2022-01-13 05:24:03 +01:00
if(dragging == 1) {
2022-11-03 11:44:49 +01:00
var _mx = clamp(mouse_mx, ui(16), WIN_W - ui(16));
2023-03-13 10:45:56 +01:00
var dw = round(_mx - drag_sm);
2022-01-13 05:24:03 +01:00
var res = true;
for(var i = 0; i < ds_list_size(childs); i++) {
var _panel = childs[| i];
switch(_panel.anchor) {
case ANCHOR.left:
res &= _panel.resizable(dw, 0, ANCHOR.left);
break;
case ANCHOR.right:
res &= _panel.resizable(-dw, 0, ANCHOR.right);
break;
}
}
2023-03-19 09:17:39 +01:00
2022-01-13 05:24:03 +01:00
if(res) {
drag_sm = _mx;
for(var i = 0; i < ds_list_size(childs); i++) {
var _panel = childs[| i];
switch(_panel.anchor) {
case ANCHOR.left:
_panel.resize(dw, 0, ANCHOR.left);
break;
case ANCHOR.right:
_panel.resize(-dw, 0, ANCHOR.right);
_panel.move(dw, 0);
break;
}
}
}
2023-03-13 10:45:56 +01:00
if(mouse_release(mb_left)) {
refreshSize();
dragging = -1;
}
2022-01-13 05:24:03 +01:00
} else if(dragging == 2) {
2022-11-03 11:44:49 +01:00
var _my = clamp(mouse_my, ui(16), WIN_H - ui(16));
2023-03-13 10:45:56 +01:00
var dh = round(_my - drag_sm);
2022-01-13 05:24:03 +01:00
var res = true;
for(var i = 0; i < ds_list_size(childs); i++) {
var _panel = childs[| i];
switch(_panel.anchor) {
case ANCHOR.top:
res &= _panel.resizable(0, dh, ANCHOR.top);
break;
case ANCHOR.bottom:
res &= _panel.resizable(0, -dh, ANCHOR.bottom);
break;
}
}
if(res) {
drag_sm = _my;
for(var i = 0; i < ds_list_size(childs); i++) {
var _panel = childs[| i];
switch(_panel.anchor) {
case ANCHOR.top:
_panel.resize(0, dh, ANCHOR.top);
break;
case ANCHOR.bottom:
_panel.resize(0, -dh, ANCHOR.bottom);
_panel.move(0, dh);
break;
}
}
}
2023-03-13 10:45:56 +01:00
if(mouse_release(mb_left)) {
refreshSize();
dragging = -1;
}
2022-01-13 05:24:03 +01:00
} else {
2023-03-19 09:17:39 +01:00
if(con && point_in_rectangle(mouse_mx, mouse_my, x + ui(2), y + ui(2), x + w - ui(4), y + h - ui(4))) {
HOVER = self;
if(mouse_press(mb_any))
setFocus(self);
if(FOCUS == self && con)
FOCUS_STR = con.context_str;
2022-11-14 03:16:15 +01:00
} else {
for(var i = 0; i < ds_list_size(childs); i++) {
var _panel = childs[| i];
_panel.stepBegin();
}
2022-01-13 05:24:03 +01:00
}
}
} #endregion
2022-01-13 05:24:03 +01:00
static step = function() { #region
2022-01-13 05:24:03 +01:00
for(var i = 0; i < ds_list_size(childs); i++) {
var _panel = childs[| i];
_panel.step();
}
} #endregion
2022-01-13 05:24:03 +01:00
static draw = function() { #region
2023-03-19 09:17:39 +01:00
if(hasContent()) {
drawPanel();
2022-11-14 03:16:15 +01:00
return;
}
2023-03-11 01:40:17 +01:00
2022-11-14 03:16:15 +01:00
if(ds_list_empty(childs))
return;
2023-03-13 10:45:56 +01:00
var min_w = ui(32);
var min_h = ui(32);
if(split == "h") {
min_w = childs[| 0].min_w + childs[| 1].min_w;
min_h = max(childs[| 0].min_h + childs[| 1].min_h);
} else {
min_w = max(childs[| 0].min_w, childs[| 1].min_w);
min_h = childs[| 0].min_h + childs[| 1].min_h;
}
2022-11-14 03:16:15 +01:00
for(var i = 0; i < ds_list_size(childs); i++) {
var _panel = childs[| i];
_panel.draw();
2023-03-19 09:17:39 +01:00
if!(HOVER == noone || is_struct(HOVER))
2022-11-14 03:16:15 +01:00
continue;
2023-03-13 10:45:56 +01:00
var p = ui(6 - 1);
2022-11-14 03:16:15 +01:00
switch(_panel.anchor) {
case ANCHOR.left :
2023-03-13 10:45:56 +01:00
if(!point_in_rectangle(mouse_mx, mouse_my, _panel.x + _panel.w - p, _panel.y, _panel.x + _panel.w + p, _panel.y + _panel.h))
2022-11-03 11:44:49 +01:00
break;
2022-11-14 03:16:15 +01:00
CURSOR = cr_size_we;
2022-12-10 05:06:01 +01:00
if(mouse_press(mb_left)) {
2022-11-14 03:16:15 +01:00
dragging = 1;
drag_sval = _panel.w;
drag_sm = mouse_mx;
}
break;
case ANCHOR.top :
2023-03-13 10:45:56 +01:00
if(!point_in_rectangle(mouse_mx, mouse_my, _panel.x, _panel.y + _panel.h - p, _panel.x + _panel.w, _panel.y + _panel.h + p))
2022-11-03 11:44:49 +01:00
break;
2022-11-14 03:16:15 +01:00
CURSOR = cr_size_ns;
2022-12-10 05:06:01 +01:00
if(mouse_press(mb_left)) {
2022-11-14 03:16:15 +01:00
dragging = 2;
drag_sval = _panel.h;
drag_sm = mouse_my;
}
break;
2022-01-13 05:24:03 +01:00
}
}
2023-03-11 06:40:34 +01:00
if(self == PANEL_MAIN && o_main.panel_dragging != noone && key_mod_press(CTRL))
checkHover();
} #endregion
2022-01-13 05:24:03 +01:00
function drawTab() { #region
2023-03-19 09:17:39 +01:00
tab_surface = surface_verify(tab_surface, w - padding * 2 + 1, tab_height + ui(4));
var tsx = x + padding - 1;
2023-06-13 14:42:06 +02:00
var tsy = y + ui(2);
2023-03-19 09:17:39 +01:00
var msx = mouse_x - tsx;
var msy = mouse_y - tsy;
2023-06-13 14:42:06 +02:00
tab_cover = noone;
2023-03-19 09:17:39 +01:00
surface_set_target(tab_surface);
DRAW_CLEAR
2023-06-10 13:59:45 +02:00
var tbx = tab_x + ui(1);
2023-03-19 09:17:39 +01:00
var tby = 0;
2023-06-10 13:59:45 +02:00
var tbh = tab_height + ui(2);
2023-03-19 09:17:39 +01:00
var tabHov = msx < 0 ? 0 : array_length(content) - 1;
tab_x = lerp_float(tab_x, tab_x_to, 5);
tab_width = 0;
2023-07-06 19:49:16 +02:00
var rem = -1;
2023-03-19 09:17:39 +01:00
draw_set_text(f_p3, fa_left, fa_bottom, COLORS._main_text_sub);
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(content); i < n; i++ ) {
2023-03-19 09:17:39 +01:00
var txt = content[i].title;
2023-03-21 03:01:53 +01:00
var icn = content[i].icon;
2023-07-06 19:49:16 +02:00
var tbw = string_width(txt) + ui(16 + 16);
2023-03-21 03:01:53 +01:00
if(icn != noone) tbw += ui(16 + 4);
2023-03-19 09:17:39 +01:00
var foc = false;
tab_width += tbw + ui(2);
if(msx >= tbx && msy <= tbx + tbw)
tabHov = i;
if(tab_holding == content[i]) {
tbx += tbw + ui(2);
continue;
}
2023-08-01 11:16:23 +02:00
content[i].tab_x = content[i].tab_x == 0? tbx : lerp_float(content[i].tab_x, tbx, 5);
2023-03-19 09:17:39 +01:00
var _tbx = content[i].tab_x;
var _hov = point_in_rectangle(msx, msy, _tbx, tby, _tbx + tbw, tab_height);
2023-06-13 14:42:06 +02:00
var _tdh = tbh + THEME_VALUE.panel_tab_extend;
2023-03-19 09:17:39 +01:00
if(i == content_index) {
foc = FOCUS == self;
2023-06-13 14:42:06 +02:00
var cc = FOCUS == self? COLORS._main_accent : COLORS.panel_tab;
draw_sprite_stretched_ext(THEME.ui_panel_tab, 1 + (FOCUS == self), _tbx, tby, tbw, _tdh, cc, 1);
if(!foc)
tab_cover = BBOX().fromWH(tsx + _tbx, tsy + tby + tbh - ui(3), tbw, THEME_VALUE.panel_tab_extend);
2023-03-19 09:17:39 +01:00
} else {
2023-06-13 14:42:06 +02:00
var cc = COLORS.panel_tab_inactive;
2023-06-10 13:59:45 +02:00
if(HOVER == self && _hov)
2023-06-13 14:42:06 +02:00
var cc = COLORS.panel_tab_hover;
draw_sprite_stretched_ext(THEME.ui_panel_tab, 0, _tbx, tby, tbw, _tdh, cc, 1);
2023-03-19 09:17:39 +01:00
}
2023-07-10 20:14:10 +02:00
var aa = 0.5;
if(point_in_rectangle(msx, msy, _tbx + tbw - ui(16), tby, _tbx + tbw, tab_height)) {
aa = 1;
if(mouse_press(mb_left, FOCUS == self))
rem = i;
} else if(HOVER == self && _hov) {
2023-03-19 09:17:39 +01:00
if(mouse_press(mb_left, FOCUS == self)) {
2023-07-06 19:49:16 +02:00
setTab(i);
2023-06-13 14:42:06 +02:00
2023-03-19 09:17:39 +01:00
tab_holding = content[i];
tab_hold_state = 0;
tab_holding_mx = msx;
tab_holding_my = msy;
tab_holding_sx = tab_holding.tab_x;
}
2023-03-21 03:01:53 +01:00
if(mouse_press(mb_right, FOCUS == self)) {
var menu = array_clone(border_rb_menu);
if(instanceof(content[i]) == "Panel_Menu")
2023-06-13 14:42:06 +02:00
array_remove(menu, 2);
2023-03-21 03:01:53 +01:00
2023-05-03 21:42:17 +02:00
menuCall("panel_border_menu",,, menu);
2023-03-21 03:01:53 +01:00
}
2023-03-28 06:58:28 +02:00
2023-07-06 19:49:16 +02:00
if(mouse_press(mb_middle, FOCUS == self))
rem = i;
if(DRAGGING)
setTab(i);
}
draw_sprite_ui(THEME.tab_exit, 0, _tbx + tbw - ui(12), tab_height / 2 + 1,,,, foc? COLORS.panel_tab_icon : COLORS._main_text_sub, aa);
2023-03-19 09:17:39 +01:00
2023-03-21 03:01:53 +01:00
if(icn != noone) {
2023-07-06 19:49:16 +02:00
draw_sprite_ui(icn, 0, _tbx + ui(8 + 8), tab_height / 2 + 1,,,, foc? COLORS.panel_tab_icon : COLORS._main_text_sub);
2023-03-21 03:01:53 +01:00
_tbx += ui(20);
}
2023-06-19 20:28:30 +02:00
draw_set_text(f_p3, fa_left, fa_bottom, foc? COLORS.panel_tab_text : COLORS._main_text_sub);
2023-06-13 14:42:06 +02:00
draw_text_add(_tbx + ui(8), tab_height - ui(4), txt);
2023-03-19 09:17:39 +01:00
tbx += tbw + ui(2);
}
2023-07-06 19:49:16 +02:00
if(rem > -1) content[rem].close();
2023-03-19 09:17:39 +01:00
tab_width = max(0, tab_width - w + ui(32));
if(point_in_rectangle(msx, msy, 0, 0, w, tab_height)) {
2023-04-07 21:25:27 +02:00
if(mouse_wheel_up()) tab_x_to = clamp(tab_x_to + ui(64) * SCROLL_SPEED, -tab_width, 0);
if(mouse_wheel_down()) tab_x_to = clamp(tab_x_to - ui(64) * SCROLL_SPEED, -tab_width, 0);
2023-03-19 09:17:39 +01:00
}
if(tab_holding) {
draw_set_font(f_p3);
var _tbx = tab_holding.tab_x;
var txt = tab_holding.title;
2023-03-21 03:01:53 +01:00
var icn = tab_holding.icon;
2023-07-06 19:49:16 +02:00
var tbw = string_width(txt) + ui(16 + 16);
2023-03-21 03:01:53 +01:00
if(icn != noone) tbw += ui(16 + 4);
2023-03-19 09:17:39 +01:00
2023-06-13 14:42:06 +02:00
draw_sprite_stretched_ext(THEME.ui_panel_tab, 2, _tbx, tby, tbw, tbh, COLORS._main_accent, 1);
2023-07-06 19:49:16 +02:00
draw_sprite_ui(THEME.tab_exit, 0, _tbx + tbw - ui(12), tab_height / 2 + 1,,,, COLORS.panel_tab_icon);
2023-03-19 09:17:39 +01:00
2023-03-21 03:01:53 +01:00
if(icn != noone) {
2023-07-06 19:49:16 +02:00
draw_sprite_ui(icn, 0, _tbx + ui(8 + 8), tab_height / 2 + 1,,,, COLORS.panel_tab_icon);
2023-03-21 03:01:53 +01:00
_tbx += ui(20);
}
2023-06-19 20:28:30 +02:00
draw_set_text(f_p3, fa_left, fa_bottom, COLORS.panel_tab_text);
2023-06-13 14:42:06 +02:00
draw_text_add(_tbx + ui(8), tab_height - ui(4), txt);
2023-03-19 09:17:39 +01:00
if(tab_hold_state == 0) {
if(point_distance(tab_holding_mx, tab_holding_my, msx, msy) > 8)
tab_hold_state = 1;
} else if(tab_hold_state == 1) {
if(point_in_rectangle(msx, msy, 0, 0, w, tab_height)) {
if(msx < ui(32)) tab_x_to = clamp(tab_x_to + ui(2), -tab_width, 0);
if(msx > w - ui(32)) tab_x_to = clamp(tab_x_to - ui(2), -tab_width, 0);
}
tab_holding.tab_x = clamp(tab_holding_sx + (msx - tab_holding_mx), 1, w - tbw - ui(4));
array_remove(content, tab_holding);
array_insert(content, tabHov, tab_holding);
2023-07-06 19:49:16 +02:00
setTab(array_find(content, tab_holding));
2023-03-19 09:17:39 +01:00
if(abs(msy - tab_holding_my) > ui(32)) {
extract();
tab_holding = noone;
}
}
if(mouse_release(mb_left))
tab_holding = noone;
}
surface_reset_target();
draw_surface(tab_surface, tsx, tsy);
} #endregion
2023-03-19 09:17:39 +01:00
function setTab(tabIndex) { #region
2023-07-06 19:49:16 +02:00
if(tabIndex < 0) return;
if(tabIndex >= array_length(content)) return;
if(content_index == tabIndex) return;
2023-07-06 19:49:16 +02:00
var prec = array_safe_get(content, content_index);
if(prec) prec.onFocusEnd();
content_index = tabIndex;
var prec = array_safe_get(content, content_index);
if(prec) prec.onFocusBegin();
} #endregion
2023-07-06 19:49:16 +02:00
function drawPanel() { #region
2022-11-03 11:44:49 +01:00
if(w <= ui(16)) return;
2023-03-19 09:17:39 +01:00
var tab = array_length(content) > 1;
tx = x; ty = y + tab * ui(tab_height);
tw = w; th = h - tab * ui(tab_height);
if(th < ui(16)) return;
2023-06-10 13:59:45 +02:00
var con = getContent();
2023-03-19 09:17:39 +01:00
if(tab) drawTab();
2023-03-13 10:45:56 +01:00
var p = ui(6);
2023-03-19 09:17:39 +01:00
var m_in = point_in_rectangle(mouse_mx, mouse_my, tx + p, ty + p, tx + tw - p, ty + th - p);
var m_ot = point_in_rectangle(mouse_mx, mouse_my, tx, ty, tx + tw, ty + th);
2023-03-11 01:40:17 +01:00
mouse_active = m_in;
2023-06-10 13:59:45 +02:00
var _tw = tw - padding * 2;
var _th = th - padding * 2;
draw_sprite_stretched(THEME.ui_panel_bg, 0, tx + padding, ty + padding, _tw, _th);
2022-01-13 05:24:03 +01:00
if(!is_surface(mask_surface)) {
2023-03-19 09:17:39 +01:00
mask_surface = surface_create_valid(tw, th);
refresh();
2022-01-13 05:24:03 +01:00
}
2023-06-10 13:59:45 +02:00
content_surface = surface_verify(content_surface, tw, th);
2023-03-11 06:40:34 +01:00
2022-01-13 05:24:03 +01:00
surface_set_target(content_surface);
2022-11-18 03:20:31 +01:00
draw_clear(COLORS.panel_bg_clear);
2023-03-19 09:17:39 +01:00
if(con) {
min_w = con.min_w;
min_h = con.min_h;
if(tw >= min_w && th >= min_h)
con.draw(self);
2022-01-13 05:24:03 +01:00
}
gpu_set_blendmode(bm_subtract);
draw_surface_safe(mask_surface, 0, 0);
gpu_set_blendmode(bm_normal);
surface_reset_target();
2023-03-19 09:17:39 +01:00
draw_surface_safe(content_surface, tx, ty);
2023-06-13 14:42:06 +02:00
draw_sprite_stretched(THEME.ui_panel_fg, 0, tx + padding, ty + padding, _tw, _th);
2023-07-25 20:12:40 +02:00
if(tab) draw_sprite_bbox(THEME.ui_panel_tab, 3, tab_cover);
2023-06-19 20:28:30 +02:00
2023-03-12 02:28:21 +01:00
if(FOCUS == self && parent != noone) {
2023-03-19 09:17:39 +01:00
draw_sprite_stretched_ext(THEME.ui_panel_active, 0, tx + padding, ty + padding, tw - padding * 2, th - padding * 2, COLORS._main_accent, 1);
2023-03-12 02:28:21 +01:00
2023-03-19 09:17:39 +01:00
if(hasContent() && !m_in && m_ot) {
draw_sprite_stretched_ext(THEME.ui_panel_active, 0, tx + padding, ty + padding, tw - padding * 2, th - padding * 2, c_white, 0.4);
2023-03-11 01:40:17 +01:00
2023-03-12 02:28:21 +01:00
if(DOUBLE_CLICK) {
extract();
panel_mouse = 0;
} else if(mouse_press(mb_right)) {
2023-03-21 03:01:53 +01:00
var menu = array_clone(border_rb_menu);
if(instanceof(getContent()) == "Panel_Menu")
array_remove(menu, 2, border_rb_close);
2023-03-11 06:40:34 +01:00
2023-05-03 21:42:17 +02:00
menuCall("panel_border_menu",,, menu);
2023-03-11 01:40:17 +01:00
}
}
2023-03-25 12:27:04 +01:00
}
2022-01-13 05:24:03 +01:00
2023-03-11 06:40:34 +01:00
if(o_main.panel_dragging != noone && m_ot && !key_mod_press(CTRL))
checkHover();
} #endregion
2023-03-11 06:40:34 +01:00
function drawGUI() { #region
2023-03-25 12:27:04 +01:00
for( var i = 0; i < ds_list_size(childs); i++ )
childs[| i].drawGUI();
var con = getContent();
if(con == noone) return;
con.drawGUI();
} #endregion
2023-03-25 12:27:04 +01:00
function extract() { #region
2023-03-19 09:17:39 +01:00
var con = getContent();
con.dragSurface = surface_clone(content_surface);
o_main.panel_dragging = con;
2023-03-12 02:28:21 +01:00
2023-03-19 09:17:39 +01:00
array_remove(content, con);
refresh();
2023-07-06 19:49:16 +02:00
setTab(0);
2023-03-19 09:17:39 +01:00
HOVER = noone;
FOCUS = noone;
if(hasContent()) return;
2023-03-12 02:28:21 +01:00
var ind = !ds_list_find_index(parent.childs, self); //index of the other child
var sib = parent.childs[| ind];
2023-03-19 09:17:39 +01:00
if(!sib.hasContent() && ds_list_size(sib.childs) == 2) { //other child is compound panel
2023-03-12 02:28:21 +01:00
var gparent = parent.parent;
if(gparent == noone) {
sib.x = PANEL_MAIN.x; sib.y = PANEL_MAIN.y;
sib.w = PANEL_MAIN.w; sib.h = PANEL_MAIN.h;
PANEL_MAIN = sib;
sib.parent = noone;
PANEL_MAIN.refreshSize();
} else {
var pind = ds_list_find_index(gparent.childs, parent); //index of parent in grandparent object
gparent.childs[| pind] = sib; //replace parent with sibling
sib.parent = gparent;
gparent.refreshSize();
}
2023-03-19 09:17:39 +01:00
} else if(sib.hasContent()) { //other child is content panel, set parent to content panel
parent.setContent(sib.content);
2023-03-12 02:28:21 +01:00
ds_list_clear(parent.childs);
}
} #endregion
2023-03-12 02:28:21 +01:00
function popWindow() { #region
2023-03-19 09:17:39 +01:00
var con = getContent();
if(con == noone) return;
dialogPanelCall(con);
2023-03-12 02:28:21 +01:00
extract();
o_main.panel_dragging = noone;
} #endregion
2023-03-12 02:28:21 +01:00
function checkHover() { #region
2023-03-11 06:40:34 +01:00
var dx = (mouse_mx - x) / w;
var dy = (mouse_my - y) / h;
var p = ui(8);
2023-03-11 01:40:17 +01:00
2023-03-11 06:40:34 +01:00
draw_set_color(COLORS._main_accent);
o_main.panel_hovering = self;
2023-03-12 02:28:21 +01:00
var x0 = x + p;
var y0 = y + p;
var x1 = x + w - p;
var y1 = y + h - p;
var xc = x + w / 2;
var yc = y + h / 2;
2023-03-19 09:17:39 +01:00
if(point_in_rectangle(mouse_mx, mouse_my, x + w * 1 / 3, y + h * 1 / 3, x + w * 2 / 3, y + h * 2 / 3)) {
2023-03-12 02:28:21 +01:00
o_main.panel_split = 4;
2023-03-11 01:40:17 +01:00
2023-03-12 02:28:21 +01:00
o_main.panel_draw_x0_to = x + w * 1 / 3;
o_main.panel_draw_y0_to = y + h * 1 / 3;
o_main.panel_draw_x1_to = x + w * 2 / 3;
o_main.panel_draw_y1_to = y + h * 2 / 3;
2023-03-11 06:40:34 +01:00
} else {
2023-03-12 02:28:21 +01:00
if(dx + dy > 1) {
if((1 - dx) + dy > 1) {
o_main.panel_draw_x0_to = x0;
o_main.panel_draw_y0_to = yc;
o_main.panel_draw_x1_to = x1;
o_main.panel_draw_y1_to = y1;
o_main.panel_split = 3;
} else {
o_main.panel_draw_x0_to = xc;
o_main.panel_draw_y0_to = y0;
o_main.panel_draw_x1_to = x1;
o_main.panel_draw_y1_to = y1;
2023-03-11 01:40:17 +01:00
2023-03-12 02:28:21 +01:00
o_main.panel_split = 1;
}
2023-03-11 06:40:34 +01:00
} else {
2023-03-12 02:28:21 +01:00
if((1 - dx) + dy > 1) {
o_main.panel_draw_x0_to = x0;
o_main.panel_draw_y0_to = y0;
o_main.panel_draw_x1_to = xc;
o_main.panel_draw_y1_to = y1;
2023-03-11 01:40:17 +01:00
2023-03-12 02:28:21 +01:00
o_main.panel_split = 2;
} else {
o_main.panel_draw_x0_to = x0;
o_main.panel_draw_y0_to = y0;
o_main.panel_draw_x1_to = x1;
o_main.panel_draw_y1_to = yc;
o_main.panel_split = 0;
}
2023-03-11 01:40:17 +01:00
}
}
} #endregion
2022-01-13 05:24:03 +01:00
function remove(con = getContent()) { #region
2023-07-25 20:12:40 +02:00
var curr = getContent();
2023-03-19 09:17:39 +01:00
array_remove(content, con);
2023-04-23 16:47:33 +02:00
if(con) con.onClose();
2023-07-25 20:12:40 +02:00
if(con == curr) setTab(0);
else setTab(array_find(content, curr));
2023-03-19 09:17:39 +01:00
refresh();
if(hasContent()) return;
2022-01-13 05:24:03 +01:00
if(parent == noone) {
2023-07-06 19:49:16 +02:00
show_message("Can't close main panel.");
2022-01-13 05:24:03 +01:00
return;
}
ds_list_delete(parent.childs, ds_list_find_index(parent.childs, self));
var otherPanel = parent.childs[| 0];
2023-03-19 09:17:39 +01:00
parent.setContent(otherPanel.content);
2022-01-13 05:24:03 +01:00
ds_list_clear(parent.childs);
} #endregion
2022-01-13 05:24:03 +01:00
}
2022-11-14 03:16:15 +01:00
function PanelContent() constructor {
2023-03-21 03:01:53 +01:00
title = "";
icon = noone;
2022-01-13 05:24:03 +01:00
context_str = "";
2023-03-12 02:28:21 +01:00
draggable = true;
expandable = true;
2023-07-15 20:01:29 +02:00
resizable = true;
2022-01-13 05:24:03 +01:00
auto_pin = false;
2023-03-11 01:40:17 +01:00
panel = noone;
2022-01-13 05:24:03 +01:00
mx = 0;
my = 0;
2022-11-14 03:16:15 +01:00
x = 0;
y = 0;
2023-03-13 10:45:56 +01:00
w = 640;
h = 480;
2023-03-25 12:27:04 +01:00
padding = ui(16);
2023-04-23 16:47:33 +02:00
title_height = ui(28);
2022-11-14 03:16:15 +01:00
2023-03-19 09:17:39 +01:00
tab_x = 0;
2023-03-13 10:45:56 +01:00
min_w = ui(40);
min_h = ui(40);
2022-01-13 05:24:03 +01:00
2022-11-14 03:16:15 +01:00
pFOCUS = false;
pHOVER = false;
2023-10-31 05:30:42 +01:00
in_dialog = false;
2023-03-12 02:28:21 +01:00
2023-03-11 01:40:17 +01:00
dragSurface = surface_create(1, 1);
2023-03-12 02:28:21 +01:00
showHeader = true;
2023-03-11 01:40:17 +01:00
function refresh() { #region
2023-03-28 06:58:28 +02:00
setPanelSize(panel);
2022-01-18 05:31:19 +01:00
onResize();
} #endregion
2022-01-13 05:24:03 +01:00
2022-01-18 05:31:19 +01:00
function onResize() {}
2022-01-13 05:24:03 +01:00
2022-01-25 10:58:11 +01:00
function onFocusBegin() {}
function onFocusEnd() {}
2023-06-23 15:39:24 +02:00
static initSize = function() {}
2023-03-28 06:58:28 +02:00
function setPanelSize(panel) { #region
2023-03-19 09:17:39 +01:00
x = panel.tx;
y = panel.ty;
w = panel.tw;
h = panel.th;
} #endregion
2022-11-14 03:16:15 +01:00
function onSetPanel(panel) { #region
2023-03-11 01:40:17 +01:00
self.panel = panel;
2022-11-14 03:16:15 +01:00
setPanelSize(panel);
initSize();
onResize();
} #endregion
2022-11-14 03:16:15 +01:00
function panelStepBegin(panel) { #region
2022-11-14 03:16:15 +01:00
setPanelSize(panel);
2022-12-16 09:18:09 +01:00
onStepBegin();
} #endregion
2022-12-16 09:18:09 +01:00
function onStepBegin() { #region
2022-01-13 05:24:03 +01:00
mx = mouse_mx - x;
my = mouse_my - y;
stepBegin();
} #endregion
2022-01-13 05:24:03 +01:00
function stepBegin() {}
static draw = function(panel) { #region
2023-03-25 12:27:04 +01:00
self.panel = panel;
2023-03-26 07:13:36 +02:00
if(o_main.panel_dragging == noone) {
pFOCUS = FOCUS == panel && panel.mouse_active;
pHOVER = HOVER == panel && panel.mouse_active;
}
2022-11-14 03:16:15 +01:00
drawContent(panel);
} #endregion
2022-01-13 05:24:03 +01:00
2022-11-14 03:16:15 +01:00
function drawContent(panel) {}
2023-03-25 12:27:04 +01:00
function drawGUI() {}
2023-04-23 16:47:33 +02:00
2023-07-23 21:15:45 +02:00
function close() { panel.remove(self); }
2023-07-06 19:49:16 +02:00
2023-09-15 20:12:02 +02:00
static checkClosable = function() { return true; }
static onClose = function() {}
2022-01-25 10:58:11 +01:00
}
2023-01-25 06:49:00 +01:00
function setFocus(target, fstring = noone) {
2023-03-19 09:17:39 +01:00
if(FOCUS != noone && is_struct(FOCUS) && FOCUS.getContent())
FOCUS.getContent().onFocusEnd();
2022-01-25 10:58:11 +01:00
FOCUS = target;
2023-01-25 06:49:00 +01:00
if(fstring != noone)
FOCUS_STR = fstring;
2022-01-25 10:58:11 +01:00
2023-03-19 09:17:39 +01:00
if(FOCUS != noone && is_struct(FOCUS) && FOCUS.getContent())
FOCUS.getContent().onFocusBegin();
2022-01-13 05:24:03 +01:00
}