Pixel-Composer/scripts/scrollBox/scrollBox.gml

58 lines
1.5 KiB
Plaintext
Raw Normal View History

2022-01-13 05:24:03 +01:00
function scrollBox(_data, _onModify) constructor {
onModify = _onModify;
data_list = _data;
2022-12-16 09:18:09 +01:00
data = [];
2022-01-13 05:24:03 +01:00
active = false;
hover = false;
open = false;
align = fa_center;
2022-12-16 09:18:09 +01:00
extra_button = noone;
2022-11-18 03:20:31 +01:00
static draw = function(_x, _y, _w, _h, _text, _m = mouse_ui, _rx = 0, _ry = 0) {
2022-12-16 09:18:09 +01:00
var ww = _w;
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);
ww -= ui(40);
}
if(open) {
hover = false;
active = false;
return;
}
if(hover && point_in_rectangle(_m[0], _m[1], _x, _y, _x + ww, _y + _h)) {
draw_sprite_stretched(THEME.textbox, 1, _x, _y, ww, _h);
if(mouse_press(mb_left, active)) {
if(is_method(data_list))
data = data_list();
else
data = data_list;
2022-12-19 13:35:30 +01:00
2022-12-16 09:18:09 +01:00
open = true;
with(dialogCall(o_dialog_scrollbox, _x + _rx, _y + _ry)) {
scrollbox = other;
dialog_w = ww;
align = other.align;
2022-01-13 05:24:03 +01:00
}
}
2022-12-16 09:18:09 +01:00
if(mouse_click(mb_left, active))
draw_sprite_stretched(THEME.textbox, 2, _x, _y, ww, _h);
2022-12-19 13:35:30 +01:00
} else
draw_sprite_stretched(THEME.textbox, 0, _x, _y, ww, _h);
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);
if(align == fa_center)
draw_text(_x + ww / 2, _y + _h / 2 - ui(2), _text);
else if(align == fa_left)
draw_text(_x + ui(8), _y + _h / 2 - ui(2), _text);
draw_sprite_ui_uniform(THEME.scroll_box_arrow, 0, _x + ww - 20, _y + _h / 2, 1, COLORS._main_icon);
2022-01-13 05:24:03 +01:00
hover = false;
active = false;
}
}