Просмотр исходного кода

Add two new default actions ui_end, ui_home

Used by Slider and Scrollbar
Fabio Alessandrelli 7 лет назад
Родитель
Сommit
920d2bfdfa
4 измененных файлов с 34 добавлено и 33 удалено
  1. 10 0
      core/input_map.cpp
  2. 14 0
      core/project_settings.cpp
  3. 4 13
      scene/gui/scroll_bar.cpp
  4. 6 20
      scene/gui/slider.cpp

+ 10 - 0
core/input_map.cpp

@@ -282,6 +282,16 @@ void InputMap::load_default() {
 	key->set_scancode(KEY_PAGEDOWN);
 	action_add_event("ui_page_down", key);
 
+	add_action("ui_home");
+	key.instance();
+	key->set_scancode(KEY_HOME);
+	action_add_event("ui_home", key);
+
+	add_action("ui_end");
+	key.instance();
+	key->set_scancode(KEY_END);
+	action_add_event("ui_end", key);
+
 	//set("display/window/handheld/orientation", "landscape");
 }
 

+ 14 - 0
core/project_settings.cpp

@@ -1027,6 +1027,20 @@ ProjectSettings::ProjectSettings() {
 	GLOBAL_DEF("input/ui_page_down", va);
 	input_presets.push_back("input/ui_page_down");
 
+	va = Array();
+	key.instance();
+	key->set_scancode(KEY_HOME);
+	va.push_back(key);
+	GLOBAL_DEF("input/ui_home", va);
+	input_presets.push_back("input/ui_home");
+
+	va = Array();
+	key.instance();
+	key->set_scancode(KEY_END);
+	va.push_back(key);
+	GLOBAL_DEF("input/ui_end", va);
+	input_presets.push_back("input/ui_end");
+
 	//GLOBAL_DEF("display/window/handheld/orientation", "landscape");
 
 	custom_prop_info["display/window/handheld/orientation"] = PropertyInfo(Variant::STRING, "display/window/handheld/orientation", PROPERTY_HINT_ENUM, "landscape,portrait,reverse_landscape,reverse_portrait,sensor_landscape,sensor_portrait,sensor");

+ 4 - 13
scene/gui/scroll_bar.cpp

@@ -199,8 +199,6 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) {
 		}
 	}
 
-	Ref<InputEventKey> k = p_event;
-
 	if (p_event->is_pressed()) {
 
 		if (p_event->is_action("ui_left")) {
@@ -228,20 +226,13 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) {
 				return;
 			set_value(get_value() + (custom_step >= 0 ? custom_step : get_step()));
 
-		} else if (k.is_valid()) {
-
-			switch (k->get_scancode()) {
-				case KEY_HOME: {
+		} else if (p_event->is_action("ui_home")) {
 
-					set_value(get_min());
+			set_value(get_min());
 
-				} break;
-				case KEY_END: {
+		} else if (p_event->is_action("ui_end")) {
 
-					set_value(get_max());
-
-				} break;
-			}
+			set_value(get_max());
 		}
 	}
 }

+ 6 - 20
scene/gui/slider.cpp

@@ -118,28 +118,14 @@ void Slider::_gui_input(Ref<InputEvent> p_event) {
 				return;
 			set_value(get_value() - (custom_step >= 0 ? custom_step : get_step()));
 			accept_event();
+		} else if (p_event->is_action("ui_home") && p_event->is_pressed()) {
 
-		} else {
-
-			Ref<InputEventKey> k = p_event;
-
-			if (!k.is_valid() || !k->is_pressed())
-				return;
-
-			switch (k->get_scancode()) {
-
-				case KEY_HOME: {
-
-					set_value(get_min());
-					accept_event();
-				} break;
-				case KEY_END: {
-
-					set_value(get_max());
-					accept_event();
+			set_value(get_min());
+			accept_event();
+		} else if (p_event->is_action("ui_end") && p_event->is_pressed()) {
 
-				} break;
-			}
+			set_value(get_max());
+			accept_event();
 		}
 	}
 }