Minor change in StatusBar::showColor() to use std::string/fmt::format

master
David Capello 2022-07-15 12:30:15 -03:00
parent 44bb1c4e48
commit 60a4ebf8f6
6 changed files with 31 additions and 34 deletions

View File

@ -139,7 +139,7 @@ bool ColorButton::onProcessMessage(Message* msg)
break;
case kMouseEnterMessage:
StatusBar::instance()->showColor(0, "", m_color);
StatusBar::instance()->showColor(0, m_color);
break;
case kMouseLeaveMessage:

View File

@ -334,7 +334,7 @@ bool ColorSelector::onProcessMessage(ui::Message* msg)
if (color != app::Color::fromMask()) {
base::ScopedValue<bool> switcher(m_lockColor, subColorPicked(), false);
StatusBar::instance()->showColor(0, "", color);
StatusBar::instance()->showColor(0, color);
if (hasCapture())
ColorChange(color, mouseMsg->button());
}

View File

@ -550,37 +550,36 @@ bool StandbyState::onUpdateStatusBar(Editor* editor)
editor->projection(),
color);
char buf[256];
sprintf(buf, " :pos: %d %d",
int(std::floor(spritePos.x)),
int(std::floor(spritePos.y)));
std::string buf =
fmt::format(" :pos: {} {}",
int(std::floor(spritePos.x)),
int(std::floor(spritePos.y)));
StatusBar::instance()->showColor(0, buf, color);
StatusBar::instance()->showColor(0, color, buf);
}
else {
Mask* mask =
(editor->document()->isMaskVisible() ?
editor->document()->mask(): NULL);
char buf[1024];
sprintf(
buf, ":pos: %d %d :size: %d %d",
int(std::floor(spritePos.x)),
int(std::floor(spritePos.y)),
sprite->width(),
sprite->height());
std::string buf = fmt::format(
":pos: {} {} :size: {} {}",
int(std::floor(spritePos.x)),
int(std::floor(spritePos.y)),
sprite->width(),
sprite->height());
if (mask)
sprintf(buf+std::strlen(buf), " :selsize: %d %d",
mask->bounds().w,
mask->bounds().h);
buf += fmt::format(" :selsize: {} {}",
mask->bounds().w,
mask->bounds().h);
if (sprite->totalFrames() > 1) {
sprintf(
buf+std::strlen(buf), " :frame: %d :clock: %s/%s",
buf += fmt::format(
" :frame: {} :clock: {}/{}",
editor->frame()+editor->docPref().timeline.firstFrame(),
human_readable_time(sprite->frameDuration(editor->frame())).c_str(),
human_readable_time(sprite->totalAnimationDuration()).c_str());
human_readable_time(sprite->frameDuration(editor->frame())),
human_readable_time(sprite->totalAnimationDuration()));
}
if (editor->docPref().show.grid()) {
@ -588,7 +587,7 @@ bool StandbyState::onUpdateStatusBar(Editor* editor)
if (!gb.isEmpty()) {
int col = int((std::floor(spritePos.x) - (gb.x % gb.w)) / gb.w);
int row = int((std::floor(spritePos.y) - (gb.y % gb.h)) / gb.h);
sprintf(buf+std::strlen(buf), " :grid: %d %d", col, row);
buf += fmt::format(" :grid: {} {}", col, row);
}
}
@ -601,14 +600,11 @@ bool StandbyState::onUpdateStatusBar(Editor* editor)
int(std::floor(spritePos.x)),
int(std::floor(spritePos.y)))) {
if (++count == 3) {
sprintf(
buf+std::strlen(buf), " :slice: ...");
buf += fmt::format(" :slice: ...");
break;
}
sprintf(
buf+std::strlen(buf), " :slice: %s",
slice->name().c_str());
buf += fmt::format(" :slice: {}", slice->name());
}
}
}

View File

@ -921,8 +921,7 @@ void PaletteView::setStatusBar()
(m_hot.color < currentPalette()->size())) {
int i = std::max(0, m_hot.color);
statusBar->showColor(
0, "", app::Color::fromIndex(i));
statusBar->showColor(0, app::Color::fromIndex(i));
}
else {
statusBar->showDefaultText();

View File

@ -740,14 +740,15 @@ void StatusBar::showTip(int msecs, const std::string& msg)
m_timeout = base::current_tick();
}
void StatusBar::showColor(int msecs, const char* text, const app::Color& color)
void StatusBar::showColor(int msecs, const app::Color& color,
const std::string& text)
{
if ((base::current_tick() > m_timeout) || (msecs > 0)) {
showIndicators();
IndicatorsGeneration gen(m_indicators);
gen.add(color);
if (text)
gen.add(text);
if (!text.empty())
gen.add(text.c_str());
m_timeout = base::current_tick() + msecs;
}

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018-2021 Igara Studio S.A.
// Copyright (C) 2018-2022 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -60,7 +60,8 @@ namespace app {
bool setStatusText(int msecs, const std::string& text);
void showTip(int msecs, const std::string& msg);
void showColor(int msecs, const char* text, const Color& color);
void showColor(int msecs, const Color& color,
const std::string& text = std::string());
void showTool(int msecs, tools::Tool* tool);
void showSnapToGridWarning(bool state);