Pixel-Composer/scripts/pathArrayBox/pathArrayBox.gml

88 lines
2.2 KiB
Plaintext
Raw Normal View History

2023-02-23 07:02:19 +01:00
function pathArrayBox(_target, _data, _onClick) : widget() constructor {
target = _target;
data = _data;
onClick = _onClick;
openPath = button(function() {
2023-11-08 04:48:09 +01:00
var path = get_open_filenames_compat(data[0], data[1]);
2023-02-28 09:43:01 +01:00
key_release();
2023-02-23 07:02:19 +01:00
if(path == "") return noone;
2023-03-29 15:02:03 +02:00
2023-02-23 07:02:19 +01:00
var paths = string_splice(path, "\n");
onClick(paths);
}, THEME.button_path_icon);
static trigger = function() {
dialogPanelCall(new Panel_Image_Array_Editor(target));
2023-02-23 07:02:19 +01:00
}
2023-07-30 19:56:53 +02:00
static drawParam = function(params) {
2024-03-27 11:51:14 +01:00
setParam(params);
2024-03-26 04:03:45 +01:00
2023-07-30 19:56:53 +02:00
return draw(params.x, params.y, params.w, params.h, params.data, params.m);
}
2023-02-23 07:02:19 +01:00
static draw = function(_x, _y, _w, _h, _files, _m) {
x = _x;
y = _y;
w = _w;
h = _h;
2024-03-28 14:18:02 +01:00
hovering = false;
var _bs = min(_h, ui(32));
2024-03-29 09:13:26 +01:00
if(_w - _bs > ui(100)) {
openPath.setFocusHover(active, hover);
openPath.draw(_x + _w - _bs, _y + _h / 2 - _bs / 2, _bs, _bs, _m, THEME.button_hide);
_w -= _bs + ui(4);
}
2023-02-23 07:02:19 +01:00
var click = false;
draw_sprite_stretched_ext(THEME.textbox, 3, _x, _y, _w, _h, boxColor);
2023-02-23 07:02:19 +01:00
if(hover && point_in_rectangle(_m[0], _m[1], _x, _y, _x + _w, _y + _h)) {
2024-03-28 14:18:02 +01:00
hovering = true;
draw_sprite_stretched_ext(THEME.textbox, 1, _x, _y, _w, _h, boxColor);
2023-02-23 07:02:19 +01:00
if(mouse_press(mb_left, active)) {
trigger();
click = true;
}
if(mouse_click(mb_left, active))
draw_sprite_stretched(THEME.textbox, 2, _x, _y, _w, _h);
} else {
draw_sprite_stretched_ext(THEME.textbox, 0, _x, _y, _w, _h, boxColor);
2023-02-23 07:02:19 +01:00
if(mouse_press(mb_left)) deactivate();
}
var aa = interactable * 0.25 + 0.75;
2024-03-26 04:03:45 +01:00
2023-02-23 07:02:19 +01:00
if(!is_array(_files)) _files = [ _files ];
var len = array_length(_files);
2024-03-26 04:03:45 +01:00
var txt = $"({len}) [";
for( var i = 0; i < len; i++ )
2023-02-23 07:02:19 +01:00
txt += (i? ", " : "") + filename_name_only(_files[i]);
txt += "]";
2024-03-26 04:03:45 +01:00
draw_set_text(font, fa_left, fa_center, COLORS._main_text);
2024-03-29 09:13:26 +01:00
if(_h >= line_get_height()) {
draw_set_alpha(aa);
draw_text_cut(_x + ui(8), _y + _h / 2, txt, _w - ui(16));
draw_set_alpha(1);
}
2023-02-23 07:02:19 +01:00
if(WIDGET_CURRENT == self)
2023-04-08 20:06:27 +02:00
draw_sprite_stretched_ext(THEME.widget_selecting, 0, _x - ui(3), _y - ui(3), _w + ui(6), _h + ui(6), COLORS._main_accent, 1);
2023-02-23 07:02:19 +01:00
resetFocus();
2023-07-30 19:56:53 +02:00
return h;
2023-02-23 07:02:19 +01:00
}
2024-03-31 11:10:14 +02:00
static clone = function() {
2024-03-31 11:10:14 +02:00
var cln = new pathArrayBox(target, data, onClick);
return cln;
}
2023-02-23 07:02:19 +01:00
}