فهرست منبع

Merge pull request #10941 from Noshyaar/pr-cursor

2DEditor: enhance viewport cursor shape
Rémi Verschelde 8 سال پیش
والد
کامیت
729cfa39e2
2فایلهای تغییر یافته به همراه47 افزوده شده و 0 حذف شده
  1. 46 0
      editor/plugins/canvas_item_editor_plugin.cpp
  2. 1 0
      editor/plugins/canvas_item_editor_plugin.h

+ 46 - 0
editor/plugins/canvas_item_editor_plugin.cpp

@@ -1019,6 +1019,51 @@ void CanvasItemEditor::_list_select(const Ref<InputEventMouseButton> &b) {
 	}
 }
 
+void CanvasItemEditor::_update_cursor() {
+
+	CursorShape c = CURSOR_ARROW;
+	switch (drag) {
+		case DRAG_NONE:
+			if (Input::get_singleton()->is_mouse_button_pressed(BUTTON_MIDDLE) || Input::get_singleton()->is_key_pressed(KEY_SPACE)) {
+				c = CURSOR_DRAG;
+			} else {
+				switch (tool) {
+					case TOOL_MOVE:
+						c = CURSOR_MOVE;
+						break;
+					case TOOL_EDIT_PIVOT:
+						c = CURSOR_CROSS;
+						break;
+					case TOOL_PAN:
+						c = CURSOR_DRAG;
+						break;
+				}
+			}
+			break;
+		case DRAG_LEFT:
+		case DRAG_RIGHT:
+			c = CURSOR_HSIZE;
+			break;
+		case DRAG_TOP:
+		case DRAG_BOTTOM:
+			c = CURSOR_VSIZE;
+			break;
+		case DRAG_TOP_LEFT:
+		case DRAG_BOTTOM_RIGHT:
+			c = CURSOR_FDIAGSIZE;
+			break;
+		case DRAG_TOP_RIGHT:
+		case DRAG_BOTTOM_LEFT:
+			c = CURSOR_BDIAGSIZE;
+			break;
+		case DRAG_ALL:
+		case DRAG_NODE_2D:
+			c = CURSOR_MOVE;
+			break;
+	}
+	viewport->set_default_cursor_shape(c);
+}
+
 void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) {
 
 	{
@@ -1457,6 +1502,7 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) {
 	Ref<InputEventMouseMotion> m = p_event;
 	if (m.is_valid()) {
 		// Mouse motion event
+		_update_cursor();
 
 		if (!viewport->has_focus() && (!get_focus_owner() || !get_focus_owner()->is_text_field()))
 			viewport->call_deferred("grab_focus");

+ 1 - 0
editor/plugins/canvas_item_editor_plugin.h

@@ -324,6 +324,7 @@ class CanvasItemEditor : public VBoxContainer {
 	bool updating_scroll;
 	void _update_scroll(float);
 	void _update_scrollbars();
+	void _update_cursor();
 	void incbeg(float &beg, float &end, float inc, float minsize, bool p_symmetric);
 	void incend(float &beg, float &end, float inc, float minsize, bool p_symmetric);