2023-01-04 02:30:04 +01:00
|
|
|
enum TEXT_AREA_FORMAT {
|
|
|
|
_default,
|
2023-09-07 20:59:14 +02:00
|
|
|
codeLUA,
|
2023-09-08 12:27:22 +02:00
|
|
|
codeHLSL,
|
2023-08-13 13:10:20 +02:00
|
|
|
delimiter,
|
|
|
|
path_template,
|
|
|
|
node_title,
|
2023-01-04 02:30:04 +01:00
|
|
|
}
|
|
|
|
|
2023-10-03 07:14:28 +02:00
|
|
|
function textArea(_input, _onModify) : textInput(_input, _onModify) constructor {
|
2023-08-31 18:49:57 +02:00
|
|
|
font = f_p0;
|
|
|
|
hide = false;
|
|
|
|
color = COLORS._main_text;
|
2023-04-16 11:53:46 +02:00
|
|
|
boxColor = c_white;
|
2022-01-26 13:02:30 +01:00
|
|
|
|
|
|
|
auto_update = false;
|
|
|
|
|
2024-03-27 11:51:14 +01:00
|
|
|
_input_text_line = [];
|
2023-07-28 19:41:57 +02:00
|
|
|
_input_text_line_index = [];
|
2024-03-27 11:51:14 +01:00
|
|
|
|
2023-07-30 13:56:22 +02:00
|
|
|
_current_text = "";
|
|
|
|
_input_text = "";
|
|
|
|
_prev_text = "";
|
|
|
|
_last_value = "";
|
|
|
|
_prev_width = 0;
|
|
|
|
_stretch_width = false;
|
2022-01-29 14:25:18 +01:00
|
|
|
|
2023-08-31 18:49:57 +02:00
|
|
|
min_lines = 0;
|
|
|
|
line_width = 1000;
|
2024-01-24 08:38:57 +01:00
|
|
|
max_height = -1;
|
2023-01-04 02:30:04 +01:00
|
|
|
|
2022-01-26 13:02:30 +01:00
|
|
|
cursor = 0;
|
2023-06-20 19:43:19 +02:00
|
|
|
cursor_tx = 0;
|
2022-01-26 13:02:30 +01:00
|
|
|
cursor_pos_x = 0;
|
|
|
|
cursor_pos_x_to = 0;
|
|
|
|
cursor_pos_y = 0;
|
|
|
|
cursor_pos_y_to = 0;
|
2023-08-31 18:49:57 +02:00
|
|
|
cursor_line = 0;
|
2022-01-26 13:02:30 +01:00
|
|
|
|
2023-07-12 16:28:32 +02:00
|
|
|
char_run = 0
|
|
|
|
|
2022-01-26 13:02:30 +01:00
|
|
|
cursor_select = -1;
|
|
|
|
|
|
|
|
click_block = 0;
|
2023-01-04 02:30:04 +01:00
|
|
|
format = TEXT_AREA_FORMAT._default;
|
|
|
|
|
|
|
|
code_line_width = 48;
|
2022-01-26 13:02:30 +01:00
|
|
|
|
2023-09-15 20:12:02 +02:00
|
|
|
shift_new_line = true;
|
|
|
|
show_line_number = true;
|
|
|
|
|
|
|
|
syntax_highlight = true;
|
2023-09-07 20:59:14 +02:00
|
|
|
|
2023-11-10 01:50:16 +01:00
|
|
|
undo_current_text = "";
|
|
|
|
undo_delay = 0;
|
|
|
|
undo_stack = ds_stack_create();
|
|
|
|
redo_stack = ds_stack_create();
|
|
|
|
|
2024-01-24 08:38:57 +01:00
|
|
|
text_surface = noone;
|
|
|
|
|
|
|
|
text_y = 0;
|
|
|
|
text_y_to = 0;
|
|
|
|
text_y_max = 0;
|
|
|
|
text_scrolling = false;
|
|
|
|
text_scroll_sy = 0;
|
|
|
|
text_scroll_my = 0;
|
|
|
|
|
2023-01-09 03:14:20 +01:00
|
|
|
_cl = -1;
|
|
|
|
|
2024-01-24 08:38:57 +01:00
|
|
|
static setMaxHieght = function(height) { #region
|
|
|
|
max_height = height;
|
|
|
|
return self;
|
|
|
|
} #endregion
|
|
|
|
|
2023-08-31 18:49:57 +02:00
|
|
|
static activate = function() { #region
|
2023-01-17 08:11:55 +01:00
|
|
|
WIDGET_CURRENT = self;
|
|
|
|
WIDGET_CURRENT_SCROLL = parent;
|
|
|
|
parentFocus();
|
|
|
|
|
|
|
|
_input_text = _current_text;
|
|
|
|
_last_value = _current_text;
|
|
|
|
|
|
|
|
cursor_pos_x = 0;
|
|
|
|
cursor_pos_y = 0;
|
2023-12-05 09:51:24 +01:00
|
|
|
|
|
|
|
cursor = string_length(_current_text);
|
|
|
|
cursor_select = 0;
|
|
|
|
click_block = 1;
|
|
|
|
|
2023-01-17 08:11:55 +01:00
|
|
|
KEYBOARD_STRING = "";
|
|
|
|
keyboard_lastkey = -1;
|
|
|
|
|
|
|
|
cut_line();
|
2023-11-10 01:50:16 +01:00
|
|
|
undo_delay = 10;
|
2024-03-02 10:08:44 +01:00
|
|
|
|
|
|
|
if(PEN_USE) keyboard_virtual_show(kbv_type_default, kbv_returnkey_default, kbv_autocapitalize_none, true);
|
2023-08-31 18:49:57 +02:00
|
|
|
} #endregion
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2023-08-31 18:49:57 +02:00
|
|
|
static deactivate = function() { #region
|
2023-01-17 08:11:55 +01:00
|
|
|
if(WIDGET_CURRENT != self) return;
|
2023-11-20 05:10:55 +01:00
|
|
|
|
2022-11-22 14:25:39 +01:00
|
|
|
apply();
|
2023-01-17 08:11:55 +01:00
|
|
|
WIDGET_CURRENT = noone;
|
2022-11-22 14:25:39 +01:00
|
|
|
UNDO_HOLDING = false;
|
2024-03-02 10:08:44 +01:00
|
|
|
|
|
|
|
if(PEN_USE) keyboard_virtual_hide();
|
2023-08-31 18:49:57 +02:00
|
|
|
} #endregion
|
2022-11-22 14:25:39 +01:00
|
|
|
|
2023-11-10 01:50:16 +01:00
|
|
|
static isCodeFormat = function() { INLINE return format == TEXT_AREA_FORMAT.codeLUA || format == TEXT_AREA_FORMAT.codeHLSL; }
|
2023-09-15 20:12:02 +02:00
|
|
|
|
2023-11-27 11:40:28 +01:00
|
|
|
static breakCharacter = function(ch) { #region
|
|
|
|
if(isCodeFormat())
|
|
|
|
return ch == "\n" || array_exists(global.CODE_BREAK_TOKEN, ch);
|
|
|
|
return ch == " " || ch == "\n";
|
|
|
|
} #endregion
|
|
|
|
|
2023-08-31 18:49:57 +02:00
|
|
|
static onModified = function() { #region
|
2023-11-30 08:55:33 +01:00
|
|
|
autocomplete_delay = 0;
|
|
|
|
o_dialog_textbox_autocomplete.deactivate(self);
|
|
|
|
o_dialog_textbox_function_guide.deactivate(self);
|
|
|
|
|
2023-09-15 20:12:02 +02:00
|
|
|
if(autocomplete_server == noone) return;
|
2023-11-30 08:55:33 +01:00
|
|
|
if(!use_autocomplete) return;
|
2023-09-15 20:12:02 +02:00
|
|
|
|
|
|
|
var crop = string_copy(_input_text, 1, cursor);
|
2023-10-12 12:25:38 +02:00
|
|
|
var slp = string_splice(crop, [" ", "(", "[", "{", ",", "\n"]);
|
2023-09-15 20:12:02 +02:00
|
|
|
var pmt = array_safe_get(slp, -1,, ARRAY_OVERFLOW.loop);
|
2023-11-30 08:55:33 +01:00
|
|
|
|
2023-10-12 14:14:08 +02:00
|
|
|
var localParams = [];
|
2023-09-15 20:12:02 +02:00
|
|
|
if(parser_server != noone)
|
2023-10-12 14:14:08 +02:00
|
|
|
localParams = parser_server(crop, autocomplete_object);
|
2023-11-30 08:55:33 +01:00
|
|
|
|
2023-10-12 14:14:08 +02:00
|
|
|
var data = autocomplete_server(pmt, localParams, autocomplete_context);
|
2024-04-22 14:13:03 +02:00
|
|
|
|
2023-11-17 12:33:25 +01:00
|
|
|
o_dialog_textbox_autocomplete.data = data;
|
2023-09-15 20:12:02 +02:00
|
|
|
if(array_length(data)) {
|
2023-11-08 13:05:24 +01:00
|
|
|
o_dialog_textbox_autocomplete.data = data;
|
|
|
|
o_dialog_textbox_autocomplete.prompt = pmt;
|
2023-11-14 14:29:11 +01:00
|
|
|
autocomplete_modi = true;
|
2023-11-08 08:38:04 +01:00
|
|
|
}
|
2024-04-22 14:13:03 +02:00
|
|
|
|
|
|
|
if(function_guide_server == noone) return;
|
2023-07-12 21:00:05 +02:00
|
|
|
|
2023-09-15 20:12:02 +02:00
|
|
|
var _c = cursor;
|
|
|
|
var _v = false;
|
|
|
|
var _fn = "";
|
|
|
|
var _el = 0;
|
|
|
|
var amo = 0;
|
2024-04-22 14:13:03 +02:00
|
|
|
|
2023-09-15 20:12:02 +02:00
|
|
|
while(_c > 1) {
|
|
|
|
var cch0 = string_char_at(_input_text, _c - 1);
|
|
|
|
var cch1 = string_char_at(_input_text, _c);
|
2023-07-12 21:00:05 +02:00
|
|
|
|
2023-09-15 20:12:02 +02:00
|
|
|
if(_el == 0 && cch1 == ",") amo++;
|
2023-07-12 21:00:05 +02:00
|
|
|
|
2023-09-15 20:12:02 +02:00
|
|
|
if(_el == 0 && cch1 == "(" && string_variable_valid(cch0))
|
|
|
|
_v = true;
|
|
|
|
else if(cch1 == ")") _el++;
|
|
|
|
else if(cch1 == "(") _el--;
|
2023-07-12 21:00:05 +02:00
|
|
|
|
2023-09-15 20:12:02 +02:00
|
|
|
if(_v) {
|
|
|
|
if(!string_variable_valid(cch0))
|
|
|
|
break;
|
|
|
|
_fn = cch0 + _fn;
|
2023-07-12 21:00:05 +02:00
|
|
|
}
|
2023-09-15 20:12:02 +02:00
|
|
|
|
|
|
|
_c--;
|
2023-07-12 21:00:05 +02:00
|
|
|
}
|
2023-09-15 20:12:02 +02:00
|
|
|
var guide = function_guide_server(_fn);
|
2023-11-26 13:16:38 +01:00
|
|
|
|
2023-09-15 20:12:02 +02:00
|
|
|
if(guide != "") {
|
2023-11-08 08:38:04 +01:00
|
|
|
o_dialog_textbox_function_guide.activate(self);
|
|
|
|
o_dialog_textbox_function_guide.prompt = guide;
|
|
|
|
o_dialog_textbox_function_guide.index = amo;
|
2023-11-30 08:55:33 +01:00
|
|
|
}
|
2023-08-31 18:49:57 +02:00
|
|
|
} #endregion
|
2023-07-12 21:00:05 +02:00
|
|
|
|
2023-09-29 02:13:17 +02:00
|
|
|
static keyboardEnter = function() { #region
|
|
|
|
if(!keyboard_check_pressed(vk_enter))
|
|
|
|
return 0;
|
|
|
|
|
2023-11-22 15:25:36 +01:00
|
|
|
if(use_autocomplete && o_dialog_textbox_autocomplete.active && o_dialog_textbox_autocomplete.textbox == self)
|
2023-09-29 02:13:17 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1 + ((shift_new_line && key_mod_press(SHIFT)) || (!shift_new_line && !key_mod_press(SHIFT)));
|
|
|
|
} #endregion
|
|
|
|
|
2023-08-31 18:49:57 +02:00
|
|
|
static onKey = function(key) { #region
|
2023-06-20 19:43:19 +02:00
|
|
|
if(key == vk_left) {
|
|
|
|
if(key_mod_press(SHIFT)) {
|
|
|
|
if(cursor_select == -1)
|
|
|
|
cursor_select = cursor;
|
|
|
|
} else
|
|
|
|
cursor_select = -1;
|
|
|
|
|
|
|
|
move_cursor(-1);
|
|
|
|
if(key_mod_press(CTRL)) {
|
|
|
|
while(cursor > 0) {
|
|
|
|
var ch = string_char_at(_input_text, cursor);
|
2023-09-08 14:51:05 +02:00
|
|
|
if(breakCharacter(ch)) break;
|
2023-06-20 19:43:19 +02:00
|
|
|
cursor--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(key == vk_right) {
|
|
|
|
if(key_mod_press(SHIFT)) {
|
|
|
|
if(cursor_select == -1)
|
|
|
|
cursor_select = cursor;
|
|
|
|
} else
|
|
|
|
cursor_select = -1;
|
|
|
|
|
|
|
|
move_cursor(1);
|
|
|
|
if(key_mod_press(CTRL)) {
|
|
|
|
while(cursor < string_length(_input_text)) {
|
|
|
|
var ch = string_char_at(_input_text, cursor);
|
2023-09-08 14:51:05 +02:00
|
|
|
if(breakCharacter(ch)) break;
|
2023-06-20 19:43:19 +02:00
|
|
|
cursor++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-07-12 16:28:32 +02:00
|
|
|
|
2023-11-26 13:16:38 +01:00
|
|
|
var tbActive = o_dialog_textbox_autocomplete.active && o_dialog_textbox_autocomplete.textbox == self;
|
|
|
|
|
|
|
|
if(!(isCodeFormat() && tbActive)) {
|
2023-09-07 20:59:14 +02:00
|
|
|
if(key == vk_up) {
|
|
|
|
var _target;
|
2023-11-26 13:16:38 +01:00
|
|
|
|
2023-09-07 20:59:14 +02:00
|
|
|
if(cursor_line == 0)
|
|
|
|
_target = 0;
|
|
|
|
else {
|
|
|
|
var _l = cursor_line - 1;
|
|
|
|
var _str = _input_text_line[_l];
|
|
|
|
var _run = cursor_tx;
|
|
|
|
var _char = 0;
|
2023-06-20 19:43:19 +02:00
|
|
|
|
2023-09-07 20:59:14 +02:00
|
|
|
for( var i = 0; i < _l; i++ )
|
|
|
|
_char += string_length(_input_text_line[i]);
|
2023-06-20 19:43:19 +02:00
|
|
|
|
2023-09-07 20:59:14 +02:00
|
|
|
for( var i = 1; i < string_length(_str); i++ ) {
|
|
|
|
var _chr = string_char_at(_str, i);
|
|
|
|
_run += string_width(_chr);
|
|
|
|
if(_run > cursor_pos_x_to)
|
|
|
|
break;
|
|
|
|
_char++;
|
|
|
|
}
|
2023-06-20 19:43:19 +02:00
|
|
|
|
2023-09-07 20:59:14 +02:00
|
|
|
_target = _char;
|
|
|
|
}
|
2023-06-20 19:43:19 +02:00
|
|
|
|
2023-09-07 20:59:14 +02:00
|
|
|
if(key_mod_press(SHIFT)) {
|
|
|
|
if(cursor_select == -1)
|
|
|
|
cursor_select = cursor;
|
|
|
|
} else
|
|
|
|
cursor_select = -1;
|
2023-06-20 19:43:19 +02:00
|
|
|
|
2023-09-07 20:59:14 +02:00
|
|
|
cursor = _target;
|
|
|
|
onModified();
|
|
|
|
}
|
2023-07-12 16:28:32 +02:00
|
|
|
|
2023-09-07 20:59:14 +02:00
|
|
|
if(key == vk_down) {
|
|
|
|
var _target;
|
2023-06-20 19:43:19 +02:00
|
|
|
|
2023-09-07 20:59:14 +02:00
|
|
|
if(cursor_line == array_length(_input_text_line) - 1)
|
|
|
|
_target = string_length(_input_text);
|
|
|
|
else {
|
|
|
|
var _l = cursor_line + 1;
|
|
|
|
var _str = _input_text_line[_l];
|
|
|
|
var _run = cursor_tx;
|
|
|
|
var _char = 0;
|
2023-06-20 19:43:19 +02:00
|
|
|
|
2023-09-07 20:59:14 +02:00
|
|
|
for( var i = 0; i < _l; i++ )
|
|
|
|
_char += string_length(_input_text_line[i]);
|
2023-06-20 19:43:19 +02:00
|
|
|
|
2023-09-07 20:59:14 +02:00
|
|
|
for( var i = 1; i < string_length(_str); i++ ) {
|
|
|
|
var _chr = string_char_at(_str, i);
|
|
|
|
_run += string_width(_chr);
|
|
|
|
if(_run > cursor_pos_x_to) break;
|
|
|
|
_char++;
|
|
|
|
}
|
2023-07-12 16:28:32 +02:00
|
|
|
|
2023-09-07 20:59:14 +02:00
|
|
|
_target = _char;
|
|
|
|
}
|
2023-06-20 19:43:19 +02:00
|
|
|
|
2023-09-07 20:59:14 +02:00
|
|
|
if(key_mod_press(SHIFT)) {
|
|
|
|
if(cursor_select == -1)
|
|
|
|
cursor_select = cursor;
|
|
|
|
} else
|
|
|
|
cursor_select = -1;
|
2023-06-20 19:43:19 +02:00
|
|
|
|
2023-09-07 20:59:14 +02:00
|
|
|
cursor = _target;
|
|
|
|
onModified();
|
|
|
|
}
|
2023-06-20 19:43:19 +02:00
|
|
|
}
|
2023-08-31 18:49:57 +02:00
|
|
|
} #endregion
|
2023-06-20 19:43:19 +02:00
|
|
|
|
2023-08-31 18:49:57 +02:00
|
|
|
static apply = function() { #region
|
2022-01-26 13:02:30 +01:00
|
|
|
if(onModify) onModify(_input_text);
|
2022-11-22 14:25:39 +01:00
|
|
|
UNDO_HOLDING = true;
|
2023-08-31 18:49:57 +02:00
|
|
|
} #endregion
|
2022-01-26 13:02:30 +01:00
|
|
|
|
2023-08-31 18:49:57 +02:00
|
|
|
static move_cursor = function(delta) { #region
|
2022-01-26 13:02:30 +01:00
|
|
|
var ll = string_length(_input_text);
|
2022-01-29 14:25:18 +01:00
|
|
|
cursor = clamp(cursor + delta, 0, ll);
|
2023-07-12 21:00:05 +02:00
|
|
|
|
|
|
|
onModified();
|
2023-08-31 18:49:57 +02:00
|
|
|
} #endregion
|
2022-01-26 13:02:30 +01:00
|
|
|
|
2023-08-31 18:49:57 +02:00
|
|
|
static cut_line = function() { #region
|
2022-01-26 13:02:30 +01:00
|
|
|
_input_text_line = [];
|
2023-07-28 19:41:57 +02:00
|
|
|
_input_text_line_index = [];
|
2022-12-22 03:09:55 +01:00
|
|
|
draw_set_font(font);
|
2022-01-26 13:02:30 +01:00
|
|
|
|
2023-01-09 03:14:20 +01:00
|
|
|
var _txtLines = string_splice(_input_text, "\n");
|
2022-12-22 03:09:55 +01:00
|
|
|
var ss = "";
|
2023-09-15 20:12:02 +02:00
|
|
|
var _code = isCodeFormat();
|
2022-01-26 13:02:30 +01:00
|
|
|
|
2023-07-25 20:12:40 +02:00
|
|
|
for( var i = 0, n = array_length(_txtLines); i < n; i++ ) {
|
2023-08-06 16:00:59 +02:00
|
|
|
var _txt = _txtLines[i] + (i < array_length(_txtLines)? "\n" : "");
|
2023-09-07 20:59:14 +02:00
|
|
|
var words;
|
|
|
|
|
2023-09-17 13:23:24 +02:00
|
|
|
if(format == TEXT_AREA_FORMAT.codeLUA)
|
|
|
|
words = lua_token_splice(_txt);
|
|
|
|
else if(format == TEXT_AREA_FORMAT.codeHLSL)
|
|
|
|
words = hlsl_token_splice(_txt);
|
2023-09-07 20:59:14 +02:00
|
|
|
else
|
|
|
|
words = string_splice(_txt, " ");
|
|
|
|
|
2023-01-04 02:30:04 +01:00
|
|
|
var currW = 0;
|
|
|
|
var currL = "";
|
|
|
|
var cut = true;
|
2023-05-28 20:00:51 +02:00
|
|
|
var len = array_length(words);
|
2023-07-28 19:41:57 +02:00
|
|
|
var _iIndex = i + 1;
|
2022-12-22 03:09:55 +01:00
|
|
|
|
2023-05-28 20:00:51 +02:00
|
|
|
for( var j = 0; j < len; j++ ) {
|
2023-01-04 02:30:04 +01:00
|
|
|
var word = words[j];
|
2023-09-07 20:59:14 +02:00
|
|
|
if(!_code && j < len - 1) word = word + " ";
|
2023-01-04 02:30:04 +01:00
|
|
|
|
2023-03-11 06:40:34 +01:00
|
|
|
if(string_width(word) > line_width) { //the entire word is longer than a line
|
|
|
|
for( var k = 1; k <= string_length(word); k++ ) {
|
|
|
|
var ch = string_char_at(word, k);
|
|
|
|
|
|
|
|
if(currW + string_width(ch) > line_width) {
|
|
|
|
array_push(_input_text_line, currL);
|
2023-07-28 19:41:57 +02:00
|
|
|
array_push(_input_text_line_index, _iIndex); _iIndex = "";
|
|
|
|
|
2023-03-11 06:40:34 +01:00
|
|
|
currW = 0;
|
|
|
|
currL = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
currL += ch;
|
|
|
|
currW += string_width(ch);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-01-04 02:30:04 +01:00
|
|
|
if(currW + string_width(word) > line_width) {
|
|
|
|
array_push(_input_text_line, currL);
|
2023-07-28 19:41:57 +02:00
|
|
|
array_push(_input_text_line_index, _iIndex); _iIndex = "";
|
|
|
|
|
2023-01-04 02:30:04 +01:00
|
|
|
currW = 0;
|
|
|
|
currL = "";
|
2022-12-22 03:09:55 +01:00
|
|
|
}
|
2023-01-04 02:30:04 +01:00
|
|
|
|
|
|
|
cut = true;
|
|
|
|
currW += string_width(word);
|
|
|
|
currL += word;
|
2022-01-26 13:02:30 +01:00
|
|
|
}
|
2023-01-04 02:30:04 +01:00
|
|
|
|
2023-07-28 19:41:57 +02:00
|
|
|
if(cut) {
|
|
|
|
array_push(_input_text_line, currL);
|
|
|
|
array_push(_input_text_line_index, _iIndex); _iIndex = "";
|
|
|
|
}
|
2022-01-26 13:02:30 +01:00
|
|
|
}
|
2023-08-31 18:49:57 +02:00
|
|
|
} #endregion
|
2022-01-26 13:02:30 +01:00
|
|
|
|
2023-08-31 18:49:57 +02:00
|
|
|
static editText = function() { #region
|
2023-09-08 19:47:48 +02:00
|
|
|
var _input_text_pre = _input_text;
|
2023-07-12 16:28:32 +02:00
|
|
|
var modified = false;
|
2023-11-10 01:50:16 +01:00
|
|
|
var undoed = true;
|
2023-07-12 16:28:32 +02:00
|
|
|
|
2022-01-26 13:02:30 +01:00
|
|
|
#region text editor
|
2022-12-22 03:09:55 +01:00
|
|
|
if(key_mod_press(CTRL) && keyboard_check_pressed(ord("A"))) {
|
2022-12-12 09:08:03 +01:00
|
|
|
cursor_select = 0;
|
|
|
|
cursor = string_length(_input_text);
|
2023-11-10 11:32:46 +01:00
|
|
|
} else if(key_mod_press(CTRL) && !key_mod_press(SHIFT) && keyboard_check_pressed(ord("Z"))) { // UNDO
|
2023-11-10 01:50:16 +01:00
|
|
|
if(!ds_stack_empty(undo_stack)) {
|
|
|
|
ds_stack_push(redo_stack, _input_text);
|
|
|
|
_input_text = ds_stack_pop(undo_stack);
|
|
|
|
undo_current_text = _input_text;
|
|
|
|
cut_line();
|
|
|
|
move_cursor(0);
|
|
|
|
|
|
|
|
modified = true;
|
|
|
|
undoed = false;
|
|
|
|
undo_delay = 10;
|
|
|
|
}
|
2023-11-10 11:32:46 +01:00
|
|
|
} else if(key_mod_press(CTRL) && key_mod_press(SHIFT) && keyboard_check_pressed(ord("Z"))) { // REDO
|
2023-11-10 01:50:16 +01:00
|
|
|
if(!ds_stack_empty(redo_stack)) {
|
|
|
|
ds_stack_push(undo_stack, _input_text);
|
|
|
|
_input_text = ds_stack_pop(redo_stack);
|
|
|
|
undo_current_text = _input_text;
|
|
|
|
cut_line();
|
|
|
|
move_cursor(0);
|
|
|
|
|
|
|
|
modified = true;
|
|
|
|
undoed = false;
|
|
|
|
undo_delay = 10;
|
|
|
|
}
|
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-12-12 09:08:03 +01:00
|
|
|
if(cursor_select != -1) {
|
2022-01-29 14:25:18 +01:00
|
|
|
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-12-12 09:08: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();
|
2023-09-08 19:47:48 +02:00
|
|
|
|
2023-01-04 02:30:04 +01:00
|
|
|
if(keyboard_check_pressed(vk_escape)) {
|
2023-07-12 16:28:32 +02:00
|
|
|
} else if(keyboard_check_pressed(vk_tab)) {
|
2023-09-29 02:13:17 +02:00
|
|
|
} else if(keyboardEnter() == 2) {
|
2023-07-12 16:28:32 +02:00
|
|
|
var ch = "\n";
|
2024-01-24 08:38:57 +01:00
|
|
|
|
2023-07-12 16:28:32 +02: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);
|
2023-01-04 02:30:04 +01:00
|
|
|
|
2023-07-12 16:28:32 +02:00
|
|
|
_input_text = str_before + ch + str_after;
|
|
|
|
cut_line();
|
|
|
|
move_cursor(string_length(ch));
|
|
|
|
} else {
|
|
|
|
var minc = min(cursor, cursor_select);
|
|
|
|
var maxc = max(cursor, cursor_select);
|
2023-01-04 02:30:04 +01:00
|
|
|
|
2023-07-12 16:28:32 +02:00
|
|
|
var str_before = string_copy(_input_text, 1, minc);
|
|
|
|
var str_after = string_copy(_input_text, maxc + 1, string_length(_input_text) - maxc);
|
2023-01-04 02:30:04 +01:00
|
|
|
|
2023-07-12 16:28:32 +02:00
|
|
|
_input_text = str_before + ch + str_after;
|
|
|
|
cut_line();
|
|
|
|
cursor = minc + string_length(ch);
|
2023-01-04 02:30:04 +01:00
|
|
|
}
|
2023-11-10 01:50:16 +01:00
|
|
|
modified = true;
|
|
|
|
undo_delay = 10;
|
2023-01-01 02:06:02 +01:00
|
|
|
} else if(KEYBOARD_PRESSED == vk_backspace) {
|
2022-12-12 09:08: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--;
|
2023-11-10 01:50:16 +01:00
|
|
|
undo_delay++;
|
2023-09-08 21:09:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2023-11-10 01:50:16 +01:00
|
|
|
undo_delay++;
|
2023-09-08 21:09:09 +02:00
|
|
|
}
|
2022-01-26 13:02:30 +01:00
|
|
|
|
2023-11-10 01:50:16 +01:00
|
|
|
_input_text = str_before + str_after;
|
2022-12-12 09:08:03 +01:00
|
|
|
cut_line();
|
|
|
|
} else {
|
|
|
|
var minc = min(cursor, cursor_select);
|
|
|
|
var maxc = max(cursor, cursor_select);
|
2022-01-26 13:02:30 +01:00
|
|
|
|
2022-12-12 09:08:03 +01:00
|
|
|
var str_before = string_copy(_input_text, 1, minc);
|
|
|
|
var str_after = string_copy(_input_text, maxc + 1, string_length(_input_text) - maxc);
|
|
|
|
|
|
|
|
cursor = minc + 1;
|
|
|
|
_input_text = str_before + str_after;
|
|
|
|
cut_line();
|
2023-11-10 01:50:16 +01:00
|
|
|
undo_delay += maxc - minc;
|
2022-12-12 09:08:03 +01:00
|
|
|
}
|
2022-01-26 13:02:30 +01:00
|
|
|
|
2023-11-10 01:50:16 +01:00
|
|
|
cursor_select = -1;
|
2022-12-12 09:08:03 +01:00
|
|
|
move_cursor(-1);
|
2023-07-12 16:28:32 +02:00
|
|
|
modified = true;
|
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-12-12 09:08: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-01-26 13:02:30 +01:00
|
|
|
|
2022-12-12 09:08:03 +01:00
|
|
|
_input_text = str_before + str_after;
|
|
|
|
cut_line();
|
2023-11-10 01:50:16 +01:00
|
|
|
undo_delay++;
|
2022-12-12 09:08:03 +01:00
|
|
|
} else {
|
|
|
|
var minc = min(cursor, cursor_select);
|
|
|
|
var maxc = max(cursor, cursor_select);
|
2022-01-26 13:02:30 +01:00
|
|
|
|
2022-12-12 09:08:03 +01:00
|
|
|
var str_before = string_copy(_input_text, 1, minc);
|
|
|
|
var str_after = string_copy(_input_text, maxc + 1, string_length(_input_text) - maxc);
|
2022-01-26 13:02:30 +01:00
|
|
|
|
2022-12-12 09:08:03 +01:00
|
|
|
cursor = minc;
|
2023-11-10 01:50:16 +01:00
|
|
|
_input_text = str_before + str_after;
|
2022-12-12 09:08:03 +01:00
|
|
|
cut_line();
|
2023-11-10 01:50:16 +01:00
|
|
|
undo_delay += maxc - minc;
|
2022-12-12 09:08:03 +01:00
|
|
|
}
|
2023-11-10 01:50:16 +01:00
|
|
|
|
|
|
|
cursor_select = -1;
|
2023-07-12 16:28:32 +02:00
|
|
|
modified = true;
|
2023-07-17 19:58:33 +02:00
|
|
|
} else if(KEYBOARD_STRING != "" && KEYBOARD_STRING != "\b" && KEYBOARD_STRING != "\r") {
|
|
|
|
var ch = KEYBOARD_STRING;
|
2022-01-26 13:02:30 +01:00
|
|
|
|
2022-12-12 09:08: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);
|
2022-01-26 13:02:30 +01:00
|
|
|
|
2022-12-12 09:08:03 +01:00
|
|
|
_input_text = str_before + ch + str_after;
|
2023-09-08 19:47:48 +02:00
|
|
|
|
2022-12-12 09:08:03 +01:00
|
|
|
cut_line();
|
|
|
|
move_cursor(string_length(ch));
|
2023-11-10 01:50:16 +01:00
|
|
|
undo_delay++;
|
2022-12-12 09:08:03 +01:00
|
|
|
} else {
|
|
|
|
var minc = min(cursor, cursor_select);
|
|
|
|
var maxc = max(cursor, cursor_select);
|
2022-01-26 13:02:30 +01:00
|
|
|
|
2022-12-12 09:08:03 +01:00
|
|
|
var str_before = string_copy(_input_text, 1, minc);
|
|
|
|
var str_after = string_copy(_input_text, maxc + 1, string_length(_input_text) - maxc);
|
2022-01-26 13:02:30 +01:00
|
|
|
|
2022-12-12 09:08:03 +01:00
|
|
|
_input_text = str_before + ch + str_after;
|
|
|
|
cut_line();
|
|
|
|
cursor = minc + string_length(ch);
|
2023-11-10 01:50:16 +01:00
|
|
|
undo_delay += maxc - minc;
|
2022-12-12 09:08:03 +01:00
|
|
|
}
|
2022-01-29 14:25:18 +01:00
|
|
|
|
2023-11-10 01:50:16 +01:00
|
|
|
if(ch == " ") undo_delay = 10;
|
|
|
|
|
|
|
|
cursor_select = -1;
|
2023-07-12 16:28:32 +02:00
|
|
|
modified = true;
|
2022-12-12 09:08:03 +01:00
|
|
|
}
|
2022-01-26 13:02:30 +01:00
|
|
|
}
|
|
|
|
|
2022-12-12 09:08:03 +01:00
|
|
|
KEYBOARD_STRING = "";
|
2022-01-26 13:02:30 +01:00
|
|
|
keyboard_lastkey = -1;
|
|
|
|
#endregion
|
|
|
|
|
2023-11-10 01:50:16 +01:00
|
|
|
if(modified) {
|
|
|
|
if(undoed && undo_delay >= 10) {
|
|
|
|
ds_stack_push(undo_stack, undo_current_text);
|
|
|
|
ds_stack_clear(redo_stack);
|
|
|
|
|
|
|
|
undo_current_text = _input_text_pre;
|
|
|
|
undo_delay = 0;
|
|
|
|
}
|
|
|
|
onModified();
|
|
|
|
}
|
2023-07-12 16:28:32 +02:00
|
|
|
|
2023-12-15 12:56:36 +01:00
|
|
|
if(auto_update && (keyboard_check_pressed(vk_anykey) || modified))
|
2022-01-26 13:02:30 +01:00
|
|
|
apply();
|
|
|
|
|
2024-03-27 11:51:14 +01:00
|
|
|
if(modified) {
|
|
|
|
typing = 100;
|
|
|
|
|
|
|
|
if(IS_PATREON) {
|
|
|
|
shake_amount = PREFERENCES.textbox_shake;
|
|
|
|
repeat(PREFERENCES.textbox_particle) spawn_particle(rx + cursor_pos_x, ry + cursor_pos_y + random(16), 8);
|
|
|
|
}
|
|
|
|
}
|
2023-12-18 04:40:21 +01:00
|
|
|
|
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);
|
|
|
|
if(keyboard_check_pressed(vk_up)) onKey(vk_up);
|
|
|
|
if(keyboard_check_pressed(vk_down)) onKey(vk_down);
|
2023-09-08 19:47:48 +02:00
|
|
|
|
2022-12-22 03:09:55 +01:00
|
|
|
if(keyboard_check_pressed(vk_home)) {
|
2023-02-14 05:32:32 +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;
|
2023-01-09 03:14:20 +01:00
|
|
|
|
|
|
|
if(cursor_line == 0)
|
|
|
|
move_cursor(-cursor);
|
|
|
|
else {
|
|
|
|
var _str = _input_text_line[cursor_line];
|
|
|
|
while(string_char_at(_input_text, cursor) != "\n") {
|
2023-03-07 14:29:47 +01:00
|
|
|
if(cursor <= 0) break;
|
2023-01-09 03:14:20 +01:00
|
|
|
cursor--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-30 08:55:33 +01:00
|
|
|
autocomplete_delay = 0;
|
|
|
|
o_dialog_textbox_autocomplete.deactivate(self);
|
|
|
|
o_dialog_textbox_function_guide.deactivate(self);
|
2022-12-22 03:09:55 +01:00
|
|
|
} else if(keyboard_check_pressed(vk_end)) {
|
2023-02-14 05:32:32 +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;
|
2023-01-09 03:14:20 +01:00
|
|
|
|
|
|
|
var _str = _input_text_line[cursor_line];
|
|
|
|
while(string_char_at(_input_text, cursor + 1) != "\n" && cursor < string_length(_input_text)) {
|
|
|
|
cursor++;
|
|
|
|
}
|
2023-11-30 08:55:33 +01:00
|
|
|
|
|
|
|
autocomplete_delay = 0;
|
|
|
|
o_dialog_textbox_autocomplete.deactivate(self);
|
|
|
|
o_dialog_textbox_function_guide.deactivate(self);
|
2023-11-08 08:38:04 +01:00
|
|
|
} else if(keyboard_check_pressed(vk_escape) && o_dialog_textbox_autocomplete.textbox != self) {
|
2022-01-26 13:02:30 +01:00
|
|
|
_input_text = _last_value;
|
|
|
|
cut_line();
|
2023-01-17 08:11:55 +01:00
|
|
|
deactivate();
|
2023-09-29 02:13:17 +02:00
|
|
|
} else if(keyboardEnter() == 1) {
|
2023-01-17 08:11:55 +01:00
|
|
|
deactivate();
|
2022-01-26 13:02:30 +01:00
|
|
|
}
|
2023-08-31 18:49:57 +02:00
|
|
|
} #endregion
|
2022-01-26 13:02:30 +01:00
|
|
|
|
2023-11-09 13:27:16 +01:00
|
|
|
static display_text = function(_x, _y, _text, _mx = -1, _my = -1, _hover = false) { #region
|
2023-02-17 04:48:54 +01:00
|
|
|
_text = string_real(_text);
|
2023-09-07 20:59:14 +02:00
|
|
|
if(line_width != _prev_width) {
|
|
|
|
_prev_width = line_width;
|
2022-01-29 14:25:18 +01:00
|
|
|
cut_line();
|
|
|
|
}
|
|
|
|
|
2023-04-16 11:53:46 +02:00
|
|
|
draw_set_text(font, fa_left, fa_top, color);
|
2023-10-03 07:14:28 +02:00
|
|
|
draw_set_alpha(0.5 + 0.5 * interactable);
|
2023-12-18 04:40:21 +01:00
|
|
|
_y += ui(1);
|
2022-01-26 13:02:30 +01:00
|
|
|
|
|
|
|
var ch_x = _x;
|
|
|
|
var ch_y = _y;
|
|
|
|
var _str;
|
|
|
|
|
2024-01-24 08:38:57 +01:00
|
|
|
text_y_max = 0;
|
|
|
|
|
2023-01-09 03:14:20 +01:00
|
|
|
if(_input_text != _text) {
|
|
|
|
_input_text = _text;
|
2022-01-26 13:02:30 +01:00
|
|
|
cut_line();
|
|
|
|
}
|
|
|
|
|
2024-03-27 11:51:14 +01:00
|
|
|
__code_draw_comment = false;
|
|
|
|
|
2023-07-25 20:12:40 +02:00
|
|
|
for( var i = 0, n = array_length(_input_text_line); i < n; i++ ) {
|
2022-01-26 13:02:30 +01:00
|
|
|
_str = _input_text_line[i];
|
2023-01-04 02:30:04 +01:00
|
|
|
|
2024-03-27 11:51:14 +01:00
|
|
|
if(_input_text_line_index[i] != "") {
|
|
|
|
draw_set_color(color);
|
|
|
|
__code_draw_comment = false;
|
|
|
|
}
|
|
|
|
|
2023-09-15 20:12:02 +02:00
|
|
|
switch(format) {
|
|
|
|
case TEXT_AREA_FORMAT._default :
|
|
|
|
draw_text_add(ch_x, ch_y, _str);
|
|
|
|
break;
|
|
|
|
case TEXT_AREA_FORMAT.delimiter :
|
|
|
|
draw_text_delimiter(ch_x, ch_y, _str);
|
|
|
|
break;
|
|
|
|
case TEXT_AREA_FORMAT.path_template :
|
|
|
|
draw_text_path(ch_x, ch_y, _str);
|
|
|
|
break;
|
|
|
|
case TEXT_AREA_FORMAT.codeLUA :
|
2023-11-07 12:07:17 +01:00
|
|
|
if(syntax_highlight) draw_code_lua(ch_x, ch_y, _str);
|
|
|
|
else draw_text_add(ch_x, ch_y, _str);
|
2023-09-15 20:12:02 +02:00
|
|
|
break;
|
|
|
|
case TEXT_AREA_FORMAT.codeHLSL :
|
2023-11-07 12:07:17 +01:00
|
|
|
if(syntax_highlight) draw_code_hlsl(ch_x, ch_y, _str);
|
|
|
|
else draw_text_add(ch_x, ch_y, _str);
|
2023-09-15 20:12:02 +02:00
|
|
|
break;
|
|
|
|
}
|
2023-01-04 02:30:04 +01:00
|
|
|
|
2024-01-24 08:38:57 +01:00
|
|
|
ch_y += line_get_height();
|
|
|
|
text_y_max += line_get_height();
|
2022-01-26 13:02:30 +01:00
|
|
|
}
|
2023-01-04 02:30:04 +01:00
|
|
|
|
2023-01-17 08:11:55 +01:00
|
|
|
draw_set_alpha(1);
|
|
|
|
|
2023-11-09 13:27:16 +01:00
|
|
|
var target = undefined;
|
|
|
|
|
|
|
|
if(_hover) {
|
|
|
|
target = 0;
|
2022-01-26 13:02:30 +01:00
|
|
|
var char_run = 0, _l, _ch_w, _ch_h, _str, _chr;
|
2023-11-09 13:27:16 +01:00
|
|
|
var sx = _x;
|
|
|
|
var ch_x = sx;
|
2023-01-09 03:14:20 +01:00
|
|
|
var ch_cxo = sx;
|
|
|
|
var ch_cxn = sx;
|
2023-11-09 13:27:16 +01:00
|
|
|
var ch_y = _y;
|
|
|
|
var _found_char = false;
|
2022-01-26 13:02:30 +01:00
|
|
|
|
2023-07-25 20:12:40 +02:00
|
|
|
for( var i = 0, n = array_length(_input_text_line); i < n; i++ ) {
|
2023-01-09 03:14:20 +01:00
|
|
|
_str = string_trim_end(_input_text_line[i]);
|
2023-11-09 13:27:16 +01:00
|
|
|
_l = string_length(_str);
|
|
|
|
_ch_h = line_get_height();
|
2023-01-09 03:14:20 +01:00
|
|
|
ch_cxo = sx;
|
2023-11-09 13:27:16 +01:00
|
|
|
ch_x = sx;
|
2022-01-26 13:02:30 +01:00
|
|
|
|
2023-11-09 13:27:16 +01:00
|
|
|
if((i == 0 || ch_y <= _my) && (i == n - 1 || _my < ch_y + _ch_h)) {
|
|
|
|
for( var j = 0; j < _l; j++ ) {
|
2022-01-26 13:02:30 +01:00
|
|
|
_chr = string_char_at(_str, j + 1);
|
|
|
|
_ch_w = string_width(_chr);
|
|
|
|
ch_cxn = ch_x + _ch_w / 2;
|
|
|
|
|
2023-11-09 13:27:16 +01:00
|
|
|
if(_mx <= ch_cxn) {
|
2022-01-26 13:02:30 +01:00
|
|
|
target = char_run + j;
|
2023-11-09 13:27:16 +01:00
|
|
|
_found_char = true;
|
2022-01-26 13:02:30 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-09-07 20:59:14 +02:00
|
|
|
ch_x += _ch_w;
|
2022-01-26 13:02:30 +01:00
|
|
|
ch_cxo = ch_cxn;
|
|
|
|
}
|
2023-11-09 13:27:16 +01:00
|
|
|
|
|
|
|
if(!_found_char) target = char_run + _l;
|
|
|
|
_found_char = true;
|
2022-01-26 13:02:30 +01:00
|
|
|
break;
|
|
|
|
}
|
2023-09-07 20:59:14 +02:00
|
|
|
|
2023-01-09 03:14:20 +01:00
|
|
|
char_run += string_length(_input_text_line[i]);
|
2022-01-26 13:02:30 +01:00
|
|
|
ch_y += _ch_h;
|
|
|
|
}
|
2023-11-09 13:27:16 +01:00
|
|
|
|
|
|
|
if(ch_y <= _my && !_found_char) target = char_run - 1;
|
2022-01-26 13:02:30 +01:00
|
|
|
}
|
|
|
|
|
2023-11-09 13:27:16 +01:00
|
|
|
if(target != undefined) {
|
2023-12-05 09:51:24 +01:00
|
|
|
if(!click_block) {
|
|
|
|
if(mouse_press(mb_left, active) && HOVER != o_dialog_textbox_autocomplete.id) {
|
|
|
|
cursor_select = target;
|
|
|
|
cursor = target;
|
|
|
|
|
|
|
|
o_dialog_textbox_autocomplete.deactivate(self);
|
|
|
|
} else if(mouse_click(mb_left, active))
|
|
|
|
cursor = target;
|
|
|
|
}
|
2022-01-26 13:02:30 +01:00
|
|
|
}
|
2023-11-09 13:27:16 +01:00
|
|
|
|
2024-01-24 08:38:57 +01:00
|
|
|
if(mouse_release(mb_left)) {
|
2023-12-05 09:51:24 +01:00
|
|
|
click_block = false;
|
2024-01-24 08:38:57 +01:00
|
|
|
|
|
|
|
if(cursor_select == cursor)
|
|
|
|
cursor_select = -1;
|
|
|
|
}
|
2023-08-31 18:49:57 +02:00
|
|
|
} #endregion
|
2022-01-26 13:02:30 +01:00
|
|
|
|
2023-08-31 18:49:57 +02:00
|
|
|
static drawParam = function(params) { #region
|
2024-03-27 11:51:14 +01:00
|
|
|
setParam(params);
|
2023-09-07 20:59:14 +02:00
|
|
|
|
2024-04-10 05:02:23 +02:00
|
|
|
if(format == TEXT_AREA_FORMAT.codeHLSL || format == TEXT_AREA_FORMAT.codeLUA)
|
|
|
|
font = f_code;
|
|
|
|
|
2023-07-30 19:56:53 +02:00
|
|
|
return draw(params.x, params.y, params.w, params.h, params.data, params.m);
|
2023-08-31 18:49:57 +02:00
|
|
|
} #endregion
|
2023-07-30 19:56:53 +02:00
|
|
|
|
2023-08-31 18:49:57 +02:00
|
|
|
static draw = function(_x, _y, _w, _h, _text, _m) { #region
|
2024-01-24 08:38:57 +01:00
|
|
|
_h = max_height == -1? _h : min(_h, max_height);
|
|
|
|
|
2023-01-17 08:11:55 +01:00
|
|
|
x = _x;
|
|
|
|
y = _y;
|
|
|
|
w = _w;
|
|
|
|
h = _h;
|
2023-07-12 16:28:32 +02:00
|
|
|
|
2024-03-28 14:18:02 +01:00
|
|
|
hovering = false;
|
|
|
|
|
2023-11-14 14:29:11 +01:00
|
|
|
autocomplete_delay += delta_time / 1000;
|
2024-01-24 08:38:57 +01:00
|
|
|
_stretch_width = _w < 0;
|
|
|
|
_text = string_real(_text);
|
|
|
|
_current_text = _text;
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2023-07-30 13:56:22 +02:00
|
|
|
draw_set_font(font);
|
2024-01-24 08:38:57 +01:00
|
|
|
if(_stretch_width) _w = string_width(self == WIDGET_CURRENT? _input_text : _text) + ui(16);
|
|
|
|
|
|
|
|
w = _w;
|
2024-03-28 14:18:02 +01:00
|
|
|
var _bs = min(h, ui(32));
|
2023-03-13 10:45:56 +01:00
|
|
|
|
2024-03-28 14:18:02 +01:00
|
|
|
if(_w - _bs > ui(100) && side_button && instanceof(side_button) == "buttonClass") {
|
2023-10-03 07:14:28 +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(8);
|
2023-01-01 02:06:02 +01:00
|
|
|
}
|
|
|
|
|
2024-01-24 08:38:57 +01:00
|
|
|
var tx = ui(8);
|
2022-01-26 13:02:30 +01:00
|
|
|
var hh = _h;
|
2023-09-15 20:12:02 +02:00
|
|
|
var pl = line_width;
|
2023-01-04 02:30:04 +01:00
|
|
|
|
|
|
|
if(format == TEXT_AREA_FORMAT._default) {
|
|
|
|
line_width = _w - ui(16);
|
2023-09-15 20:12:02 +02:00
|
|
|
} else if(isCodeFormat()) {
|
|
|
|
line_width = _w - ui(16 + code_line_width * show_line_number);
|
|
|
|
tx += ui(code_line_width * show_line_number);
|
2023-01-04 02:30:04 +01:00
|
|
|
}
|
2022-01-26 13:02:30 +01:00
|
|
|
|
2023-07-30 13:56:22 +02:00
|
|
|
if(_stretch_width) line_width = 9999999;
|
2024-01-24 08:38:57 +01:00
|
|
|
cursor_tx = _x + tx;
|
2023-06-20 19:43:19 +02:00
|
|
|
|
2024-01-24 08:38:57 +01:00
|
|
|
var c_h = line_get_height();
|
2023-01-04 02:30:04 +01:00
|
|
|
var line_count = max(min_lines, array_length(_input_text_line));
|
2024-01-24 08:38:57 +01:00
|
|
|
|
2023-01-04 02:30:04 +01:00
|
|
|
hh = max(_h, ui(14) + c_h * line_count);
|
2024-01-24 08:38:57 +01:00
|
|
|
if(max_height) hh = min(hh, max_height);
|
|
|
|
|
|
|
|
var _hw = _w;
|
|
|
|
if(max_height && text_y_max) {
|
|
|
|
_hw -= 16;
|
|
|
|
line_width -= 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
var hoverRect = point_in_rectangle(_m[0], _m[1], _x, _y, _x + _hw, _y + hh);
|
|
|
|
var tsw = _w;
|
|
|
|
var tsh = hh;
|
2024-04-01 11:10:01 +02:00
|
|
|
var _update = !surface_valid(text_surface, tsw, tsh);
|
|
|
|
if(_update) text_surface = surface_verify(text_surface, tsw, tsh);
|
2023-01-04 02:30:04 +01:00
|
|
|
|
2023-04-16 11:53:46 +02:00
|
|
|
draw_sprite_stretched_ext(THEME.textbox, 3, _x, _y, _w, hh, boxColor, 1);
|
2023-01-04 02:30:04 +01:00
|
|
|
|
2024-01-24 08:38:57 +01:00
|
|
|
surface_set_shader(text_surface, noone, true, BLEND.add);
|
|
|
|
if(isCodeFormat() && show_line_number) {
|
|
|
|
draw_sprite_stretched_ext(THEME.textbox_code, 0, 0, 0, ui(code_line_width), hh, boxColor, 1);
|
|
|
|
draw_set_text(f_code, fa_right, fa_top, COLORS._main_text_sub);
|
2023-01-04 02:30:04 +01:00
|
|
|
|
2024-01-24 08:38:57 +01:00
|
|
|
var lx = ui(code_line_width - 8);
|
|
|
|
|
|
|
|
for( var i = 0; i < array_length(_input_text_line_index); i++ ) {
|
|
|
|
var ly = text_y + ui(7) + i * c_h;
|
|
|
|
draw_text_add(lx, ly, _input_text_line_index[i]);
|
|
|
|
}
|
2023-01-04 02:30:04 +01:00
|
|
|
}
|
2024-01-24 08:38:57 +01:00
|
|
|
surface_reset_shader();
|
2023-03-26 07:13:36 +02:00
|
|
|
|
2023-10-03 07:14:28 +02:00
|
|
|
if(selecting) {
|
2023-07-12 16:28:32 +02:00
|
|
|
WIDGET_TAB_BLOCK = true;
|
|
|
|
|
2023-01-09 03:14:20 +01:00
|
|
|
draw_set_text(font, fa_left, fa_top, COLORS._main_text);
|
2022-01-26 13:02:30 +01:00
|
|
|
editText();
|
|
|
|
|
2024-04-20 05:42:23 +02:00
|
|
|
#region draw selecting
|
2024-01-24 08:38:57 +01:00
|
|
|
var msx = _m[0] - _x;
|
|
|
|
var msy = _m[1] - _y;
|
2022-01-26 13:02:30 +01:00
|
|
|
|
2024-01-24 08:38:57 +01:00
|
|
|
surface_set_shader(text_surface, noone, false, BLEND.add);
|
|
|
|
draw_set_text(font, fa_left, fa_top, COLORS._main_text);
|
|
|
|
|
|
|
|
#region draw cursor highlight
|
|
|
|
var _l, _str;
|
|
|
|
|
|
|
|
var ch_x = tx;
|
|
|
|
var ch_y = text_y + ui(7);
|
|
|
|
var ch_sel_min = -1;
|
|
|
|
var ch_sel_max = -1;
|
|
|
|
var char_line = 0;
|
|
|
|
var curs_found = false;
|
|
|
|
|
|
|
|
char_run = 0;
|
2022-01-26 13:02:30 +01:00
|
|
|
|
|
|
|
if(cursor_select != -1) {
|
2024-01-24 08:38:57 +01:00
|
|
|
ch_sel_min = min(cursor_select, cursor);
|
|
|
|
ch_sel_max = max(cursor_select, cursor);
|
|
|
|
}
|
|
|
|
|
|
|
|
for( var i = 0, n = array_length(_input_text_line); i < n; i++ ) {
|
|
|
|
_str = _input_text_line[i];
|
|
|
|
_l = string_length(_str);
|
|
|
|
|
|
|
|
if(cursor_select != -1) {
|
|
|
|
draw_set_color(COLORS.widget_text_highlight);
|
2022-01-26 13:02:30 +01:00
|
|
|
|
2024-01-24 08:38:57 +01:00
|
|
|
if(char_line <= ch_sel_min && char_line + _l > ch_sel_min) {
|
|
|
|
var _hstr1 = string_copy(_str, 1, ch_sel_min - char_line);
|
|
|
|
var _hstr2 = string_copy(_str, 1, ch_sel_max - char_line);
|
2023-12-05 09:51:24 +01:00
|
|
|
|
2024-01-24 08:38:57 +01:00
|
|
|
if(format == TEXT_AREA_FORMAT.delimiter) {
|
|
|
|
_hstr1 = string_replace_all(_hstr1, " ", "<space>");
|
|
|
|
_hstr2 = string_replace_all(_hstr2, " ", "<space>");
|
|
|
|
}
|
2023-12-05 09:51:24 +01:00
|
|
|
|
2024-01-24 08:38:57 +01:00
|
|
|
var x1 = tx + string_width(_hstr1);
|
|
|
|
var x2 = tx + string_width(_hstr2);
|
2023-09-15 20:12:02 +02:00
|
|
|
|
2024-01-24 08:38:57 +01:00
|
|
|
draw_roundrect_ext(x1, ch_y, x2, ch_y + c_h, THEME_VALUE.highlight_corner_radius, THEME_VALUE.highlight_corner_radius, 0);
|
|
|
|
} else if(char_line >= ch_sel_min && char_line + _l < ch_sel_max) {
|
|
|
|
var _hstr = _str;
|
2023-12-05 09:51:24 +01:00
|
|
|
|
2024-01-24 08:38:57 +01:00
|
|
|
if(format == TEXT_AREA_FORMAT.delimiter)
|
|
|
|
_hstr = string_replace_all(_hstr, " ", "<space>");
|
2023-12-05 09:51:24 +01:00
|
|
|
|
2024-01-24 08:38:57 +01:00
|
|
|
var x2 = tx + string_width(_hstr);
|
2022-01-26 13:02:30 +01:00
|
|
|
|
2024-01-24 08:38:57 +01:00
|
|
|
draw_roundrect_ext(tx, ch_y, x2, ch_y + c_h, THEME_VALUE.highlight_corner_radius, THEME_VALUE.highlight_corner_radius, 0);
|
|
|
|
} else if(char_line > ch_sel_min && char_line <= ch_sel_max && char_line + _l >= ch_sel_max) {
|
|
|
|
var _hstr = string_copy(_str, 1, ch_sel_max - char_line);
|
2023-12-05 09:51:24 +01:00
|
|
|
|
2024-01-24 08:38:57 +01:00
|
|
|
if(format == TEXT_AREA_FORMAT.delimiter)
|
|
|
|
_hstr = string_replace_all(_hstr, " ", "<space>");
|
2023-12-05 09:51:24 +01:00
|
|
|
|
2024-01-24 08:38:57 +01:00
|
|
|
var x2 = tx + string_width(_hstr);
|
2022-01-26 13:02:30 +01:00
|
|
|
|
2024-01-24 08:38:57 +01:00
|
|
|
draw_roundrect_ext(tx, ch_y, x2, ch_y + c_h, THEME_VALUE.highlight_corner_radius, THEME_VALUE.highlight_corner_radius, 0);
|
|
|
|
}
|
2022-01-26 13:02:30 +01:00
|
|
|
}
|
|
|
|
|
2024-01-24 08:38:57 +01:00
|
|
|
if(!curs_found && char_line <= cursor && cursor < char_line + _l) {
|
|
|
|
if(format == TEXT_AREA_FORMAT.delimiter) {
|
|
|
|
var str_cur = string_copy(_str, 1, cursor - char_line);
|
|
|
|
str_cur = string_replace_all(str_cur, " ", "<space>");
|
|
|
|
cursor_pos_x_to = ch_x + string_width(str_cur);
|
|
|
|
} else
|
|
|
|
cursor_pos_x_to = ch_x + string_width(string_copy(_str, 1, cursor - char_line));
|
|
|
|
cursor_pos_y_to = ch_y;
|
|
|
|
cursor_line = i;
|
|
|
|
char_run = char_line;
|
2023-07-12 16:28:32 +02:00
|
|
|
|
2024-01-24 08:38:57 +01:00
|
|
|
curs_found = true;
|
|
|
|
}
|
2023-07-12 16:28:32 +02:00
|
|
|
|
2024-01-24 08:38:57 +01:00
|
|
|
char_line += _l;
|
|
|
|
ch_y += line_get_height();
|
|
|
|
}
|
|
|
|
|
2024-06-19 09:04:03 +02:00
|
|
|
cursor_pos_x = cursor_pos_x == 0? cursor_pos_x_to : lerp_float(cursor_pos_x, cursor_pos_x_to, 1);
|
|
|
|
cursor_pos_y = cursor_pos_y == 0? cursor_pos_y_to : lerp_float(cursor_pos_y, cursor_pos_y_to, 1);
|
2024-01-24 08:38:57 +01:00
|
|
|
#endregion
|
2022-01-26 13:02:30 +01:00
|
|
|
|
2024-01-24 08:38:57 +01:00
|
|
|
display_text(tx, text_y + ui(7), _input_text, msx, msy, hover && hoverRect);
|
|
|
|
|
|
|
|
if(cursor_pos_y != 0 && cursor_pos_x != 0) {
|
|
|
|
draw_set_color(COLORS._main_text_accent);
|
|
|
|
draw_set_alpha(typing || current_time % (PREFERENCES.caret_blink * 2000) > PREFERENCES.caret_blink * 1000);
|
|
|
|
draw_line_width(cursor_pos_x, cursor_pos_y, cursor_pos_x, cursor_pos_y + c_h, 2);
|
|
|
|
draw_set_alpha(1);
|
|
|
|
}
|
|
|
|
surface_reset_shader();
|
|
|
|
|
|
|
|
BLEND_ALPHA
|
|
|
|
draw_surface(text_surface, _x, _y);
|
|
|
|
BLEND_NORMAL
|
2022-01-26 13:02:30 +01:00
|
|
|
|
2024-01-24 08:38:57 +01:00
|
|
|
if(typing) typing--;
|
2023-01-09 03:14:20 +01:00
|
|
|
|
2024-01-24 08:38:57 +01:00
|
|
|
draw_sprite_stretched_ext(THEME.textbox, 2, _x, _y, _w, hh, COLORS._main_accent, 1);
|
2023-09-15 20:12:02 +02:00
|
|
|
|
2023-11-08 08:38:04 +01:00
|
|
|
if(o_dialog_textbox_autocomplete.textbox == self) {
|
2024-01-24 08:38:57 +01:00
|
|
|
o_dialog_textbox_autocomplete.dialog_x = rx + _x + cursor_pos_x + 1;
|
|
|
|
o_dialog_textbox_autocomplete.dialog_y = ry + _y + cursor_pos_y + line_get_height() + 1;
|
2023-09-15 20:12:02 +02:00
|
|
|
}
|
2024-04-08 07:13:46 +02:00
|
|
|
|
|
|
|
if(o_dialog_textbox_function_guide.textbox == self) {
|
|
|
|
o_dialog_textbox_function_guide.dialog_x = rx + _x + cursor_pos_x + 1;
|
|
|
|
o_dialog_textbox_function_guide.dialog_y = ry + _y + cursor_pos_y - 12;
|
|
|
|
}
|
2022-01-26 13:02:30 +01:00
|
|
|
#endregion
|
|
|
|
|
2023-11-14 14:29:11 +01:00
|
|
|
if(autocomplete_modi && PREFERENCES.widget_autocomplete_delay >= 0 && autocomplete_delay >= PREFERENCES.widget_autocomplete_delay) {
|
|
|
|
o_dialog_textbox_autocomplete.activate(self);
|
|
|
|
autocomplete_modi = false;
|
|
|
|
}
|
|
|
|
|
2024-01-24 08:38:57 +01:00
|
|
|
if(!point_in_rectangle(_m[0], _m[1], _x, _y, _x + _w, _y + hh) && mouse_press(mb_left) && HOVER != o_dialog_textbox_autocomplete.id)
|
2023-01-17 08:11:55 +01:00
|
|
|
deactivate();
|
2024-01-24 08:38:57 +01:00
|
|
|
|
2022-01-26 13:02:30 +01:00
|
|
|
} else {
|
2024-04-02 05:24:55 +02:00
|
|
|
surface_set_shader(text_surface, noone, false, BLEND.add);
|
|
|
|
display_text(tx, text_y + ui(7), _text);
|
|
|
|
surface_reset_shader();
|
2024-01-24 08:38:57 +01:00
|
|
|
|
|
|
|
BLEND_ALPHA
|
|
|
|
draw_surface(text_surface, _x, _y);
|
|
|
|
BLEND_NORMAL
|
|
|
|
|
2023-03-26 07:13:36 +02:00
|
|
|
if(hover && hoverRect) {
|
2024-03-28 14:18:02 +01:00
|
|
|
hovering = true;
|
|
|
|
|
2022-01-26 13:02:30 +01:00
|
|
|
if(hide)
|
2023-04-16 11:53:46 +02:00
|
|
|
draw_sprite_stretched_ext(THEME.textbox, 1, _x, _y, _w, hh, boxColor, 0.5);
|
2022-01-26 13:02:30 +01:00
|
|
|
else
|
2023-04-16 11:53:46 +02:00
|
|
|
draw_sprite_stretched_ext(THEME.textbox, 1, _x, _y, _w, hh, boxColor, 0.5 + 0.5 * interactable);
|
2023-01-17 08:11:55 +01:00
|
|
|
if(mouse_press(mb_left, active))
|
|
|
|
activate();
|
2023-04-16 11:53:46 +02:00
|
|
|
} else if(!hide)
|
|
|
|
draw_sprite_stretched_ext(THEME.textbox, 0, _x, _y, _w, hh, boxColor, 0.5 + 0.5 * interactable);
|
2024-01-24 08:38:57 +01:00
|
|
|
|
2023-11-08 08:38:04 +01:00
|
|
|
o_dialog_textbox_autocomplete.deactivate(self);
|
2022-01-26 13:02:30 +01:00
|
|
|
}
|
|
|
|
|
2024-01-24 08:38:57 +01:00
|
|
|
#region scroll height
|
|
|
|
if(max_height) {
|
|
|
|
var total_h = text_y_max;
|
|
|
|
text_y_max = max(0, total_h - hh + 16);
|
|
|
|
text_y = lerp_float(text_y, text_y_to, 5);
|
|
|
|
|
|
|
|
if(hover) {
|
|
|
|
if(mouse_wheel_down()) text_y_to = clamp(text_y_to - ui(64) * SCROLL_SPEED, -text_y_max, 0);
|
|
|
|
if(mouse_wheel_up()) text_y_to = clamp(text_y_to + ui(64) * SCROLL_SPEED, -text_y_max, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
var scr_w = ui(sprite_get_width(THEME.ui_scrollbar));
|
|
|
|
var scr_h = hh - (ui(12) - scr_w) * 2;
|
|
|
|
var scr_x = _x + _w - ui(12);
|
|
|
|
var scr_y = _y + ui(12) - scr_w;
|
|
|
|
|
|
|
|
var bar_h = hh / total_h * scr_h;
|
|
|
|
var bar_y = scr_y + (scr_h - bar_h) * abs(text_y / text_y_max);
|
|
|
|
|
|
|
|
if(text_scrolling) {
|
|
|
|
text_y_to = text_scroll_sy - (_m[1] - text_scroll_my) / bar_h * scr_h;
|
|
|
|
text_y_to = clamp(text_y_to, -text_y_max, 0);
|
|
|
|
|
|
|
|
if(mouse_release(mb_left))
|
|
|
|
text_scrolling = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(text_y_max) {
|
|
|
|
var hov = hover && point_in_rectangle(_m[0], _m[1], scr_x - 3, _y, _x + _w, _y + _h);
|
|
|
|
|
|
|
|
draw_sprite_stretched_ext(THEME.ui_scrollbar, 0, scr_x, scr_y, scr_w, scr_h, COLORS.scrollbar_bg, 1);
|
|
|
|
draw_sprite_stretched_ext(THEME.ui_scrollbar, 0, scr_x, bar_y, scr_w, bar_h, hov || text_scrolling? COLORS.scrollbar_hover : COLORS.scrollbar_idle, 1);
|
|
|
|
|
|
|
|
if(mouse_press(mb_left, hov && active)) {
|
|
|
|
text_scrolling = true;
|
|
|
|
text_scroll_sy = text_y;
|
|
|
|
text_scroll_my = _m[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
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, hh, COLORS._main_value_positive, 1);
|
|
|
|
if(mouse_release(mb_left))
|
|
|
|
onModify(DRAGGING.data);
|
|
|
|
}
|
|
|
|
|
2024-01-24 08:38:57 +01:00
|
|
|
selecting = self == WIDGET_CURRENT;
|
2023-09-07 20:59:14 +02:00
|
|
|
shift_new_line = true;
|
2024-01-24 08:38:57 +01:00
|
|
|
resetFocus();
|
2022-01-26 13:02:30 +01:00
|
|
|
|
|
|
|
return hh;
|
2023-08-31 18:49:57 +02:00
|
|
|
} #endregion
|
2024-03-31 11:10:14 +02:00
|
|
|
|
2022-01-26 13:02:30 +01:00
|
|
|
}
|