summaryrefslogtreecommitdiff
path: root/scene/gui/line_edit.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui/line_edit.cpp')
-rw-r--r--scene/gui/line_edit.cpp603
1 files changed, 300 insertions, 303 deletions
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp
index 8bb6828fa6..38debe8a77 100644
--- a/scene/gui/line_edit.cpp
+++ b/scene/gui/line_edit.cpp
@@ -42,445 +42,442 @@ static bool _is_text_char(CharType c) {
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_';
}
-void LineEdit::_gui_input(InputEvent p_event) {
+void LineEdit::_gui_input(Ref<InputEvent> p_event) {
- switch (p_event.type) {
+ Ref<InputEventMouseButton> b = p_event;
- case InputEvent::MOUSE_BUTTON: {
+ if (b.is_valid()) {
- const InputEventMouseButton &b = p_event.mouse_button;
-
- if (b.pressed && b.button_index == BUTTON_RIGHT) {
- menu->set_position(get_global_transform().xform(get_local_mouse_pos()));
- menu->set_size(Vector2(1, 1));
- menu->popup();
- grab_focus();
- return;
- }
+ if (b->is_pressed() && b->get_button_index() == BUTTON_RIGHT) {
+ menu->set_position(get_global_transform().xform(get_local_mouse_pos()));
+ menu->set_size(Vector2(1, 1));
+ menu->popup();
+ grab_focus();
+ return;
+ }
- if (b.button_index != BUTTON_LEFT)
- break;
+ if (b->get_button_index() != BUTTON_LEFT)
+ return;
- _reset_caret_blink_timer();
- if (b.pressed) {
+ _reset_caret_blink_timer();
+ if (b->is_pressed()) {
- shift_selection_check_pre(b.mod.shift);
+ shift_selection_check_pre(b->get_shift());
- set_cursor_at_pixel_pos(b.x);
+ set_cursor_at_pixel_pos(b->get_pos().x);
- if (b.mod.shift) {
+ if (b->get_shift()) {
- selection_fill_at_cursor();
- selection.creating = true;
+ selection_fill_at_cursor();
+ selection.creating = true;
- } else {
+ } else {
- if (b.doubleclick) {
+ if (b->is_doubleclick()) {
- selection.enabled = true;
- selection.begin = 0;
- selection.end = text.length();
- selection.doubleclick = true;
- }
+ selection.enabled = true;
+ selection.begin = 0;
+ selection.end = text.length();
+ selection.doubleclick = true;
+ }
- selection.drag_attempt = false;
+ selection.drag_attempt = false;
- if ((cursor_pos < selection.begin) || (cursor_pos > selection.end) || !selection.enabled) {
+ if ((cursor_pos < selection.begin) || (cursor_pos > selection.end) || !selection.enabled) {
- selection_clear();
- selection.cursor_start = cursor_pos;
- selection.creating = true;
- } else if (selection.enabled) {
+ selection_clear();
+ selection.cursor_start = cursor_pos;
+ selection.creating = true;
+ } else if (selection.enabled) {
- selection.drag_attempt = true;
- }
+ selection.drag_attempt = true;
}
+ }
- update();
-
- } else {
+ update();
- if ((!selection.creating) && (!selection.doubleclick)) {
- selection_clear();
- }
- selection.creating = false;
- selection.doubleclick = false;
+ } else {
- if (OS::get_singleton()->has_virtual_keyboard())
- OS::get_singleton()->show_virtual_keyboard(text, get_global_rect());
+ if ((!selection.creating) && (!selection.doubleclick)) {
+ selection_clear();
}
+ selection.creating = false;
+ selection.doubleclick = false;
- update();
- } break;
- case InputEvent::MOUSE_MOTION: {
+ if (OS::get_singleton()->has_virtual_keyboard())
+ OS::get_singleton()->show_virtual_keyboard(text, get_global_rect());
+ }
- const InputEventMouseMotion &m = p_event.mouse_motion;
+ update();
+ }
- if (m.button_mask & BUTTON_LEFT) {
+ Ref<InputEventMouseMotion> m = p_event;
- if (selection.creating) {
- set_cursor_at_pixel_pos(m.x);
- selection_fill_at_cursor();
- }
- }
+ if (m.is_valid()) {
- } break;
- case InputEvent::KEY: {
+ if (m->get_button_mask() & BUTTON_LEFT) {
- const InputEventKey &k = p_event.key;
+ if (selection.creating) {
+ set_cursor_at_pixel_pos(m->get_pos().x);
+ selection_fill_at_cursor();
+ }
+ }
+ }
- if (!k.pressed)
- return;
- unsigned int code = k.scancode;
+ Ref<InputEventKey> k = p_event;
- if (k.mod.command) {
+ if (k.is_valid()) {
- bool handled = true;
+ if (!k->is_pressed())
+ return;
+ unsigned int code = k->get_scancode();
- switch (code) {
+ if (k->get_command()) {
- case (KEY_X): { // CUT
+ bool handled = true;
- if (editable) {
- cut_text();
- }
+ switch (code) {
- } break;
+ case (KEY_X): { // CUT
- case (KEY_C): { // COPY
+ if (editable) {
+ cut_text();
+ }
- copy_text();
+ } break;
- } break;
+ case (KEY_C): { // COPY
- case (KEY_V): { // PASTE
+ copy_text();
- if (editable) {
+ } break;
- paste_text();
- }
+ case (KEY_V): { // PASTE
- } break;
+ if (editable) {
- case (KEY_Z): { // Simple One level undo
+ paste_text();
+ }
- if (editable) {
+ } break;
- undo();
- }
+ case (KEY_Z): { // Simple One level undo
- } break;
+ if (editable) {
+
+ undo();
+ }
- case (KEY_U): { // Delete from start to cursor
+ } break;
- if (editable) {
+ case (KEY_U): { // Delete from start to cursor
- selection_clear();
- undo_text = text;
- text = text.substr(cursor_pos, text.length() - cursor_pos);
+ if (editable) {
- Ref<Font> font = get_font("font");
+ selection_clear();
+ undo_text = text;
+ text = text.substr(cursor_pos, text.length() - cursor_pos);
- cached_width = 0;
- if (font != NULL) {
- for (int i = 0; i < text.length(); i++)
- cached_width += font->get_char_size(text[i]).width;
- }
+ Ref<Font> font = get_font("font");
- set_cursor_pos(0);
- _text_changed();
+ cached_width = 0;
+ if (font != NULL) {
+ for (int i = 0; i < text.length(); i++)
+ cached_width += font->get_char_size(text[i]).width;
}
- } break;
+ set_cursor_pos(0);
+ _text_changed();
+ }
- case (KEY_Y): { // PASTE (Yank for unix users)
+ } break;
- if (editable) {
+ case (KEY_Y): { // PASTE (Yank for unix users)
- paste_text();
- }
+ if (editable) {
- } break;
- case (KEY_K): { // Delete from cursor_pos to end
+ paste_text();
+ }
- if (editable) {
+ } break;
+ case (KEY_K): { // Delete from cursor_pos to end
- selection_clear();
- undo_text = text;
- text = text.substr(0, cursor_pos);
- _text_changed();
- }
+ if (editable) {
- } break;
- case (KEY_A): { //Select All
- select();
- } break;
- default: { handled = false; }
- }
+ selection_clear();
+ undo_text = text;
+ text = text.substr(0, cursor_pos);
+ _text_changed();
+ }
- if (handled) {
- accept_event();
- return;
- }
+ } break;
+ case (KEY_A): { //Select All
+ select();
+ } break;
+ default: { handled = false; }
}
- _reset_caret_blink_timer();
- if (!k.mod.meta) {
+ if (handled) {
+ accept_event();
+ return;
+ }
+ }
- bool handled = true;
- switch (code) {
+ _reset_caret_blink_timer();
+ if (!k->get_metakey()) {
- case KEY_ENTER:
- case KEY_RETURN: {
+ bool handled = true;
+ switch (code) {
- emit_signal("text_entered", text);
- if (OS::get_singleton()->has_virtual_keyboard())
- OS::get_singleton()->hide_virtual_keyboard();
+ case KEY_ENTER:
+ case KEY_RETURN: {
- return;
- } break;
+ emit_signal("text_entered", text);
+ if (OS::get_singleton()->has_virtual_keyboard())
+ OS::get_singleton()->hide_virtual_keyboard();
- case KEY_BACKSPACE: {
+ return;
+ } break;
- if (!editable)
- break;
+ case KEY_BACKSPACE: {
- if (selection.enabled) {
- undo_text = text;
- selection_delete();
- break;
- }
+ if (!editable)
+ break;
+
+ if (selection.enabled) {
+ undo_text = text;
+ selection_delete();
+ break;
+ }
#ifdef APPLE_STYLE_KEYS
- if (k.mod.alt) {
+ if (k->get_alt()) {
#else
- if (k.mod.alt) {
- handled = false;
- break;
- } else if (k.mod.command) {
+ if (k->get_alt()) {
+ handled = false;
+ break;
+ } else if (k->get_command()) {
#endif
- int cc = cursor_pos;
- bool prev_char = false;
+ int cc = cursor_pos;
+ bool prev_char = false;
- while (cc > 0) {
- bool ischar = _is_text_char(text[cc - 1]);
+ while (cc > 0) {
+ bool ischar = _is_text_char(text[cc - 1]);
- if (prev_char && !ischar)
- break;
+ if (prev_char && !ischar)
+ break;
- prev_char = ischar;
- cc--;
- }
+ prev_char = ischar;
+ cc--;
+ }
- delete_text(cc, cursor_pos);
+ delete_text(cc, cursor_pos);
- set_cursor_pos(cc);
+ set_cursor_pos(cc);
- } else {
- undo_text = text;
- delete_char();
- }
+ } else {
+ undo_text = text;
+ delete_char();
+ }
- } break;
- case KEY_KP_4: {
- if (k.unicode != 0) {
- handled = false;
- break;
- }
- // numlock disabled. fallthrough to key_left
+ } break;
+ case KEY_KP_4: {
+ if (k->get_unicode() != 0) {
+ handled = false;
+ break;
}
- case KEY_LEFT: {
+ // numlock disabled. fallthrough to key_left
+ }
+ case KEY_LEFT: {
#ifndef APPLE_STYLE_KEYS
- if (!k.mod.alt)
+ if (!k->get_alt())
#endif
- shift_selection_check_pre(k.mod.shift);
+ shift_selection_check_pre(k->get_shift());
#ifdef APPLE_STYLE_KEYS
- if (k.mod.command) {
- set_cursor_pos(0);
- } else if (k.mod.alt) {
+ if (k->get_command()) {
+ set_cursor_pos(0);
+ } else if (k->get_alt()) {
#else
- if (k.mod.alt) {
- handled = false;
- break;
- } else if (k.mod.command) {
+ if (k->get_alt()) {
+ handled = false;
+ break;
+ } else if (k->get_command()) {
#endif
- bool prev_char = false;
- int cc = cursor_pos;
+ bool prev_char = false;
+ int cc = cursor_pos;
- while (cc > 0) {
- bool ischar = _is_text_char(text[cc - 1]);
+ while (cc > 0) {
+ bool ischar = _is_text_char(text[cc - 1]);
- if (prev_char && !ischar)
- break;
+ if (prev_char && !ischar)
+ break;
- prev_char = ischar;
- cc--;
- }
+ prev_char = ischar;
+ cc--;
+ }
- set_cursor_pos(cc);
+ set_cursor_pos(cc);
- } else {
- set_cursor_pos(get_cursor_pos() - 1);
- }
+ } else {
+ set_cursor_pos(get_cursor_pos() - 1);
+ }
- shift_selection_check_post(k.mod.shift);
+ shift_selection_check_post(k->get_shift());
- } break;
- case KEY_KP_6: {
- if (k.unicode != 0) {
- handled = false;
- break;
- }
- // numlock disabled. fallthrough to key_right
+ } break;
+ case KEY_KP_6: {
+ if (k->get_unicode() != 0) {
+ handled = false;
+ break;
}
- case KEY_RIGHT: {
+ // numlock disabled. fallthrough to key_right
+ }
+ case KEY_RIGHT: {
- shift_selection_check_pre(k.mod.shift);
+ shift_selection_check_pre(k->get_shift());
#ifdef APPLE_STYLE_KEYS
- if (k.mod.command) {
- set_cursor_pos(text.length());
- } else if (k.mod.alt) {
+ if (k->get_command()) {
+ set_cursor_pos(text.length());
+ } else if (k->get_alt()) {
#else
- if (k.mod.alt) {
- handled = false;
- break;
- } else if (k.mod.command) {
+ if (k->get_alt()) {
+ handled = false;
+ break;
+ } else if (k->get_command()) {
#endif
- bool prev_char = false;
- int cc = cursor_pos;
+ bool prev_char = false;
+ int cc = cursor_pos;
- while (cc < text.length()) {
- bool ischar = _is_text_char(text[cc]);
+ while (cc < text.length()) {
+ bool ischar = _is_text_char(text[cc]);
- if (prev_char && !ischar)
- break;
+ if (prev_char && !ischar)
+ break;
- prev_char = ischar;
- cc++;
- }
+ prev_char = ischar;
+ cc++;
+ }
- set_cursor_pos(cc);
+ set_cursor_pos(cc);
- } else {
- set_cursor_pos(get_cursor_pos() + 1);
- }
+ } else {
+ set_cursor_pos(get_cursor_pos() + 1);
+ }
- shift_selection_check_post(k.mod.shift);
+ shift_selection_check_post(k->get_shift());
- } break;
- case KEY_DELETE: {
+ } break;
+ case KEY_DELETE: {
- if (!editable)
- break;
+ if (!editable)
+ break;
- if (k.mod.shift && !k.mod.command && !k.mod.alt) {
- cut_text();
- break;
- }
+ if (k->get_shift() && !k->get_command() && !k->get_alt()) {
+ cut_text();
+ break;
+ }
- if (selection.enabled) {
- undo_text = text;
- selection_delete();
- break;
- }
+ if (selection.enabled) {
+ undo_text = text;
+ selection_delete();
+ break;
+ }
- int text_len = text.length();
+ int text_len = text.length();
- if (cursor_pos == text_len)
- break; // nothing to do
+ if (cursor_pos == text_len)
+ break; // nothing to do
#ifdef APPLE_STYLE_KEYS
- if (k.mod.alt) {
+ if (k->get_alt()) {
#else
- if (k.mod.alt) {
- handled = false;
- break;
- } else if (k.mod.command) {
+ if (k->get_alt()) {
+ handled = false;
+ break;
+ } else if (k->get_command()) {
#endif
- int cc = cursor_pos;
-
- bool prev_char = false;
+ int cc = cursor_pos;
- while (cc < text.length()) {
+ bool prev_char = false;
- bool ischar = _is_text_char(text[cc]);
+ while (cc < text.length()) {
- if (prev_char && !ischar)
- break;
- prev_char = ischar;
- cc++;
- }
+ bool ischar = _is_text_char(text[cc]);
- delete_text(cursor_pos, cc);
-
- } else {
- undo_text = text;
- set_cursor_pos(cursor_pos + 1);
- delete_char();
+ if (prev_char && !ischar)
+ break;
+ prev_char = ischar;
+ cc++;
}
- } break;
- case KEY_KP_7: {
- if (k.unicode != 0) {
- handled = false;
- break;
- }
- // numlock disabled. fallthrough to key_home
- }
- case KEY_HOME: {
+ delete_text(cursor_pos, cc);
- shift_selection_check_pre(k.mod.shift);
- set_cursor_pos(0);
- shift_selection_check_post(k.mod.shift);
- } break;
- case KEY_KP_1: {
- if (k.unicode != 0) {
- handled = false;
- break;
- }
- // numlock disabled. fallthrough to key_end
+ } else {
+ undo_text = text;
+ set_cursor_pos(cursor_pos + 1);
+ delete_char();
}
- case KEY_END: {
- shift_selection_check_pre(k.mod.shift);
- set_cursor_pos(text.length());
- shift_selection_check_post(k.mod.shift);
- } break;
-
- default: {
+ } break;
+ case KEY_KP_7: {
+ if (k->get_unicode() != 0) {
+ handled = false;
+ break;
+ }
+ // numlock disabled. fallthrough to key_home
+ }
+ case KEY_HOME: {
+ shift_selection_check_pre(k->get_shift());
+ set_cursor_pos(0);
+ shift_selection_check_post(k->get_shift());
+ } break;
+ case KEY_KP_1: {
+ if (k->get_unicode() != 0) {
handled = false;
- } break;
+ break;
+ }
+ // numlock disabled. fallthrough to key_end
}
+ case KEY_END: {
- if (handled) {
- accept_event();
- } else if (!k.mod.alt && !k.mod.command) {
- if (k.unicode >= 32 && k.scancode != KEY_DELETE) {
-
- if (editable) {
- selection_delete();
- CharType ucodestr[2] = { (CharType)k.unicode, 0 };
- append_at_cursor(ucodestr);
- _text_changed();
- accept_event();
- }
+ shift_selection_check_pre(k->get_shift());
+ set_cursor_pos(text.length());
+ shift_selection_check_post(k->get_shift());
+ } break;
- } else {
- return;
+ default: {
+
+ handled = false;
+ } break;
+ }
+
+ if (handled) {
+ accept_event();
+ } else if (!k->get_alt() && !k->get_command()) {
+ if (k->get_unicode() >= 32 && k->get_scancode() != KEY_DELETE) {
+
+ if (editable) {
+ selection_delete();
+ CharType ucodestr[2] = { (CharType)k->get_unicode(), 0 };
+ append_at_cursor(ucodestr);
+ _text_changed();
+ accept_event();
}
- }
- update();
+ } else {
+ return;
+ }
}
- return;
+ update();
+ }
- } break;
+ return;
}
}
@@ -576,7 +573,7 @@ void LineEdit::_notification(int p_what) {
RID ci = get_canvas_item();
- Ref<StyleBox> style = has_focus() ? get_stylebox("active") : get_stylebox("normal");
+ Ref<StyleBox> style = get_stylebox("normal");
if (!is_editable())
style = get_stylebox("read_only");
@@ -617,7 +614,7 @@ void LineEdit::_notification(int p_what) {
int font_ascent = font->get_ascent();
Color selection_color = get_color("selection_color");
- Color font_color = is_editable() ? has_focus() ? get_color("font_color_active") : get_color("font_color") : get_color("font_color_read_only");
+ Color font_color = get_color("font_color");
Color font_color_selected = get_color("font_color_selected");
Color cursor_color = get_color("cursor_color");