Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exposed Control::focus_mode to the scene editor #4300

Merged
merged 1 commit into from
Jun 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions doc/base/classes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5655,6 +5655,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">
Expand Down Expand Up @@ -9088,6 +9102,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>
Expand Down
17 changes: 16 additions & 1 deletion scene/gui/base_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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() {
Expand All @@ -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")));
Expand All @@ -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 );
Expand All @@ -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;


Expand Down
4 changes: 4 additions & 0 deletions scene/gui/base_button.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class BaseButton : public Control {
OBJ_TYPE( BaseButton, Control );

bool toggle_mode;
FocusMode enabled_focus_mode;

struct Status {

Expand Down Expand Up @@ -97,6 +98,9 @@ class BaseButton : public Control {
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();
Expand Down
1 change: 1 addition & 0 deletions scene/gui/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2265,6 +2265,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);
Expand Down
2 changes: 1 addition & 1 deletion scene/gui/line_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,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") );

}

Expand Down
2 changes: 1 addition & 1 deletion scene/gui/link_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion scene/gui/menu_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions scene/gui/slider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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") );

}

Expand Down