diff options
Diffstat (limited to 'scene/2d/sprite.cpp')
-rw-r--r-- | scene/2d/sprite.cpp | 38 |
1 files changed, 8 insertions, 30 deletions
diff --git a/scene/2d/sprite.cpp b/scene/2d/sprite.cpp index ebe0e81f6e..bb5990fa79 100644 --- a/scene/2d/sprite.cpp +++ b/scene/2d/sprite.cpp @@ -298,6 +298,11 @@ int Sprite::get_hframes() const { bool Sprite::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { + return is_pixel_opaque(p_point); +} + +bool Sprite::is_pixel_opaque(const Point2 &p_point) const { + if (texture.is_null()) return false; @@ -316,32 +321,6 @@ bool Sprite::_edit_is_selected_on_click(const Point2 &p_point, double p_toleranc q.y = 1.0f - q.y; q = q * src_rect.size + src_rect.position; - 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); - if (image->is_compressed()) { - return dst_rect.has_point(p_point); - } - bool is_repeat = texture->get_flags() & Texture::FLAG_REPEAT; bool is_mirrored_repeat = texture->get_flags() & Texture::FLAG_MIRRORED_REPEAT; if (is_repeat) { @@ -363,11 +342,8 @@ bool Sprite::_edit_is_selected_on_click(const Point2 &p_point, double p_toleranc q.x = MIN(q.x, texture->get_size().width - 1); q.y = MIN(q.y, texture->get_size().height - 1); } - image->lock(); - const Color c = image->get_pixel((int)q.x, (int)q.y); - image->unlock(); - return c.a > 0.01; + return texture->is_pixel_opaque((int)q.x, (int)q.y); } Rect2 Sprite::get_rect() const { @@ -437,6 +413,8 @@ void Sprite::_bind_methods() { ClassDB::bind_method(D_METHOD("set_region", "enabled"), &Sprite::set_region); ClassDB::bind_method(D_METHOD("is_region"), &Sprite::is_region); + ClassDB::bind_method(D_METHOD("is_pixel_opaque", "pos"), &Sprite::is_pixel_opaque); + ClassDB::bind_method(D_METHOD("set_region_rect", "rect"), &Sprite::set_region_rect); ClassDB::bind_method(D_METHOD("get_region_rect"), &Sprite::get_region_rect); |