summaryrefslogtreecommitdiff
path: root/scene/2d/sprite.cpp
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2018-03-08 08:37:22 +0100
committerGitHub <noreply@github.com>2018-03-08 08:37:22 +0100
commit0b600fde3fc3603be610b201257a5d03e0987fe4 (patch)
tree6eb9202a5b7fe49641ba588c10166f48a9746686 /scene/2d/sprite.cpp
parent938469157fb6d513bab8b4b9e715761bb8376c1b (diff)
parenta01ba4523b3132e6307d222fc20c704eabbb87fb (diff)
Merge pull request #17189 from CodeAndWeb/master
Fixes Selection of Sprites using AtlasTexture
Diffstat (limited to 'scene/2d/sprite.cpp')
-rw-r--r--scene/2d/sprite.cpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/scene/2d/sprite.cpp b/scene/2d/sprite.cpp
index 0dd02a982c..11447c382c 100644
--- a/scene/2d/sprite.cpp
+++ b/scene/2d/sprite.cpp
@@ -287,7 +287,27 @@ bool Sprite::_edit_is_selected_on_click(const Point2 &p_point, double p_toleranc
Vector2 q = ((p_point - dst_rect.position) / dst_rect.size) * src_rect.size + src_rect.position;
- Ref<Image> image = texture->get_data();
+ Ref<Image> image;
+ Ref<AtlasTexture> atlasTexture = texture;
+ if (atlasTexture.is_null()) {
+ image = texture->get_data();
+ } else {
+ ERR_FAIL_COND_V(atlasTexture->get_atlas().is_null(), false);
+
+ image = atlasTexture->get_atlas()->get_data();
+
+ Rect2 region = atlasTexture->get_region();
+ Rect2 margin = atlasTexture->get_margin();
+
+ q -= margin.position;
+
+ if ((q.x > region.size.width) || (q.y > region.size.height)) {
+ return false;
+ }
+
+ q += region.position;
+ }
+
ERR_FAIL_COND_V(image.is_null(), false);
image->lock();