From 7b4560b1dcde29721af3189a6d584a12873172f4 Mon Sep 17 00:00:00 2001 From: Kasper Arnklit Frandsen Date: Fri, 21 Mar 2025 12:58:04 +0000 Subject: [PATCH] Add correct cursors when scaling bezier keys with box scaling --- editor/animation_bezier_editor.cpp | 42 ++++++++++++++++++++++++++++++ editor/animation_bezier_editor.h | 1 + 2 files changed, 43 insertions(+) diff --git a/editor/animation_bezier_editor.cpp b/editor/animation_bezier_editor.cpp index 16e15cbf29..5337b53154 100644 --- a/editor/animation_bezier_editor.cpp +++ b/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)); diff --git a/editor/animation_bezier_editor.h b/editor/animation_bezier_editor.h index 46ac16eb91..5297d617e9 100644 --- a/editor/animation_bezier_editor.h +++ b/editor/animation_bezier_editor.h @@ -214,6 +214,7 @@ public: void set_animation_and_track(const Ref &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);