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);
|
|
|
|
|
|
|
|
content = noone;
|
|
|
|
childs = ds_list_create();
|
|
|
|
anchor = ANCHOR.none;
|
|
|
|
|
|
|
|
x = _x;
|
|
|
|
y = _y;
|
|
|
|
w = _w;
|
|
|
|
h = _h;
|
|
|
|
|
2022-11-03 11:44:49 +01:00
|
|
|
min_w = ui(32);
|
|
|
|
min_h = ui(32);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
dragging = -1;
|
|
|
|
drag_sval = 0;
|
|
|
|
drag_sm = 0;
|
|
|
|
|
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
|
|
|
|
|
|
|
function resetMask() {
|
|
|
|
surface_set_target(mask_surface);
|
|
|
|
draw_clear(c_black);
|
|
|
|
gpu_set_blendmode(bm_subtract);
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_sprite_stretched(THEME.ui_panel_bg, 0, ui(2), ui(2), w - ui(4), h - ui(4));
|
2022-01-13 05:24:03 +01:00
|
|
|
gpu_set_blendmode(bm_normal);
|
|
|
|
surface_reset_target();
|
|
|
|
}
|
|
|
|
resetMask();
|
|
|
|
|
|
|
|
function refresh() {
|
|
|
|
if(is_surface(content_surface) && surface_exists(content_surface))
|
|
|
|
surface_size_to(content_surface, w, h);
|
|
|
|
else
|
2022-11-01 03:06:03 +01:00
|
|
|
content_surface = surface_create_valid(w, h);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
if(is_surface(mask_surface) && surface_exists(mask_surface))
|
|
|
|
surface_size_to(mask_surface, w, h);
|
|
|
|
else
|
2022-11-01 03:06:03 +01:00
|
|
|
mask_surface = surface_create_valid(w, h);
|
2022-01-13 05:24:03 +01:00
|
|
|
resetMask();
|
|
|
|
|
|
|
|
if(content != noone)
|
|
|
|
content.refresh();
|
|
|
|
|
|
|
|
for( var i = 0; i < ds_list_size(childs); i++ ) {
|
|
|
|
childs[| i].refresh();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function move(dx, dy) {
|
|
|
|
x += dx;
|
|
|
|
y += dy;
|
|
|
|
|
|
|
|
for(var i = 0; i < ds_list_size(childs); i++) {
|
|
|
|
var _panel = childs[| i];
|
|
|
|
_panel.move(dx, dy);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(content) {
|
|
|
|
content.x = x;
|
|
|
|
content.y = y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function resizable(dw, dh, oppose = ANCHOR.left) {
|
|
|
|
if(content && (w + dw < content.min_w || h + dh < content.min_h)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
var rec = true;
|
|
|
|
for(var i = 0; i < ds_list_size(childs); i++) {
|
|
|
|
var panel = childs[| i];
|
|
|
|
|
|
|
|
if(panel.anchor != oppose || panel.content == noone)
|
|
|
|
if(!panel.resizable(dw, dh))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-12-27 04:00:50 +01:00
|
|
|
function refreshSize() {
|
|
|
|
for(var i = 0; i < ds_list_size(childs); i++)
|
|
|
|
childs[| i].refreshSize();
|
|
|
|
|
|
|
|
refreshContentSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
function refreshContentSize() {
|
|
|
|
if(content) {
|
|
|
|
content.w = w;
|
|
|
|
content.h = h;
|
|
|
|
content.onResize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
function resize(dw, dh, oppose = ANCHOR.left) {
|
|
|
|
if(dw == 0 && dh == 0) return;
|
|
|
|
|
|
|
|
var _w = dw, _h = dh;
|
|
|
|
|
|
|
|
for(var i = 0; i < ds_list_size(childs); i++) {
|
|
|
|
var panel = childs[| i];
|
|
|
|
|
|
|
|
if(panel.anchor != oppose || panel.content == noone)
|
|
|
|
panel.resize(dw, dh, oppose);
|
|
|
|
}
|
|
|
|
|
|
|
|
w = max(w + dw, min_w);
|
|
|
|
h = max(h + dh, min_h);
|
|
|
|
|
|
|
|
if(w > 1 && h > 1) {
|
|
|
|
if(is_surface(content_surface))
|
|
|
|
surface_size_to(content_surface, w, h);
|
|
|
|
|
|
|
|
if(is_surface(mask_surface))
|
|
|
|
surface_size_to(mask_surface, w, h);
|
|
|
|
else
|
2022-11-01 03:06:03 +01:00
|
|
|
mask_surface = surface_create_valid(w, h);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
resetMask();
|
|
|
|
}
|
|
|
|
|
2022-12-27 04:00:50 +01:00
|
|
|
refreshContentSize();
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function set(_content) {
|
|
|
|
content = _content;
|
2022-11-14 03:16:15 +01:00
|
|
|
content.onSetPanel(self);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function split_h(_w) {
|
2022-11-01 03:06:03 +01:00
|
|
|
if(abs(_w) > w) return noone;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
if(content) {
|
|
|
|
content.w = w;
|
2022-01-18 05:31:19 +01:00
|
|
|
content.onResize();
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(parent == noone) PANEL_MAIN = _panelParent;
|
|
|
|
else {
|
|
|
|
ds_list_delete(parent.childs, ds_list_find_index(parent.childs, self));
|
|
|
|
}
|
|
|
|
parent = _panelParent;
|
|
|
|
anchor = ANCHOR.left;
|
|
|
|
|
|
|
|
if(content) content = noone;
|
|
|
|
|
|
|
|
return [ _panelL, _panelR ];
|
|
|
|
}
|
|
|
|
|
|
|
|
function split_v(_h) {
|
2022-11-01 03:06:03 +01:00
|
|
|
if(abs(_h) > h) return noone;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
if(content) {
|
|
|
|
content.h = h;
|
2022-01-18 05:31:19 +01:00
|
|
|
content.onResize();
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(parent == noone) PANEL_MAIN = _panelParent;
|
|
|
|
else {
|
|
|
|
ds_list_delete(parent.childs, ds_list_find_index(parent.childs, self));
|
|
|
|
}
|
|
|
|
parent = _panelParent;
|
|
|
|
anchor = ANCHOR.top;
|
|
|
|
|
|
|
|
if(content) content = noone;
|
|
|
|
|
|
|
|
return [_panelT, _panelB];
|
|
|
|
}
|
|
|
|
|
|
|
|
function stepBegin() {
|
2022-12-16 09:18:09 +01:00
|
|
|
if(content) content.panelStepBegin(self);
|
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));
|
2022-01-13 05:24:03 +01:00
|
|
|
var dw = _mx - drag_sm;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-10 05:06:01 +01:00
|
|
|
if(mouse_release(mb_left)) 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));
|
2022-01-13 05:24:03 +01:00
|
|
|
var dh = _my - drag_sm;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-10 05:06:01 +01:00
|
|
|
if(mouse_release(mb_left)) dragging = -1;
|
2022-01-13 05:24:03 +01:00
|
|
|
} else {
|
2022-11-14 03:16:15 +01:00
|
|
|
if(content != noone) {
|
2022-11-03 11:44:49 +01:00
|
|
|
if(point_in_rectangle(mouse_mx, mouse_my, x + ui(2), y + ui(2), x + w - ui(4), y + h - ui(4))) {
|
2022-01-13 05:24:03 +01:00
|
|
|
HOVER = self;
|
2023-01-25 06:49:00 +01:00
|
|
|
if(mouse_press(mb_any))
|
|
|
|
setFocus(self);
|
|
|
|
if(FOCUS == self && content)
|
2022-01-13 05:24:03 +01:00
|
|
|
FOCUS_STR = content.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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-18 05:31:19 +01:00
|
|
|
static step = function() {
|
2022-01-13 05:24:03 +01:00
|
|
|
for(var i = 0; i < ds_list_size(childs); i++) {
|
|
|
|
var _panel = childs[| i];
|
|
|
|
_panel.step();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function draw() {
|
2022-11-14 03:16:15 +01:00
|
|
|
if(content != noone) {
|
2022-01-13 05:24:03 +01:00
|
|
|
drawPanel();
|
2022-11-14 03:16:15 +01:00
|
|
|
return;
|
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-11-14 03:16:15 +01:00
|
|
|
if(ds_list_empty(childs))
|
|
|
|
return;
|
|
|
|
|
|
|
|
var _drag = true;
|
|
|
|
for(var i = 0; i < ds_list_size(childs); i++) {
|
|
|
|
var _panel = childs[| i];
|
|
|
|
if(_panel.content && !_panel.content.draggable)
|
|
|
|
_drag = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(var i = 0; i < ds_list_size(childs); i++) {
|
|
|
|
var _panel = childs[| i];
|
|
|
|
_panel.draw();
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-11-14 03:16:15 +01:00
|
|
|
if!(_drag && (HOVER == noone || is_struct(HOVER)))
|
|
|
|
continue;
|
2022-11-03 11:44:49 +01:00
|
|
|
|
2022-11-14 03:16:15 +01:00
|
|
|
switch(_panel.anchor) {
|
|
|
|
case ANCHOR.left :
|
|
|
|
if(!point_in_rectangle(mouse_mx, mouse_my, _panel.x + _panel.w - ui(2), _panel.y, _panel.x + _panel.w + ui(2), _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 :
|
|
|
|
if(!point_in_rectangle(mouse_mx, mouse_my, _panel.x, _panel.y + _panel.h - ui(2), _panel.x + _panel.w, _panel.y + _panel.h + ui(2)))
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function drawPanel() {
|
2022-11-03 11:44:49 +01:00
|
|
|
if(w <= ui(16)) return;
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_sprite_stretched(THEME.ui_panel_bg, 0, x + ui(2), y + ui(2), w - ui(4), h - ui(4));
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
if(!is_surface(mask_surface)) {
|
2022-11-01 03:06:03 +01:00
|
|
|
mask_surface = surface_create_valid(w, h);
|
2022-01-13 05:24:03 +01:00
|
|
|
resetMask();
|
|
|
|
}
|
|
|
|
|
2022-11-03 11:44:49 +01:00
|
|
|
if(!is_surface(content_surface)) content_surface = surface_create_valid(w, h);
|
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);
|
2022-01-13 05:24:03 +01:00
|
|
|
if(content) {
|
|
|
|
min_w = content.min_w;
|
|
|
|
min_h = content.min_h;
|
|
|
|
if(w >= min_w && h >= min_h)
|
2022-11-14 03:16:15 +01:00
|
|
|
content.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();
|
|
|
|
|
|
|
|
draw_surface_safe(content_surface, x, y);
|
|
|
|
|
2023-01-25 06:49:00 +01:00
|
|
|
if(FOCUS == self)
|
|
|
|
draw_sprite_stretched_ext(THEME.ui_panel_active, 0, x + ui(2), y + ui(2), w - ui(4), h - ui(4), COLORS._main_accent, 1);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function remove() {
|
|
|
|
if(parent == noone) {
|
|
|
|
show_message("What are you trying to do!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ds_list_delete(parent.childs, ds_list_find_index(parent.childs, self));
|
|
|
|
var otherPanel = parent.childs[| 0];
|
|
|
|
parent.set(otherPanel.content);
|
|
|
|
ds_list_clear(parent.childs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-14 03:16:15 +01:00
|
|
|
function PanelContent() constructor {
|
2022-01-13 05:24:03 +01:00
|
|
|
context_str = "";
|
|
|
|
draggable = true;
|
2022-11-14 03:16:15 +01:00
|
|
|
expandable = true;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
mx = 0;
|
|
|
|
my = 0;
|
|
|
|
|
2022-11-14 03:16:15 +01:00
|
|
|
x = 0;
|
|
|
|
y = 0;
|
|
|
|
w = 1;
|
|
|
|
h = 1;
|
|
|
|
|
2022-11-03 11:44:49 +01:00
|
|
|
min_w = ui(32);
|
|
|
|
min_h = ui(32);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-11-14 03:16:15 +01:00
|
|
|
pFOCUS = false;
|
|
|
|
pHOVER = false;
|
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
function refresh() {
|
2022-01-18 05:31:19 +01:00
|
|
|
onResize();
|
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() {}
|
|
|
|
|
2022-11-14 03:16:15 +01:00
|
|
|
function initSize() {}
|
|
|
|
function setPanelSize(panel) {
|
|
|
|
x = panel.x;
|
|
|
|
y = panel.y;
|
|
|
|
w = panel.w;
|
|
|
|
h = panel.h;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onSetPanel(panel) {
|
|
|
|
setPanelSize(panel);
|
|
|
|
initSize();
|
|
|
|
onResize();
|
|
|
|
}
|
|
|
|
|
2022-12-16 09:18:09 +01:00
|
|
|
function panelStepBegin(panel) {
|
2022-11-14 03:16:15 +01:00
|
|
|
setPanelSize(panel);
|
2022-12-16 09:18:09 +01:00
|
|
|
onStepBegin();
|
|
|
|
}
|
|
|
|
|
|
|
|
function onStepBegin() {
|
2022-01-13 05:24:03 +01:00
|
|
|
mx = mouse_mx - x;
|
|
|
|
my = mouse_my - y;
|
|
|
|
|
|
|
|
stepBegin();
|
|
|
|
}
|
|
|
|
|
|
|
|
function stepBegin() {}
|
|
|
|
|
2022-11-14 03:16:15 +01:00
|
|
|
function draw(panel) {
|
|
|
|
pFOCUS = FOCUS == panel;
|
|
|
|
pHOVER = HOVER == panel;
|
|
|
|
|
|
|
|
drawContent(panel);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
2022-11-14 03:16:15 +01:00
|
|
|
function drawContent(panel) {}
|
2022-01-25 10:58:11 +01:00
|
|
|
}
|
|
|
|
|
2023-01-25 06:49:00 +01:00
|
|
|
function setFocus(target, fstring = noone) {
|
2022-01-25 10:58:11 +01:00
|
|
|
if(FOCUS != noone && is_struct(FOCUS) && FOCUS.content)
|
|
|
|
FOCUS.content.onFocusEnd();
|
|
|
|
|
|
|
|
FOCUS = target;
|
2023-01-25 06:49:00 +01:00
|
|
|
if(fstring != noone)
|
|
|
|
FOCUS_STR = fstring;
|
2022-01-25 10:58:11 +01:00
|
|
|
|
|
|
|
if(FOCUS != noone && is_struct(FOCUS) && FOCUS.content)
|
|
|
|
FOCUS.content.onFocusBegin();
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|