Pixel-Composer/scripts/scrollBox/scrollBox.gml

75 lines
1.9 KiB
Plaintext
Raw Normal View History

2023-01-17 08:11:55 +01:00
function scrollBox(_data, _onModify) : widget() constructor {
2022-01-13 05:24:03 +01:00
onModify = _onModify;
data_list = _data;
2022-12-16 09:18:09 +01:00
data = [];
2022-01-13 05:24:03 +01:00
2023-01-17 08:11:55 +01:00
open = false;
open_rx = 0;
open_ry = 0;
2022-01-13 05:24:03 +01:00
align = fa_center;
2022-12-16 09:18:09 +01:00
extra_button = noone;
2023-01-17 08:11:55 +01:00
static trigger = function() {
if(is_method(data_list))
data = data_list();
else
data = data_list;
open = true;
with(dialogCall(o_dialog_scrollbox, x + open_rx, y + open_ry)) {
scrollbox = other;
dialog_w = other.w;
align = other.align;
}
}
2022-11-18 03:20:31 +01:00
static draw = function(_x, _y, _w, _h, _text, _m = mouse_ui, _rx = 0, _ry = 0) {
2023-01-17 08:11:55 +01:00
x = _x;
y = _y;
open_rx = _rx;
open_ry = _ry;
h = _h;
w = _w;
2022-12-16 09:18:09 +01:00
if(extra_button != noone) {
extra_button.hover = hover;
extra_button.active = active;
extra_button.draw(_x + _w - ui(32), _y + _h / 2 - ui(32 / 2), ui(32), ui(32), _m, THEME.button_hide);
2023-01-17 08:11:55 +01:00
w -= ui(40);
2022-12-16 09:18:09 +01:00
}
if(open) {
2023-01-17 08:11:55 +01:00
resetFocus();
2022-12-16 09:18:09 +01:00
return;
}
2023-01-17 08:11:55 +01:00
draw_sprite_stretched(THEME.textbox, 3, _x, _y, w, _h);
if(hover && point_in_rectangle(_m[0], _m[1], _x, _y, _x + w, _y + _h)) {
draw_sprite_stretched(THEME.textbox, 1, _x, _y, w, _h);
if(mouse_press(mb_left, active))
trigger();
2022-12-16 09:18:09 +01:00
if(mouse_click(mb_left, active))
2023-01-17 08:11:55 +01:00
draw_sprite_stretched(THEME.textbox, 2, _x, _y, w, _h);
} else {
draw_sprite_stretched_ext(THEME.textbox, 0, _x, _y, w, _h, c_white, 0.5 + 0.5 * interactable);
if(mouse_press(mb_left)) deactivate();
}
2022-01-13 05:24:03 +01:00
2022-12-16 09:18:09 +01:00
draw_set_text(f_p0, align, fa_center, COLORS._main_text);
2023-01-17 08:11:55 +01:00
draw_set_alpha(0.5 + 0.5 * interactable);
2022-12-16 09:18:09 +01:00
if(align == fa_center)
2023-01-17 08:11:55 +01:00
draw_text(_x + w / 2, _y + _h / 2 - ui(2), _text);
2022-12-16 09:18:09 +01:00
else if(align == fa_left)
draw_text(_x + ui(8), _y + _h / 2 - ui(2), _text);
2023-01-17 08:11:55 +01:00
draw_set_alpha(1);
draw_sprite_ui_uniform(THEME.scroll_box_arrow, 0, _x + w - 20, _y + _h / 2, 1, COLORS._main_icon, 0.5 + 0.5 * interactable);
if(WIDGET_CURRENT == self)
draw_sprite_stretched(THEME.widget_selecting, 0, _x - ui(3), _y - ui(3), _w + ui(6), _h + ui(6));
2022-12-16 09:18:09 +01:00
2023-01-17 08:11:55 +01:00
resetFocus();
2022-01-13 05:24:03 +01:00
}
}