Browse Source

Implement Input.set_default_cursor_shape to change the default shape

Closes #18043
Guilherme Felipe 7 years ago
parent
commit
4f05190fb0
5 changed files with 16 additions and 1 deletions
  1. 1 0
      core/os/input.cpp
  2. 2 0
      core/os/input.h
  3. 9 0
      main/input_default.cpp
  4. 3 0
      main/input_default.h
  5. 1 1
      scene/main/viewport.cpp

+ 1 - 0
core/os/input.cpp

@@ -85,6 +85,7 @@ void Input::_bind_methods() {
 	ClassDB::bind_method(D_METHOD("warp_mouse_position", "to"), &Input::warp_mouse_position);
 	ClassDB::bind_method(D_METHOD("warp_mouse_position", "to"), &Input::warp_mouse_position);
 	ClassDB::bind_method(D_METHOD("action_press", "action"), &Input::action_press);
 	ClassDB::bind_method(D_METHOD("action_press", "action"), &Input::action_press);
 	ClassDB::bind_method(D_METHOD("action_release", "action"), &Input::action_release);
 	ClassDB::bind_method(D_METHOD("action_release", "action"), &Input::action_release);
+	ClassDB::bind_method(D_METHOD("set_default_cursor_shape", "shape"), &Input::set_default_cursor_shape, DEFVAL(CURSOR_ARROW));
 	ClassDB::bind_method(D_METHOD("set_custom_mouse_cursor", "image", "shape", "hotspot"), &Input::set_custom_mouse_cursor, DEFVAL(CURSOR_ARROW), DEFVAL(Vector2()));
 	ClassDB::bind_method(D_METHOD("set_custom_mouse_cursor", "image", "shape", "hotspot"), &Input::set_custom_mouse_cursor, DEFVAL(CURSOR_ARROW), DEFVAL(Vector2()));
 	ClassDB::bind_method(D_METHOD("parse_input_event", "event"), &Input::parse_input_event);
 	ClassDB::bind_method(D_METHOD("parse_input_event", "event"), &Input::parse_input_event);
 
 

+ 2 - 0
core/os/input.h

@@ -119,6 +119,8 @@ public:
 
 
 	virtual bool is_emulating_touchscreen() const = 0;
 	virtual bool is_emulating_touchscreen() const = 0;
 
 
+	virtual CursorShape get_default_cursor_shape() = 0;
+	virtual void set_default_cursor_shape(CursorShape p_shape) = 0;
 	virtual void set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape = CURSOR_ARROW, const Vector2 &p_hotspot = Vector2()) = 0;
 	virtual void set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape = CURSOR_ARROW, const Vector2 &p_hotspot = Vector2()) = 0;
 	virtual void set_mouse_in_window(bool p_in_window) = 0;
 	virtual void set_mouse_in_window(bool p_in_window) = 0;
 
 

+ 9 - 0
main/input_default.cpp

@@ -495,6 +495,15 @@ bool InputDefault::is_emulating_touchscreen() const {
 	return emulate_touch;
 	return emulate_touch;
 }
 }
 
 
+Input::CursorShape InputDefault::get_default_cursor_shape() {
+	return default_shape;
+}
+
+void InputDefault::set_default_cursor_shape(CursorShape p_shape) {
+	default_shape = p_shape;
+	OS::get_singleton()->set_cursor_shape((OS::CursorShape)p_shape);
+}
+
 void InputDefault::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) {
 void InputDefault::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) {
 	if (Engine::get_singleton()->is_editor_hint())
 	if (Engine::get_singleton()->is_editor_hint())
 		return;
 		return;

+ 3 - 0
main/input_default.h

@@ -115,6 +115,7 @@ class InputDefault : public Input {
 	SpeedTrack mouse_speed_track;
 	SpeedTrack mouse_speed_track;
 	Map<int, Joypad> joy_names;
 	Map<int, Joypad> joy_names;
 	int fallback_mapping;
 	int fallback_mapping;
+	CursorShape default_shape = CURSOR_ARROW;
 
 
 public:
 public:
 	enum HatMask {
 	enum HatMask {
@@ -225,6 +226,8 @@ public:
 	void set_emulate_touch(bool p_emulate);
 	void set_emulate_touch(bool p_emulate);
 	virtual bool is_emulating_touchscreen() const;
 	virtual bool is_emulating_touchscreen() const;
 
 
+	virtual CursorShape get_default_cursor_shape();
+	virtual void set_default_cursor_shape(CursorShape p_shape);
 	virtual void set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape = Input::CURSOR_ARROW, const Vector2 &p_hotspot = Vector2());
 	virtual void set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape = Input::CURSOR_ARROW, const Vector2 &p_hotspot = Vector2());
 	virtual void set_mouse_in_window(bool p_in_window);
 	virtual void set_mouse_in_window(bool p_in_window);
 
 

+ 1 - 1
scene/main/viewport.cpp

@@ -1814,7 +1814,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
 		}
 		}
 
 
 		if (!over) {
 		if (!over) {
-			OS::get_singleton()->set_cursor_shape(OS::CURSOR_ARROW);
+			OS::get_singleton()->set_cursor_shape((OS::CursorShape)Input::get_singleton()->get_default_cursor_shape());
 			return;
 			return;
 		}
 		}