diff options
author | Andreas Loew <andreas@codeandweb.com> | 2018-03-02 18:19:24 +0100 |
---|---|---|
committer | Andreas Loew <andreas@codeandweb.com> | 2018-03-02 19:17:47 +0100 |
commit | a01ba4523b3132e6307d222fc20c704eabbb87fb (patch) | |
tree | a6ef18de24d7049475e5f55bc0ac022b441a5a13 | |
parent | 2067932e2afac7fc8106f037bafaee7c89d01a99 (diff) |
Fix selection of Sprites using AtlasTexture in the editor.
Fixes #16261.
-rw-r--r-- | scene/2d/sprite.cpp | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/scene/2d/sprite.cpp b/scene/2d/sprite.cpp index 796969be1e..c7b17dcb35 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(); |