diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index d816a4dbc..6e9ccd7ec 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -696,6 +696,7 @@ add_library(app-lib util/range_utils.cpp util/readable_time.cpp util/resize_image.cpp + util/tile_flags_utils.cpp util/tileset_utils.cpp util/wrap_point.cpp xml_document.cpp diff --git a/src/app/ui/editor/editor.cpp b/src/app/ui/editor/editor.cpp index 94279ab86..e1241021c 100644 --- a/src/app/ui/editor/editor.cpp +++ b/src/app/ui/editor/editor.cpp @@ -54,6 +54,7 @@ #include "app/ui/toolbar.h" #include "app/ui_context.h" #include "app/util/layer_utils.h" +#include "app/util/tile_flags_utils.h" #include "base/chrono.h" #include "base/convert_to.h" #include "doc/doc.h" @@ -1196,7 +1197,8 @@ void Editor::drawTileNumbers(ui::Graphics* g, const Cel* cel) const doc::Grid grid = getSite().grid(); const gfx::Size tileSize = editorToScreen(grid.tileToCanvas(gfx::Rect(0, 0, 1, 1))).size(); - if (tileSize.h > g->font()->height()) { + const int th = g->font()->height(); + if (tileSize.h > th) { const gfx::Point offset = gfx::Point(tileSize.w/2, tileSize.h/2 - g->font()->height()/2) @@ -1211,13 +1213,28 @@ void Editor::drawTileNumbers(ui::Graphics* g, const Cel* cel) for (int x=0; xwidth(); ++x) { doc::tile_t t = image->getPixel(x, y); if (t != doc::notile) { + const doc::tile_index ti = doc::tile_geti(t); + const doc::tile_index tf = doc::tile_getf(t); + gfx::Point pt = editorToScreen(grid.tileToCanvas(gfx::Point(x, y))); pt -= bounds().origin(); pt += offset; - text = fmt::format("{}", int(t & doc::tile_i_mask) + ti_offset); - pt.x -= g->measureUIText(text).w/2; - g->drawText(text, fgColor, color, pt); + text = fmt::format("{}", ti + ti_offset); + + gfx::Point pt2(pt); + pt2.x -= g->measureUIText(text).w/2; + g->drawText(text, fgColor, color, pt2); + + if (tf && tileSize.h > 2*th) { + text.clear(); + build_tile_flags_string(tf, text); + + const gfx::Size tsize = g->measureUIText(text); + pt.x -= tsize.w/2; + pt.y += tsize.h; + g->drawText(text, fgColor, color, pt); + } } } } diff --git a/src/app/ui/editor/standby_state.cpp b/src/app/ui/editor/standby_state.cpp index 709c66067..f29361b65 100644 --- a/src/app/ui/editor/standby_state.cpp +++ b/src/app/ui/editor/standby_state.cpp @@ -53,6 +53,7 @@ #include "app/util/layer_utils.h" #include "app/util/new_image_from_mask.h" #include "app/util/readable_time.h" +#include "app/util/tile_flags_utils.h" #include "base/pi.h" #include "base/vector2d.h" #include "doc/grid.h" @@ -611,9 +612,7 @@ bool StandbyState::onUpdateStatusBar(Editor* editor) doc::tile_index ti = doc::tile_geti(t); doc::tile_flags tf = doc::tile_getf(t); std::string str; - if (tf & doc::tile_f_xflip) str += "x"; - if (tf & doc::tile_f_yflip) str += "y"; - if (tf & doc::tile_f_dflip) str += "d"; + build_tile_flags_string(tf, str); buf += fmt::format(" [{}{}]", ti, str); } } diff --git a/src/app/ui/status_bar.cpp b/src/app/ui/status_bar.cpp index fa9294c5e..0843b7045 100644 --- a/src/app/ui/status_bar.cpp +++ b/src/app/ui/status_bar.cpp @@ -35,6 +35,7 @@ #include "app/ui/zoom_entry.h" #include "app/ui_context.h" #include "app/util/range_utils.h" +#include "app/util/tile_flags_utils.h" #include "base/fs.h" #include "base/string.h" #include "doc/image.h" @@ -525,9 +526,7 @@ public: str += fmt::format("{}", ti + baseIndex - 1); if (tf) { str += " Flip "; - if (tf & doc::tile_f_xflip) str += "X"; - if (tf & doc::tile_f_yflip) str += "Y"; - if (tf & doc::tile_f_dflip) str += "D"; + build_tile_flags_string(tf, str); } } m_indicators->addTextIndicator(str.c_str()); diff --git a/src/app/util/tile_flags_utils.cpp b/src/app/util/tile_flags_utils.cpp new file mode 100644 index 000000000..304cc3816 --- /dev/null +++ b/src/app/util/tile_flags_utils.cpp @@ -0,0 +1,23 @@ +// Aseprite +// Copyright (C) 2023 Igara Studio S.A. +// +// This program is distributed under the terms of +// the End-User License Agreement for Aseprite. + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "app/util/tile_flags_utils.h" + +namespace app { + +void build_tile_flags_string(const doc::tile_flags tf, + std::string& result) +{ + if (tf & doc::tile_f_xflip) result += "X"; + if (tf & doc::tile_f_yflip) result += "Y"; + if (tf & doc::tile_f_dflip) result += "D"; +} + +} // namespace app diff --git a/src/app/util/tile_flags_utils.h b/src/app/util/tile_flags_utils.h new file mode 100644 index 000000000..7ec511b9a --- /dev/null +++ b/src/app/util/tile_flags_utils.h @@ -0,0 +1,22 @@ +// Aseprite +// Copyright (C) 2023 Igara Studio S.A. +// +// This program is distributed under the terms of +// the End-User License Agreement for Aseprite. + +#ifndef APP_TILE_FLAGS_UTILS_H_INCLUDED +#define APP_TILE_FLAGS_UTILS_H_INCLUDED +#pragma once + +#include "doc/tile.h" + +#include + +namespace app { + + void build_tile_flags_string(const doc::tile_flags tf, + std::string& result); + +} // namespace app + +#endif