Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into replace_tool
Browse files Browse the repository at this point in the history
  • Loading branch information
Narre committed Jul 15, 2023
2 parents e798c88 + 9cfad1a commit def08c7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 25 deletions.
37 changes: 12 additions & 25 deletions src/editor/overlay_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,7 @@ void
EditorOverlayWidget::input_tile(const Vector& pos, uint32_t tile, bool save_state)
{
auto tilemap = m_editor.get_selected_tilemap();
if (!tilemap)
return;

if ( pos.x < 0 ||
pos.y < 0 ||
pos.x >= static_cast<float>(tilemap->get_width()) ||
pos.y >= static_cast<float>(tilemap->get_height()))
if (!tilemap || !is_position_inside_tilemap(tilemap, pos))
{
return;
}
Expand All @@ -178,13 +172,7 @@ void
EditorOverlayWidget::autotile(const Vector& pos, uint32_t tile, bool save_state)
{
auto tilemap = m_editor.get_selected_tilemap();
if (!tilemap)
return;

if ( pos.x < 0 ||
pos.y < 0 ||
pos.x >= static_cast<float>(tilemap->get_width()) ||
pos.y >= static_cast<float>(tilemap->get_height()))
if (!tilemap || !is_position_inside_tilemap(tilemap, pos))
{
return;
}
Expand Down Expand Up @@ -217,13 +205,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<float>(tilemap->get_width()) ||
pos.y >= static_cast<float>(tilemap->get_height()))
if (!tilemap || !is_position_inside_tilemap(tilemap, pos))
{
return;
}
Expand Down Expand Up @@ -503,10 +485,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<float>(tilemap->get_width()) ||
pos.y >= static_cast<float>(tilemap->get_height()))
if (!is_position_inside_tilemap(tilemap, pos))
{
pos_stack.pop_back();
continue;
Expand Down Expand Up @@ -1656,4 +1635,12 @@ EditorOverlayWidget::align_to_tilemap(const Vector& sp, int tile_size) const
return glm::trunc(sp_) * static_cast<float>(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<float>(tilemap->get_width()) &&
pos.y <= static_cast<float>(tilemap->get_height());
}

/* EOF */
1 change: 1 addition & 0 deletions src/editor/overlay_widget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,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;
Expand Down

0 comments on commit def08c7

Please sign in to comment.