diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2022-10-31 11:00:19 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2022-10-31 11:00:19 +0100 |
commit | 869c2bd6dee72bdb4d205bcc3d958255e7fc1a07 (patch) | |
tree | 273d4bb66b22f794db82b89cd48319b8a6af5caa | |
parent | 51cd380167a04afd0cb94dfa176cd3f9765eddb9 (diff) | |
parent | d1359579874b747ab34bdbdb23411b5dc733a609 (diff) | |
download | redot-engine-869c2bd6dee72bdb4d205bcc3d958255e7fc1a07.tar.gz |
Merge pull request #68064 from kleonc/sprite-frames-editor-fix-frame-index-calculation
`SpriteFramesEditor` Fix calculating frame index from mouse position
-rw-r--r-- | editor/plugins/sprite_frames_editor_plugin.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/editor/plugins/sprite_frames_editor_plugin.cpp b/editor/plugins/sprite_frames_editor_plugin.cpp index 5dac66d3e1..d3ab5b6f77 100644 --- a/editor/plugins/sprite_frames_editor_plugin.cpp +++ b/editor/plugins/sprite_frames_editor_plugin.cpp @@ -67,14 +67,18 @@ int SpriteFramesEditor::_sheet_preview_position_to_frame_index(const Point2 &p_p const Size2i block_size = frame_size + separation; const Point2i position = p_position / sheet_zoom - offset; - if (position.x % block_size.x > frame_size.x || position.y % block_size.y > frame_size.y) { + if (position.x < 0 || position.y < 0) { + return -1; // Out of bounds. + } + + if (position.x % block_size.x >= frame_size.x || position.y % block_size.y >= frame_size.y) { return -1; // Gap between frames. } const Point2i frame = position / block_size; const Size2i frame_count = _get_frame_count(); - if (frame.x < 0 || frame.y < 0 || frame.x >= frame_count.x || frame.y >= frame_count.y) { - return -1; // Out of bound. + if (frame.x >= frame_count.x || frame.y >= frame_count.y) { + return -1; // Out of bounds. } return frame_count.x * frame.y + frame.x; |