Skip to content

Commit

Permalink
Fix click-selecting Sprites with repeated texture
Browse files Browse the repository at this point in the history
  • Loading branch information
kleonc committed Jun 22, 2023
1 parent 28a60b3 commit edba45e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions scene/2d/sprite_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,9 @@ bool Sprite2D::is_pixel_opaque(const Point2 &p_point) const {
q.y = 1.0f - q.y;
}
q = q * src_rect.size + src_rect.position;
// TODO: This need to be obtained from CanvasItem new repeat mode (but it needs to guess it from hierarchy, need to add a function for that).
bool is_repeat = false;
bool is_mirrored_repeat = false;
TextureRepeat repeat_mode = get_texture_repeat_in_tree();
bool is_repeat = repeat_mode == TEXTURE_REPEAT_ENABLED || repeat_mode == TEXTURE_REPEAT_MIRROR;
bool is_mirrored_repeat = repeat_mode == TEXTURE_REPEAT_MIRROR;
if (is_repeat) {
int mirror_x = 0;
int mirror_y = 0;
Expand Down
8 changes: 4 additions & 4 deletions scene/main/canvas_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1343,7 +1343,7 @@ bool CanvasItem::get_visibility_layer_bit(uint32_t p_visibility_layer) const {
return (visibility_layer & (1 << p_visibility_layer));
}

void CanvasItem::_refresh_texture_filter_cache() {
void CanvasItem::_refresh_texture_filter_cache() const {
if (!is_inside_tree()) {
return;
}
Expand Down Expand Up @@ -1394,7 +1394,7 @@ CanvasItem::TextureFilter CanvasItem::get_texture_filter() const {
return texture_filter;
}

void CanvasItem::_refresh_texture_repeat_cache() {
void CanvasItem::_refresh_texture_repeat_cache() const {
if (!is_inside_tree()) {
return;
}
Expand Down Expand Up @@ -1465,13 +1465,13 @@ CanvasItem::TextureRepeat CanvasItem::get_texture_repeat() const {
return texture_repeat;
}

CanvasItem::TextureFilter CanvasItem::get_texture_filter_in_tree() {
CanvasItem::TextureFilter CanvasItem::get_texture_filter_in_tree() const {
ERR_READ_THREAD_GUARD_V(TEXTURE_FILTER_NEAREST);
_refresh_texture_filter_cache();
return (TextureFilter)texture_filter_cache;
}

CanvasItem::TextureRepeat CanvasItem::get_texture_repeat_in_tree() {
CanvasItem::TextureRepeat CanvasItem::get_texture_repeat_in_tree() const {
ERR_READ_THREAD_GUARD_V(TEXTURE_REPEAT_DISABLED);
_refresh_texture_repeat_cache();
return (TextureRepeat)texture_repeat_cache;
Expand Down
12 changes: 6 additions & 6 deletions scene/main/canvas_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ class CanvasItem : public Node {

ClipChildrenMode clip_children_mode = CLIP_CHILDREN_DISABLED;

RS::CanvasItemTextureFilter texture_filter_cache = RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR;
RS::CanvasItemTextureRepeat texture_repeat_cache = RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED;
mutable RS::CanvasItemTextureFilter texture_filter_cache = RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR;
mutable RS::CanvasItemTextureRepeat texture_repeat_cache = RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED;
TextureFilter texture_filter = TEXTURE_FILTER_PARENT_NODE;
TextureRepeat texture_repeat = TEXTURE_REPEAT_PARENT_NODE;

Expand Down Expand Up @@ -143,9 +143,9 @@ class CanvasItem : public Node {

static CanvasItem *current_item_drawn;
friend class Viewport;
void _refresh_texture_repeat_cache();
void _refresh_texture_repeat_cache() const;
void _update_texture_repeat_changed(bool p_propagate);
void _refresh_texture_filter_cache();
void _refresh_texture_filter_cache() const;
void _update_texture_filter_changed(bool p_propagate);

void _notify_transform_deferred();
Expand Down Expand Up @@ -360,8 +360,8 @@ class CanvasItem : public Node {
virtual void set_texture_repeat(TextureRepeat p_texture_repeat);
TextureRepeat get_texture_repeat() const;

TextureFilter get_texture_filter_in_tree();
TextureRepeat get_texture_repeat_in_tree();
TextureFilter get_texture_filter_in_tree() const;
TextureRepeat get_texture_repeat_in_tree() const;

// Used by control nodes to retrieve the parent's anchorable area
virtual Rect2 get_anchorable_rect() const { return Rect2(0, 0, 0, 0); };
Expand Down

0 comments on commit edba45e

Please sign in to comment.