Pixel-Composer/scripts/textArea/textArea.gml

616 lines
16 KiB
Text
Raw Normal View History

2023-01-04 02:30:04 +01:00
enum TEXT_AREA_FORMAT {
_default,
2023-02-14 05:32:32 +01:00
code,
delimiter
2023-01-04 02:30:04 +01:00
}
2023-01-17 08:11:55 +01:00
function textArea(_input, _onModify, _extras = noone) : textInput(_input, _onModify, _extras) constructor {
2022-01-26 13:02:30 +01:00
font = f_p0;
hide = false;
line_width = 1000;
auto_update = false;
_input_text_line = [];
2023-01-17 08:11:55 +01:00
_current_text = "";
2022-01-26 13:02:30 +01:00
_input_text = "";
_prev_text = "";
_last_value = "";
2022-01-29 14:25:18 +01:00
_prev_width = 0;
2023-01-04 02:30:04 +01:00
min_lines = 0;
2022-01-26 13:02:30 +01:00
cursor = 0;
cursor_pos_x = 0;
cursor_pos_x_to = 0;
cursor_pos_y = 0;
cursor_pos_y_to = 0;
cursor_line = 0;
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-01-09 03:14:20 +01:00
_cl = -1;
2023-01-17 08:11:55 +01:00
static activate = function() {
WIDGET_CURRENT = self;
WIDGET_CURRENT_SCROLL = parent;
parentFocus();
_input_text = _current_text;
_last_value = _current_text;
cursor_pos_x = 0;
cursor_pos_y = 0;
click_block = 1;
KEYBOARD_STRING = "";
keyboard_lastkey = -1;
cut_line();
}
static deactivate = function() {
if(WIDGET_CURRENT != self) return;
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;
}
2022-01-26 13:02:30 +01:00
static apply = function() {
if(onModify) onModify(_input_text);
2022-11-22 14:25:39 +01:00
UNDO_HOLDING = true;
2022-01-26 13:02:30 +01:00
}
static move_cursor = function(delta) {
var ll = string_length(_input_text);
2022-01-29 14:25:18 +01:00
cursor = clamp(cursor + delta, 0, ll);
2022-01-26 13:02:30 +01:00
}
static cut_line = function() {
_input_text_line = [];
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 = "";
2022-01-26 13:02:30 +01:00
2022-12-22 03:09:55 +01:00
for( var i = 0; i < array_length(_txtLines); i++ ) {
2023-01-09 03:14:20 +01:00
var _txt = _txtLines[i] + (i < array_length(_txtLines)? "\n" : "");
2023-01-04 02:30:04 +01:00
var words = string_splice(_txt, " ");
var currW = 0;
var currL = "";
var cut = true;
2022-12-22 03:09:55 +01:00
2023-01-04 02:30:04 +01:00
for( var j = 0; j < array_length(words); j++ ) {
var word = words[j];
if(j) word = " " + word;
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);
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);
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
if(cut) array_push(_input_text_line, currL);
2022-01-26 13:02:30 +01:00
}
}
static editText = function() {
#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);
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);
2022-12-12 09:08:03 +01:00
clipboard_set_text(string_copy(_input_text, minc, maxc - minc));
}
} 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-01-04 02:30:04 +01:00
if(keyboard_check_pressed(vk_escape)) {
} else if(keyboard_check_pressed(vk_enter)) {
if(key_mod_press(SHIFT)) {
var ch = "\n";
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;
cut_line();
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;
cut_line();
cursor = minc + string_length(ch);
}
}
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) {
var str_before = string_copy(_input_text, 1, cursor - 1);
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 + str_after;
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();
}
2022-01-26 13:02:30 +01:00
2022-12-12 09:08:03 +01:00
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-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();
} 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;
_input_text = str_before + str_after;
cut_line();
}
cursor_select = -1;
} else if(KEYBOARD_STRING != "") {
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;
cut_line();
move_cursor(string_length(ch));
} 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);
}
2022-01-29 14:25:18 +01:00
2022-12-12 09:08:03 +01:00
cursor_select = -1;
}
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
if(auto_update && keyboard_check_pressed(vk_anykey))
apply();
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--;
}
}
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++;
}
2022-12-22 03:09:55 +01:00
} else if(keyboard_check_pressed(vk_escape)) {
2022-01-26 13:02:30 +01:00
_input_text = _last_value;
cut_line();
2023-01-17 08:11:55 +01:00
deactivate();
2023-01-04 02:30:04 +01:00
} else if(keyboard_check_pressed(vk_enter) && !key_mod_press(SHIFT)) {
2023-01-17 08:11:55 +01:00
deactivate();
2022-01-26 13:02:30 +01:00
}
}
static display_text = function(_x, _y, _text, _w, _mx = -1, _my = -1) {
2023-02-17 04:48:54 +01:00
_text = string_real(_text);
2022-01-29 14:25:18 +01:00
if(_w != _prev_width) {
_prev_width = _w;
cut_line();
}
2022-01-26 13:02:30 +01:00
var _xx = _x, _ch, _chw;
var target = -999;
2022-11-18 03:20:31 +01:00
draw_set_text(font, fa_left, fa_top, COLORS._main_text);
2023-01-17 08:11:55 +01:00
draw_set_alpha(0.5 + 0.5 * interactable)
2022-01-26 13:02:30 +01:00
var ch_x = _x;
var ch_y = _y;
var _str;
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();
}
for( var i = 0; i < array_length(_input_text_line); i++ ) {
_str = _input_text_line[i];
2023-01-04 02:30:04 +01:00
if(format == TEXT_AREA_FORMAT._default)
draw_text(ch_x, ch_y, _str);
else if(format == TEXT_AREA_FORMAT.code)
draw_code(ch_x, ch_y, _str);
2023-02-14 05:32:32 +01:00
else if(format == TEXT_AREA_FORMAT.delimiter)
draw_text_delimiter(ch_x, ch_y, _str);
2023-01-04 02:30:04 +01:00
2023-01-09 03:14:20 +01:00
ch_y += line_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);
2022-01-26 13:02:30 +01:00
if(_mx != -1 && _my != -1) {
var char_run = 0, _l, _ch_w, _ch_h, _str, _chr;
2023-01-09 03:14:20 +01:00
var sx = _x;
var ch_x = sx;
var ch_cxo = sx;
var ch_cxn = sx;
2022-01-26 13:02:30 +01:00
var ch_y = _y;
for( var i = 0; i < array_length(_input_text_line); i++ ) {
2023-01-09 03:14:20 +01:00
_str = string_trim_end(_input_text_line[i]);
2022-01-26 13:02:30 +01:00
_l = string_length(_str);
2023-01-09 03:14:20 +01:00
_ch_h = line_height();
ch_cxo = sx;
ch_x = sx;
2022-01-26 13:02:30 +01:00
if(ch_y <= _my && ch_y + _ch_h >= _my) {
2023-01-09 03:14:20 +01:00
target = char_run + _l;
2022-01-26 13:02:30 +01:00
for( var j = 0; j < string_length(_str); j++ ) {
_chr = string_char_at(_str, j + 1);
_ch_w = string_width(_chr);
ch_cxn = ch_x + _ch_w / 2;
2023-01-09 03:14:20 +01:00
if(ch_cxo <= _mx && _mx <= ch_cxn) {
2022-01-26 13:02:30 +01:00
target = char_run + j;
break;
}
ch_x += _ch_w;
ch_cxo = ch_cxn;
}
break;
}
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;
}
}
if(target != -999) {
2022-12-10 05:06:01 +01:00
if(mouse_press(mb_left, active) || click_block == 1) {
2022-01-26 13:02:30 +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-26 13:02:30 +01:00
cursor_select = target;
}
}
}
static draw = function(_x, _y, _w, _h, _text, _m) {
2023-01-17 08:11:55 +01:00
x = _x;
y = _y;
w = _w;
h = _h;
2023-02-17 04:48:54 +01:00
_text = string_real(_text);
2023-01-17 08:11:55 +01:00
_current_text = _text;
2023-03-13 10:45:56 +01:00
//if(format == TEXT_AREA_FORMAT.code) {
// print("=== TEXT BOX ===");
// print(_text);
// print(_current_text);
//}
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);
}
2022-11-03 11:44:49 +01:00
var tx = _x + ui(8);
2022-01-26 13:02:30 +01:00
var hh = _h;
2023-01-04 02:30:04 +01:00
if(format == TEXT_AREA_FORMAT._default) {
line_width = _w - ui(16);
} else if(format == TEXT_AREA_FORMAT.code) {
line_width = _w - ui(16 + code_line_width);
tx += ui(code_line_width);
}
2022-01-26 13:02:30 +01:00
draw_set_font(font);
2023-01-09 03:14:20 +01:00
var c_h = line_height();
2023-01-04 02:30:04 +01:00
var line_count = max(min_lines, array_length(_input_text_line));
hh = max(_h, ui(14) + c_h * line_count);
draw_sprite_stretched(THEME.textbox, 3, _x, _y, _w, hh);
if(format == TEXT_AREA_FORMAT.code) {
draw_sprite_stretched(THEME.textbox_code, 0, _x, _y, ui(code_line_width), hh);
draw_set_text(f_p1, fa_right, fa_top, COLORS._main_text_sub);
var lx = _x + ui(code_line_width - 8);
for( var i = 0; i < line_count; i++ ) {
var ly = _y + ui(7) + i * c_h;
draw_text(lx, ly, string(i + 1));
}
}
2022-01-26 13:02:30 +01:00
2023-03-26 07:13:36 +02:00
var hoverRect = point_in_rectangle(_m[0], _m[1], _x, _y, _x + _w, _y + hh);
2023-01-17 08:11:55 +01:00
if(self == WIDGET_CURRENT) {
2023-01-09 03:14:20 +01:00
draw_set_text(font, fa_left, fa_top, COLORS._main_text);
2022-11-18 03:20:31 +01:00
draw_sprite_stretched(THEME.textbox, 2, _x, _y, _w, hh);
2022-01-26 13:02:30 +01:00
editText();
#region cursor
2023-01-01 02:06:02 +01:00
if(KEYBOARD_PRESSED == vk_left) {
2023-02-14 05:32:32 +01:00
if(key_mod_press(SHIFT)) {
2022-01-26 13:02:30 +01:00
if(cursor_select == -1)
cursor_select = cursor;
} else
cursor_select = -1;
move_cursor(-1);
2022-12-22 03:09:55 +01:00
if(key_mod_press(CTRL)) {
2022-01-29 14:25:18 +01:00
while(cursor > 0) {
2023-01-09 03:14:20 +01:00
var ch = string_char_at(_input_text, cursor);
2023-01-04 02:30:04 +01:00
if(ch == " " || ch == "\n") break;
2022-01-29 14:25:18 +01:00
cursor--;
}
}
2022-01-26 13:02:30 +01:00
}
2023-01-01 02:06:02 +01:00
if(KEYBOARD_PRESSED == vk_right) {
2023-02-14 05:32:32 +01:00
if(key_mod_press(SHIFT)) {
2022-01-26 13:02:30 +01:00
if(cursor_select == -1)
cursor_select = cursor;
} else
cursor_select = -1;
move_cursor(1);
2022-12-22 03:09:55 +01:00
if(key_mod_press(CTRL)) {
2023-01-09 03:14:20 +01:00
while(cursor < string_length(_input_text)) {
var ch = string_char_at(_input_text, cursor);
2023-01-04 02:30:04 +01:00
if(ch == " " || ch == "\n") break;
2022-01-29 14:25:18 +01:00
cursor++;
}
}
2022-01-26 13:02:30 +01:00
}
2023-01-01 02:06:02 +01:00
if(KEYBOARD_PRESSED == vk_up) {
2022-01-29 14:25:18 +01:00
var _target;
2022-01-26 13:02:30 +01:00
if(cursor_line == 0)
2022-01-29 14:25:18 +01:00
_target = 0;
2022-01-26 13:02:30 +01:00
else {
var _l = cursor_line - 1;
var _str = _input_text_line[_l];
var _run = tx;
var _char = 0;
2022-01-29 14:25:18 +01:00
for( var i = 0; i < _l; i++ ) {
2022-01-26 13:02:30 +01:00
_char += string_length(_input_text_line[i]);
}
2022-01-29 14:25:18 +01:00
for( var i = 1; i <= string_length(_str); i++ ) {
var _chr = string_char_at(_str, i);
2022-01-26 13:02:30 +01:00
_run += string_width(_chr);
2023-01-09 03:14:20 +01:00
if(_run > cursor_pos_x_to)
break;
2022-01-29 14:25:18 +01:00
_char++;
2022-01-26 13:02:30 +01:00
}
2022-01-29 14:25:18 +01:00
_target = _char;
2022-01-26 13:02:30 +01:00
}
2022-01-29 14:25:18 +01:00
2023-02-14 05:32:32 +01:00
if(key_mod_press(SHIFT)) {
2022-01-29 14:25:18 +01:00
if(cursor_select == -1)
cursor_select = cursor;
} else
cursor_select = -1;
cursor = _target;
2022-01-26 13:02:30 +01:00
}
2023-01-01 02:06:02 +01:00
if(KEYBOARD_PRESSED == vk_down) {
2022-01-29 14:25:18 +01:00
var _target;
2022-01-26 13:02:30 +01:00
if(cursor_line == array_length(_input_text_line) - 1)
2023-01-09 03:14:20 +01:00
_target = string_length(_input_text);
2022-01-26 13:02:30 +01:00
else {
var _l = cursor_line + 1;
var _str = _input_text_line[_l];
var _run = tx;
var _char = 0;
for( var i = 0; i < _l; i++ ) {
_char += string_length(_input_text_line[i]);
}
2022-01-29 14:25:18 +01:00
for( var i = 1; i <= string_length(_str); i++ ) {
var _chr = string_char_at(_str, i);
2022-01-26 13:02:30 +01:00
_run += string_width(_chr);
2022-01-29 14:25:18 +01:00
if(_run > cursor_pos_x_to) break;
_char++;
2022-01-26 13:02:30 +01:00
}
2022-01-29 14:25:18 +01:00
_target = _char;
2022-01-26 13:02:30 +01:00
}
2022-01-29 14:25:18 +01:00
2023-02-14 05:32:32 +01:00
if(key_mod_press(SHIFT)) {
2022-01-29 14:25:18 +01:00
if(cursor_select == -1)
cursor_select = cursor;
} else
cursor_select = -1;
cursor = _target;
2022-01-26 13:02:30 +01:00
}
#endregion
#region draw
2022-11-18 03:20:31 +01:00
draw_set_text(font, fa_left, fa_top, COLORS._main_text);
2022-01-26 13:02:30 +01:00
#region draw cursor highlight
var char_run = 0, _l, _str;
var ch_x = tx;
2022-11-03 11:44:49 +01:00
var ch_y = _y + ui(7);
2022-01-26 13:02:30 +01:00
var ch_sel_min = -1;
var ch_sel_max = -1;
if(cursor_select != -1) {
ch_sel_min = min(cursor_select, cursor);
ch_sel_max = max(cursor_select, cursor);
}
for( var i = 0; i < array_length(_input_text_line); i++ ) {
_str = _input_text_line[i];
_l = string_length(_str);
if(cursor_select != -1) {
2022-11-18 03:20:31 +01:00
draw_set_color(COLORS.widget_text_highlight);
2022-01-26 13:02:30 +01:00
if(char_run <= ch_sel_min && char_run + _l > ch_sel_min) {
var x1 = tx + string_width(string_copy(_str, 1, ch_sel_min - char_run));
var x2 = tx + string_width(string_copy(_str, 1, ch_sel_max - char_run));
2022-11-03 11:44:49 +01:00
draw_roundrect_ext(x1, ch_y, x2, ch_y + c_h, ui(8), ui(8), 0);
2022-01-26 13:02:30 +01:00
} else if(char_run >= ch_sel_min && char_run + _l < ch_sel_max) {
var x2 = tx + string_width(_str);
2022-11-03 11:44:49 +01:00
draw_roundrect_ext(tx, ch_y, x2, ch_y + c_h, ui(8), ui(8), 0);
2022-01-29 14:25:18 +01:00
} else if(char_run > ch_sel_min && char_run <= ch_sel_max && char_run + _l >= ch_sel_max) {
2022-01-26 13:02:30 +01:00
var x2 = tx + string_width(string_copy(_str, 1, ch_sel_max - char_run));
2022-11-03 11:44:49 +01:00
draw_roundrect_ext(tx, ch_y, x2, ch_y + c_h, ui(8), ui(8), 0);
2022-01-26 13:02:30 +01:00
}
}
2023-01-04 02:30:04 +01:00
if(char_run <= cursor && cursor <= char_run + _l) {
2023-02-14 05:32:32 +01:00
if(format == TEXT_AREA_FORMAT.delimiter) {
var str_cur = string_copy(_str, 1, cursor - char_run);
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_run));
2022-01-26 13:02:30 +01:00
cursor_pos_y_to = ch_y;
cursor_line = i;
}
2023-01-09 03:14:20 +01:00
char_run += _l;
ch_y += line_height();
2022-01-26 13:02:30 +01:00
}
2022-12-10 05:06:01 +01:00
cursor_pos_x = cursor_pos_x == 0? cursor_pos_x_to : lerp_float(cursor_pos_x, cursor_pos_x_to, 4);
cursor_pos_y = cursor_pos_y == 0? cursor_pos_y_to : lerp_float(cursor_pos_y, cursor_pos_y_to, 4);
2022-01-26 13:02:30 +01:00
#endregion
var _mx = -1;
var _my = -1;
2023-03-26 07:13:36 +02:00
if(hover && hoverRect) {
2022-01-26 13:02:30 +01:00
_mx = _m[0];
_my = _m[1];
}
2022-11-03 11:44:49 +01:00
display_text(tx, _y + ui(7), _input_text, _w - ui(4), _mx, _my);
2023-01-09 03:14:20 +01:00
2022-09-21 06:09:40 +02:00
if(cursor_pos_y != 0 && cursor_pos_x != 0) {
2022-11-18 03:20:31 +01:00
draw_set_color(COLORS._main_text_accent);
2022-09-21 06:09:40 +02:00
draw_line_width(cursor_pos_x, cursor_pos_y, cursor_pos_x, cursor_pos_y + c_h, 2);
}
2022-01-26 13:02:30 +01:00
#endregion
2022-12-10 05:06:01 +01:00
if(!point_in_rectangle(_m[0], _m[1], _x, _y, _x + _w, _y + hh) && mouse_press(mb_left)) {
2023-01-17 08:11:55 +01:00
deactivate();
2022-01-26 13:02:30 +01:00
}
} else {
2023-03-26 07:13:36 +02:00
if(hover && hoverRect) {
2022-01-26 13:02:30 +01:00
if(hide)
2022-11-18 03:20:31 +01:00
draw_sprite_stretched_ext(THEME.textbox, 1, _x, _y, _w, hh, c_white, 0.5);
2022-01-26 13:02:30 +01:00
else
2023-01-17 08:11:55 +01:00
draw_sprite_stretched_ext(THEME.textbox, 1, _x, _y, _w, hh, c_white, 0.5 + 0.5 * interactable);
if(mouse_press(mb_left, active))
activate();
2022-01-26 13:02:30 +01:00
} else if(!hide) {
2022-11-18 03:20:31 +01:00
draw_sprite_stretched(THEME.textbox, 0, _x, _y, _w, hh);
2022-01-26 13:02:30 +01:00
}
2023-02-17 04:48:54 +01:00
display_text(tx, _y + ui(7), _text, _w - ui(4));
2022-01-26 13:02:30 +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, hh, COLORS._main_value_positive, 1);
if(mouse_release(mb_left))
onModify(DRAGGING.data);
}
2023-01-17 08:11:55 +01:00
resetFocus();
2022-01-26 13:02:30 +01:00
return hh;
}
}