Pixel-Composer/scripts/widget/widget.gml

163 lines
3.3 KiB
Text
Raw Normal View History

2023-01-17 08:11:55 +01:00
function widget() constructor {
active = false;
hover = false;
hovering = false;
2024-11-29 06:18:28 +01:00
iactive = false;
ihover = false;
2024-11-29 06:18:28 +01:00
temp_hovering = false;
parent = noone;
keyframe = noone;
2023-01-17 08:11:55 +01:00
interactable = true;
2024-05-17 15:25:01 +02:00
2024-07-28 13:55:57 +02:00
hover_content = false;
2024-05-26 04:51:14 +02:00
right_click_block = true;
2024-03-27 11:51:14 +01:00
side_button = noone;
2024-05-17 15:25:01 +02:00
front_button = noone;
2023-01-17 08:11:55 +01:00
2024-03-28 14:18:02 +01:00
hide = false;
2023-05-07 20:55:13 +02:00
lua_thread = noone;
lua_thread_key = "";
2024-09-10 11:48:51 +02:00
font = f_p1;
2024-07-03 05:32:12 +02:00
sep_axis = false;
unit = noone;
2024-03-26 04:03:45 +01:00
boxColor = c_white;
2023-01-17 08:11:55 +01:00
x = 0;
y = 0;
w = 0;
h = 0;
2023-07-12 16:28:32 +02:00
rx = 0;
ry = 0;
static setLua = function(_lua_thread, _lua_key, _lua_func) {
2023-05-07 20:55:13 +02:00
lua_thread = _lua_thread;
lua_thread_key = _lua_key;
onModify = method(self, _lua_func);
}
2023-05-07 20:55:13 +02:00
static setInteract = function(interactable = noone) {
2023-01-25 06:49:00 +01:00
self.interactable = interactable;
}
2023-01-25 06:49:00 +01:00
static register = function(parent = noone) {
2023-01-17 08:11:55 +01:00
if(!interactable) return;
array_push(WIDGET_ACTIVE, self);
self.parent = parent;
}
2023-01-17 08:11:55 +01:00
static setParam = function(params) {
2024-03-27 11:51:14 +01:00
font = params.font;
rx = params.rx;
ry = params.ry;
2024-07-03 05:32:12 +02:00
sep_axis = params.sep_axis;
boxColor = params.color;
2024-12-15 12:19:48 +01:00
if(!is_undefined(params.interact))
setInteract(params.interact);
if(!is_undefined(params.focus))
setFocusHover(params.focus, params.hover);
if(!is_undefined(params.scrollpane) && inBBOX(params.m)) {
register(params.scrollpane);
params.scrollpane.hover_content = true;
}
}
2024-03-27 11:51:14 +01:00
2023-01-17 08:11:55 +01:00
static trigger = function() { }
static parentFocus = function() {
2023-01-17 08:11:55 +01:00
if(parent == noone) return;
if(y < 0)
parent.scroll_y_to += abs(y) + ui(16);
else if(y + ui(16) > parent.surface_h)
parent.scroll_y_to -= abs(parent.surface_h - y) + h + ui(16);
}
2023-01-17 08:11:55 +01:00
2024-03-28 14:18:02 +01:00
static isHovering = function() { return hovering; }
static activate = function() {
2023-01-17 08:11:55 +01:00
if(!interactable) return;
WIDGET_CURRENT = self;
WIDGET_CURRENT_SCROLL = parent;
parentFocus();
}
2023-01-17 08:11:55 +01:00
static deactivate = function() {
2023-01-17 08:11:55 +01:00
if(WIDGET_CURRENT != self) return;
WIDGET_CURRENT = noone;
WIDGET_CURRENT_SCROLL = noone;
}
2023-01-17 08:11:55 +01:00
static setFocusHover = function(active = false, hover = false) {
2023-01-25 06:49:00 +01:00
self.active = interactable && active;
self.hover = interactable && hover;
self.iactive = active;
self.ihover = hover;
}
2023-01-17 08:11:55 +01:00
static resetFocus = function() {
2023-01-17 08:11:55 +01:00
active = false;
hover = false;
}
2024-03-31 11:10:14 +02:00
2024-08-18 04:51:54 +02:00
static inBBOX = function(_m) { return point_in_rectangle(_m[0], _m[1], x, y, x + w, y + h); }
static clone = function() { return struct_clone(self); }
2023-06-21 20:36:53 +02:00
2023-07-23 20:21:35 +02:00
static drawParam = function(params) {}
2024-08-18 04:51:54 +02:00
static draw = function() {}
2024-11-24 11:39:17 +01:00
static free = function() {}
2023-07-30 19:56:53 +02:00
}
function widgetParam(x, y, w, h, data, display_data = {}, m = mouse_ui, rx = 0, ry = 0) constructor {
2023-07-30 19:56:53 +02:00
self.x = x;
self.y = y;
self.w = w;
self.h = h;
self.s = ui(24);
2023-07-30 19:56:53 +02:00
self.data = data;
self.m = m;
self.rx = rx;
self.ry = ry;
self.halign = fa_left;
self.valign = fa_top;
self.display_data = display_data;
2024-03-26 04:03:45 +01:00
2024-09-10 11:48:51 +02:00
self.font = f_p1;
2024-07-03 05:32:12 +02:00
color = c_white;
sep_axis = false;
2024-12-15 12:19:48 +01:00
focus = undefined;
hover = undefined;
interact = undefined;
scrollpane = undefined;
2024-12-16 12:03:02 +01:00
static setColor = function(c) { color = c; return self; }
static setFont = function(f) { font = f; return self; }
static setScrollpane = function(s) { scrollpane = s; return self; }
2024-12-15 12:19:48 +01:00
static setFocusHover = function(f, h, i = undefined) {
focus = f;
hover = h;
interact = i;
return self;
}
2023-01-17 08:11:55 +01:00
}