From 5464c4a3c2a614b65b547a17b70b003f741de369 Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 9 Dec 2024 15:26:16 -0300 Subject: [PATCH] Minor fixes for the new "tile index" in status bar (#2082) * Only show when we are inside the grid bounds or tilemap layer bounds (don't show it for negative tile positions) * Count final "partial column" for the tile index --- src/app/ui/editor/standby_state.cpp | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/app/ui/editor/standby_state.cpp b/src/app/ui/editor/standby_state.cpp index 1ae540ded..3dd5a310c 100644 --- a/src/app/ui/editor/standby_state.cpp +++ b/src/app/ui/editor/standby_state.cpp @@ -597,6 +597,12 @@ bool StandbyState::onUpdateStatusBar(Editor* editor) gfx::Point pt = grid.canvasToTile(gfx::Point(spritePos)); buf += fmt::format(" :grid: {} {}", pt.x, pt.y); + // Number of columns of the current grid/tilemap to show a + // "tile index", i.e. a linear index that might be used in a + // 1D array to represent the current grid tile/cell. If it's 0 + // we don't show the index. + int tileIndexColumns = 0; + // Show the tile index of this specific tile if (site.layer() && site.layer()->isTilemap() && @@ -608,20 +614,20 @@ bool StandbyState::onUpdateStatusBar(Editor* editor) std::string str; build_tile_flags_string(tf, str); buf += fmt::format(" [{}{}]", ti, str); + + // Show tile index for a tilemaps (using the tilemap size) + tileIndexColumns = site.image()->width(); } } - // Show the grid cell index - if (sprite->bounds().contains(gfx::Point(spritePos))) { - int columns = int(std::floor( - sprite->bounds().w/grid.tileSize().w)); - int rows = int(std::floor( - sprite->bounds().h/grid.tileSize().h)); - int column = (columns ? pt.x%columns: 0); - int row = (rows ? pt.y%rows: 0); - if (row < 0) row = row + rows; - if (column < 0) column = column + columns; - buf += fmt::format(" :search: {}", column+row*columns); + // Show the tile index for a regular layer/grid + else if (sprite->bounds().contains(gfx::Point(spritePos))) { + tileIndexColumns = + int(std::ceil(double(sprite->bounds().w - grid.origin().x) + / grid.tileSize().w)); } + + if (tileIndexColumns > 0 && pt.x >= 0 && pt.y >= 0) + buf += fmt::format(" :search: {}", pt.x+pt.y*tileIndexColumns); } }