Pixel-Composer/scripts/fontScrollBox/fontScrollBox.gml

90 lines
2.7 KiB
Plaintext
Raw Normal View History

2023-01-17 08:11:55 +01:00
function fontScrollBox(_onModify) : widget() constructor {
onModify = _onModify;
open = false;
open_rx = 0;
open_ry = 0;
align = fa_center;
2023-03-13 10:45:56 +01:00
extra_button = button(function() { shellOpenExplorer(DIRECTORY + "Fonts"); } )
2023-06-04 18:28:29 +02:00
.setTooltip(__txtx("widget_font_open_folder", "Open font folder"))
2023-01-17 08:11:55 +01:00
.setIcon(THEME.folder_content, 0, COLORS._main_icon);
static trigger = function() {
refreshFontFolder();
open = true;
with(dialogCall(o_dialog_fontscrollbox, x + open_rx, y + open_ry)) {
scrollbox = other;
align = other.align;
}
}
2023-01-25 06:49:00 +01:00
static setInteract = function(interactable = noone) {
self.interactable = interactable;
extra_button.interactable = interactable;
}
2023-07-30 19:56:53 +02:00
static drawParam = function(params) {
2024-03-26 04:03:45 +01:00
font = params.font;
2023-07-30 19:56:53 +02:00
return draw(params.x, params.y, params.w, params.h, params.data, params.m, params.rx, params.ry);
}
2023-01-17 08:11:55 +01:00
static draw = function(_x, _y, _w, _h, _text, _m = mouse_ui, _rx = 0, _ry = 0) {
x = _x;
y = _y;
open_rx = _rx;
open_ry = _ry;
h = _h;
w = _w;
var _bs = min(_h, ui(32));
2023-01-17 08:11:55 +01:00
if(extra_button != noone) {
2023-06-21 20:36:53 +02:00
extra_button.setFocusHover(active, hover);
extra_button.draw(_x + _w - _bs, _y + _h / 2 - _bs / 2, _bs, _bs, _m, THEME.button_hide);
w -= _bs + ui(4);
2023-01-17 08:11:55 +01:00
}
if(open) {
resetFocus();
return h;
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();
if(mouse_click(mb_left, active))
2023-04-08 20:06:27 +02:00
draw_sprite_stretched_ext(THEME.textbox, 2, _x, _y, w, _h, COLORS._main_accent, 1);
2023-01-17 08:11:55 +01:00
} 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();
}
2023-08-24 11:59:05 +02:00
var _txt = "";
var _texts = is_array(_text)? _text : [ _text ];
for( var i = 0, n = array_length(_texts); i < n; i++ )
_txt += (i? ", " : "") + filename_name_only(_texts[i]);
_txt = $"[{_txt}]";
_text = is_array(_text)? _txt : filename_name_only(_text);
2024-03-26 04:03:45 +01:00
draw_set_text(font, align, fa_center, COLORS._main_text);
2023-01-17 08:11:55 +01:00
draw_set_alpha(0.5 + 0.5 * interactable);
if(align == fa_center)
draw_text(_x + w / 2, _y + _h / 2 - ui(2), _text);
else if(align == fa_left)
draw_text(_x + ui(8), _y + _h / 2 - ui(2), _text);
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)
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-01-17 08:11:55 +01:00
resetFocus();
2023-07-30 19:56:53 +02:00
return h;
2023-01-17 08:11:55 +01:00
}
}