瀏覽代碼

Add correct cursors when scaling bezier keys with box scaling

Kasper Arnklit Frandsen 5 月之前
父節點
當前提交
7b4560b1dc
共有 2 個文件被更改,包括 43 次插入0 次删除
  1. 42 0
      editor/animation_bezier_editor.cpp
  2. 1 0
      editor/animation_bezier_editor.h

+ 42 - 0
editor/animation_bezier_editor.cpp

@@ -743,6 +743,48 @@ Size2 AnimationBezierTrackEdit::get_minimum_size() const {
 	return Vector2(1, 1);
 }
 
+Control::CursorShape AnimationBezierTrackEdit::get_cursor_shape(const Point2 &p_pos) const {
+	// Box selecting or moving a handle
+	if (box_selecting || Math::abs(moving_handle) == 1) {
+		return get_default_cursor_shape();
+	}
+	// Hovering a handle
+	if (!read_only) {
+		for (const EditPoint &edit_point : edit_points) {
+			if (edit_point.in_rect.has_point(p_pos) || edit_point.out_rect.has_point(p_pos)) {
+				return get_default_cursor_shape();
+			}
+		}
+	}
+	// Currently box scaling
+	if (scaling_selection) {
+		if (scaling_selection_handles == Vector2i(1, 1) || scaling_selection_handles == Vector2i(-1, -1)) {
+			return CURSOR_FDIAGSIZE;
+		} else if (scaling_selection_handles == Vector2i(1, -1) || scaling_selection_handles == Vector2i(-1, 1)) {
+			return CURSOR_BDIAGSIZE;
+		} else if (abs(scaling_selection_handles.x) == 1) {
+			return CURSOR_HSIZE;
+		} else if (abs(scaling_selection_handles.y) == 1) {
+			return CURSOR_VSIZE;
+		}
+	}
+	// Hovering the scaling box
+	const Vector2i rel_pos = p_pos - selection_rect.position;
+	if (selection_handles_rect.has_point(p_pos)) {
+		if ((rel_pos.x < 0 && rel_pos.y < 0) || (rel_pos.x > selection_rect.size.width && rel_pos.y > selection_rect.size.height)) {
+			return CURSOR_FDIAGSIZE;
+		} else if ((rel_pos.x < 0 && rel_pos.y > selection_rect.size.height) || (rel_pos.x > selection_rect.size.width && rel_pos.y < 0)) {
+			return CURSOR_BDIAGSIZE;
+		} else if (rel_pos.x < 0 || rel_pos.x > selection_rect.size.width) {
+			return CURSOR_HSIZE;
+		} else if (rel_pos.y < 0 || rel_pos.y > selection_rect.size.height) {
+			return CURSOR_VSIZE;
+		}
+		return CURSOR_MOVE;
+	}
+	return get_default_cursor_shape();
+}
+
 void AnimationBezierTrackEdit::set_timeline(AnimationTimelineEdit *p_timeline) {
 	timeline = p_timeline;
 	timeline->connect("zoom_changed", callable_mp(this, &AnimationBezierTrackEdit::_zoom_changed));

+ 1 - 0
editor/animation_bezier_editor.h

@@ -214,6 +214,7 @@ public:
 
 	void set_animation_and_track(const Ref<Animation> &p_animation, int p_track, bool p_read_only);
 	virtual Size2 get_minimum_size() const override;
+	virtual CursorShape get_cursor_shape(const Point2 &p_pos) const override;
 
 	void set_timeline(AnimationTimelineEdit *p_timeline);
 	void set_editor(AnimationTrackEditor *p_editor);