mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-14 04:19:12 +00:00
Show grayscale colors in color buttons when we're editing a grayscale image
This commit is contained in:
parent
155c74a633
commit
c09dfa89f0
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2015 David Capello
|
||||
// Copyright (C) 2001-2016 David Capello
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 2 as
|
||||
@ -62,12 +62,16 @@ static void rectgrid(ui::Graphics* g, const gfx::Rect& rc, const gfx::Size& tile
|
||||
}
|
||||
}
|
||||
|
||||
void draw_color(ui::Graphics* g, const Rect& rc, const app::Color& color)
|
||||
void draw_color(ui::Graphics* g,
|
||||
const Rect& rc,
|
||||
const app::Color& _color,
|
||||
const doc::ColorMode colorMode)
|
||||
{
|
||||
if (rc.w < 1 || rc.h < 1)
|
||||
return;
|
||||
|
||||
app::Color::Type type = color.getType();
|
||||
app::Color color = _color;
|
||||
|
||||
int alpha = color.getAlpha();
|
||||
|
||||
if (alpha < 255) {
|
||||
@ -78,7 +82,13 @@ void draw_color(ui::Graphics* g, const Rect& rc, const app::Color& color)
|
||||
}
|
||||
|
||||
if (alpha > 0) {
|
||||
if (type == app::Color::IndexType) {
|
||||
if (colorMode == doc::ColorMode::GRAYSCALE) {
|
||||
color = app::Color::fromGray(
|
||||
color.getGray(),
|
||||
color.getAlpha());
|
||||
}
|
||||
|
||||
if (color.getType() == app::Color::IndexType) {
|
||||
int index = color.getIndex();
|
||||
|
||||
if (index >= 0 && index < get_current_palette()->size()) {
|
||||
@ -91,24 +101,30 @@ void draw_color(ui::Graphics* g, const Rect& rc, const app::Color& color)
|
||||
gfx::Point(rc.x+1, rc.y+rc.h-2));
|
||||
}
|
||||
}
|
||||
else
|
||||
else {
|
||||
g->fillRect(color_utils::color_for_ui(color), rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void draw_color_button(ui::Graphics* g,
|
||||
const Rect& rc, const app::Color& color,
|
||||
bool hot, bool drag)
|
||||
const Rect& rc,
|
||||
const app::Color& color,
|
||||
const doc::ColorMode colorMode,
|
||||
const bool hot,
|
||||
const bool drag)
|
||||
{
|
||||
SkinTheme* theme = SkinTheme::instance();
|
||||
int scale = ui::guiscale();
|
||||
|
||||
// Draw background (the color)
|
||||
draw_color(g,
|
||||
Rect(rc.x+1*scale,
|
||||
rc.y+1*scale,
|
||||
rc.w-2*scale,
|
||||
rc.h-2*scale), color);
|
||||
Rect(rc.x+1*scale,
|
||||
rc.y+1*scale,
|
||||
rc.w-2*scale,
|
||||
rc.h-2*scale),
|
||||
color,
|
||||
colorMode);
|
||||
|
||||
// Draw opaque border
|
||||
theme->drawRect(
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2015 David Capello
|
||||
// Copyright (C) 2001-2016 David Capello
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 2 as
|
||||
@ -10,6 +10,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "app/color.h"
|
||||
#include "doc/color_mode.h"
|
||||
#include "gfx/color.h"
|
||||
#include "gfx/rect.h"
|
||||
#include "ui/base.h"
|
||||
@ -19,11 +20,16 @@ namespace app {
|
||||
using namespace doc;
|
||||
|
||||
void draw_color(ui::Graphics* g,
|
||||
const gfx::Rect& rc, const app::Color& color);
|
||||
const gfx::Rect& rc,
|
||||
const app::Color& color,
|
||||
const doc::ColorMode colorMode);
|
||||
|
||||
void draw_color_button(ui::Graphics* g,
|
||||
const gfx::Rect& rc, const app::Color& color,
|
||||
bool hot, bool drag);
|
||||
const gfx::Rect& rc,
|
||||
const app::Color& color,
|
||||
const doc::ColorMode colorMode,
|
||||
const bool hot,
|
||||
const bool drag);
|
||||
|
||||
} // namespace app
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2015 David Capello
|
||||
// Copyright (C) 2001-2016 David Capello
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 2 as
|
||||
@ -209,7 +209,9 @@ void ColorButton::onPaint(PaintEvent& ev)
|
||||
}
|
||||
|
||||
draw_color_button(g, rc,
|
||||
color, hasMouseOver(), false);
|
||||
color,
|
||||
(doc::ColorMode)m_pixelFormat,
|
||||
hasMouseOver(), false);
|
||||
|
||||
// Draw text
|
||||
std::string str = m_color.toHumanReadableString(m_pixelFormat,
|
||||
|
@ -609,7 +609,8 @@ class ContextBar::InkShadesField : public HBox {
|
||||
color = app::Color::fromMask();
|
||||
}
|
||||
|
||||
draw_color(g, box, color);
|
||||
draw_color(g, box, color,
|
||||
(doc::ColorMode)app_get_current_pixel_format());
|
||||
|
||||
if (m_hotIndex == i)
|
||||
hotBounds = box;
|
||||
|
@ -992,7 +992,7 @@ gfx::Color PaletteView::drawEntry(ui::Graphics* g, const gfx::Rect& box, int pal
|
||||
rgba_geta(palColor));
|
||||
|
||||
g->drawRect(gfx::rgba(0, 0, 0), gfx::Rect(box).enlarge(guiscale()));
|
||||
draw_color(g, box, appColor);
|
||||
draw_color(g, box, appColor, doc::ColorMode::RGB);
|
||||
return gfxColor;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2015 David Capello
|
||||
// Copyright (C) 2001-2016 David Capello
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 2 as
|
||||
@ -435,13 +435,16 @@ void StatusBar::onPaint(ui::PaintEvent& ev)
|
||||
}
|
||||
|
||||
// Draw color
|
||||
draw_color_button(g, gfx::Rect(x, rc.y, 32*guiscale(), rc.h),
|
||||
m_color, false, false);
|
||||
draw_color_button(
|
||||
g, gfx::Rect(x, rc.y, 32*guiscale(), rc.h),
|
||||
m_color,
|
||||
(doc::ColorMode)app_get_current_pixel_format(), false, false);
|
||||
|
||||
x += (32+4)*guiscale();
|
||||
|
||||
// Draw color description
|
||||
std::string str = m_color.toHumanReadableString(app_get_current_pixel_format(),
|
||||
std::string str = m_color.toHumanReadableString(
|
||||
app_get_current_pixel_format(),
|
||||
app::Color::LongHumanReadableString);
|
||||
if (m_color.getAlpha() < 255) {
|
||||
char buf[256];
|
||||
|
Loading…
x
Reference in New Issue
Block a user