Pixel-Composer/scripts/textBox/textBox.gml

587 lines
16 KiB
Plaintext
Raw Normal View History

2022-01-13 05:24:03 +01:00
enum TEXTBOX_INPUT {
text,
2023-02-14 02:51:14 +01:00
number
2022-01-13 05:24:03 +01:00
}
2023-01-17 08:11:55 +01:00
function textBox(_input, _onModify, _extras = noone) : textInput(_input, _onModify, _extras) constructor {
2023-04-21 19:08:10 +02:00
align = _input == TEXTBOX_INPUT.number? fa_right : fa_left;
2022-01-13 05:24:03 +01:00
hide = false;
2022-11-03 11:44:49 +01:00
font = noone;
2022-12-10 05:06:01 +01:00
color = COLORS._main_text;
2023-03-05 07:16:44 +01:00
boxColor = c_white;
2022-01-13 05:24:03 +01:00
no_empty = true;
auto_update = false;
slidable = false;
sliding = false;
slide_mx = 0;
2022-12-19 13:35:30 +01:00
slide_my = 0;
2023-02-14 02:51:14 +01:00
slide_speed = 1 / 10;
2022-01-13 05:24:03 +01:00
2022-01-26 13:02:30 +01:00
starting_char = 1;
2023-01-17 08:11:55 +01:00
_current_text = "";
2022-01-13 05:24:03 +01:00
_input_text = "";
2022-12-18 03:20:38 +01:00
_last_text = "";
2023-05-03 21:42:17 +02:00
current_value = "";
2022-01-13 05:24:03 +01:00
cursor = 0;
cursor_pos = 0;
cursor_pos_to = 0;
cursor_select = -1;
2023-01-01 02:06:02 +01:00
disp_x = 0;
disp_x_to = 0;
2023-01-09 03:14:20 +01:00
disp_x_min = 0;
2023-01-01 02:06:02 +01:00
disp_x_max = 0;
2022-01-13 05:24:03 +01:00
click_block = 0;
2022-09-21 06:09:40 +02:00
sprite_index = -1;
2023-01-01 02:06:02 +01:00
text_surface = surface_create(1, 1);
2023-04-21 19:08:10 +02:00
static setFont = function(font) {
self.font = font;
return self;
}
static setEmpty = function() {
no_empty = false;
return self;
}
2023-01-17 08:11:55 +01:00
static activate = function() {
WIDGET_CURRENT = self;
WIDGET_CURRENT_SCROLL = parent;
parentFocus();
_input_text = _current_text;
_last_text = _current_text;
cursor_select = 0;
cursor = string_length(_current_text);
click_block = 1;
KEYBOARD_STRING = "";
keyboard_lastkey = -1;
}
static deactivate = function() {
apply();
WIDGET_CURRENT = noone;
UNDO_HOLDING = false;
}
2022-01-24 02:21:25 +01:00
static apply = function() {
2022-01-13 05:24:03 +01:00
var _input_text_current = _input_text;
2023-02-14 02:51:14 +01:00
disp_x_to = 0;
2022-01-13 05:24:03 +01:00
switch(input) {
2023-02-14 02:51:14 +01:00
case TEXTBOX_INPUT.number :
2022-01-13 05:24:03 +01:00
_input_text_current = evaluateFunction(_input_text);
break;
}
if(no_empty && _input_text_current == "")
2022-12-18 03:20:38 +01:00
_input_text_current = _last_text;
2023-05-03 21:42:17 +02:00
current_value = _input_text_current;
2022-01-13 05:24:03 +01:00
if(onModify)
2023-02-14 02:51:14 +01:00
return onModify(_input_text_current);
return false;
2022-01-13 05:24:03 +01:00
}
2022-01-24 02:21:25 +01:00
static move_cursor = function(delta) {
2022-01-13 05:24:03 +01:00
var ll = string_length(_input_text) + 1;
cursor = safe_mod(cursor + delta + ll, ll);
}
2022-01-24 02:21:25 +01:00
static editText = function() {
2022-01-13 05:24:03 +01:00
#region text editor
2022-12-22 03:09:55 +01:00
if(key_mod_press(CTRL) && keyboard_check_pressed(ord("A"))) {
2022-11-21 06:38:44 +01:00
cursor_select = 0;
cursor = string_length(_input_text);
2022-12-22 03:09:55 +01:00
} else if(key_mod_press(CTRL) && (keyboard_check_pressed(ord("C")) || keyboard_check_pressed(ord("X")))) {
2022-11-21 06:38:44 +01:00
if(cursor_select != -1) {
var minc = min(cursor, cursor_select);
var maxc = max(cursor, cursor_select);
clipboard_set_text(string_copy(_input_text, minc, maxc - minc));
2022-01-13 05:24:03 +01:00
}
} else {
2022-12-22 03:09:55 +01:00
if(key_mod_press(CTRL) && keyboard_check_pressed(ord("V")))
2022-12-12 09:08:03 +01:00
KEYBOARD_STRING = clipboard_get_text();
2022-11-21 06:38:44 +01:00
2022-01-13 05:24:03 +01:00
if(keyboard_check_pressed(vk_escape) || keyboard_check_pressed(vk_enter)) {
2023-01-01 02:06:02 +01:00
} else if(KEYBOARD_PRESSED == vk_backspace) {
2022-01-13 05:24:03 +01:00
if(cursor_select == -1) {
var str_before = string_copy(_input_text, 1, cursor - 1);
var str_after = string_copy(_input_text, cursor + 1, string_length(_input_text) - cursor);
_input_text = str_before + str_after;
} else {
var minc = min(cursor, cursor_select);
var maxc = max(cursor, cursor_select);
var str_before = string_copy(_input_text, 1, minc);
2022-01-26 13:02:30 +01:00
var str_after = string_copy(_input_text, maxc + 1, string_length(_input_text) - maxc);
2022-01-13 05:24:03 +01:00
2022-01-26 13:02:30 +01:00
cursor = minc + 1;
2022-01-13 05:24:03 +01:00
_input_text = str_before + str_after;
}
cursor_select = -1;
move_cursor(-1);
2023-01-01 02:06:02 +01:00
} else if(KEYBOARD_PRESSED == vk_delete || (keyboard_check_pressed(ord("X")) && key_mod_press(CTRL) && cursor_select != -1)) {
2022-01-13 05:24:03 +01:00
if(cursor_select == -1) {
var str_before = string_copy(_input_text, 1, cursor);
var str_after = string_copy(_input_text, cursor + 2, string_length(_input_text) - cursor - 1);
2022-09-21 06:09:40 +02:00
2022-01-13 05:24:03 +01:00
_input_text = str_before + str_after;
} else {
var minc = min(cursor, cursor_select);
var maxc = max(cursor, cursor_select);
var str_before = string_copy(_input_text, 1, minc);
2022-01-26 13:02:30 +01:00
var str_after = string_copy(_input_text, maxc + 1, string_length(_input_text) - maxc);
2022-01-13 05:24:03 +01:00
2022-01-26 13:02:30 +01:00
cursor = minc;
2022-01-13 05:24:03 +01:00
_input_text = str_before + str_after;
}
cursor_select = -1;
2022-12-12 09:08:03 +01:00
} else if(KEYBOARD_STRING != "") {
var ch = KEYBOARD_STRING;
2022-01-13 05:24:03 +01:00
if(cursor_select == -1) {
var str_before = string_copy(_input_text, 1, cursor);
var str_after = string_copy(_input_text, cursor + 1, string_length(_input_text) - cursor);
_input_text = str_before + ch + str_after;
move_cursor(string_length(ch));
} else {
var minc = min(cursor, cursor_select);
var maxc = max(cursor, cursor_select);
var str_before = string_copy(_input_text, 1, minc);
var str_after = string_copy(_input_text, maxc + 1, string_length(_input_text) - maxc);
_input_text = str_before + ch + str_after;
2022-01-26 13:02:30 +01:00
cursor = minc + string_length(ch);
2022-01-13 05:24:03 +01:00
}
cursor_select = -1;
}
}
2022-12-12 09:08:03 +01:00
KEYBOARD_STRING = "";
2022-01-13 05:24:03 +01:00
keyboard_lastkey = -1;
#endregion
2022-12-22 03:09:55 +01:00
if(keyboard_check_pressed(vk_home)) {
2023-02-14 02:51:14 +01:00
if(key_mod_press(SHIFT)) {
2022-12-22 03:09:55 +01:00
if(cursor_select == -1)
cursor_select = cursor;
} else
cursor_select = -1;
move_cursor(-cursor);
} else if(keyboard_check_pressed(vk_end)) {
2023-02-14 02:51:14 +01:00
if(key_mod_press(SHIFT)) {
2022-12-22 03:09:55 +01:00
if(cursor_select == -1)
cursor_select = cursor;
} else
cursor_select = -1;
move_cursor(string_length(_input_text) - cursor);
} else if(keyboard_check_pressed(vk_escape)) {
2022-12-18 03:20:38 +01:00
_input_text = _last_text;
2023-01-17 08:11:55 +01:00
deactivate();
} else if(keyboard_check_pressed(vk_enter))
deactivate();
else if(auto_update && keyboard_check_pressed(vk_anykey))
2022-01-13 05:24:03 +01:00
apply();
}
2022-01-24 02:21:25 +01:00
static display_text = function(_x, _y, _text, _w, _format, _m = -1) {
2023-02-17 04:48:54 +01:00
_text = string_real(_text);
2023-02-14 02:51:14 +01:00
BLEND_OVERRIDE;
2023-01-17 08:11:55 +01:00
if(!interactable) draw_set_alpha(0.5);
2023-01-01 02:06:02 +01:00
2022-01-13 05:24:03 +01:00
switch(_format) {
case VALUE_DISPLAY._default :
2023-01-01 02:06:02 +01:00
draw_set_text(font == noone? f_p0 : font, fa_left, fa_top, color);
2023-01-09 03:14:20 +01:00
draw_text(_x + disp_x, _y, _text);
2022-01-13 05:24:03 +01:00
break;
case VALUE_DISPLAY.export_format :
2023-01-01 02:06:02 +01:00
draw_set_text(font == noone? f_p0 : font, fa_left, fa_top, color);
2023-01-09 03:14:20 +01:00
var _x0 = _x + disp_x, ch = "", len = string_length(_text), i = 1;
2022-01-13 05:24:03 +01:00
var cc = draw_get_color();
var str = "", _comm = false;
while(i <= len) {
ch = string_char_at(_text, i);
if(ch == "%")
_comm = true;
if(!_comm) {
2023-01-01 02:06:02 +01:00
draw_text(_x0, 0, ch);
2022-01-13 05:24:03 +01:00
_x0 += string_width(ch);
} else {
str += ch;
switch(ch) {
2022-11-18 03:20:31 +01:00
case "d" : draw_set_color(COLORS.widget_text_dec_d); break;
case "n" : draw_set_color(COLORS.widget_text_dec_n); break;
case "e" : draw_set_color(COLORS.widget_text_dec_e); break;
case "f" : draw_set_color(COLORS.widget_text_dec_f); break;
case "i" : draw_set_color(COLORS.widget_text_dec_i); break;
2022-01-13 05:24:03 +01:00
}
switch(ch) {
case "d" : case "n" : case "e" : case "f" : case "i" :
2023-01-01 02:06:02 +01:00
draw_text(_x0, 0, str);
2022-01-13 05:24:03 +01:00
_x0 += string_width(str);
_comm = false;
str = "";
draw_set_color(cc);
break;
}
}
i++;
}
2023-02-14 02:51:14 +01:00
draw_text(_x0, _y, str);
break;
case VALUE_DISPLAY.node_title :
draw_set_text(font == noone? f_p0 : font, fa_left, fa_top, color);
var _x0 = _x + disp_x, ch = "", len = string_length(_text), i = 1;
var cc = draw_get_color();
var str = "", title = 0;
while(i <= len) {
ch = string_char_at(_text, i);
if(ch == "[")
draw_set_color(COLORS._main_text_sub);
draw_text(_x0, 0, ch);
_x0 += string_width(ch);
if(ch == "]")
draw_set_color(cc);
i++;
}
2022-01-13 05:24:03 +01:00
draw_text(_x0, _y, str);
break;
}
2023-01-17 08:11:55 +01:00
draw_set_alpha(1);
2023-02-14 02:51:14 +01:00
BLEND_NORMAL;
2023-01-09 03:14:20 +01:00
var _xx = _x, _ch, _chw;
var target = -999;
2023-01-01 02:06:02 +01:00
if(!sliding && _m != -1) {
2022-01-13 05:24:03 +01:00
for( var i = 1; i <= string_length(_text); i++ ) {
_ch = string_char_at(_text, i);
_chw = string_width(_ch);
if(_m < _xx + _chw / 2) {
target = i - 1;
break;
} else if(_m < _xx + _chw) {
target = i;
break;
}
_xx += _chw;
}
}
if(target != -999) {
2022-12-10 05:06:01 +01:00
if(mouse_press(mb_left, active) || click_block == 1) {
2022-01-13 05:24:03 +01:00
cursor_select = -1;
cursor = target;
click_block = 0;
2022-12-10 05:06:01 +01:00
} else if(mouse_click(mb_left, active) && cursor != target) {
2022-01-13 05:24:03 +01:00
cursor_select = target;
}
}
}
2023-05-03 21:42:17 +02:00
static draw = function(_x, _y, _w, _h, _text = "", _m = mouse_ui, _format = VALUE_DISPLAY._default, halign = fa_left, valign = fa_top) {
2023-01-17 08:11:55 +01:00
x = _x;
y = _y;
w = _w;
h = _h;
2023-04-21 19:08:10 +02:00
switch(halign) {
case fa_left: _x = _x; break;
case fa_center: _x = _x - _w / 2; break;
case fa_right: _x = _x - _w; break;
}
switch(valign) {
case fa_top: _y = _y; break;
case fa_center: _y = _y - _h / 2; break;
case fa_bottom: _y = _y - _h; break;
}
2023-01-01 02:06:02 +01:00
if(extras && instanceof(extras) == "buttonClass") {
2023-03-25 12:27:04 +01:00
extras.setActiveFocus(hover, active);
2023-01-01 02:06:02 +01:00
extras.draw(_x + _w - ui(32), _y + _h / 2 - ui(32 / 2), ui(32), ui(32), _m, THEME.button_hide);
_w -= ui(40);
}
2023-02-28 09:43:01 +01:00
draw_set_font(font == noone? f_p0 : font);
2023-05-03 21:42:17 +02:00
var _raw_text = _text;
2023-02-28 09:43:01 +01:00
_text = string_real(_text);
_current_text = _text;
2022-01-13 05:24:03 +01:00
if(sliding > 0) {
2022-12-23 04:45:52 +01:00
var dx = _m[0] - slide_mx;
var dy = -(_m[1] - slide_my);
2022-12-19 13:35:30 +01:00
if(sliding == 1 && (abs(dx) > 16 || abs(dy) > 16)) {
2022-01-13 05:24:03 +01:00
sliding = 2;
2022-12-19 13:35:30 +01:00
slide_mx = _m[0];
slide_my = _m[1];
2023-01-09 03:14:20 +01:00
dx = 0;
dy = 0;
2022-12-19 13:35:30 +01:00
}
2022-01-13 05:24:03 +01:00
if(sliding == 2) {
2022-12-23 04:45:52 +01:00
var _ip = _input_text;
2022-12-19 13:35:30 +01:00
2022-12-23 04:45:52 +01:00
if(!MOUSE_WRAPPING) {
var spd = (abs(dx) > abs(dy)? dx : dy) * slide_speed;
2023-03-05 07:16:44 +01:00
2023-02-14 02:51:14 +01:00
if(key_mod_press(ALT))
2022-12-23 04:45:52 +01:00
spd /= 10;
if(key_mod_press(CTRL))
spd *= 10;
2023-02-17 04:48:54 +01:00
_input_text = string_real(toNumber(_input_text) + spd);
2022-12-23 04:45:52 +01:00
2023-02-14 02:51:14 +01:00
if(apply())
UNDO_HOLDING = true;
2022-12-18 03:20:38 +01:00
}
2022-01-13 05:24:03 +01:00
2022-12-23 04:45:52 +01:00
if(MOUSE_WRAPPING || _input_text != _ip) {
2022-12-19 13:35:30 +01:00
slide_mx = _m[0];
slide_my = _m[1];
}
2022-12-23 04:45:52 +01:00
setMouseWrap();
2023-01-17 08:11:55 +01:00
if(mouse_release(mb_left))
deactivate();
2022-01-13 05:24:03 +01:00
}
2023-02-14 02:51:14 +01:00
if(mouse_release(mb_left)) {
2022-01-13 05:24:03 +01:00
sliding = 0;
2023-02-14 02:51:14 +01:00
UNDO_HOLDING = false;
}
2022-01-13 05:24:03 +01:00
}
2023-02-28 09:43:01 +01:00
var tb_surf_x = _x + ui(8);
var tb_surf_y = _y;
2023-01-17 08:11:55 +01:00
2023-01-09 03:14:20 +01:00
draw_set_text(font == noone? f_p0 : font, fa_left, fa_top);
2023-01-01 02:06:02 +01:00
var tx = _x;
switch(align) {
case fa_left : tx = _x + ui(8); break;
case fa_center : tx = _x + _w / 2; break;
case fa_right : tx = _x + _w - ui(8); break;
}
2023-01-04 02:30:04 +01:00
text_surface = surface_verify(text_surface, _w - ui(16), _h);
2023-03-05 07:16:44 +01:00
draw_sprite_stretched_ext(THEME.textbox, 3, _x, _y, _w, _h, boxColor, 1);
2023-01-09 03:14:20 +01:00
disp_x = lerp_float(disp_x, disp_x_to, 5);
2023-01-01 02:06:02 +01:00
2023-03-26 07:13:36 +02:00
var hoverRect = point_in_rectangle(_m[0], _m[1], _x, _y, _x + _w, _y + _h);
2023-01-17 08:11:55 +01:00
if(self == WIDGET_CURRENT) {
2023-04-08 20:06:27 +02:00
if(sprite_index == -1)
draw_sprite_stretched_ext(THEME.textbox, 2, _x, _y, _w, _h, COLORS._main_accent, 1);
else
draw_sprite_stretched(THEME.textbox, sprite_index, _x, _y, _w, _h);
2022-01-13 05:24:03 +01:00
editText();
2023-01-09 03:14:20 +01:00
#region cursor position
2023-01-01 02:06:02 +01:00
if(KEYBOARD_PRESSED == vk_left) {
2023-02-14 02:51:14 +01:00
if(key_mod_press(SHIFT)) {
2022-01-13 05:24:03 +01:00
if(cursor_select == -1)
cursor_select = cursor;
2023-01-17 08:11:55 +01:00
} else if(cursor_select != -1)
cursor_select = -1;
else
move_cursor(-1);
2022-01-13 05:24:03 +01:00
}
2023-04-08 20:06:27 +02:00
2023-01-01 02:06:02 +01:00
if(KEYBOARD_PRESSED == vk_right) {
2023-02-14 02:51:14 +01:00
if(key_mod_press(SHIFT)) {
2022-01-13 05:24:03 +01:00
if(cursor_select == -1)
cursor_select = cursor;
2023-01-17 08:11:55 +01:00
} else if(cursor_select != -1)
2022-01-13 05:24:03 +01:00
cursor_select = -1;
2023-01-17 08:11:55 +01:00
else
move_cursor(1);
2022-01-13 05:24:03 +01:00
}
#endregion
#region multiplier
2023-02-14 02:51:14 +01:00
if(_w > ui(80) && input == TEXTBOX_INPUT.number) {
2022-11-18 03:20:31 +01:00
draw_set_text(f_p0b, fa_left, fa_center, COLORS._main_text_sub);
2022-01-13 05:24:03 +01:00
draw_set_alpha(0.5);
2023-01-04 02:30:04 +01:00
if(hover && point_in_rectangle(_m[0], _m[1], _x, _y, _x + ui(32), _y + _h)) {
2022-01-13 05:24:03 +01:00
draw_set_alpha(1);
2022-12-10 05:06:01 +01:00
if(mouse_press(mb_left, active)) {
2023-02-17 04:48:54 +01:00
if(key_mod_press(ALT)) _input_text = string_real(toNumber(_input_text) / 2);
else _input_text = string_real(toNumber(_input_text) * 2);
2022-11-22 14:25:39 +01:00
apply();
2022-01-13 05:24:03 +01:00
}
}
2023-02-14 02:51:14 +01:00
if(key_mod_press(ALT))
2023-01-04 02:30:04 +01:00
draw_text(_x + ui(8), _y + _h / 2, "/2");
2022-01-13 05:24:03 +01:00
else
2023-01-04 02:30:04 +01:00
draw_text(_x + ui(8), _y + _h / 2, "x2");
2022-01-13 05:24:03 +01:00
draw_set_alpha(1);
}
#endregion
#region draw
2023-02-28 09:43:01 +01:00
var txt = _input_text;
2022-11-18 03:20:31 +01:00
draw_set_text(font == noone? f_p0 : font, fa_left, fa_top);
2023-01-01 02:06:02 +01:00
var tw = string_width(txt);
var th = string_height(txt);
2022-01-13 05:24:03 +01:00
2023-01-01 02:06:02 +01:00
var cs = string_copy(txt, 1, cursor);
2022-01-13 05:24:03 +01:00
var c_w = string_width(cs);
2023-01-01 02:06:02 +01:00
var c_y0 = _y + _h / 2 - th / 2;
var c_y1 = _y + _h / 2 + th / 2;
2023-01-09 03:14:20 +01:00
switch(align) {
case fa_left :
disp_x_min = -max(0, tw - _w + ui(16 + 8));
disp_x_max = 0;
break;
case fa_center :
disp_x_min = -max(0, tw - _w + ui(16 + 8)) / 2;
disp_x_max = max(0, tw - _w + ui(16 + 8)) / 2;
tx -= tw / 2;
break;
case fa_right :
disp_x_min = 0;
disp_x_max = max(0, tw - _w + ui(16 + 8));
tx -= tw;
break;
}
2023-01-01 02:06:02 +01:00
cursor_pos_to = disp_x + tx + c_w;
if(cursor_pos_to < _x)
disp_x_to += _w - ui(16);
if(cursor_pos_to > _x + _w - ui(16))
disp_x_to -= _w - ui(16);
2022-12-10 05:06:01 +01:00
cursor_pos = cursor_pos == 0? cursor_pos_to : lerp_float(cursor_pos, cursor_pos_to, 4);
2022-01-13 05:24:03 +01:00
2023-01-09 03:14:20 +01:00
if(cursor_select > -1) { //draw highlight
2022-11-18 03:20:31 +01:00
draw_set_color(COLORS.widget_text_highlight);
2023-01-01 02:06:02 +01:00
var x1 = tx + string_width(string_copy(txt, 1, cursor_select));
2022-01-13 05:24:03 +01:00
2023-04-08 20:06:27 +02:00
draw_roundrect_ext(cursor_pos, c_y0, x1, c_y1, THEME_VALUE.highlight_corner_radius, THEME_VALUE.highlight_corner_radius, 0);
2022-01-13 05:24:03 +01:00
}
var _mx = -1;
2022-01-26 13:02:30 +01:00
var _my = -1;
2023-03-26 07:13:36 +02:00
if(mouse_press(mb_any, active) && hover && hoverRect) {
2022-01-13 05:24:03 +01:00
_mx = _m[0];
2022-01-26 13:02:30 +01:00
_my = _m[1];
2022-01-13 05:24:03 +01:00
}
2023-01-09 03:14:20 +01:00
surface_set_target(text_surface);
2023-03-19 09:17:39 +01:00
DRAW_CLEAR
2023-02-28 09:43:01 +01:00
display_text(tx - tb_surf_x, _h / 2 - th / 2, txt, _w - ui(4), _format, _mx);
2023-01-09 03:14:20 +01:00
surface_reset_target();
2023-02-28 09:43:01 +01:00
draw_surface(text_surface, tb_surf_x, tb_surf_y);
2023-01-09 03:14:20 +01:00
2022-11-18 03:20:31 +01:00
draw_set_color(COLORS._main_text_accent);
2022-01-13 05:24:03 +01:00
draw_line_width(cursor_pos, c_y0, cursor_pos, c_y1, 2);
#endregion
2023-01-09 03:14:20 +01:00
disp_x_to = clamp(disp_x_to, disp_x_min, disp_x_max);
2023-01-01 02:06:02 +01:00
2023-01-17 08:11:55 +01:00
if(!point_in_rectangle(_m[0], _m[1], _x, _y, _x + _w, _y + _h) && mouse_press(mb_left))
deactivate();
2022-01-13 05:24:03 +01:00
} else {
2022-11-18 03:20:31 +01:00
draw_set_text(font == noone? f_p0 : font, fa_left, fa_center);
2023-05-03 21:42:17 +02:00
var _display_text = _raw_text;
2023-02-28 09:43:01 +01:00
if(input == TEXTBOX_INPUT.number) {
var dig = floor(_w / string_width("0")) - 3;
_display_text = string_real(_display_text, dig);
}
var tw = string_width(_display_text);
var th = string_height(_display_text);
2022-01-13 05:24:03 +01:00
switch(align) {
case fa_left : break;
2023-01-01 02:06:02 +01:00
case fa_center : tx -= tw / 2; break;
case fa_right : tx -= tw; break;
2022-01-13 05:24:03 +01:00
}
2023-03-26 07:13:36 +02:00
if(hover && hoverRect) {
2022-01-13 05:24:03 +01:00
if(hide)
2023-03-08 07:35:51 +01:00
draw_sprite_stretched_ext(THEME.textbox, 1, _x, _y, _w, _h, boxColor, 0.5);
2022-01-13 05:24:03 +01:00
else
2023-04-16 11:53:46 +02:00
draw_sprite_stretched_ext(THEME.textbox, 1, _x, _y, _w, _h, boxColor, 0.5 + 0.5 * interactable);
2023-01-17 08:11:55 +01:00
if(mouse_press(mb_left, active))
activate();
2023-02-14 02:51:14 +01:00
if(input == TEXTBOX_INPUT.number && key_mod_press(SHIFT)) {
var amo = slide_speed;
if(key_mod_press(CTRL)) amo *= 10;
if(key_mod_press(ALT)) amo /= 10;
2023-04-07 21:25:27 +02:00
if(mouse_wheel_down()) onModify(toNumber(_text) + amo * SCROLL_SPEED);
if(mouse_wheel_up()) onModify(toNumber(_text) - amo * SCROLL_SPEED);
2023-02-14 02:51:14 +01:00
}
2023-01-17 08:11:55 +01:00
} else if(!hide)
2023-03-08 07:35:51 +01:00
draw_sprite_stretched_ext(THEME.textbox, 0, _x, _y, _w, _h, boxColor, 0.5 + 0.5 * interactable);
2022-01-13 05:24:03 +01:00
2022-12-27 04:00:50 +01:00
if(slidable) {
if(_w > ui(64))
2023-01-04 02:30:04 +01:00
draw_sprite_ui_uniform(THEME.text_slider, 0, _x + ui(20), _y + _h / 2, 1, COLORS._main_icon, 0.5);
2022-12-27 04:00:50 +01:00
2023-02-14 02:51:14 +01:00
if(hover && point_in_rectangle(_m[0], _m[1], _x, _y, _x + _w, _y + _h) && mouse_press(mb_left, active)) {
sliding = 1;
2022-12-19 13:35:30 +01:00
2023-02-14 02:51:14 +01:00
slide_mx = _m[0];
slide_my = _m[1];
2022-01-13 05:24:03 +01:00
}
}
2023-01-01 02:06:02 +01:00
2023-01-09 03:14:20 +01:00
surface_set_target(text_surface);
2023-03-19 09:17:39 +01:00
DRAW_CLEAR
2023-02-28 09:43:01 +01:00
display_text(tx - tb_surf_x, _h / 2 - th / 2, _display_text, _w - ui(4), _format);
2023-01-09 03:14:20 +01:00
surface_reset_target();
2023-02-28 09:43:01 +01:00
draw_surface(text_surface, tb_surf_x, tb_surf_y);
2022-01-13 05:24:03 +01:00
}
2023-03-26 07:13:36 +02:00
if(DRAGGING && (DRAGGING.type == "Text" || DRAGGING.type == "Number") && hover && hoverRect) {
draw_sprite_stretched_ext(THEME.ui_panel_active, 0, _x, _y, _w, _h, COLORS._main_value_positive, 1);
if(mouse_release(mb_left))
onModify(DRAGGING.data);
}
2022-01-26 13:02:30 +01:00
2023-03-26 07:13:36 +02:00
resetFocus();
2022-09-21 06:09:40 +02:00
sprite_index = -1;
2023-01-04 02:30:04 +01:00
return _h;
2022-01-13 05:24:03 +01:00
}
}