mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-29 19:20:09 +00:00
Improved color indicators in status bar (StatusBar::showColor()).
This commit is contained in:
parent
21a979874b
commit
f2265b2034
@ -677,17 +677,15 @@ void color_to_formalstring(int imgtype, color_t color,
|
||||
case COLOR_TYPE_RGB:
|
||||
data = GET_COLOR_DATA_RGB(color);
|
||||
if (imgtype == IMAGE_GRAYSCALE) {
|
||||
uszprintf(buf, size, "%s %d",
|
||||
_("Gray"),
|
||||
uszprintf(buf, size, "Gray %d",
|
||||
_graya_getv(get_color_for_image(imgtype, color)));
|
||||
}
|
||||
else {
|
||||
uszprintf(buf, size, "%s %d %d %d",
|
||||
_("RGB"),
|
||||
uszprintf(buf, size, "RGB %d %d %d",
|
||||
GET_DATA_C1(data),
|
||||
GET_DATA_C2(data),
|
||||
GET_DATA_C3(data));
|
||||
|
||||
|
||||
if (imgtype == IMAGE_INDEXED)
|
||||
uszprintf(buf+ustrlen(buf), size, " %s %d",
|
||||
_("Index"), get_color_for_image(imgtype, color));
|
||||
@ -697,34 +695,32 @@ void color_to_formalstring(int imgtype, color_t color,
|
||||
case COLOR_TYPE_HSV:
|
||||
data = GET_COLOR_DATA_HSV(color);
|
||||
if (imgtype == IMAGE_GRAYSCALE) {
|
||||
uszprintf(buf, size, "%s %d",
|
||||
_("Gray"), GET_DATA_C3(data));
|
||||
uszprintf(buf, size, "Gray %d",
|
||||
GET_DATA_C3(data));
|
||||
}
|
||||
else {
|
||||
uszprintf(buf, size, "%s %d %d %d",
|
||||
_("HSV"),
|
||||
uszprintf(buf, size, "HSV %d %d %d",
|
||||
GET_DATA_C1(data),
|
||||
GET_DATA_C2(data),
|
||||
GET_DATA_C3(data));
|
||||
|
||||
if (imgtype == IMAGE_INDEXED)
|
||||
uszprintf(buf+ustrlen(buf), size, " %s %d",
|
||||
_("Index"), get_color_for_image(imgtype, color));
|
||||
uszprintf(buf+ustrlen(buf), size, " Index %d",
|
||||
get_color_for_image(imgtype, color));
|
||||
}
|
||||
break;
|
||||
|
||||
case COLOR_TYPE_GRAY:
|
||||
data = GET_COLOR_DATA_GRAY(color);
|
||||
uszprintf(buf, size, "%s %d",
|
||||
_("Gray"), data);
|
||||
uszprintf(buf, size, "Gray %d",
|
||||
data);
|
||||
break;
|
||||
|
||||
case COLOR_TYPE_INDEX: {
|
||||
ase_uint32 _c;
|
||||
data = GET_COLOR_DATA_INDEX(color);
|
||||
_c = get_current_palette()->getEntry(data & 0xff);
|
||||
uszprintf(buf, size, "%s %d (RGB %d %d %d)",
|
||||
_("Index"),
|
||||
uszprintf(buf, size, "Index %d (RGB %d %d %d)",
|
||||
data & 0xff,
|
||||
_rgba_getr(_c),
|
||||
_rgba_getg(_c),
|
||||
|
@ -562,5 +562,5 @@ Rect ColorBar::getBgBounds() const
|
||||
void ColorBar::updateStatusBar(color_t color, int msecs)
|
||||
{
|
||||
app_get_statusbar()
|
||||
->showColor(msecs, app_get_current_image_type(), color);
|
||||
->showColor(msecs, "", color, 255);
|
||||
}
|
||||
|
@ -628,42 +628,34 @@ void Editor::hide_drawing_cursor()
|
||||
|
||||
void Editor::editor_update_statusbar_for_standby()
|
||||
{
|
||||
char buf[256];
|
||||
int x, y;
|
||||
|
||||
screen_to_editor(jmouse_x(0), jmouse_y(0), &x, &y);
|
||||
|
||||
/* for eye-dropper */
|
||||
// For eye-dropper
|
||||
if (m_alt_pressed) {
|
||||
color_t color = color_from_image(m_sprite->getImgType(),
|
||||
m_sprite->getPixel(x, y));
|
||||
if (color_type(color) != COLOR_TYPE_MASK) {
|
||||
usprintf(buf, "%s ", _("Color"));
|
||||
color_to_formalstring(m_sprite->getImgType(),
|
||||
color,
|
||||
buf+ustrlen(buf),
|
||||
sizeof(buf)-ustrlen(buf), true);
|
||||
}
|
||||
else {
|
||||
usprintf(buf, "%s", _("Transparent"));
|
||||
int imgtype = m_sprite->getImgType();
|
||||
ase_uint32 pixel = m_sprite->getPixel(x, y);
|
||||
color_t color = color_from_image(imgtype, pixel);
|
||||
|
||||
int alpha = 255;
|
||||
switch (imgtype) {
|
||||
case IMAGE_RGB: alpha = _rgba_geta(pixel); break;
|
||||
case IMAGE_GRAYSCALE: alpha = _graya_geta(pixel); break;
|
||||
}
|
||||
|
||||
char buf[256];
|
||||
usprintf(buf, "- Pos %d %d", x, y);
|
||||
|
||||
app_get_statusbar()->showColor(0, buf, color, alpha);
|
||||
}
|
||||
else {
|
||||
ustrcpy(buf, empty_string);
|
||||
app_get_statusbar()->setStatusText
|
||||
(0, "Pos %d %d, Size %d %d, Frame %d",
|
||||
x, y,
|
||||
((m_sprite->getMask()->bitmap)? m_sprite->getMask()->w: m_sprite->getWidth()),
|
||||
((m_sprite->getMask()->bitmap)? m_sprite->getMask()->h: m_sprite->getHeight()),
|
||||
m_sprite->getCurrentFrame()+1);
|
||||
}
|
||||
|
||||
app_get_statusbar()->setStatusText
|
||||
(0, "%s %3d %3d (%s %3d %3d) [%s %d] %s",
|
||||
_("Pos"), x, y,
|
||||
_("Size"),
|
||||
((m_sprite->getMask()->bitmap)?
|
||||
m_sprite->getMask()->w:
|
||||
m_sprite->getWidth()),
|
||||
((m_sprite->getMask()->bitmap)?
|
||||
m_sprite->getMask()->h:
|
||||
m_sprite->getHeight()),
|
||||
_("Frame"), m_sprite->getCurrentFrame()+1,
|
||||
buf);
|
||||
}
|
||||
|
||||
void Editor::editor_refresh_region()
|
||||
|
@ -87,6 +87,7 @@ StatusBar::StatusBar()
|
||||
jwidget_focusrest(this, true);
|
||||
|
||||
m_timeout = 0;
|
||||
m_state = SHOW_TEXT;
|
||||
m_progress = jlist_new();
|
||||
m_tipwindow = NULL;
|
||||
m_hot_layer = -1;
|
||||
@ -151,7 +152,7 @@ void StatusBar::onCurrentToolChange()
|
||||
}
|
||||
}
|
||||
|
||||
void StatusBar::setStatusText(int msecs, const char *format, ...)
|
||||
bool StatusBar::setStatusText(int msecs, const char *format, ...)
|
||||
{
|
||||
if ((ji_clock > m_timeout) || (msecs > 0)) {
|
||||
char buf[256]; // TODO warning buffer overflow
|
||||
@ -162,9 +163,15 @@ void StatusBar::setStatusText(int msecs, const char *format, ...)
|
||||
va_end(ap);
|
||||
|
||||
m_timeout = ji_clock + msecs;
|
||||
m_state = SHOW_TEXT;
|
||||
|
||||
this->setText(buf);
|
||||
this->dirty();
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
void StatusBar::showTip(int msecs, const char *format, ...)
|
||||
@ -207,11 +214,13 @@ void StatusBar::showTip(int msecs, const char *format, ...)
|
||||
this->dirty();
|
||||
}
|
||||
|
||||
void StatusBar::showColor(int msecs, int imgtype, color_t color)
|
||||
void StatusBar::showColor(int msecs, const char* text, color_t color, int alpha)
|
||||
{
|
||||
char buf[128]; // TODO warning buffer overflow
|
||||
color_to_formalstring(imgtype, color, buf, sizeof(buf), true);
|
||||
setStatusText(msecs, "%s %s", _("Color"), buf);
|
||||
if (setStatusText(msecs, text)) {
|
||||
m_state = SHOW_COLOR;
|
||||
m_color = color;
|
||||
m_alpha = alpha;
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
@ -309,12 +318,50 @@ bool StatusBar::msg_proc(JMessage msg)
|
||||
rc->x2 -= 2*jguiscale();
|
||||
rc->y2 -= 2*jguiscale();
|
||||
|
||||
int x = rc->x1+4*jguiscale();
|
||||
|
||||
// Color
|
||||
if (m_state == SHOW_COLOR) {
|
||||
// Draw eyedropper icon
|
||||
BITMAP* icon = theme->get_toolicon("eyedropper");
|
||||
if (icon) {
|
||||
set_alpha_blender();
|
||||
draw_trans_sprite(doublebuffer, icon,
|
||||
x, (rc->y1+rc->y2)/2-icon->h/2);
|
||||
|
||||
x += icon->w + 4*jguiscale();
|
||||
}
|
||||
|
||||
// Draw color
|
||||
draw_color_button(doublebuffer, Rect(x, rc->y1, 32*jguiscale(), rc->y2-rc->y1),
|
||||
true, true, true, true,
|
||||
true, true, true, true,
|
||||
app_get_current_image_type(), m_color,
|
||||
false, false);
|
||||
|
||||
x += (32+4)*jguiscale();
|
||||
|
||||
// Draw color description
|
||||
char buf[256]; // TODO warning buffer overflow
|
||||
color_to_formalstring(app_get_current_image_type(),
|
||||
m_color, buf, sizeof(buf), true);
|
||||
|
||||
textout_ex(doublebuffer, this->getFont(), buf,
|
||||
x, (rc->y1+rc->y2)/2-text_height(this->getFont())/2,
|
||||
text_color, -1);
|
||||
|
||||
x += ji_font_text_len(this->getFont(), buf) + 4*jguiscale();
|
||||
|
||||
}
|
||||
|
||||
// Status bar text
|
||||
if (this->getText()) {
|
||||
if (this->getTextSize() > 0) {
|
||||
textout_ex(doublebuffer, this->getFont(), this->getText(),
|
||||
rc->x1+4*jguiscale(),
|
||||
x,
|
||||
(rc->y1+rc->y2)/2-text_height(this->getFont())/2,
|
||||
text_color, -1);
|
||||
|
||||
x += ji_font_text_len(this->getFont(), this->getText()) + 4*jguiscale();
|
||||
}
|
||||
|
||||
// Draw progress bar
|
||||
|
@ -49,9 +49,9 @@ public:
|
||||
StatusBar();
|
||||
~StatusBar();
|
||||
|
||||
void setStatusText(int msecs, const char *format, ...);
|
||||
bool setStatusText(int msecs, const char *format, ...);
|
||||
void showTip(int msecs, const char *format, ...);
|
||||
void showColor(int msecs, int imgtype, color_t color);
|
||||
void showColor(int msecs, const char* text, color_t color, int alpha);
|
||||
|
||||
Progress* addProgress();
|
||||
void removeProgress(Progress* progress);
|
||||
@ -63,7 +63,14 @@ private:
|
||||
void onCurrentToolChange();
|
||||
void updateFromLayer();
|
||||
|
||||
enum State { SHOW_TEXT, SHOW_COLOR };
|
||||
|
||||
int m_timeout;
|
||||
State m_state;
|
||||
|
||||
// Showing a color
|
||||
color_t m_color;
|
||||
int m_alpha;
|
||||
|
||||
// Progress bar
|
||||
JList m_progress;
|
||||
|
Loading…
x
Reference in New Issue
Block a user