Show tile flags in the editor canvas when we use Ctrl key/move tool

Added build_tile_flags_string() utility to create the string used in
to show the tile flags (XYD) on the status bar, the editor canvas,
etc.
This commit is contained in:
David Capello 2023-10-04 20:00:49 -03:00
parent 75b10d40be
commit 34bd6cf336
6 changed files with 71 additions and 10 deletions

View File

@ -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

View File

@ -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; x<image->width(); ++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);
}
}
}
}

View File

@ -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);
}
}

View File

@ -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());

View File

@ -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

View File

@ -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 <string>
namespace app {
void build_tile_flags_string(const doc::tile_flags tf,
std::string& result);
} // namespace app
#endif