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.cpp602
1 files changed, 479 insertions, 123 deletions
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp
index 21dee62b38..fcea12fd6b 100644
--- a/scene/gui/line_edit.cpp
+++ b/scene/gui/line_edit.cpp
@@ -31,6 +31,15 @@
#include "os/os.h"
#include "print_string.h"
#include "label.h"
+#include "translation.h"
+#ifdef TOOLS_ENABLED
+#include "tools/editor/editor_settings.h"
+#endif
+
+static bool _is_text_char(CharType c) {
+
+ return (c>='a' && c<='z') || (c>='A' && c<='Z') || (c>='0' && c<='9') || c=='_';
+}
void LineEdit::_input_event(InputEvent p_event) {
@@ -41,31 +50,50 @@ void LineEdit::_input_event(InputEvent p_event) {
const InputEventMouseButton &b = p_event.mouse_button;
- if (b.button_index!=1)
+ if (b.pressed && b.button_index==BUTTON_RIGHT) {
+ menu->set_pos(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;
+ _reset_caret_blink_timer();
if (b.pressed) {
+ shift_selection_check_pre(b.mod.shift);
+
set_cursor_at_pixel_pos(b.x);
- if (b.doubleclick) {
+ if (b.mod.shift) {
- selection.enabled=true;
- selection.begin=0;
- selection.end=text.length();
- selection.doubleclick=true;
- }
+ selection_fill_at_cursor();
+ selection.creating=true;
- selection.drag_attempt=false;
+ } else {
- if ((cursor_pos<selection.begin) || (cursor_pos>selection.end) || !selection.enabled) {
+ if (b.doubleclick) {
- selection_clear();
- selection.cursor_start=cursor_pos;
- selection.creating=true;
- } else if (selection.enabled) {
+ selection.enabled=true;
+ selection.begin=0;
+ selection.end=text.length();
+ selection.doubleclick=true;
+ }
- selection.drag_attempt=true;
+ selection.drag_attempt=false;
+
+ 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.drag_attempt=true;
+ }
}
// if (!editable)
@@ -81,7 +109,7 @@ void LineEdit::_input_event(InputEvent p_event) {
selection.doubleclick=false;
if (OS::get_singleton()->has_virtual_keyboard())
- OS::get_singleton()->show_virtual_keyboard(get_text(),get_global_rect());
+ OS::get_singleton()->show_virtual_keyboard(text,get_global_rect());
}
update();
@@ -90,7 +118,7 @@ void LineEdit::_input_event(InputEvent p_event) {
const InputEventMouseMotion& m=p_event.mouse_motion;
- if (m.button_mask&1) {
+ if (m.button_mask&BUTTON_LEFT) {
if (selection.creating) {
set_cursor_at_pixel_pos(m.x);
@@ -116,7 +144,7 @@ void LineEdit::_input_event(InputEvent p_event) {
case (KEY_X): { // CUT
- if(k.mod.command && editable) {
+ if(editable) {
cut_text();
}
@@ -124,15 +152,13 @@ void LineEdit::_input_event(InputEvent p_event) {
case (KEY_C): { // COPY
- if(k.mod.command) {
- copy_text();
- }
+ copy_text();
} break;
case (KEY_V): { // PASTE
- if(k.mod.command && editable) {
+ if(editable) {
paste_text();
}
@@ -141,32 +167,18 @@ void LineEdit::_input_event(InputEvent p_event) {
case (KEY_Z): { // Simple One level undo
- if( k.mod.command && editable) {
-
- int old_cursor_pos = cursor_pos;
- text = undo_text;
+ if(editable) {
- Ref<Font> font = get_font("font");
+ undo();
- cached_width = 0;
- for (int i = 0; i<text.length(); i++)
- cached_width += font->get_char_size(text[i]).width;
-
- if(old_cursor_pos > text.length()) {
- set_cursor_pos(text.length());
- } else {
- set_cursor_pos(old_cursor_pos);
- }
}
- emit_signal("text_changed",text);
- _change_notify("text");
} break;
case (KEY_U): { // Delete from start to cursor
- if( k.mod.command && editable) {
+ if(editable) {
selection_clear();
undo_text = text;
@@ -190,7 +202,7 @@ void LineEdit::_input_event(InputEvent p_event) {
case (KEY_Y): { // PASTE (Yank for unix users)
- if(k.mod.command && editable) {
+ if(editable) {
paste_text();
}
@@ -198,7 +210,7 @@ void LineEdit::_input_event(InputEvent p_event) {
} break;
case (KEY_K): { // Delete from cursor_pos to end
- if(k.mod.command && editable) {
+ if(editable) {
selection_clear();
undo_text = text;
@@ -220,8 +232,8 @@ void LineEdit::_input_event(InputEvent p_event) {
}
}
-
- if (!k.mod.alt && !k.mod.meta && !k.mod.command) {
+ _reset_caret_blink_timer();
+ if (!k.mod.meta) {
bool handled=true;
switch (code) {
@@ -238,13 +250,45 @@ void LineEdit::_input_event(InputEvent p_event) {
case KEY_BACKSPACE: {
- if (editable) {
- undo_text = text;
- if (selection.enabled)
- selection_delete();
- else
- delete_char();
+ if (!editable)
+ break;
+
+ if (selection.enabled) {
+ undo_text=text;
+ selection_delete();
+ break;
+ }
+
+#ifdef APPLE_STYLE_KEYS
+ if (k.mod.alt) {
+#else
+ if (k.mod.alt) {
+ handled=false;
+ break;
+ } else if (k.mod.command) {
+#endif
+ int cc=cursor_pos;
+ bool prev_char=false;
+
+ while (cc>0) {
+ bool ischar=_is_text_char(text[cc-1]);
+
+ if (prev_char && !ischar)
+ break;
+
+ prev_char=ischar;
+ cc--;
+ }
+
+ delete_text(cc, cursor_pos);
+
+ set_cursor_pos(cc);
+
+ } else {
+ undo_text=text;
+ delete_char();
}
+
} break;
case KEY_KP_4: {
if (k.unicode != 0) {
@@ -254,8 +298,42 @@ void LineEdit::_input_event(InputEvent p_event) {
// numlock disabled. fallthrough to key_left
}
case KEY_LEFT: {
+
+#ifndef APPLE_STYLE_KEYS
+ if (!k.mod.alt)
+#endif
shift_selection_check_pre(k.mod.shift);
- set_cursor_pos(get_cursor_pos()-1);
+
+#ifdef APPLE_STYLE_KEYS
+ if (k.mod.command) {
+ set_cursor_pos(0);
+ } else if (k.mod.alt) {
+
+#else
+ if (k.mod.alt) {
+ handled=false;
+ break;
+ } else if (k.mod.command) {
+#endif
+ bool prev_char=false;
+ int cc=cursor_pos;
+
+ while (cc>0) {
+ bool ischar=_is_text_char(text[cc-1]);
+
+ if (prev_char && !ischar)
+ break;
+
+ prev_char=ischar;
+ cc--;
+ }
+
+ set_cursor_pos(cc);
+
+ } else {
+ set_cursor_pos(get_cursor_pos()-1);
+ }
+
shift_selection_check_post(k.mod.shift);
} break;
@@ -269,25 +347,88 @@ void LineEdit::_input_event(InputEvent p_event) {
case KEY_RIGHT: {
shift_selection_check_pre(k.mod.shift);
- set_cursor_pos(get_cursor_pos()+1);
+
+#ifdef APPLE_STYLE_KEYS
+ if (k.mod.command) {
+ set_cursor_pos(text.length());
+ } else if (k.mod.alt) {
+#else
+ if (k.mod.alt) {
+ handled=false;
+ break;
+ } else if (k.mod.command) {
+#endif
+ bool prev_char=false;
+ int cc=cursor_pos;
+
+ while (cc<text.length()) {
+ bool ischar=_is_text_char(text[cc]);
+
+ if (prev_char && !ischar)
+ break;
+
+ prev_char=ischar;
+ cc++;
+ }
+
+ set_cursor_pos(cc);
+
+ } else {
+ set_cursor_pos(get_cursor_pos()+1);
+ }
+
shift_selection_check_post(k.mod.shift);
+
} break;
case KEY_DELETE: {
- if (k.mod.shift && !k.mod.command && !k.mod.alt && editable) {
+ if (!editable)
+ break;
+
+ if (k.mod.shift && !k.mod.command && !k.mod.alt) {
cut_text();
break;
}
- if (editable) {
- undo_text = text;
- if (selection.enabled)
- selection_delete();
- else if (cursor_pos<text.length()) {
+ if (selection.enabled) {
+ undo_text=text;
+ selection_delete();
+ break;
+ }
+
+ int text_len = text.length();
+
+ if (cursor_pos==text_len)
+ break; // nothing to do
- set_cursor_pos(get_cursor_pos()+1);
- delete_char();
+#ifdef APPLE_STYLE_KEYS
+ if (k.mod.alt) {
+#else
+ if (k.mod.alt) {
+ handled=false;
+ break;
+ } else if (k.mod.command) {
+#endif
+ int cc=cursor_pos;
+
+ bool prev_char=false;
+
+ while (cc<text.length()) {
+
+ bool ischar=_is_text_char(text[cc]);
+
+ if (prev_char && !ischar)
+ break;
+ prev_char=ischar;
+ cc++;
}
+
+ delete_text(cursor_pos,cc);
+
+ } else {
+ undo_text=text;
+ set_cursor_pos(cursor_pos+1);
+ delete_char();
}
} break;
@@ -327,7 +468,7 @@ void LineEdit::_input_event(InputEvent p_event) {
if (handled) {
accept_event();
- } else {
+ } else if (!k.mod.alt && !k.mod.command) {
if (k.unicode>=32 && k.scancode!=KEY_DELETE) {
if (editable) {
@@ -345,8 +486,6 @@ void LineEdit::_input_event(InputEvent p_event) {
}
}
-
- selection.old_shift=k.mod.shift;
update();
}
@@ -412,14 +551,39 @@ void LineEdit::drop_data(const Point2& p_point,const Variant& p_data){
void LineEdit::_notification(int p_what) {
switch(p_what) {
-
+#ifdef TOOLS_ENABLED
+ case NOTIFICATION_ENTER_TREE: {
+ if (get_tree()->is_editor_hint()) {
+ cursor_set_blink_enabled(EDITOR_DEF("text_editor/caret_blink", false));
+ cursor_set_blink_speed(EDITOR_DEF("text_editor/caret_blink_speed", 0.65));
+
+ if (!EditorSettings::get_singleton()->is_connected("settings_changed",this,"_editor_settings_changed")) {
+ EditorSettings::get_singleton()->connect("settings_changed",this,"_editor_settings_changed");
+ }
+ }
+ } break;
+#endif
case NOTIFICATION_RESIZED: {
set_cursor_pos( get_cursor_pos() );
} break;
+ case MainLoop::NOTIFICATION_WM_FOCUS_IN: {
+ window_has_focus = true;
+ draw_caret = true;
+ update();
+ } break;
+ case MainLoop::NOTIFICATION_WM_FOCUS_OUT: {
+ window_has_focus = false;
+ draw_caret = false;
+ update();
+ } break;
case NOTIFICATION_DRAW: {
+ if ((!has_focus() && !menu->has_focus()) || !window_has_focus) {
+ draw_caret = false;
+ }
+
int width,height;
Size2 size=get_size();
@@ -452,11 +616,11 @@ void LineEdit::_notification(int p_what) {
} break;
case ALIGN_CENTER: {
- x_ofs=x_ofs=int(size.width-(cached_width))/2;
+ x_ofs=int(size.width-(cached_width))/2;
} break;
case ALIGN_RIGHT: {
- x_ofs=x_ofs=int(size.width-style->get_offset().x-(cached_width));
+ x_ofs=int(size.width-style->get_offset().x-(cached_width));
} break;
}
@@ -473,14 +637,19 @@ void LineEdit::_notification(int p_what) {
Color font_color_selected=get_color("font_color_selected");
Color cursor_color=get_color("cursor_color");
+ const String& t = text.empty() ? placeholder : text;
+ // draw placeholder color
+ if(text.empty())
+ font_color.a *= placeholder_alpha;
+
while(true) {
//end of string, break!
- if (char_ofs>=text.length())
+ if (char_ofs>=t.length())
break;
- CharType cchar=pass?'*':text[char_ofs];
- CharType next=pass?'*':text[char_ofs+1];
+ CharType cchar=pass?'*':t[char_ofs];
+ CharType next=pass?'*':t[char_ofs+1];
int char_width=font->get_char_size( cchar,next ).width;
// end of widget, break!
@@ -496,23 +665,28 @@ void LineEdit::_notification(int p_what) {
font->draw_char(ci, Point2(x_ofs, y_ofs + font_ascent), cchar, next, selected ? font_color_selected : font_color);
- if (char_ofs==cursor_pos && has_focus())
+ if (char_ofs==cursor_pos && draw_caret) {
VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(
Point2( x_ofs , y_ofs ), Size2( 1, y_area ) ), cursor_color );
+ }
x_ofs+=char_width;
char_ofs++;
}
- if (char_ofs==cursor_pos && has_focus()) //may be at the end
+ if (char_ofs==cursor_pos && draw_caret) {//may be at the end
VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(
Point2( x_ofs , y_ofs ), Size2( 1, y_area ) ), cursor_color );
-
+ }
} break;
case NOTIFICATION_FOCUS_ENTER: {
+ if (!caret_blink_enabled) {
+ draw_caret = true;
+ }
+
if (OS::get_singleton()->has_virtual_keyboard())
- OS::get_singleton()->show_virtual_keyboard(get_text(),get_global_rect());
+ OS::get_singleton()->show_virtual_keyboard(text,get_global_rect());
} break;
case NOTIFICATION_FOCUS_EXIT: {
@@ -559,9 +733,31 @@ void LineEdit::paste_text() {
}
+void LineEdit::undo() {
+
+ int old_cursor_pos = cursor_pos;
+ text = undo_text;
+
+ Ref<Font> font = get_font("font");
+
+ cached_width = 0;
+ for (int i = 0; i<text.length(); i++)
+ cached_width += font->get_char_size(text[i]).width;
+
+ if(old_cursor_pos > text.length()) {
+ set_cursor_pos(text.length());
+ } else {
+ set_cursor_pos(old_cursor_pos);
+ }
+
+ emit_signal("text_changed",text);
+ _change_notify("text");
+
+}
+
void LineEdit::shift_selection_check_pre(bool p_shift) {
- if (!selection.old_shift && p_shift) {
+ if (!selection.enabled && p_shift) {
selection.cursor_start=cursor_pos;
}
if (!p_shift)
@@ -615,6 +811,9 @@ void LineEdit::set_cursor_at_pixel_pos(int p_x) {
if ( (pixel_ofs-p_x) < (char_w >> 1 ) ) {
ofs+=1;
+ } else if ( (pixel_ofs-p_x) > (char_w >> 1 ) ) {
+
+ ofs-=1;
}
break;
@@ -635,6 +834,45 @@ void LineEdit::set_cursor_at_pixel_pos(int p_x) {
}
+bool LineEdit::cursor_get_blink_enabled() const {
+ return caret_blink_enabled;
+}
+
+void LineEdit::cursor_set_blink_enabled(const bool p_enabled) {
+ caret_blink_enabled = p_enabled;
+ if (p_enabled) {
+ caret_blink_timer->start();
+ } else {
+ caret_blink_timer->stop();
+ }
+ draw_caret = true;
+}
+
+float LineEdit::cursor_get_blink_speed() const {
+ return caret_blink_timer->get_wait_time();
+}
+
+void LineEdit::cursor_set_blink_speed(const float p_speed) {
+ ERR_FAIL_COND(p_speed <= 0);
+ caret_blink_timer->set_wait_time(p_speed);
+}
+
+void LineEdit::_reset_caret_blink_timer() {
+ if (caret_blink_enabled) {
+ caret_blink_timer->stop();
+ caret_blink_timer->start();
+ draw_caret = true;
+ update();
+ }
+ }
+
+void LineEdit::_toggle_draw_caret() {
+ draw_caret = !draw_caret;
+ if (is_visible()) {
+ update();
+ }
+}
+
void LineEdit::delete_char() {
if ((text.length()<=0) || (cursor_pos==0)) return;
@@ -657,6 +895,39 @@ void LineEdit::delete_char() {
_change_notify("text");
}
+void LineEdit::delete_text(int p_from_column, int p_to_column) {
+
+ undo_text = text;
+
+ if (text.size() > 0)
+ {
+ Ref<Font> font = get_font("font");
+ if (font != NULL) {
+ for (int i = p_from_column; i < p_to_column; i++)
+ cached_width -= font->get_char_size(text[i]).width;
+ }
+ }
+ else
+ {
+ cached_width = 0;
+ }
+
+ text.erase(p_from_column,p_to_column-p_from_column);
+ cursor_pos-=CLAMP( cursor_pos-p_from_column, 0, p_to_column-p_from_column);
+
+ if (cursor_pos>=text.length()) {
+
+ cursor_pos=text.length();
+ }
+ if (window_pos>cursor_pos) {
+
+ window_pos=cursor_pos;
+ }
+
+ emit_signal("text_changed",text);
+ _change_notify("text");
+}
+
void LineEdit::set_text(String p_text) {
clear_internal();
@@ -669,6 +940,8 @@ void LineEdit::set_text(String p_text) {
void LineEdit::clear() {
clear_internal();
+ emit_signal("text_changed",text);
+ _change_notify("text");
}
String LineEdit::get_text() const {
@@ -676,6 +949,29 @@ String LineEdit::get_text() const {
return text;
}
+void LineEdit::set_placeholder(String p_text) {
+
+ placeholder = XL_MESSAGE(p_text);
+ update();
+}
+
+String LineEdit::get_placeholder() const {
+
+ return placeholder;
+}
+
+
+void LineEdit::set_placeholder_alpha(float p_alpha) {
+
+ placeholder_alpha = p_alpha;
+ update();
+}
+
+float LineEdit::get_placeholder_alpha() const {
+
+ return placeholder_alpha;
+}
+
void LineEdit::set_cursor_pos(int p_pos) {
if (p_pos>(int)text.length())
@@ -688,10 +984,6 @@ void LineEdit::set_cursor_pos(int p_pos) {
cursor_pos=p_pos;
-// if (cursor_pos>(window_pos+get_window_length())) {
-// set_window_pos(cursor_pos-get_window_lengt//h());
-// }
-
if (!is_inside_tree()) {
window_pos=cursor_pos;
@@ -710,17 +1002,23 @@ void LineEdit::set_cursor_pos(int p_pos) {
if (window_width<0)
return;
- int width_to_cursor=0;
int wp=window_pos;
- if (font != NULL) {
- for (int i=window_pos;i<cursor_pos;i++)
- width_to_cursor+=font->get_char_size( text[i] ).width;
+ if (font.is_valid()) {
- while (width_to_cursor >= window_width && wp < text.length()) {
+ int accum_width=0;
- width_to_cursor -= font->get_char_size(text[wp]).width;
- wp++;
+ for(int i=cursor_pos;i>=window_pos;i--) {
+
+ if (i>=text.length()) {
+ accum_width=font->get_char_size(' ').width; //anything should do
+ } else {
+ accum_width+=font->get_char_size(text[i],i+1<text.length()?text[i+1]:0).width; //anything should do
+ }
+ if (accum_width>=window_width)
+ break;
+
+ wp=i;
}
}
@@ -783,7 +1081,6 @@ Size2 LineEdit::get_minimum_size() const {
Size2 min=style->get_minimum_size();
min.height+=font->get_height();
min.width+=get_constant("minimum_spaces")*font->get_char_size(' ').x;
-
return min;
}
@@ -796,46 +1093,14 @@ void LineEdit::selection_clear() {
selection.cursor_start=0;
selection.enabled=false;
selection.creating=false;
- selection.old_shift=false;
selection.doubleclick=false;
update();
}
-
void LineEdit::selection_delete() {
- if (selection.enabled) {
-
- undo_text = text;
-
- if (text.size() > 0)
- {
- Ref<Font> font = get_font("font");
- if (font != NULL) {
- for (int i = selection.begin; i < selection.end; i++)
- cached_width -= font->get_char_size(text[i]).width;
- }
- }
- else
- {
- cached_width = 0;
- }
-
- text.erase(selection.begin,selection.end-selection.begin);
- cursor_pos-=CLAMP( cursor_pos-selection.begin, 0, selection.end-selection.begin);
-
- if (cursor_pos>=text.length()) {
-
- cursor_pos=text.length();
- }
- if (window_pos>cursor_pos) {
-
- window_pos=cursor_pos;
- }
-
- emit_signal("text_changed",text);
- _change_notify("text");
- };
+ if (selection.enabled)
+ delete_text(selection.begin,selection.end);
selection_clear();
}
@@ -922,7 +1187,6 @@ void LineEdit::select(int p_from, int p_to) {
selection.begin=p_from;
selection.end=p_to;
selection.creating=false;
- selection.old_shift=false;
selection.doubleclick=false;
update();
}
@@ -932,8 +1196,54 @@ bool LineEdit::is_text_field() const {
return true;
}
+void LineEdit::menu_option(int p_option) {
+
+ switch(p_option) {
+ case MENU_CUT: {
+ cut_text();
+ } break;
+ case MENU_COPY: {
+
+ copy_text();
+ } break;
+ case MENU_PASTE: {
+
+ paste_text();
+ } break;
+ case MENU_CLEAR: {
+ clear();
+ } break;
+ case MENU_SELECT_ALL: {
+ select_all();
+ } break;
+ case MENU_UNDO: {
+
+ undo();
+ } break;
+
+ }
+
+}
+
+PopupMenu *LineEdit::get_menu() const {
+ return menu;
+}
+
+#ifdef TOOLS_ENABLED
+ void LineEdit::_editor_settings_changed() {
+ cursor_set_blink_enabled(EDITOR_DEF("text_editor/caret_blink", false));
+ cursor_set_blink_speed(EDITOR_DEF("text_editor/caret_blink_speed", 0.65));
+ }
+#endif
+
void LineEdit::_bind_methods() {
+ ObjectTypeDB::bind_method(_MD("_toggle_draw_caret"),&LineEdit::_toggle_draw_caret);
+
+#ifdef TOOLS_ENABLED
+ ObjectTypeDB::bind_method("_editor_settings_changed",&LineEdit::_editor_settings_changed);
+#endif
+
ObjectTypeDB::bind_method(_MD("set_align", "align"), &LineEdit::set_align);
ObjectTypeDB::bind_method(_MD("get_align"), &LineEdit::get_align);
@@ -942,8 +1252,16 @@ void LineEdit::_bind_methods() {
ObjectTypeDB::bind_method(_MD("select_all"),&LineEdit::select_all);
ObjectTypeDB::bind_method(_MD("set_text","text"),&LineEdit::set_text);
ObjectTypeDB::bind_method(_MD("get_text"),&LineEdit::get_text);
+ ObjectTypeDB::bind_method(_MD("set_placeholder","text"),&LineEdit::set_placeholder);
+ ObjectTypeDB::bind_method(_MD("get_placeholder"),&LineEdit::get_placeholder);
+ ObjectTypeDB::bind_method(_MD("set_placeholder_alpha","alpha"),&LineEdit::set_placeholder_alpha);
+ ObjectTypeDB::bind_method(_MD("get_placeholder_alpha"),&LineEdit::get_placeholder_alpha);
ObjectTypeDB::bind_method(_MD("set_cursor_pos","pos"),&LineEdit::set_cursor_pos);
ObjectTypeDB::bind_method(_MD("get_cursor_pos"),&LineEdit::get_cursor_pos);
+ ObjectTypeDB::bind_method(_MD("cursor_set_blink_enabled", "enable"),&LineEdit::cursor_set_blink_enabled);
+ ObjectTypeDB::bind_method(_MD("cursor_get_blink_enabled"),&LineEdit::cursor_get_blink_enabled);
+ ObjectTypeDB::bind_method(_MD("cursor_set_blink_speed", "blink_speed"),&LineEdit::cursor_set_blink_speed);
+ ObjectTypeDB::bind_method(_MD("cursor_get_blink_speed"),&LineEdit::cursor_get_blink_speed);
ObjectTypeDB::bind_method(_MD("set_max_length","chars"),&LineEdit::set_max_length);
ObjectTypeDB::bind_method(_MD("get_max_length"),&LineEdit::get_max_length);
ObjectTypeDB::bind_method(_MD("append_at_cursor","text"),&LineEdit::append_at_cursor);
@@ -952,6 +1270,8 @@ void LineEdit::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_secret","enabled"),&LineEdit::set_secret);
ObjectTypeDB::bind_method(_MD("is_secret"),&LineEdit::is_secret);
ObjectTypeDB::bind_method(_MD("select","from","to"),&LineEdit::select,DEFVAL(0),DEFVAL(-1));
+ ObjectTypeDB::bind_method(_MD("menu_option","option"),&LineEdit::menu_option);
+ ObjectTypeDB::bind_method(_MD("get_menu:PopupMenu"),&LineEdit::get_menu);
ADD_SIGNAL( MethodInfo("text_changed", PropertyInfo( Variant::STRING, "text" )) );
ADD_SIGNAL( MethodInfo("text_entered", PropertyInfo( Variant::STRING, "text" )) );
@@ -961,11 +1281,24 @@ void LineEdit::_bind_methods() {
BIND_CONSTANT(ALIGN_RIGHT);
BIND_CONSTANT(ALIGN_FILL);
- ADD_PROPERTY( PropertyInfo( Variant::STRING, "text" ), _SCS("set_text"),_SCS("get_text") );
+ BIND_CONSTANT( MENU_CUT );
+ BIND_CONSTANT( MENU_COPY );
+ BIND_CONSTANT( MENU_PASTE );
+ BIND_CONSTANT( MENU_CLEAR );
+ BIND_CONSTANT( MENU_SELECT_ALL );
+ BIND_CONSTANT( MENU_UNDO );
+ BIND_CONSTANT( MENU_MAX );
+
+ ADD_PROPERTYNZ( PropertyInfo( Variant::STRING, "text" ), _SCS("set_text"),_SCS("get_text") );
+ ADD_PROPERTYNZ( PropertyInfo( Variant::STRING, "placeholder/text" ), _SCS("set_placeholder"),_SCS("get_placeholder") );
+ ADD_PROPERTYNZ( PropertyInfo( Variant::REAL, "placeholder/alpha",PROPERTY_HINT_RANGE,"0,1,0.001" ), _SCS("set_placeholder_alpha"),_SCS("get_placeholder_alpha") );
ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "align", PROPERTY_HINT_ENUM, "Left,Center,Right,Fill"), _SCS("set_align"), _SCS("get_align"));
- ADD_PROPERTY( PropertyInfo( Variant::INT, "max_length" ), _SCS("set_max_length"),_SCS("get_max_length") );
- ADD_PROPERTY( PropertyInfo( Variant::BOOL, "editable" ), _SCS("set_editable"),_SCS("is_editable") );
- ADD_PROPERTY( PropertyInfo( Variant::BOOL, "secret" ), _SCS("set_secret"),_SCS("is_secret") );
+ ADD_PROPERTYNZ( PropertyInfo( Variant::INT, "max_length" ), _SCS("set_max_length"),_SCS("get_max_length") );
+ ADD_PROPERTYNO( PropertyInfo( Variant::BOOL, "editable" ), _SCS("set_editable"),_SCS("is_editable") );
+ ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "secret" ), _SCS("set_secret"),_SCS("is_secret") );
+ ADD_PROPERTY( PropertyInfo( Variant::INT,"focus_mode", PROPERTY_HINT_ENUM, "None,Click,All" ), _SCS("set_focus_mode"), _SCS("get_focus_mode") );
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret/caret_blink"), _SCS("cursor_set_blink_enabled"), _SCS("cursor_get_blink_enabled"));;
+ ADD_PROPERTYNZ(PropertyInfo(Variant::REAL, "caret/caret_blink_speed",PROPERTY_HINT_RANGE,"0.1,10,0.1"), _SCS("cursor_set_blink_speed"),_SCS("cursor_get_blink_speed") );
}
LineEdit::LineEdit() {
@@ -974,8 +1307,10 @@ LineEdit::LineEdit() {
cached_width = 0;
cursor_pos=0;
window_pos=0;
+ window_has_focus=true;
max_length = 0;
pass=false;
+ placeholder_alpha=0.6;
selection_clear();
set_focus_mode( FOCUS_ALL );
@@ -983,6 +1318,27 @@ LineEdit::LineEdit() {
set_default_cursor_shape(CURSOR_IBEAM);
set_stop_mouse(true);
+ draw_caret=true;
+ caret_blink_enabled=false;
+ caret_blink_timer = memnew(Timer);
+ add_child(caret_blink_timer);
+ caret_blink_timer->set_wait_time(0.65);
+ caret_blink_timer->connect("timeout", this,"_toggle_draw_caret");
+ cursor_set_blink_enabled(false);
+
+ menu = memnew( PopupMenu );
+ add_child(menu);
+ menu->add_item(TTR("Cut"),MENU_CUT,KEY_MASK_CMD|KEY_X);
+ menu->add_item(TTR("Copy"),MENU_COPY,KEY_MASK_CMD|KEY_C);
+ menu->add_item(TTR("Paste"),MENU_PASTE,KEY_MASK_CMD|KEY_V);
+ menu->add_separator();
+ menu->add_item(TTR("Select All"),MENU_SELECT_ALL,KEY_MASK_CMD|KEY_A);
+ menu->add_item(TTR("Clear"),MENU_CLEAR);
+ menu->add_separator();
+ menu->add_item(TTR("Undo"),MENU_UNDO,KEY_MASK_CMD|KEY_Z);
+ menu->connect("item_pressed",this,"menu_option");
+
+
}