diff options
-rw-r--r-- | core/array.cpp | 31 | ||||
-rw-r--r-- | core/array.h | 2 | ||||
-rw-r--r-- | core/variant_call.cpp | 4 | ||||
-rw-r--r-- | doc/base/classes.xml | 39 | ||||
-rw-r--r-- | modules/gdscript/gd_functions.cpp | 4 | ||||
-rw-r--r-- | platform/osx/os_osx.mm | 50 | ||||
-rw-r--r-- | scene/gui/base_button.cpp | 17 | ||||
-rw-r--r-- | scene/gui/base_button.h | 4 | ||||
-rw-r--r-- | scene/gui/control.cpp | 1 | ||||
-rw-r--r-- | scene/gui/label.cpp | 4 | ||||
-rw-r--r-- | scene/gui/line_edit.cpp | 7 | ||||
-rw-r--r-- | scene/gui/link_button.cpp | 2 | ||||
-rw-r--r-- | scene/gui/menu_button.cpp | 2 | ||||
-rw-r--r-- | scene/gui/slider.cpp | 1 | ||||
-rw-r--r-- | tools/editor/editor_help.cpp | 9 | ||||
-rw-r--r-- | tools/editor/editor_help.h | 1 |
16 files changed, 156 insertions, 22 deletions
diff --git a/core/array.cpp b/core/array.cpp index fef0fcbb40..1d283a14aa 100644 --- a/core/array.cpp +++ b/core/array.cpp @@ -155,6 +155,37 @@ int Array::find(const Variant& p_value) const { return _p->array.find(p_value); } +int Array::find_last(const Variant& p_value) const { + + if(_p->array.size() == 0) + return -1; + + for (int i=_p->array.size()-1; i>=0; i--) { + + if(_p->array[i] == p_value){ + return i; + }; + }; + + return -1; +} + +int Array::count(const Variant& p_value) const { + + if(_p->array.size() == 0) + return 0; + + int amount=0; + for (int i=0; i<_p->array.size(); i++) { + + if(_p->array[i] == p_value){ + amount++; + }; + }; + + return amount; +} + void Array::remove(int p_pos) { _p->array.remove(p_pos); diff --git a/core/array.h b/core/array.h index ecb91b69dc..9472a6dd21 100644 --- a/core/array.h +++ b/core/array.h @@ -72,6 +72,8 @@ public: void invert(); int find(const Variant& p_value) const; + int find_last(const Variant& p_value) const; + int count(const Variant& p_value) const; void erase(const Variant& p_value); diff --git a/core/variant_call.cpp b/core/variant_call.cpp index 4be763a511..f5dcd75691 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -463,6 +463,8 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var VCALL_LOCALMEM2(Array,insert); VCALL_LOCALMEM1(Array,remove); VCALL_LOCALMEM1R(Array,find); + VCALL_LOCALMEM1R(Array,find_last); + VCALL_LOCALMEM1R(Array,count); VCALL_LOCALMEM1(Array,erase); VCALL_LOCALMEM0(Array,sort); VCALL_LOCALMEM2(Array,sort_custom); @@ -1448,6 +1450,8 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl ADDFUNC1(ARRAY,NIL,Array,remove,INT,"pos",varray()); ADDFUNC1(ARRAY,NIL,Array,erase,NIL,"value",varray()); ADDFUNC1(ARRAY,INT,Array,find,NIL,"value",varray()); + ADDFUNC1(ARRAY,INT,Array,find_last,NIL,"value",varray()); + ADDFUNC1(ARRAY,INT,Array,count,NIL,"value",varray()); ADDFUNC0(ARRAY,NIL,Array,pop_back,varray()); ADDFUNC0(ARRAY,NIL,Array,pop_front,varray()); ADDFUNC0(ARRAY,NIL,Array,sort,varray()); diff --git a/doc/base/classes.xml b/doc/base/classes.xml index a380c19115..7dee3c6267 100644 --- a/doc/base/classes.xml +++ b/doc/base/classes.xml @@ -4340,6 +4340,15 @@ Clear the array (resize to 0). </description> </method> + <method name="count"> + <return type="int"> + </return> + <argument index="0" name="value" type="var"> + </argument> + <description> + Return the amount of times an element is in the array. + </description> + </method> <method name="empty"> <return type="bool"> </return> @@ -4363,6 +4372,15 @@ Searches the array for a value and returns its index or -1 if not found. </description> </method> + <method name="find_last"> + <return type="int"> + </return> + <argument index="0" name="value" type="var"> + </argument> + <description> + Searches the array in reverse order for a value and returns its index or -1 if not found. + </description> + </method> <method name="hash"> <return type="int"> </return> @@ -5738,6 +5756,20 @@ Return the visual state used to draw the button. This is useful mainly when implementing your own draw code by either overriding _draw() or connecting to "draw" signal. The visual state of the button is defined by the DRAW_* enum. </description> </method> + <method name="set_enabled_focus_mode"> + <argument index="0" name="mode" type="int"> + </argument> + <description> + Sets the focus access mode to use when switching between enabled/disabled (see [method Control.set_focus_mode] and [method set_disabled]). + </description> + </method> + <method name="get_enabled_focus_mode" qualifiers="const"> + <return type="int"> + </return> + <description> + Returns focus access mode used when switching between enabled/disabled (see [method Control.set_focus_mode] and [method set_disabled]). + </description> + </method> </methods> <signals> <signal name="released"> @@ -9171,6 +9203,13 @@ Set the focus access mode for the control (FOCUS_NONE, FOCUS_CLICK, FOCUS_ALL). Only one Control can be focused at the same time, and it will receive keyboard signals. </description> </method> + <method name="get_focus_mode" qualifiers="const"> + <return type="int"> + </return> + <description> + Returns the focus access mode for the control (FOCUS_NONE, FOCUS_CLICK, FOCUS_ALL) (see [method set_focus_mode]). + </description> + </method> <method name="has_focus" qualifiers="const"> <return type="bool"> </return> diff --git a/modules/gdscript/gd_functions.cpp b/modules/gdscript/gd_functions.cpp index 1c05a71d01..5ea5908c5f 100644 --- a/modules/gdscript/gd_functions.cpp +++ b/modules/gdscript/gd_functions.cpp @@ -1010,11 +1010,11 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va VALIDATE_ARG_NUM(1); VALIDATE_ARG_NUM(2); - Color color(*p_args[0],*p_args[1],*p_args[2]); + Color color((float)*p_args[0]/255.0f,(float)*p_args[1]/255.0f,(float)*p_args[2]/255.0f); if (p_arg_count==4) { VALIDATE_ARG_NUM(3); - color.a=*p_args[3]; + color.a=(float)*p_args[3]/255.0f; } r_ret=color; diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index 065fe52b09..1d97ffacb6 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -772,20 +772,48 @@ static int translateKey(unsigned int key) - (void)flagsChanged:(NSEvent *)event { - /* int action; - unsigned int newModifierFlags = - [event modifierFlags] & NSDeviceIndependentModifierFlagsMask; + InputEvent ev; + int key = [event keyCode]; + int mod = [event modifierFlags]; - if (newModifierFlags > window->ns.modifierFlags) - action = GLFW_PRESS; - else - action = GLFW_RELEASE; + ev.type=InputEvent::KEY; - window->ns.modifierFlags = newModifierFlags; + if (key == 0x36 || key == 0x37) { + if (mod & NSCommandKeyMask) { + mod&= ~NSCommandKeyMask; + ev.key.pressed = true; + } else { + ev.key.pressed = false; + } + } else if (key == 0x38 || key == 0x3c) { + if (mod & NSShiftKeyMask) { + mod&= ~NSShiftKeyMask; + ev.key.pressed = true; + } else { + ev.key.pressed = false; + } + } else if (key == 0x3a || key == 0x3d) { + if (mod & NSAlternateKeyMask) { + mod&= ~NSAlternateKeyMask; + ev.key.pressed = true; + } else { + ev.key.pressed = false; + } + } else if (key == 0x3b || key == 0x3e) { + if (mod & NSControlKeyMask) { + mod&= ~NSControlKeyMask; + ev.key.pressed = true; + } else { + ev.key.pressed = false; + } + } else { + return; + } - const int key = translateKey([event keyCode]); - const int mods = translateFlags([event modifierFlags]); - _glfwInputKey(window, key, [event keyCode], action, mods);*/ + ev.key.mod=translateFlags(mod); + ev.key.scancode = latin_keyboard_keycode_convert(translateKey(key)); + + OS_OSX::singleton->push_input(ev); } - (void)keyUp:(NSEvent *)event diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp index 3bcc60b86a..21820d7f10 100644 --- a/scene/gui/base_button.cpp +++ b/scene/gui/base_button.cpp @@ -289,7 +289,7 @@ void BaseButton::set_disabled(bool p_disabled) { if (p_disabled) set_focus_mode(FOCUS_NONE); else - set_focus_mode(FOCUS_ALL); + set_focus_mode(enabled_focus_mode); } bool BaseButton::is_disabled() const { @@ -377,7 +377,18 @@ bool BaseButton::get_click_on_press() const { return status.click_on_press; } +void BaseButton::set_enabled_focus_mode(FocusMode p_mode) { + enabled_focus_mode = p_mode; + if (!status.disabled) { + set_focus_mode( p_mode ); + } +} + +Control::FocusMode BaseButton::get_enabled_focus_mode() const { + + return enabled_focus_mode; +} void BaseButton::_bind_methods() { @@ -393,6 +404,8 @@ void BaseButton::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_click_on_press","enable"),&BaseButton::set_click_on_press); ObjectTypeDB::bind_method(_MD("get_click_on_press"),&BaseButton::get_click_on_press); ObjectTypeDB::bind_method(_MD("get_draw_mode"),&BaseButton::get_draw_mode); + ObjectTypeDB::bind_method(_MD("set_enabled_focus_mode","mode"),&BaseButton::set_enabled_focus_mode); + ObjectTypeDB::bind_method(_MD("get_enabled_focus_mode"),&BaseButton::get_enabled_focus_mode); BIND_VMETHOD(MethodInfo("_pressed")); BIND_VMETHOD(MethodInfo("_toggled",PropertyInfo(Variant::BOOL,"pressed"))); @@ -404,6 +417,7 @@ void BaseButton::_bind_methods() { ADD_PROPERTY( PropertyInfo( Variant::BOOL, "toggle_mode"), _SCS("set_toggle_mode"), _SCS("is_toggle_mode")); ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "is_pressed"), _SCS("set_pressed"), _SCS("is_pressed")); ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "click_on_press"), _SCS("set_click_on_press"), _SCS("get_click_on_press")); + ADD_PROPERTY( PropertyInfo( Variant::INT,"enabled_focus_mode", PROPERTY_HINT_ENUM, "None,Click,All" ), _SCS("set_enabled_focus_mode"), _SCS("get_enabled_focus_mode") ); BIND_CONSTANT( DRAW_NORMAL ); @@ -424,6 +438,7 @@ BaseButton::BaseButton() { status.click_on_press=false; status.pressing_button=0; set_focus_mode( FOCUS_ALL ); + enabled_focus_mode = FOCUS_ALL; group=NULL; diff --git a/scene/gui/base_button.h b/scene/gui/base_button.h index 9a5213d971..0247fb2f21 100644 --- a/scene/gui/base_button.h +++ b/scene/gui/base_button.h @@ -42,6 +42,7 @@ class BaseButton : public Control { OBJ_TYPE( BaseButton, Control ); bool toggle_mode; + FocusMode enabled_focus_mode; struct Status { @@ -97,6 +98,9 @@ public: void set_click_on_press(bool p_click_on_press); bool get_click_on_press() const; + void set_enabled_focus_mode(FocusMode p_mode); + FocusMode get_enabled_focus_mode() const; + BaseButton(); ~BaseButton(); diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 0522b2efed..c99d3aa0f5 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -2266,6 +2266,7 @@ void Control::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_area_as_parent_rect","margin"),&Control::set_area_as_parent_rect,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("show_modal","exclusive"),&Control::show_modal,DEFVAL(false)); ObjectTypeDB::bind_method(_MD("set_focus_mode","mode"),&Control::set_focus_mode); + ObjectTypeDB::bind_method(_MD("get_focus_mode"),&Control::get_focus_mode); ObjectTypeDB::bind_method(_MD("has_focus"),&Control::has_focus); ObjectTypeDB::bind_method(_MD("grab_focus"),&Control::grab_focus); ObjectTypeDB::bind_method(_MD("release_focus"),&Control::release_focus); diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp index 09c6a77b42..8652aab649 100644 --- a/scene/gui/label.cpp +++ b/scene/gui/label.cpp @@ -488,9 +488,9 @@ void Label::regenerate_word_cache() { if (!autowrap) { minsize.width=width; if (max_lines_visible > 0 && line_count > max_lines_visible) { - minsize.height=(font->get_height()+line_spacing)*max_lines_visible; + minsize.height=(font->get_height() * max_lines_visible) + (line_spacing * (max_lines_visible - 1)); } else { - minsize.height=(font->get_height()+line_spacing)*line_count; + minsize.height=(font->get_height() * line_count)+(line_spacing * (line_count - 1)); } } diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index 14dac454bd..44cc798447 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -454,7 +454,7 @@ void LineEdit::_notification(int p_what) { } break; } - int ofs_max=width-style->get_minimum_size().width; + int ofs_max=width-style->get_minimum_size().width+x_ofs; int char_ofs=window_pos; int y_area=height-style->get_minimum_size().height; @@ -799,8 +799,7 @@ Size2 LineEdit::get_minimum_size() const { Ref<Font> font=get_font("font"); Size2 min=style->get_minimum_size(); - min.height+=font->get_height(); - min.width+=get_constant("minimum_spaces")*font->get_char_size(' ').x; + min+=font->get_string_size(this->text); return min; } @@ -1027,7 +1026,7 @@ void LineEdit::_bind_methods() { 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") ); } diff --git a/scene/gui/link_button.cpp b/scene/gui/link_button.cpp index 007d0a709e..065423ae2d 100644 --- a/scene/gui/link_button.cpp +++ b/scene/gui/link_button.cpp @@ -119,6 +119,6 @@ void LinkButton::_bind_methods() { LinkButton::LinkButton() { underline_mode=UNDERLINE_MODE_ALWAYS; - set_focus_mode(FOCUS_NONE); + set_enabled_focus_mode(FOCUS_NONE); set_default_cursor_shape(CURSOR_POINTING_HAND); } diff --git a/scene/gui/menu_button.cpp b/scene/gui/menu_button.cpp index 0f415f013d..0e39ee8a76 100644 --- a/scene/gui/menu_button.cpp +++ b/scene/gui/menu_button.cpp @@ -123,7 +123,7 @@ MenuButton::MenuButton() { set_flat(true); - set_focus_mode(FOCUS_NONE); + set_enabled_focus_mode(FOCUS_NONE); popup = memnew( PopupMenu ); popup->hide(); add_child(popup); diff --git a/scene/gui/slider.cpp b/scene/gui/slider.cpp index f66f909517..d5d14ad649 100644 --- a/scene/gui/slider.cpp +++ b/scene/gui/slider.cpp @@ -237,6 +237,7 @@ void Slider::_bind_methods() { ADD_PROPERTY( PropertyInfo( Variant::INT, "tick_count", PROPERTY_HINT_RANGE,"0,4096,1"), _SCS("set_ticks"), _SCS("get_ticks") ); ADD_PROPERTY( PropertyInfo( Variant::BOOL, "ticks_on_borders" ), _SCS("set_ticks_on_borders"), _SCS("get_ticks_on_borders") ); + ADD_PROPERTY( PropertyInfo( Variant::INT,"focus_mode", PROPERTY_HINT_ENUM, "None,Click,All" ), _SCS("set_focus_mode"), _SCS("get_focus_mode") ); } diff --git a/tools/editor/editor_help.cpp b/tools/editor/editor_help.cpp index b426def503..2d0a8a80b0 100644 --- a/tools/editor/editor_help.cpp +++ b/tools/editor/editor_help.cpp @@ -644,6 +644,13 @@ void EditorHelp::_class_desc_select(const String& p_select) { } +void EditorHelp::_class_desc_input(const InputEvent& p_input) { + if (p_input.type==InputEvent::MOUSE_BUTTON && p_input.mouse_button.pressed && p_input.mouse_button.button_index==1) { + class_desc->set_selection_enabled(false); + class_desc->set_selection_enabled(true); + } +} + void EditorHelp::_add_type(const String& p_type) { String t = p_type; @@ -1625,6 +1632,7 @@ void EditorHelp::_bind_methods() { ObjectTypeDB::bind_method("_class_list_select",&EditorHelp::_class_list_select); ObjectTypeDB::bind_method("_class_desc_select",&EditorHelp::_class_desc_select); + ObjectTypeDB::bind_method("_class_desc_input",&EditorHelp::_class_desc_input); // ObjectTypeDB::bind_method("_button_pressed",&EditorHelp::_button_pressed); ObjectTypeDB::bind_method("_scroll_changed",&EditorHelp::_scroll_changed); ObjectTypeDB::bind_method("_request_help",&EditorHelp::_request_help); @@ -1659,6 +1667,7 @@ EditorHelp::EditorHelp() { pc->add_child(class_desc); class_desc->set_area_as_parent_rect(8); class_desc->connect("meta_clicked",this,"_class_desc_select"); + class_desc->connect("input_event",this,"_class_desc_input"); } class_desc->get_v_scroll()->connect("value_changed",this,"_scroll_changed"); diff --git a/tools/editor/editor_help.h b/tools/editor/editor_help.h index f6dda9f545..c3d19894df 100644 --- a/tools/editor/editor_help.h +++ b/tools/editor/editor_help.h @@ -157,6 +157,7 @@ class EditorHelp : public VBoxContainer { void _scroll_changed(double p_scroll); void _class_list_select(const String& p_select); void _class_desc_select(const String& p_select); + void _class_desc_input(const InputEvent& p_input); Error _goto_desc(const String& p_class, int p_vscr=-1); //void _update_history_buttons(); |