Skip to content

Commit 7b4560b

Browse files
committed
Add correct cursors when scaling bezier keys with box scaling
1 parent aef0065 commit 7b4560b

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

editor/animation_bezier_editor.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,48 @@ Size2 AnimationBezierTrackEdit::get_minimum_size() const {
743743
return Vector2(1, 1);
744744
}
745745

746+
Control::CursorShape AnimationBezierTrackEdit::get_cursor_shape(const Point2 &p_pos) const {
747+
// Box selecting or moving a handle
748+
if (box_selecting || Math::abs(moving_handle) == 1) {
749+
return get_default_cursor_shape();
750+
}
751+
// Hovering a handle
752+
if (!read_only) {
753+
for (const EditPoint &edit_point : edit_points) {
754+
if (edit_point.in_rect.has_point(p_pos) || edit_point.out_rect.has_point(p_pos)) {
755+
return get_default_cursor_shape();
756+
}
757+
}
758+
}
759+
// Currently box scaling
760+
if (scaling_selection) {
761+
if (scaling_selection_handles == Vector2i(1, 1) || scaling_selection_handles == Vector2i(-1, -1)) {
762+
return CURSOR_FDIAGSIZE;
763+
} else if (scaling_selection_handles == Vector2i(1, -1) || scaling_selection_handles == Vector2i(-1, 1)) {
764+
return CURSOR_BDIAGSIZE;
765+
} else if (abs(scaling_selection_handles.x) == 1) {
766+
return CURSOR_HSIZE;
767+
} else if (abs(scaling_selection_handles.y) == 1) {
768+
return CURSOR_VSIZE;
769+
}
770+
}
771+
// Hovering the scaling box
772+
const Vector2i rel_pos = p_pos - selection_rect.position;
773+
if (selection_handles_rect.has_point(p_pos)) {
774+
if ((rel_pos.x < 0 && rel_pos.y < 0) || (rel_pos.x > selection_rect.size.width && rel_pos.y > selection_rect.size.height)) {
775+
return CURSOR_FDIAGSIZE;
776+
} else if ((rel_pos.x < 0 && rel_pos.y > selection_rect.size.height) || (rel_pos.x > selection_rect.size.width && rel_pos.y < 0)) {
777+
return CURSOR_BDIAGSIZE;
778+
} else if (rel_pos.x < 0 || rel_pos.x > selection_rect.size.width) {
779+
return CURSOR_HSIZE;
780+
} else if (rel_pos.y < 0 || rel_pos.y > selection_rect.size.height) {
781+
return CURSOR_VSIZE;
782+
}
783+
return CURSOR_MOVE;
784+
}
785+
return get_default_cursor_shape();
786+
}
787+
746788
void AnimationBezierTrackEdit::set_timeline(AnimationTimelineEdit *p_timeline) {
747789
timeline = p_timeline;
748790
timeline->connect("zoom_changed", callable_mp(this, &AnimationBezierTrackEdit::_zoom_changed));

editor/animation_bezier_editor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ class AnimationBezierTrackEdit : public Control {
214214

215215
void set_animation_and_track(const Ref<Animation> &p_animation, int p_track, bool p_read_only);
216216
virtual Size2 get_minimum_size() const override;
217+
virtual CursorShape get_cursor_shape(const Point2 &p_pos) const override;
217218

218219
void set_timeline(AnimationTimelineEdit *p_timeline);
219220
void set_editor(AnimationTrackEditor *p_editor);

0 commit comments

Comments
 (0)