diff options
Diffstat (limited to 'scene/gui/spin_box.cpp')
| -rw-r--r-- | scene/gui/spin_box.cpp | 63 |
1 files changed, 37 insertions, 26 deletions
diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp index 98e1a32ae..efb55b79b 100644 --- a/scene/gui/spin_box.cpp +++ b/scene/gui/spin_box.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -39,7 +39,7 @@ Size2 SpinBox::get_minimum_size() const { void SpinBox::_value_changed(double) { - String value = String::num(get_val(),Math::step_decimals(get_step())); + String value = String::num(get_value(),Math::step_decimals(get_step())); if (prefix!="") value=prefix+" "+value; if (suffix!="") @@ -51,7 +51,10 @@ void SpinBox::_text_entered(const String& p_string) { //if (!p_string.is_numeric()) // return; - set_val( p_string.to_double() ); + String value = p_string; + if (prefix!="" && p_string.begins_with(prefix)) + value = p_string.substr(prefix.length(), p_string.length()-prefix.length()); + set_value( value.to_double() ); _value_changed(0); } @@ -73,7 +76,7 @@ void SpinBox::_range_click_timeout() { if (!drag.enabled && Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT)) { bool up = get_local_mouse_pos().y < (get_size().height/2); - set_val( get_val() + (up?get_step():-get_step())); + set_value( get_value() + (up?get_step():-get_step())); if (range_click_timer->is_one_shot()) { range_click_timer->set_wait_time(0.075); @@ -89,6 +92,9 @@ void SpinBox::_range_click_timeout() { void SpinBox::_input_event(const InputEvent& p_event) { + if (!is_editable()) { + return; + } if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.pressed) { const InputEventMouseButton &mb=p_event.mouse_button; @@ -101,25 +107,30 @@ void SpinBox::_input_event(const InputEvent& p_event) { case BUTTON_LEFT: { - set_val( get_val() + (up?get_step():-get_step())); + set_value( get_value() + (up?get_step():-get_step())); range_click_timer->set_wait_time(0.6); range_click_timer->set_one_shot(true); range_click_timer->start(); + line_edit->grab_focus(); } break; case BUTTON_RIGHT: { - set_val( (up?get_max():get_min()) ); - + set_value( (up?get_max():get_min()) ); + line_edit->grab_focus(); } break; case BUTTON_WHEEL_UP: { - - set_val( get_val() + get_step() ); + if (line_edit->has_focus()) { + set_value( get_value() + get_step() ); + accept_event(); + } } break; case BUTTON_WHEEL_DOWN: { - - set_val( get_val() - get_step() ); + if (line_edit->has_focus()) { + set_value( get_value() - get_step() ); + accept_event(); + } } break; } } @@ -155,13 +166,13 @@ void SpinBox::_input_event(const InputEvent& p_event) { drag.mouse_pos=cpos; drag.base_val=CLAMP(drag.base_val + get_step() * diff_y, get_min(), get_max()); - set_val( drag.base_val); + set_value( drag.base_val); } else if (drag.mouse_pos.distance_to(cpos)>2) { Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_CAPTURED); drag.enabled=true; - drag.base_val=get_val(); + drag.base_val=get_value(); drag.mouse_pos=cpos; drag.capture_pos=cpos; @@ -240,19 +251,19 @@ bool SpinBox::is_editable() const { void SpinBox::_bind_methods() { - //ObjectTypeDB::bind_method(_MD("_value_changed"),&SpinBox::_value_changed); - ObjectTypeDB::bind_method(_MD("_input_event"),&SpinBox::_input_event); - ObjectTypeDB::bind_method(_MD("_text_entered"),&SpinBox::_text_entered); - ObjectTypeDB::bind_method(_MD("set_suffix","suffix"),&SpinBox::set_suffix); - ObjectTypeDB::bind_method(_MD("get_suffix"),&SpinBox::get_suffix); - ObjectTypeDB::bind_method(_MD("set_prefix","prefix"),&SpinBox::set_prefix); - ObjectTypeDB::bind_method(_MD("get_prefix"),&SpinBox::get_prefix); - ObjectTypeDB::bind_method(_MD("set_editable","editable"),&SpinBox::set_editable); - ObjectTypeDB::bind_method(_MD("is_editable"),&SpinBox::is_editable); - ObjectTypeDB::bind_method(_MD("_line_edit_focus_exit"),&SpinBox::_line_edit_focus_exit); - ObjectTypeDB::bind_method(_MD("get_line_edit"),&SpinBox::get_line_edit); - ObjectTypeDB::bind_method(_MD("_line_edit_input"),&SpinBox::_line_edit_input); - ObjectTypeDB::bind_method(_MD("_range_click_timeout"),&SpinBox::_range_click_timeout); + //ClassDB::bind_method(_MD("_value_changed"),&SpinBox::_value_changed); + ClassDB::bind_method(_MD("_input_event"),&SpinBox::_input_event); + ClassDB::bind_method(_MD("_text_entered"),&SpinBox::_text_entered); + ClassDB::bind_method(_MD("set_suffix","suffix"),&SpinBox::set_suffix); + ClassDB::bind_method(_MD("get_suffix"),&SpinBox::get_suffix); + ClassDB::bind_method(_MD("set_prefix","prefix"),&SpinBox::set_prefix); + ClassDB::bind_method(_MD("get_prefix"),&SpinBox::get_prefix); + ClassDB::bind_method(_MD("set_editable","editable"),&SpinBox::set_editable); + ClassDB::bind_method(_MD("is_editable"),&SpinBox::is_editable); + ClassDB::bind_method(_MD("_line_edit_focus_exit"),&SpinBox::_line_edit_focus_exit); + ClassDB::bind_method(_MD("get_line_edit"),&SpinBox::get_line_edit); + ClassDB::bind_method(_MD("_line_edit_input"),&SpinBox::_line_edit_input); + ClassDB::bind_method(_MD("_range_click_timeout"),&SpinBox::_range_click_timeout); ADD_PROPERTY(PropertyInfo(Variant::BOOL,"editable"),_SCS("set_editable"),_SCS("is_editable")); |
