Pixel-Composer/scripts/textArrayBox/textArrayBox.gml

78 lines
2.1 KiB
Text
Raw Normal View History

2023-02-21 04:48:50 +01:00
function textArrayBox(arraySet, data, onModify = noone) : widget() constructor {
2023-02-15 10:43:24 +01:00
self.getArray = arraySet;
self.arraySet = noone;
2023-02-14 02:48:33 +01:00
self.data = data;
2023-02-21 04:48:50 +01:00
self.onModify = onModify;
2023-02-14 02:48:33 +01:00
2023-02-15 10:43:24 +01:00
hide = false;
2023-02-14 02:48:33 +01:00
open = false;
2023-07-30 19:56:53 +02:00
static drawParam = function(params) {
2023-09-28 13:15:29 +02:00
return draw(params.x, params.y, params.w, params.h, params.m, params.rx, params.ry);
2023-07-30 19:56:53 +02:00
}
2023-02-15 10:43:24 +01:00
static draw = function(_x, _y, _w, _h, _m, _rx = 0, _ry = 0) {
2023-02-14 02:48:33 +01:00
x = _x;
y = _y;
w = _w;
2023-02-15 10:43:24 +01:00
if(getArray != noone)
arraySet = getArray();
2023-02-14 02:48:33 +01:00
var tx = _x + ui(4);
var ty = _y + ui(4);
2023-05-28 20:00:51 +02:00
var hh = line_get_height(f_p0, ui(4));
2023-02-14 02:48:33 +01:00
var th = hh + ui(8);
draw_set_text(f_p0, fa_left, fa_center, COLORS._main_text);
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(arraySet); i < n; i++ ) {
2023-02-15 10:43:24 +01:00
var ww = string_width(arraySet[i]) + ui(16);
2023-02-14 02:48:33 +01:00
if(tx + ww + ui(2) > _x + _w - ui(8)) {
tx = _x + ui(4);
ty += hh + ui(2);
th += hh + ui(2);
}
tx += ww + ui(2);
}
h = th;
draw_sprite_stretched(THEME.textbox, 3, _x, _y, _w, th);
if(open) {
2023-04-08 20:06:27 +02:00
draw_sprite_stretched_ext(THEME.textbox, 2, _x, _y, _w, th, COLORS._main_accent, 1);
2023-02-14 02:48:33 +01:00
} else {
if(hover && point_in_rectangle(_m[0], _m[1], _x, _y, _x + _w, _y + th)) {
2023-02-17 04:48:54 +01:00
draw_sprite_stretched_ext(THEME.textbox, 1, _x, _y, _w, th, c_white, 0.5 + !hide * 0.5);
2023-02-14 02:48:33 +01:00
if(mouse_press(mb_left, active)) {
2023-02-15 10:43:24 +01:00
with(dialogCall(o_dialog_arrayBox, _rx + _x, _ry + _y + th)) {
2023-02-14 02:48:33 +01:00
arrayBox = other;
dialog_w = other.w;
}
}
2023-02-15 10:43:24 +01:00
} else if(!hide)
2023-02-14 02:48:33 +01:00
draw_sprite_stretched_ext(THEME.textbox, 0, _x, _y, _w, th, c_white, 0.5 + 0.5 * interactable);
}
var tx = _x + ui(4);
var ty = _y + ui(4);
2023-05-28 20:00:51 +02:00
var hh = line_get_height(f_p0, ui(4));
2023-02-14 02:48:33 +01:00
draw_set_text(f_p0, fa_left, fa_center, COLORS._main_text);
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(arraySet); i < n; i++ ) {
2023-02-15 10:43:24 +01:00
var ww = string_width(arraySet[i]) + ui(16);
2023-02-14 02:48:33 +01:00
if(tx + ww + ui(2) > _x + _w - ui(8)) {
tx = _x + ui(4);
ty += hh + ui(2);
}
draw_sprite_stretched_ext(THEME.group_label, 0, tx, ty, ww, hh, COLORS._main_icon, 1);
2023-02-15 10:43:24 +01:00
draw_text(tx + ui(8), ty + hh / 2, arraySet[i]);
2023-02-14 02:48:33 +01:00
tx += ww + ui(2);
}
resetFocus();
return th;
}
}