diff options
author | Juan Linietsky <reduzio@gmail.com> | 2016-06-04 21:31:29 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2016-06-04 21:31:47 -0300 |
commit | 007efb6a20dcaa9230f1cfdc1cda92db24c5510f (patch) | |
tree | db29be67ba32768ba96037d06c82cb8f1ac7f1c2 /scene/gui/base_button.cpp | |
parent | 279b7921e8dc8feb44a7650b983f6b3878a01d14 (diff) | |
download | redot-engine-007efb6a20dcaa9230f1cfdc1cda92db24c5510f.tar.gz |
-customizable shortcuts in editor
-editor settings now save to .tres instead of .xml
-buttons can now hold a shortcut
Diffstat (limited to 'scene/gui/base_button.cpp')
-rw-r--r-- | scene/gui/base_button.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp index 21820d7f10..2200cac5da 100644 --- a/scene/gui/base_button.cpp +++ b/scene/gui/base_button.cpp @@ -390,10 +390,43 @@ Control::FocusMode BaseButton::get_enabled_focus_mode() const { return enabled_focus_mode; } +void BaseButton::set_shortcut(const Ref<ShortCut>& p_shortcut) { + + if (shortcut.is_null() == p_shortcut.is_null()) + return; + + shortcut=p_shortcut; + set_process_unhandled_input(shortcut.is_valid()); +} + +Ref<ShortCut> BaseButton:: get_shortcut() const { + return shortcut; +} + +void BaseButton::_unhandled_input(InputEvent p_event) { + + if (!is_disabled() && is_visible() && shortcut.is_valid() && shortcut->is_shortcut(p_event)) { + if (is_toggle_mode()) { + set_pressed(!is_pressed()); + emit_signal("toggled",is_pressed()); + } + + emit_signal("pressed"); + } +} + +String BaseButton::get_tooltip(const Point2& p_pos) const { + + String tooltip=Control::get_tooltip(p_pos); + if (shortcut.is_valid() && shortcut->is_valid()) + tooltip+=" ("+shortcut->get_as_text()+")"; + return tooltip; +} void BaseButton::_bind_methods() { ObjectTypeDB::bind_method(_MD("_input_event"),&BaseButton::_input_event); + ObjectTypeDB::bind_method(_MD("_unhandled_input"),&BaseButton::_unhandled_input); ObjectTypeDB::bind_method(_MD("set_pressed","pressed"),&BaseButton::set_pressed); ObjectTypeDB::bind_method(_MD("is_pressed"),&BaseButton::is_pressed); ObjectTypeDB::bind_method(_MD("is_hovered"),&BaseButton::is_hovered); @@ -406,6 +439,8 @@ void BaseButton::_bind_methods() { 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); + ObjectTypeDB::bind_method(_MD("set_shortcut","shortcut"),&BaseButton::set_shortcut); + ObjectTypeDB::bind_method(_MD("get_shortcut"),&BaseButton::get_shortcut); BIND_VMETHOD(MethodInfo("_pressed")); BIND_VMETHOD(MethodInfo("_toggled",PropertyInfo(Variant::BOOL,"pressed"))); @@ -418,6 +453,7 @@ void BaseButton::_bind_methods() { 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") ); + ADD_PROPERTY( PropertyInfo( Variant::OBJECT, "shortcut",PROPERTY_HINT_RESOURCE_TYPE,"ShortCut"), _SCS("set_shortcut"), _SCS("get_shortcut")); BIND_CONSTANT( DRAW_NORMAL ); |