diff options
-rw-r--r-- | core/ustring.cpp | 7 | ||||
-rw-r--r-- | doc/base/classes.xml | 28 | ||||
-rw-r--r-- | modules/gdscript/gd_parser.cpp | 4 | ||||
-rw-r--r-- | scene/gui/base_button.cpp | 10 | ||||
-rw-r--r-- | scene/gui/control.cpp | 4 | ||||
-rw-r--r-- | scene/gui/line_edit.cpp | 107 | ||||
-rw-r--r-- | scene/gui/line_edit.h | 18 | ||||
-rw-r--r-- | scene/main/viewport.cpp | 1 |
8 files changed, 163 insertions, 16 deletions
diff --git a/core/ustring.cpp b/core/ustring.cpp index ea9a9d903e..4dbe41890d 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -257,13 +257,10 @@ bool String::operator==(const StrRange &p_range) const { return true; const CharType *c_str=p_range.c_str; - - int l=length(); - - const CharType *dst = p_range.c_str; + const CharType *dst = &operator[](0); /* Compare char by char */ - for (int i=0;i<l;i++) { + for (int i=0;i<len;i++) { if (c_str[i]!=dst[i]) return false; diff --git a/doc/base/classes.xml b/doc/base/classes.xml index 808bf20c25..7224ae8554 100644 --- a/doc/base/classes.xml +++ b/doc/base/classes.xml @@ -18959,6 +18959,34 @@ Example: (content-length:12), (Content-Type:application/json; charset=UTF-8) Set the cursor position inside the [LineEdit], causing it to scroll if needed. </description> </method> + <method name="cursor_set_blink_enabled"> + <argument index="0" name="enable" type="bool"> + </argument> + <description> + Set the line edit caret to blink. + </description> + </method> + <method name="cursor_get_blink_enabled" qualifiers="const"> + <return type="float"> + </return> + <description> + Gets whether the line edit caret is blinking. + </description> + </method> + <method name="cursor_set_blink_speed"> + <argument index="0" name="blink_speed" type="float"> + </argument> + <description> + Set the line edit caret blink speed. Cannot be less then or equal to 0. + </description> + </method> + <method name="cursor_get_blink_speed" qualifiers="const"> + <return type="float"> + </return> + <description> + Gets the line edit caret blink speed. + </description> + </method> <method name="set_editable"> <argument index="0" name="enabled" type="bool"> </argument> diff --git a/modules/gdscript/gd_parser.cpp b/modules/gdscript/gd_parser.cpp index ac96a2117c..3ef42f81a4 100644 --- a/modules/gdscript/gd_parser.cpp +++ b/modules/gdscript/gd_parser.cpp @@ -1069,8 +1069,8 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_ // can be followed by an unary op in a valid combination, // due to how precedence works, unaries will always dissapear first - _set_error("Parser bug.."); - + _set_error("Unexpected two consecutive operators."); + return NULL; } diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp index bc498f47bc..d7632b14b8 100644 --- a/scene/gui/base_button.cpp +++ b/scene/gui/base_button.cpp @@ -225,11 +225,21 @@ void BaseButton::_notification(int p_what) { status.hovering=false; update(); } + if (p_what==NOTIFICATION_DRAG_BEGIN) { + + if (status.press_attempt) { + status.press_attempt=false; + status.pressing_button=0; + update(); + } + } + if (p_what==NOTIFICATION_FOCUS_EXIT) { if (status.pressing_button && status.press_attempt) { status.press_attempt=false; status.pressing_button=0; + update(); } } diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index edc8a8bcb8..2e28baa137 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -2460,8 +2460,8 @@ void Control::_bind_methods() { ADD_PROPERTY( PropertyInfo(Variant::BOOL,"focus/ignore_mouse"), _SCS("set_ignore_mouse"),_SCS("is_ignoring_mouse") ); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"focus/stop_mouse"), _SCS("set_stop_mouse"),_SCS("is_stopping_mouse") ); - ADD_PROPERTYNZ( PropertyInfo(Variant::INT,"size_flags/horizontal", PROPERTY_HINT_FLAGS, "Expand,Fill"), _SCS("set_h_size_flags"),_SCS("get_h_size_flags") ); - ADD_PROPERTYNZ( PropertyInfo(Variant::INT,"size_flags/vertical", PROPERTY_HINT_FLAGS, "Expand,Fill"), _SCS("set_v_size_flags"),_SCS("get_v_size_flags") ); + ADD_PROPERTY( PropertyInfo(Variant::INT,"size_flags/horizontal", PROPERTY_HINT_FLAGS, "Expand,Fill"), _SCS("set_h_size_flags"),_SCS("get_h_size_flags") ); + ADD_PROPERTY( PropertyInfo(Variant::INT,"size_flags/vertical", PROPERTY_HINT_FLAGS, "Expand,Fill"), _SCS("set_v_size_flags"),_SCS("get_v_size_flags") ); ADD_PROPERTYNO( PropertyInfo(Variant::INT,"size_flags/stretch_ratio", PROPERTY_HINT_RANGE, "1,128,0.01"), _SCS("set_stretch_ratio"),_SCS("get_stretch_ratio") ); ADD_PROPERTYNZ( PropertyInfo(Variant::OBJECT,"theme/theme", PROPERTY_HINT_RESOURCE_TYPE, "Theme"), _SCS("set_theme"),_SCS("get_theme") ); diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index 88dbd33e55..579a6e2f0a 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -31,6 +31,9 @@ #include "os/os.h" #include "print_string.h" #include "label.h" +#ifdef TOOLS_ENABLED +#include "tools/editor/editor_settings.h" +#endif static bool _is_text_char(CharType c) { @@ -57,6 +60,7 @@ void LineEdit::_input_event(InputEvent p_event) { if (b.button_index!=BUTTON_LEFT) break; + _reset_caret_blink_timer(); if (b.pressed) { shift_selection_check_pre(b.mod.shift); @@ -227,7 +231,7 @@ void LineEdit::_input_event(InputEvent p_event) { } } - + _reset_caret_blink_timer(); if (!k.mod.meta) { bool handled=true; @@ -546,14 +550,37 @@ 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)); + 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(); @@ -630,21 +657,26 @@ 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()); @@ -791,6 +823,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; @@ -1129,8 +1200,21 @@ 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); @@ -1141,6 +1225,10 @@ void LineEdit::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_text"),&LineEdit::get_text); 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); @@ -1174,7 +1262,8 @@ void LineEdit::_bind_methods() { 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() { @@ -1183,6 +1272,7 @@ LineEdit::LineEdit() { cached_width = 0; cursor_pos=0; window_pos=0; + window_has_focus=true; max_length = 0; pass=false; @@ -1192,6 +1282,13 @@ 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); diff --git a/scene/gui/line_edit.h b/scene/gui/line_edit.h index ce3958db02..e4da0f0b87 100644 --- a/scene/gui/line_edit.h +++ b/scene/gui/line_edit.h @@ -87,6 +87,11 @@ private: bool drag_attempt; } selection; + Timer *caret_blink_timer; + bool caret_blink_enabled; + bool draw_caret; + bool window_has_focus; + void shift_selection_check_pre(bool); void shift_selection_check_post(bool); @@ -97,10 +102,15 @@ private: void set_cursor_at_pixel_pos(int p_x); + void _reset_caret_blink_timer(); + void _toggle_draw_caret(); + void clear_internal(); void changed_internal(); - +#ifdef TOOLS_ENABLED + void _editor_settings_changed(); +#endif void _input_event(InputEvent p_event); void _notification(int p_what); @@ -132,6 +142,12 @@ public: void append_at_cursor(String p_text); void clear(); + bool cursor_get_blink_enabled() const; + void cursor_set_blink_enabled(const bool p_enabled); + + float cursor_get_blink_speed() const; + void cursor_set_blink_speed(const float p_speed); + void copy_text(); void cut_text(); void paste_text(); diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index a1df7062ea..3c52af1c1e 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -1933,7 +1933,6 @@ void Viewport::_gui_input_event(InputEvent p_event) { } - if (over!=gui.mouse_over) { if (gui.mouse_over) |