Pixel-Composer/scripts/widget/widget.gml

94 lines
1.8 KiB
Text
Raw Normal View History

2023-01-17 08:11:55 +01:00
function widget() constructor {
2023-01-25 06:49:00 +01:00
active = false;
hover = false;
iactive = false;
ihover = false;
2023-10-04 09:49:31 +02:00
parent = noone;
2023-01-17 08:11:55 +01:00
interactable = true;
2023-05-07 20:55:13 +02:00
lua_thread = noone;
lua_thread_key = "";
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;
2023-05-07 20:55:13 +02:00
static setLua = function(_lua_thread, _lua_key, _lua_func) {
lua_thread = _lua_thread;
lua_thread_key = _lua_key;
onModify = method(self, _lua_func);
}
2023-01-25 06:49:00 +01:00
static setInteract = function(interactable = noone) {
self.interactable = interactable;
}
2023-01-17 08:11:55 +01:00
static register = function(parent = noone) {
if(!interactable) return;
array_push(WIDGET_ACTIVE, self);
self.parent = parent;
}
static trigger = function() { }
static parentFocus = function() {
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);
}
static activate = function() {
if(!interactable) return;
WIDGET_CURRENT = self;
WIDGET_CURRENT_SCROLL = parent;
parentFocus();
}
static deactivate = function() {
if(WIDGET_CURRENT != self) return;
WIDGET_CURRENT = noone;
WIDGET_CURRENT_SCROLL = noone;
}
2023-06-21 20:36:53 +02: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() {
active = false;
hover = false;
}
2023-06-21 20:36:53 +02:00
2023-07-23 20:21:35 +02:00
static drawParam = function(params) {}
2023-06-21 20:36:53 +02:00
static draw = 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;
2023-01-17 08:11:55 +01:00
}