diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-02-19 13:45:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-19 13:45:23 +0100 |
commit | b84f65f13c21cd5319b6cf96c80364d6e87e24cb (patch) | |
tree | e8017b05df1197853d1e836353733f0e565eb4cc /scene/2d/touch_screen_button.cpp | |
parent | 13303dd56d11248681a204b92849558a20a7846e (diff) | |
parent | f814f58942d7578897830dd727fe684ef6b42396 (diff) |
Merge pull request #44737 from KoBeWi/touch_shape_screen_centered_button
Fix shape_centered property in TouchScreenButton
Diffstat (limited to 'scene/2d/touch_screen_button.cpp')
-rw-r--r-- | scene/2d/touch_screen_button.cpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/scene/2d/touch_screen_button.cpp b/scene/2d/touch_screen_button.cpp index fccf126dad..9d6868a1b2 100644 --- a/scene/2d/touch_screen_button.cpp +++ b/scene/2d/touch_screen_button.cpp @@ -129,8 +129,11 @@ void TouchScreenButton::_notification(int p_what) { if (shape.is_valid()) { Color draw_col = get_tree()->get_debug_collisions_color(); - Vector2 size = texture.is_null() ? shape->get_rect().size : texture->get_size(); - Vector2 pos = shape_centered ? size * 0.5f : Vector2(); + Vector2 pos; + if (shape_centered && texture.is_valid()) { + pos = texture->get_size() * 0.5; + } + draw_set_transform_matrix(get_canvas_transform().translated(pos)); shape->draw(get_canvas_item(), draw_col); } @@ -251,9 +254,12 @@ bool TouchScreenButton::_is_point_inside(const Point2 &p_point) { if (shape.is_valid()) { check_rect = false; - Vector2 size = texture.is_null() ? shape->get_rect().size : texture->get_size(); - Transform2D xform = shape_centered ? Transform2D().translated(size * 0.5f) : Transform2D(); - touched = shape->collide(xform, unit_rect, Transform2D(0, coord + Vector2(0.5, 0.5))); + Vector2 pos; + if (shape_centered && texture.is_valid()) { + pos = texture->get_size() * 0.5; + } + + touched = shape->collide(Transform2D().translated(pos), unit_rect, Transform2D(0, coord + Vector2(0.5, 0.5))); } if (bitmask.is_valid()) { |