2024-07-26 09:38:39 +02:00
|
|
|
enum TEXTBOX_INPUT { text, number }
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-10-03 07:14:28 +02:00
|
|
|
function textBox(_input, _onModify) : textInput(_input, _onModify) constructor {
|
2024-03-27 11:51:14 +01:00
|
|
|
onRelease = noone;
|
|
|
|
|
2024-05-01 14:28:15 +02:00
|
|
|
align = _input == TEXTBOX_INPUT.number? fa_center : fa_left;
|
|
|
|
hide = false;
|
|
|
|
color = COLORS._main_text;
|
2024-01-23 11:01:19 +01:00
|
|
|
boxColor = c_white;
|
2024-10-12 08:35:36 +02:00
|
|
|
postBlend = c_white;
|
|
|
|
postAlpha = 1;
|
2024-01-23 11:01:19 +01:00
|
|
|
format = TEXT_AREA_FORMAT._default;
|
|
|
|
precision = 5;
|
2024-06-30 08:52:55 +02:00
|
|
|
padding = ui(8);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-10-21 05:35:29 +02:00
|
|
|
unit = noone;
|
2024-03-26 04:03:45 +01:00
|
|
|
suffix = "";
|
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
no_empty = true;
|
|
|
|
|
2024-07-26 09:38:39 +02:00
|
|
|
slidable = true;
|
2024-01-16 09:56:20 +01:00
|
|
|
sliding = false;
|
2024-04-18 08:01:23 +02:00
|
|
|
slidePen = false;
|
2024-03-26 04:03:45 +01:00
|
|
|
slide_delta = 0;
|
2024-01-16 09:56:20 +01:00
|
|
|
slide_int = false;
|
2024-07-26 10:30:29 +02:00
|
|
|
slide_speed = 1 / 250;
|
2024-07-26 09:38:39 +02:00
|
|
|
|
2024-03-27 11:51:14 +01:00
|
|
|
slide_snap = 0;
|
2024-01-16 11:00:39 +01:00
|
|
|
slide_range = noone;
|
2024-03-24 04:58:08 +01:00
|
|
|
curr_range = [ 0, 1 ];
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-07-26 10:30:29 +02:00
|
|
|
slider_dx = 0;
|
2024-07-26 09:38:39 +02:00
|
|
|
slider_dy = 0;
|
|
|
|
slider_my = 0;
|
|
|
|
slider_mulp = 0;
|
2024-03-31 11:10:14 +02:00
|
|
|
slider_def_val = 0;
|
|
|
|
slider_cur_val = 0;
|
2024-07-26 09:38:39 +02:00
|
|
|
slider_cur_del = 0;
|
|
|
|
slider_object = noone;
|
2024-03-31 11:10:14 +02:00
|
|
|
|
2024-07-03 05:32:12 +02:00
|
|
|
label = "";
|
|
|
|
labelColor = COLORS._main_text_sub;
|
2024-06-30 08:52:55 +02:00
|
|
|
highlight_color = -1;
|
|
|
|
highlight_alpha = 1;
|
2024-01-23 11:01:19 +01:00
|
|
|
|
2022-01-26 13:02:30 +01:00
|
|
|
starting_char = 1;
|
|
|
|
|
2023-01-17 08:11:55 +01:00
|
|
|
_current_text = "";
|
2023-08-13 13:10:20 +02:00
|
|
|
_input_text = "";
|
2024-07-27 04:07:29 +02:00
|
|
|
_input_value = 0;
|
2023-08-13 13:10:20 +02:00
|
|
|
_last_text = "";
|
2023-05-03 21:42:17 +02:00
|
|
|
current_value = "";
|
2023-12-11 05:45:12 +01:00
|
|
|
_disp_text = "";
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
cursor = 0;
|
|
|
|
cursor_pos = 0;
|
2024-03-27 11:51:14 +01:00
|
|
|
cursor_pos_y = 0;
|
2022-01-13 05:24:03 +01:00
|
|
|
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;
|
|
|
|
|
2023-11-25 08:54:35 +01:00
|
|
|
use_range = false;
|
|
|
|
range_min = 0;
|
|
|
|
range_max = 0;
|
|
|
|
|
2023-12-18 04:40:21 +01:00
|
|
|
disp_text_fx = [];
|
|
|
|
|
2022-09-21 06:09:40 +02:00
|
|
|
sprite_index = -1;
|
|
|
|
|
2024-11-23 12:08:44 +01:00
|
|
|
text_surface = noone;
|
2023-01-01 02:06:02 +01:00
|
|
|
|
2024-03-27 11:51:14 +01:00
|
|
|
shake_amount = 0;
|
2024-07-19 12:42:15 +02:00
|
|
|
onDeactivate = -1;
|
2024-03-27 11:51:14 +01:00
|
|
|
|
|
|
|
static setOnRelease = function(release) { onRelease = release; return self; }
|
|
|
|
|
2024-07-11 06:48:33 +02:00
|
|
|
static modifyValue = function(value) {
|
2023-11-25 08:54:35 +01:00
|
|
|
if(input == TEXTBOX_INPUT.number) {
|
|
|
|
if(use_range) value = clamp(value, range_min, range_max);
|
|
|
|
}
|
|
|
|
|
2024-10-05 10:30:21 +02:00
|
|
|
if(onModifyParam == noone) onModify(value);
|
|
|
|
else onModify(value, onModifyParam);
|
2024-07-11 06:48:33 +02:00
|
|
|
}
|
2023-11-25 08:54:35 +01:00
|
|
|
|
2024-07-26 09:38:39 +02:00
|
|
|
static setSlideType = function(_slide_int = false) { slide_int = _slide_int; return self; }
|
|
|
|
static setSlideStep = function(_slide_step = 0) { slide_snap = _slide_step; return self; }
|
|
|
|
static setSlideRange = function(_min = 0, _max = 1) { slide_range = [_min, _max]; return self; }
|
2023-08-29 14:33:44 +02:00
|
|
|
|
2024-07-11 06:48:33 +02:00
|
|
|
static setRange = function(_rng_min, _rng_max) {
|
2023-11-25 08:54:35 +01:00
|
|
|
use_range = true;
|
|
|
|
range_min = _rng_min;
|
|
|
|
range_max = _rng_max;
|
|
|
|
|
|
|
|
return self;
|
2024-07-11 06:48:33 +02:00
|
|
|
}
|
2023-11-25 08:54:35 +01:00
|
|
|
|
2024-07-03 11:34:05 +02:00
|
|
|
static setFont = function(font) { self.font = font; return self; }
|
|
|
|
static setLabel = function(label) { self.label = label; return self; }
|
|
|
|
static setPrecision = function(precision) { self.precision = precision; return self; }
|
|
|
|
static setPadding = function(padding) { self.padding = padding; return self; }
|
|
|
|
static setEmpty = function() { no_empty = false; return self; }
|
2023-04-21 19:08:10 +02:00
|
|
|
|
2024-07-29 10:08:08 +02:00
|
|
|
static activate = function(_def_str = _current_text) {
|
2023-01-17 08:11:55 +01:00
|
|
|
WIDGET_CURRENT = self;
|
|
|
|
WIDGET_CURRENT_SCROLL = parent;
|
|
|
|
parentFocus();
|
|
|
|
|
2024-07-29 10:08:08 +02:00
|
|
|
_input_text = _def_str;
|
|
|
|
_last_text = _def_str;
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2024-07-29 10:08:08 +02:00
|
|
|
cursor = string_length(_def_str);
|
2023-01-17 08:11:55 +01:00
|
|
|
cursor_select = 0;
|
2023-12-01 05:49:44 +01:00
|
|
|
click_block = 1;
|
|
|
|
|
2024-07-27 05:46:16 +02:00
|
|
|
KEYBOARD_STRING = "";
|
2023-01-17 08:11:55 +01:00
|
|
|
keyboard_lastkey = -1;
|
2024-03-02 10:08:44 +01:00
|
|
|
|
|
|
|
if(PEN_USE) keyboard_virtual_show(input == TEXTBOX_INPUT.number? kbv_type_numbers : kbv_type_default, kbv_returnkey_default, kbv_autocapitalize_none, true);
|
2024-07-11 06:48:33 +02:00
|
|
|
}
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2024-07-11 06:48:33 +02:00
|
|
|
static deactivate = function() {
|
2023-11-20 05:10:55 +01:00
|
|
|
if(WIDGET_CURRENT != self) return;
|
|
|
|
|
2023-01-17 08:11:55 +01:00
|
|
|
apply();
|
2024-04-08 07:13:46 +02:00
|
|
|
if(is_callable(onRelease))
|
|
|
|
apply(true);
|
|
|
|
|
2023-01-17 08:11:55 +01:00
|
|
|
WIDGET_CURRENT = noone;
|
|
|
|
UNDO_HOLDING = false;
|
2024-03-02 10:08:44 +01:00
|
|
|
|
|
|
|
if(PEN_USE) keyboard_virtual_hide();
|
2024-07-19 12:42:15 +02:00
|
|
|
|
|
|
|
if(onDeactivate != -1) onDeactivate();
|
2024-07-11 06:48:33 +02:00
|
|
|
}
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2024-07-11 06:48:33 +02:00
|
|
|
static onKey = function(key) {
|
2023-06-20 19:43:19 +02:00
|
|
|
if(KEYBOARD_PRESSED == vk_left) {
|
|
|
|
if(key_mod_press(SHIFT)) {
|
|
|
|
if(cursor_select == -1)
|
|
|
|
cursor_select = cursor;
|
|
|
|
} else if(cursor_select != -1)
|
|
|
|
cursor_select = -1;
|
2023-12-01 05:49:44 +01:00
|
|
|
|
|
|
|
move_cursor(-1);
|
2023-06-20 19:43:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(KEYBOARD_PRESSED == vk_right) {
|
|
|
|
if(key_mod_press(SHIFT)) {
|
|
|
|
if(cursor_select == -1)
|
|
|
|
cursor_select = cursor;
|
|
|
|
} else if(cursor_select != -1)
|
|
|
|
cursor_select = -1;
|
2023-12-01 05:49:44 +01:00
|
|
|
|
|
|
|
move_cursor(1);
|
2023-06-20 19:43:19 +02:00
|
|
|
}
|
2024-07-11 06:48:33 +02:00
|
|
|
}
|
2023-06-20 19:43:19 +02:00
|
|
|
|
2024-07-11 06:48:33 +02:00
|
|
|
static apply = function(release = false) {
|
2024-06-06 09:54:13 +02:00
|
|
|
var _val = _input_text;
|
2023-02-14 02:51:14 +01:00
|
|
|
disp_x_to = 0;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-11-07 06:01:38 +01:00
|
|
|
if(input == TEXTBOX_INPUT.number)
|
2024-06-06 09:54:13 +02:00
|
|
|
_val = evaluateFunction(_input_text);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-06-06 09:54:13 +02:00
|
|
|
if(no_empty && _val == "")
|
|
|
|
_val = _last_text;
|
|
|
|
current_value = _val;
|
2023-05-03 21:42:17 +02:00
|
|
|
|
2024-03-31 11:10:14 +02:00
|
|
|
if(release) {
|
|
|
|
if(is_callable(onRelease)) {
|
2024-06-06 09:54:13 +02:00
|
|
|
var _modi = onRelease(_val);
|
2024-03-31 11:10:14 +02:00
|
|
|
if(_modi && IS_PATREON) shake_amount = PREFERENCES.textbox_shake / 4;
|
|
|
|
return _modi;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if(is_callable(onModify)) {
|
2024-10-05 10:30:21 +02:00
|
|
|
var _modi = onModifyParam == noone? onModify(_val) : onModify(_val, onModifyParam);
|
|
|
|
|
2024-03-31 11:10:14 +02:00
|
|
|
if(_modi && IS_PATREON) shake_amount = PREFERENCES.textbox_shake / 4;
|
|
|
|
return _modi;
|
|
|
|
}
|
2024-03-27 11:51:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(IS_PATREON) shake_amount = PREFERENCES.textbox_shake / 4;
|
2023-02-14 02:51:14 +01:00
|
|
|
return false;
|
2024-07-11 06:48:33 +02:00
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-07-11 06:48:33 +02: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);
|
2024-07-11 06:48:33 +02:00
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-07-11 06:48:33 +02:00
|
|
|
static editText = function() {
|
2023-12-15 12:56:36 +01:00
|
|
|
var edited = false;
|
|
|
|
|
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);
|
2024-02-25 11:02:10 +01:00
|
|
|
clipboard_set_text(string_copy(_input_text, minc + 1, maxc - minc));
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
} else {
|
2023-12-15 12:56:36 +01:00
|
|
|
if(key_mod_press(CTRL) && keyboard_check_pressed(ord("V"))) {
|
2024-09-23 13:27:31 +02:00
|
|
|
var _ctxt = clipboard_get_text();
|
|
|
|
_ctxt = string_replace_all(_ctxt, "\t", " ");
|
|
|
|
KEYBOARD_STRING = _ctxt;
|
2023-12-15 12:56:36 +01:00
|
|
|
edited = true;
|
|
|
|
}
|
|
|
|
|
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) {
|
2023-09-08 21:09:09 +02:00
|
|
|
var str_before, str_after;
|
|
|
|
|
|
|
|
if(key_mod_press(CTRL)) {
|
|
|
|
var _c = cursor - 1;
|
|
|
|
while(_c > 0) {
|
|
|
|
var ch = string_char_at(_input_text, _c);
|
|
|
|
if(breakCharacter(ch)) break;
|
|
|
|
_c--;
|
|
|
|
}
|
|
|
|
|
|
|
|
str_before = string_copy(_input_text, 1, _c);
|
|
|
|
str_after = string_copy(_input_text, cursor + 1, string_length(_input_text) - cursor);
|
|
|
|
cursor = _c + 1;
|
|
|
|
} else {
|
|
|
|
str_before = string_copy(_input_text, 1, cursor - 1);
|
|
|
|
str_after = string_copy(_input_text, cursor + 1, string_length(_input_text) - cursor);
|
|
|
|
}
|
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 + 1;
|
2022-01-13 05:24:03 +01:00
|
|
|
_input_text = str_before + str_after;
|
|
|
|
}
|
|
|
|
|
2023-12-15 12:56:36 +01:00
|
|
|
edited = true;
|
2022-01-13 05:24:03 +01:00
|
|
|
cursor_select = -1;
|
|
|
|
move_cursor(-1);
|
2024-09-12 12:42:35 +02:00
|
|
|
|
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;
|
|
|
|
}
|
2023-12-15 12:56:36 +01:00
|
|
|
|
|
|
|
edited = true;
|
2022-01-13 05:24:03 +01:00
|
|
|
cursor_select = -1;
|
2024-09-12 12:42:35 +02:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-12-15 12:56:36 +01:00
|
|
|
edited = true;
|
2022-01-13 05:24:03 +01:00
|
|
|
cursor_select = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-18 04:40:21 +01:00
|
|
|
KEYBOARD_STRING = "";
|
2022-01-13 05:24:03 +01:00
|
|
|
keyboard_lastkey = -1;
|
|
|
|
#endregion
|
2023-07-17 19:58:33 +02:00
|
|
|
|
|
|
|
if(keyboard_check_pressed(vk_left)) onKey(vk_left);
|
|
|
|
if(keyboard_check_pressed(vk_right)) onKey(vk_right);
|
2023-11-21 11:54:45 +01:00
|
|
|
|
|
|
|
if(input == TEXTBOX_INPUT.number) {
|
|
|
|
var _inc = 1;
|
|
|
|
if(key_mod_press(CTRL)) _inc *= 10;
|
|
|
|
if(key_mod_press(ALT)) _inc /= 10;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-11-21 11:54:45 +01:00
|
|
|
if(KEYBOARD_PRESSED == vk_up || keyboard_check_pressed(vk_up)) { _input_text = string(toNumber(_input_text) + _inc); apply(); }
|
|
|
|
if(KEYBOARD_PRESSED == vk_down || keyboard_check_pressed(vk_down)) { _input_text = string(toNumber(_input_text) - _inc); apply(); }
|
|
|
|
}
|
|
|
|
|
2024-03-27 11:51:14 +01:00
|
|
|
if(edited) {
|
|
|
|
typing = 100;
|
|
|
|
|
|
|
|
if(IS_PATREON) {
|
|
|
|
shake_amount = PREFERENCES.textbox_shake;
|
|
|
|
repeat(PREFERENCES.textbox_particle) spawn_particle(rx + cursor_pos, ry + cursor_pos_y + random(16), 8);
|
|
|
|
}
|
|
|
|
}
|
2023-12-18 04:40:21 +01:00
|
|
|
|
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);
|
2024-04-08 07:13:46 +02:00
|
|
|
|
2022-12-22 03:09:55 +01:00
|
|
|
} 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);
|
2024-04-08 07:13:46 +02:00
|
|
|
|
2022-12-22 03:09:55 +01:00
|
|
|
} 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();
|
2024-04-08 07:13:46 +02:00
|
|
|
|
|
|
|
} else if(keyboard_check_pressed(vk_enter)) {
|
2023-01-17 08:11:55 +01:00
|
|
|
deactivate();
|
2024-04-08 07:13:46 +02:00
|
|
|
|
|
|
|
} else if(auto_update && (edited || keyboard_check_pressed(vk_anykey))) {
|
2022-01-13 05:24:03 +01:00
|
|
|
apply();
|
2024-04-08 07:13:46 +02:00
|
|
|
}
|
2024-07-11 06:48:33 +02:00
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-07-11 06:48:33 +02:00
|
|
|
static display_text = function(_x, _y, _text, _w, _m = -1) {
|
2023-10-03 07:14:28 +02:00
|
|
|
draw_set_alpha(0.5 + 0.5 * interactable);
|
2024-03-29 09:13:26 +01:00
|
|
|
_y += ui(1); //Huh?
|
2023-01-01 02:06:02 +01:00
|
|
|
|
2024-07-27 04:07:29 +02:00
|
|
|
var cc = sliding == 2? COLORS._main_accent : color;
|
2024-03-29 09:13:26 +01:00
|
|
|
draw_set_text(font, fa_left, fa_top, cc);
|
2024-07-27 04:07:29 +02:00
|
|
|
|
2024-08-14 09:55:53 +02:00
|
|
|
if(input == TEXTBOX_INPUT.number && string_char_at(_text, 1) != "[") {
|
2024-07-27 04:07:29 +02:00
|
|
|
var _tx = string_pos(".", _text);
|
|
|
|
|
|
|
|
if(_tx != 0) {
|
|
|
|
var _wh = string_copy(_text, 1, _tx - 1);
|
|
|
|
var _dc = string_copy(_text, _tx + 1, string_length(_text) - _tx);
|
|
|
|
|
|
|
|
var _wh_w = string_width(_wh);
|
|
|
|
var _dt_w = string_width(".");
|
|
|
|
|
|
|
|
var _tx = _x + disp_x;
|
|
|
|
if(sliding == 2)
|
|
|
|
_tx = _w / 2 - _wh_w - padding;
|
|
|
|
|
|
|
|
var _inv = _wh == "0" ||_wh == "-0";
|
|
|
|
|
|
|
|
draw_set_alpha(0.5 + (!_inv) * 0.5);
|
|
|
|
draw_text_add(_tx, _y, _wh); _tx += _wh_w;
|
|
|
|
|
|
|
|
draw_set_alpha(0.5 + (_inv) * 0.5);
|
|
|
|
draw_text_add(_tx, _y, "."); _tx += _dt_w;
|
|
|
|
draw_text_add(_tx, _y, _dc);
|
|
|
|
|
2024-10-12 08:35:36 +02:00
|
|
|
} else if(sliding == 2 && align == fa_center) {
|
2024-07-27 04:07:29 +02:00
|
|
|
var _wh_w = string_width(_text);
|
|
|
|
draw_text_add(_w / 2 - _wh_w - padding, _y, _text);
|
|
|
|
|
|
|
|
} else
|
2024-07-31 05:53:28 +02:00
|
|
|
draw_text_add(_x + disp_x, _y, $"{_text}{suffix}");
|
2024-07-27 04:07:29 +02:00
|
|
|
|
|
|
|
} else
|
2024-07-31 05:53:28 +02:00
|
|
|
draw_text_add(_x + disp_x, _y, $"{_text}{suffix}");
|
2024-07-27 04:07:29 +02:00
|
|
|
|
2023-01-17 08:11:55 +01:00
|
|
|
draw_set_alpha(1);
|
2023-01-09 03:14:20 +01:00
|
|
|
|
2024-03-29 09:13:26 +01:00
|
|
|
_disp_text = _text;
|
|
|
|
|
2024-03-27 11:51:14 +01:00
|
|
|
var _xx = _x + disp_x;
|
|
|
|
var _mm = _m;
|
2023-01-09 03:14:20 +01:00
|
|
|
var target = -999;
|
2023-01-01 02:06:02 +01:00
|
|
|
|
2024-03-29 09:13:26 +01:00
|
|
|
if(!sliding && selecting) {
|
2022-01-13 05:24:03 +01:00
|
|
|
for( var i = 1; i <= string_length(_text); i++ ) {
|
2023-10-03 07:14:28 +02:00
|
|
|
var _ch = string_char_at(_text, i);
|
|
|
|
var _chw = string_width(_ch);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-10-03 07:14:28 +02:00
|
|
|
if(_mm < _xx + _chw / 2) {
|
2022-01-13 05:24:03 +01:00
|
|
|
target = i - 1;
|
|
|
|
break;
|
2023-10-03 07:14:28 +02:00
|
|
|
} else if(_mm < _xx + _chw) {
|
2022-01-13 05:24:03 +01:00
|
|
|
target = i;
|
|
|
|
break;
|
|
|
|
}
|
2023-10-03 07:14:28 +02:00
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
_xx += _chw;
|
|
|
|
}
|
2024-03-29 09:13:26 +01:00
|
|
|
|
|
|
|
if(target != -999) {
|
|
|
|
if(!click_block) {
|
|
|
|
if(mouse_press(mb_left, active)) {
|
|
|
|
cursor_select = target;
|
|
|
|
cursor = target;
|
|
|
|
} else if(mouse_click(mb_left, active) && cursor != target)
|
|
|
|
cursor = target;
|
|
|
|
}
|
2023-12-05 09:51:24 +01:00
|
|
|
}
|
|
|
|
|
2024-03-29 09:13:26 +01:00
|
|
|
if(mouse_release(mb_left, active))
|
|
|
|
click_block = false;
|
|
|
|
}
|
2024-07-11 06:48:33 +02:00
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-07-11 06:48:33 +02:00
|
|
|
static drawParam = function(params) {
|
2024-03-27 11:51:14 +01:00
|
|
|
setParam(params);
|
2023-08-13 13:10:20 +02:00
|
|
|
return draw(params.x, params.y, params.w, params.h, params.data, params.m, params.halign, params.valign);
|
2024-07-11 06:48:33 +02:00
|
|
|
}
|
2023-07-30 19:56:53 +02:00
|
|
|
|
2024-10-12 08:35:36 +02:00
|
|
|
static draw = function(_x, _y, _w, _h, _text = "", _m = mouse_ui, halign = fa_left, valign = fa_top) {
|
2023-01-17 08:11:55 +01:00
|
|
|
x = _x;
|
|
|
|
y = _y;
|
|
|
|
w = _w;
|
|
|
|
h = _h;
|
|
|
|
|
2024-03-28 14:18:02 +01:00
|
|
|
hovering = false;
|
2024-03-29 09:13:26 +01:00
|
|
|
if(shake_amount != 0) {
|
|
|
|
_x += irandom_range(-shake_amount, shake_amount);
|
|
|
|
_y += irandom_range(-shake_amount, shake_amount);
|
|
|
|
if(shake_amount) shake_amount--;
|
|
|
|
}
|
2024-03-27 11:51:14 +01:00
|
|
|
|
2024-03-31 11:10:14 +02:00
|
|
|
var drawText = selecting || _h >= line_get_height(font);
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2024-03-28 14:18:02 +01:00
|
|
|
var _bs = min(h, ui(32));
|
|
|
|
|
2024-05-17 15:25:01 +02:00
|
|
|
if(_w - _bs > ui(100) && front_button) {
|
|
|
|
front_button.setFocusHover(active, hover);
|
|
|
|
front_button.draw(_x, _y + _h / 2 - _bs / 2, _bs, _bs, _m, THEME.button_hide);
|
|
|
|
|
|
|
|
_x += _bs + ui(4);
|
|
|
|
_w -= _bs + ui(4);
|
|
|
|
}
|
|
|
|
|
2024-10-21 05:35:29 +02:00
|
|
|
if(unit != noone && unit.reference != noone) {
|
|
|
|
unit.triggerButton.setFocusHover(iactive, ihover);
|
|
|
|
unit.draw(_x + _w - _bs, _y + _h / 2 - _bs / 2, _bs, _bs, _m);
|
|
|
|
_w -= _bs + ui(4);
|
|
|
|
}
|
|
|
|
|
2024-03-29 09:13:26 +01:00
|
|
|
if(_w - _bs > ui(100) && side_button) {
|
2023-10-03 04:29:58 +02:00
|
|
|
side_button.setFocusHover(active, hover);
|
2024-03-28 14:18:02 +01:00
|
|
|
side_button.draw(_x + _w - _bs, _y + _h / 2 - _bs / 2, _bs, _bs, _m, THEME.button_hide);
|
|
|
|
_w -= _bs + ui(4);
|
2023-01-01 02:06:02 +01:00
|
|
|
}
|
|
|
|
|
2023-05-03 21:42:17 +02:00
|
|
|
var _raw_text = _text;
|
2024-03-29 09:13:26 +01:00
|
|
|
_text = string_real(_text);
|
2023-02-28 09:43:01 +01:00
|
|
|
_current_text = _text;
|
|
|
|
|
2024-06-30 08:52:55 +02:00
|
|
|
var tb_surf_x = _x + padding;
|
2023-02-28 09:43:01 +01:00
|
|
|
var tb_surf_y = _y;
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2023-01-01 02:06:02 +01:00
|
|
|
var tx = _x;
|
|
|
|
switch(align) {
|
2024-06-30 08:52:55 +02:00
|
|
|
case fa_left : tx = _x + padding; break;
|
2024-03-29 05:20:49 +01:00
|
|
|
case fa_center : tx = _x + _w / 2; break;
|
2024-06-30 08:52:55 +02:00
|
|
|
case fa_right : tx = _x + _w - padding; break;
|
2023-01-01 02:06:02 +01:00
|
|
|
}
|
|
|
|
|
2024-03-31 11:10:14 +02:00
|
|
|
if(drawText) {
|
2024-06-30 08:52:55 +02:00
|
|
|
var _update = !surface_valid(text_surface, _w - padding * 2, _h);
|
|
|
|
if(_update) text_surface = surface_verify(text_surface, _w - padding * 2, _h);
|
2024-03-31 11:10:14 +02:00
|
|
|
}
|
2023-12-11 05:45:12 +01:00
|
|
|
|
2024-03-24 04:58:08 +01:00
|
|
|
if(!hide) {
|
|
|
|
draw_sprite_stretched_ext(THEME.textbox, 3, _x, _y, _w, _h, boxColor, 1);
|
2024-03-26 04:03:45 +01:00
|
|
|
|
2024-03-24 04:58:08 +01:00
|
|
|
if(slide_range != noone) {
|
2024-03-29 05:20:49 +01:00
|
|
|
var _minn = slide_range[0];
|
|
|
|
var _maxx = slide_range[1];
|
|
|
|
var _rang = abs(_maxx - _minn);
|
2024-03-24 04:58:08 +01:00
|
|
|
var _currVal = toNumber(_current_text);
|
|
|
|
|
|
|
|
if(sliding != 2) {
|
|
|
|
curr_range[0] = (_currVal >= _minn)? _minn : _minn - ceil(abs(_currVal - _minn) / _rang) * _rang;
|
|
|
|
curr_range[1] = (_currVal <= _maxx)? _maxx : _maxx + ceil(abs(_currVal - _maxx) / _rang) * _rang;
|
|
|
|
}
|
|
|
|
|
|
|
|
var lw = _w * (_currVal - curr_range[0]) / (curr_range[1] - curr_range[0]);
|
|
|
|
draw_sprite_stretched_ext(THEME.textbox, 4, _x, _y, lw, _h, boxColor, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-29 05:20:49 +01:00
|
|
|
if(_w > ui(48)) {
|
2024-10-12 08:35:36 +02:00
|
|
|
if(sliding == 2 && hide < 3) {
|
2024-03-29 05:20:49 +01:00
|
|
|
var _ax0 = _x + ui(10);
|
|
|
|
var _ax1 = _x + _w - ui(10);
|
|
|
|
var _ay = _y + _h / 2;
|
2024-03-26 04:03:45 +01:00
|
|
|
|
2024-03-29 05:20:49 +01:00
|
|
|
draw_sprite_ui_uniform(THEME.arrow, 2, _ax0, _ay, 1, COLORS._main_accent, 1);
|
|
|
|
draw_sprite_ui_uniform(THEME.arrow, 0, _ax1, _ay, 1, COLORS._main_accent, 1);
|
2024-03-26 04:03:45 +01:00
|
|
|
|
2024-03-29 05:20:49 +01:00
|
|
|
} else if(label != "") {
|
2024-07-03 05:32:12 +02:00
|
|
|
draw_set_text(font, fa_left, fa_center, labelColor);
|
2024-03-29 09:13:26 +01:00
|
|
|
|
2024-03-29 05:20:49 +01:00
|
|
|
draw_set_alpha(0.5);
|
2024-06-30 08:52:55 +02:00
|
|
|
draw_text_add(_x + padding, _y + _h / 2, label);
|
2024-03-29 05:20:49 +01:00
|
|
|
draw_set_alpha(1);
|
|
|
|
}
|
2024-03-26 04:03:45 +01:00
|
|
|
}
|
2024-05-01 14:28:15 +02:00
|
|
|
|
|
|
|
var _dpx = disp_x;
|
2023-01-09 03:14:20 +01:00
|
|
|
disp_x = lerp_float(disp_x, disp_x_to, 5);
|
2024-05-01 14:28:15 +02:00
|
|
|
if(_dpx != disp_x) _update = true;
|
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);
|
|
|
|
|
2024-04-18 07:12:31 +02:00
|
|
|
if(sliding > 0) { #region slide
|
|
|
|
slide_delta += PEN_USE? PEN_X_DELTA : window_mouse_get_delta_x();
|
|
|
|
slide_delta += PEN_USE? PEN_Y_DELTA : window_mouse_get_delta_y();
|
2024-03-31 05:36:11 +02:00
|
|
|
|
|
|
|
if(sliding == 1 && abs(slide_delta) > 8) {
|
|
|
|
deactivate();
|
2024-03-31 11:10:14 +02:00
|
|
|
var _defval = toNumber(_current_text);
|
|
|
|
slider_def_val = _defval;
|
|
|
|
slider_cur_val = _defval;
|
2024-07-26 09:38:39 +02:00
|
|
|
slider_cur_del = 0;
|
2024-04-18 08:01:23 +02:00
|
|
|
|
2024-07-26 09:38:39 +02:00
|
|
|
slidePen = PEN_USE;
|
2024-07-26 10:30:29 +02:00
|
|
|
slider_dx = 0;
|
2024-07-26 09:38:39 +02:00
|
|
|
slider_dy = 0;
|
|
|
|
slider_mulp = 0;
|
2024-04-18 08:01:23 +02:00
|
|
|
|
2024-07-28 13:55:57 +02:00
|
|
|
if(!slidePen && PREFERENCES.slider_lock_mouse) {
|
2024-04-18 08:01:23 +02:00
|
|
|
CURSOR_LOCK_X = mouse_mx;
|
|
|
|
CURSOR_LOCK_Y = mouse_my;
|
|
|
|
}
|
2024-04-18 07:12:31 +02:00
|
|
|
|
2024-07-26 09:38:39 +02:00
|
|
|
sliding = 2;
|
2024-10-12 08:35:36 +02:00
|
|
|
if(hide < 3) {
|
|
|
|
slider_object = instance_create_depth(rx + _x, ry + _y, -16000, slider_Slider, { w: _w, h: _h });
|
|
|
|
slider_object.text = self;
|
|
|
|
}
|
2024-03-31 05:36:11 +02:00
|
|
|
}
|
2024-07-26 09:38:39 +02:00
|
|
|
|
|
|
|
var _mdx = slidePen? PEN_X_DELTA : window_mouse_get_delta_x();
|
|
|
|
var _mdy = slidePen? PEN_Y_DELTA : window_mouse_get_delta_y();
|
2024-03-31 05:36:11 +02:00
|
|
|
|
|
|
|
if(sliding == 2) {
|
2024-10-12 08:35:36 +02:00
|
|
|
if(slider_object) {
|
|
|
|
slider_object.x = rx + _x;
|
|
|
|
slider_object.y = ry + _y;
|
|
|
|
slider_object.w = slider_object.w;
|
|
|
|
slider_object.h = slider_object.h;
|
|
|
|
}
|
|
|
|
|
2024-07-17 06:19:55 +02:00
|
|
|
if(!slidePen && PREFERENCES.slider_lock_mouse) CURSOR_LOCK = true;
|
2024-07-26 09:38:39 +02:00
|
|
|
|
|
|
|
if(abs(_mdy) > abs(_mdx))
|
|
|
|
slider_dy += slidePen? PEN_Y_DELTA : window_mouse_get_delta_y();
|
|
|
|
|
|
|
|
var _mulp = slider_mulp;
|
2024-07-28 13:55:57 +02:00
|
|
|
var _stpH = slidePen || !PREFERENCES.slider_lock_mouse? 24 : 160;
|
|
|
|
|
|
|
|
if(slider_dy < -_stpH * (1 + abs(slider_mulp) * .5)) { slider_mulp = clamp(slider_mulp + 1, -2, 2); slider_dy = 0; }
|
|
|
|
else if(slider_dy > _stpH * (1 + abs(slider_mulp) * .5)) { slider_mulp = clamp(slider_mulp - 1, -2, 2); slider_dy = 0; }
|
2024-07-26 09:38:39 +02:00
|
|
|
|
2024-07-26 10:30:29 +02:00
|
|
|
if(_mulp != slider_mulp) {
|
|
|
|
slider_dx = 0;
|
|
|
|
slider_cur_del = 0;
|
|
|
|
}
|
2024-07-26 09:38:39 +02:00
|
|
|
|
|
|
|
if(mouse_press(mb_right)) { //cancel
|
2024-03-31 11:10:14 +02:00
|
|
|
_input_text = string_real(slider_def_val);
|
|
|
|
sliding = 0;
|
|
|
|
apply();
|
|
|
|
deactivate();
|
2024-04-18 08:01:23 +02:00
|
|
|
|
2024-03-31 11:10:14 +02:00
|
|
|
UNDO_HOLDING = false;
|
|
|
|
|
|
|
|
} else {
|
2024-04-18 08:01:23 +02:00
|
|
|
MOUSE_BLOCK = true;
|
2024-07-28 13:55:57 +02:00
|
|
|
var _s = slide_speed;
|
|
|
|
// print($"{_s} : {slide_range} | {_w} / {_s * _w} - {slider_cur_del}");
|
|
|
|
if(!PREFERENCES.slider_lock_mouse)
|
|
|
|
_s = slide_range != noone? (slide_range[1] - slide_range[0]) / _w * 2 : 1 / 100;
|
|
|
|
|
|
|
|
var _sc = power(10, slider_mulp + slide_int);
|
2024-07-26 10:30:29 +02:00
|
|
|
_s *= _sc;
|
2024-04-18 08:01:23 +02:00
|
|
|
|
2024-03-31 11:10:14 +02:00
|
|
|
if(key_mod_press(CTRL) && !slide_snap) _s *= 10;
|
2024-07-26 10:30:29 +02:00
|
|
|
if(key_mod_press(ALT)) _s /= 10;
|
|
|
|
|
2024-07-28 13:55:57 +02:00
|
|
|
if(abs(_mdx) > abs(_mdy)) {
|
|
|
|
slider_dx += _mdx / w;
|
|
|
|
slider_cur_del += _mdx;
|
|
|
|
slider_cur_val = slider_def_val + slider_cur_del * _s;
|
2024-07-26 10:30:29 +02:00
|
|
|
|
2024-07-28 13:55:57 +02:00
|
|
|
if(slide_range != noone)
|
|
|
|
slider_cur_val = clamp(slider_cur_val, curr_range[0], curr_range[1]);
|
|
|
|
|
|
|
|
var _val = value_snap(slider_cur_val, _sc / 100);
|
|
|
|
|
|
|
|
if(key_mod_press(CTRL) && slide_snap) _val = value_snap(slider_cur_val, slide_snap);
|
|
|
|
if(slide_int) _val = round(_val);
|
|
|
|
|
|
|
|
_input_text = string_real(_val);
|
|
|
|
}
|
2024-07-27 04:07:29 +02:00
|
|
|
|
2024-03-31 11:10:14 +02:00
|
|
|
if(apply()) UNDO_HOLDING = true;
|
|
|
|
}
|
|
|
|
|
2024-03-31 05:36:11 +02:00
|
|
|
if(mouse_release(mb_left)) {
|
|
|
|
deactivate();
|
2024-03-31 11:10:14 +02:00
|
|
|
if(onRelease != noone) apply(true);
|
2024-03-31 05:36:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mouse_release(mb_left)) {
|
|
|
|
sliding = 0;
|
|
|
|
_update = true;
|
|
|
|
UNDO_HOLDING = false;
|
|
|
|
}
|
2024-07-26 09:38:39 +02:00
|
|
|
|
|
|
|
} else {
|
|
|
|
if(slider_object) {
|
|
|
|
slider_object.anim = 1;
|
|
|
|
slider_object = noone;
|
|
|
|
}
|
|
|
|
}
|
2024-03-31 05:36:11 +02:00
|
|
|
|
2023-10-03 07:14:28 +02:00
|
|
|
if(selecting) {
|
2024-06-30 08:52:55 +02:00
|
|
|
if(hide < 2) {
|
|
|
|
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);
|
|
|
|
}
|
2024-03-29 09:13:26 +01:00
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
editText();
|
|
|
|
|
|
|
|
#region multiplier
|
2023-02-14 02:51:14 +01:00
|
|
|
if(_w > ui(80) && input == TEXTBOX_INPUT.number) {
|
2022-01-13 05:24:03 +01:00
|
|
|
draw_set_alpha(0.5);
|
|
|
|
|
2024-03-24 08:01:24 +01:00
|
|
|
if(hover && point_in_rectangle(_m[0], _m[1], _x + _w - ui(32), _y, _x + _w, _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();
|
2024-03-27 11:51:14 +01:00
|
|
|
|
|
|
|
if(IS_PATREON) shake_amount = PREFERENCES.textbox_shake;
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
}
|
2024-03-24 08:01:24 +01:00
|
|
|
|
2024-08-23 06:14:52 +02:00
|
|
|
draw_set_text(font, fa_center, fa_center, COLORS._main_text_sub);
|
2024-03-24 08:01:24 +01:00
|
|
|
if(key_mod_press(ALT)) draw_text_add(_x + _w - ui(16), _y + _h / 2, "/2");
|
|
|
|
else draw_text_add(_x + _w - ui(16), _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;
|
2024-03-29 09:13:26 +01:00
|
|
|
draw_set_text(font, fa_left, fa_top);
|
2023-01-01 02:06:02 +01:00
|
|
|
var tw = string_width(txt);
|
2023-12-15 12:56:36 +01:00
|
|
|
var th = string_height(txt == ""? "l" : 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)
|
2024-06-30 08:52:55 +02:00
|
|
|
disp_x_to += _w - padding * 2;
|
2024-07-27 04:07:29 +02:00
|
|
|
|
2024-06-30 08:52:55 +02:00
|
|
|
if(cursor_pos_to > _x + _w - padding * 2)
|
|
|
|
disp_x_to -= _w - padding * 2;
|
2023-01-01 02:06:02 +01:00
|
|
|
|
2024-03-27 11:51:14 +01:00
|
|
|
cursor_pos_y = c_y0;
|
2024-06-19 09:04:03 +02:00
|
|
|
cursor_pos = cursor_pos == 0? cursor_pos_to : lerp_float(cursor_pos, cursor_pos_to, 1);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-01-09 03:14:20 +01:00
|
|
|
if(cursor_select > -1) { //draw highlight
|
2024-06-30 08:52:55 +02:00
|
|
|
if(highlight_color == -1) highlight_color = COLORS.widget_text_highlight;
|
|
|
|
draw_set_color(highlight_color);
|
|
|
|
draw_set_alpha(highlight_alpha);
|
|
|
|
|
2023-12-01 05:49:44 +01:00
|
|
|
var c_x1 = tx + disp_x + string_width(string_copy(txt, 1, cursor_select));
|
|
|
|
var _rx0 = clamp(min(cursor_pos, c_x1), tx, tx + _w);
|
|
|
|
var _rx1 = clamp(max(cursor_pos, c_x1), tx, tx + _w);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-12-01 05:49:44 +01:00
|
|
|
draw_roundrect_ext(_rx0, c_y0, _rx1, c_y1, THEME_VALUE.highlight_corner_radius, THEME_VALUE.highlight_corner_radius, 0);
|
2024-06-30 08:52:55 +02:00
|
|
|
draw_set_alpha(1);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var _mx = -1;
|
2022-01-26 13:02:30 +01:00
|
|
|
var _my = -1;
|
2023-10-03 07:14:28 +02:00
|
|
|
if(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
|
|
|
}
|
|
|
|
|
2024-03-29 09:13:26 +01:00
|
|
|
var _display_text = string_real(txt);
|
|
|
|
if(_update || _display_text != _disp_text) {
|
|
|
|
surface_set_shader(text_surface, noone, true, BLEND.add);
|
|
|
|
display_text(tx - tb_surf_x, _h / 2 - th / 2, _display_text, _w - ui(4), _mx - tb_surf_x);
|
|
|
|
surface_reset_shader();
|
|
|
|
}
|
2023-10-03 07:14:28 +02:00
|
|
|
|
|
|
|
BLEND_ALPHA
|
2024-10-12 08:35:36 +02:00
|
|
|
draw_surface_ext(text_surface, tb_surf_x, tb_surf_y, 1, 1, 0, postBlend, postAlpha);
|
2023-10-03 07:14:28 +02:00
|
|
|
BLEND_NORMAL
|
2023-12-15 12:56:36 +01:00
|
|
|
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_set_color(COLORS._main_text_accent);
|
2024-07-27 05:46:16 +02:00
|
|
|
draw_set_alpha((typing || current_time % (PREFERENCES.caret_blink * 2000) > PREFERENCES.caret_blink * 1000) * 0.75 + 0.25);
|
2022-01-13 05:24:03 +01:00
|
|
|
draw_line_width(cursor_pos, c_y0, cursor_pos, c_y1, 2);
|
2023-12-18 04:40:21 +01:00
|
|
|
draw_set_alpha(1);
|
|
|
|
|
|
|
|
if(typing) typing--;
|
2022-01-13 05:24:03 +01:00
|
|
|
#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-10-03 07:14:28 +02:00
|
|
|
if(!hoverRect && mouse_press(mb_left))
|
2023-01-17 08:11:55 +01:00
|
|
|
deactivate();
|
2024-03-29 09:13:26 +01:00
|
|
|
|
|
|
|
} else {
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-03-26 07:13:36 +02:00
|
|
|
if(hover && hoverRect) {
|
2024-03-28 14:18:02 +01:00
|
|
|
hovering = true;
|
2024-10-12 08:35:36 +02:00
|
|
|
if(hide < 3) 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-11-25 08:54:35 +01:00
|
|
|
if(mouse_wheel_down()) modifyValue(toNumber(_text) + amo * SCROLL_SPEED);
|
|
|
|
if(mouse_wheel_up()) modifyValue(toNumber(_text) - amo * SCROLL_SPEED);
|
2023-02-14 02:51:14 +01:00
|
|
|
}
|
2024-03-29 09:13:26 +01:00
|
|
|
|
|
|
|
if(slidable && mouse_press(mb_left, active)) {
|
2024-04-18 08:01:23 +02:00
|
|
|
sliding = 1;
|
2024-03-29 09:13:26 +01:00
|
|
|
slide_delta = 0;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2024-03-31 11:10:14 +02:00
|
|
|
if(drawText) {
|
|
|
|
draw_set_text(font, fa_left, fa_center);
|
|
|
|
var _display_text = _raw_text;
|
2023-10-03 07:14:28 +02:00
|
|
|
|
2024-03-31 11:10:14 +02:00
|
|
|
if(input == TEXTBOX_INPUT.number) {
|
|
|
|
var dig = floor(_w / string_width("0")) - 3;
|
|
|
|
_display_text = string_real(_display_text, dig, precision);
|
|
|
|
}
|
|
|
|
|
|
|
|
var tw = string_width(_display_text);
|
|
|
|
var th = string_height(_display_text);
|
|
|
|
|
|
|
|
switch(align) {
|
|
|
|
case fa_left : break;
|
|
|
|
case fa_center : tx -= tw / 2; break;
|
|
|
|
case fa_right : tx -= tw; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(_update || _display_text != _disp_text) {
|
|
|
|
surface_set_shader(text_surface, noone, true, BLEND.add);
|
|
|
|
display_text(tx - tb_surf_x, _h / 2 - th / 2, _display_text, _w - ui(4));
|
|
|
|
surface_reset_shader();
|
|
|
|
}
|
2024-10-12 08:35:36 +02:00
|
|
|
|
2024-03-31 11:10:14 +02:00
|
|
|
BLEND_ALPHA
|
2024-10-12 08:35:36 +02:00
|
|
|
draw_surface_ext(text_surface, tb_surf_x, tb_surf_y, 1, 1, 0, postBlend, postAlpha);
|
2024-03-31 11:10:14 +02:00
|
|
|
BLEND_NORMAL
|
|
|
|
}
|
2024-03-29 09:13:26 +01:00
|
|
|
}
|
2023-11-06 12:08:59 +01:00
|
|
|
|
2023-03-26 07:13:36 +02:00
|
|
|
if(DRAGGING && (DRAGGING.type == "Text" || DRAGGING.type == "Number") && hover && hoverRect) {
|
2024-08-06 04:30:00 +02:00
|
|
|
draw_sprite_stretched_ext(THEME.ui_panel, 1, _x, _y, _w, _h, COLORS._main_value_positive, 1);
|
2024-10-05 10:30:21 +02:00
|
|
|
if(mouse_release(mb_left)) {
|
|
|
|
if(onModifyParam == noone) onModify(DRAGGING.data);
|
|
|
|
else onModify(DRAGGING.data, onModifyParam);
|
|
|
|
}
|
2023-03-26 07:13:36 +02:00
|
|
|
}
|
2022-01-26 13:02:30 +01:00
|
|
|
|
2023-10-03 07:14:28 +02:00
|
|
|
selecting = self == WIDGET_CURRENT;
|
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;
|
2024-10-12 08:35:36 +02:00
|
|
|
}
|
2024-08-18 04:51:54 +02:00
|
|
|
|
|
|
|
static clone = function() {
|
|
|
|
var cln = new textBox(input, onModify);
|
|
|
|
return cln;
|
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|