diff --git a/src/editor/overlay_widget.cpp b/src/editor/overlay_widget.cpp index d41ffc01cc8..9e26db89a2b 100644 --- a/src/editor/overlay_widget.cpp +++ b/src/editor/overlay_widget.cpp @@ -153,14 +153,7 @@ void EditorOverlayWidget::input_tile(const Vector& pos, uint32_t tile) { auto tilemap = m_editor.get_selected_tilemap(); - if (!tilemap) { - return; - } - - if ( pos.x < 0 || - pos.y < 0 || - pos.x >= static_cast(tilemap->get_width()) || - pos.y >= static_cast(tilemap->get_height())) { + if (!tilemap || !is_position_inside_tilemap(tilemap, pos)) { return; } @@ -172,14 +165,7 @@ void EditorOverlayWidget::autotile(const Vector& pos, uint32_t tile) { auto tilemap = m_editor.get_selected_tilemap(); - if (!tilemap) { - return; - } - - if ( pos.x < 0 || - pos.y < 0 || - pos.x >= static_cast(tilemap->get_width()) || - pos.y >= static_cast(tilemap->get_height())) { + if (!tilemap || !is_position_inside_tilemap(tilemap, pos)) { return; } @@ -211,14 +197,7 @@ EditorOverlayWidget::autotile_corner(const Vector& pos, uint32_t tile, TileMap::AutotileCornerOperation op) { auto tilemap = m_editor.get_selected_tilemap(); - if (!tilemap) { - return; - } - - if ( pos.x < 0 || - pos.y < 0 || - pos.x >= static_cast(tilemap->get_width()) || - pos.y >= static_cast(tilemap->get_height())) { + if (!tilemap || !is_position_inside_tilemap(tilemap, pos)) { return; } @@ -461,10 +440,7 @@ EditorOverlayWidget::fill() Vector tpos = pos - m_hovered_tile; // Tests for being inside tilemap: - if ( pos.x < 0 || - pos.y < 0 || - pos.x >= static_cast(tilemap->get_width()) || - pos.y >= static_cast(tilemap->get_height())) + if (!is_position_inside_tilemap(tilemap, pos)) { pos_stack.pop_back(); continue; @@ -1522,4 +1498,12 @@ EditorOverlayWidget::align_to_tilemap(const Vector& sp, int tile_size) const return glm::trunc(sp_) * static_cast(tile_size); } +bool +EditorOverlayWidget::is_position_inside_tilemap(const TileMap* tilemap, const Vector& pos) const +{ + return pos.x > 0 && pos.y > 0 && + pos.x <= static_cast(tilemap->get_width()) && + pos.y <= static_cast(tilemap->get_height()); +} + /* EOF */ diff --git a/src/editor/overlay_widget.hpp b/src/editor/overlay_widget.hpp index f657b8dda69..63e0b2801ca 100644 --- a/src/editor/overlay_widget.hpp +++ b/src/editor/overlay_widget.hpp @@ -111,6 +111,7 @@ class EditorOverlayWidget final : public Widget Vector sp_to_tp(const Vector& sp, int tile_size = 32) const; Vector tile_screen_pos(const Vector& tp, int tile_size = 32) const; Vector align_to_tilemap(const Vector& sp, int tile_size = 32) const; + bool is_position_inside_tilemap(const TileMap* tilemap, const Vector& pos) const; // in sector position Rectf drag_rect() const;