mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-30 15:32:38 +00:00
Show foreground/background color indicators in ColorBar
Related to #16 and #545
This commit is contained in:
parent
9a6f635d31
commit
2ac04c1c16
@ -98,7 +98,7 @@ ColorBar* ColorBar::m_instance = NULL;
|
||||
ColorBar::ColorBar(int align)
|
||||
: Box(align)
|
||||
, m_buttons(int(PalButton::MAX))
|
||||
, m_paletteView(true, this,
|
||||
, m_paletteView(true, PaletteView::FgBgColors, this,
|
||||
App::instance()->preferences().colorBar.boxSize() * guiscale())
|
||||
, m_remapButton("Remap")
|
||||
, m_fgColor(app::Color::fromRgb(255, 255, 255), IMAGE_RGB)
|
||||
@ -220,12 +220,14 @@ app::Color ColorBar::getBgColor()
|
||||
void ColorBar::setFgColor(const app::Color& color)
|
||||
{
|
||||
m_fgColor.setColor(color);
|
||||
m_paletteView.invalidate();
|
||||
FgColorChange(color);
|
||||
}
|
||||
|
||||
void ColorBar::setBgColor(const app::Color& color)
|
||||
{
|
||||
m_bgColor.setColor(color);
|
||||
m_paletteView.invalidate();
|
||||
BgColorChange(color);
|
||||
}
|
||||
|
||||
@ -463,8 +465,10 @@ void ColorBar::onPaletteViewPasteColors(
|
||||
|
||||
void ColorBar::onFgColorButtonChange(const app::Color& color)
|
||||
{
|
||||
if (!m_lock)
|
||||
if (!m_lock) {
|
||||
m_paletteView.deselect();
|
||||
m_paletteView.invalidate();
|
||||
}
|
||||
|
||||
FgColorChange(color);
|
||||
onColorButtonChange(color);
|
||||
@ -472,8 +476,10 @@ void ColorBar::onFgColorButtonChange(const app::Color& color)
|
||||
|
||||
void ColorBar::onBgColorButtonChange(const app::Color& color)
|
||||
{
|
||||
if (!m_lock)
|
||||
if (!m_lock) {
|
||||
m_paletteView.deselect();
|
||||
m_paletteView.invalidate();
|
||||
}
|
||||
|
||||
BgColorChange(color);
|
||||
onColorButtonChange(color);
|
||||
|
@ -55,7 +55,7 @@ ColorSelector::ColorSelector()
|
||||
, m_vbox(JI_VERTICAL)
|
||||
, m_topBox(JI_HORIZONTAL)
|
||||
, m_color(app::Color::fromMask())
|
||||
, m_colorPalette(false, this, 7*guiscale())
|
||||
, m_colorPalette(false, PaletteView::SelectOneColor, this, 7*guiscale())
|
||||
, m_indexButton("Index", 1, kButtonWidget)
|
||||
, m_rgbButton("RGB", 1, kButtonWidget)
|
||||
, m_hsvButton("HSB", 1, kButtonWidget)
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "app/modules/editors.h"
|
||||
#include "app/modules/gui.h"
|
||||
#include "app/modules/palettes.h"
|
||||
#include "app/ui/color_bar.h" // TODO avoid depending on ColorBar
|
||||
#include "app/ui/editor/editor.h"
|
||||
#include "app/ui/palette_view.h"
|
||||
#include "app/ui/skin/skin_theme.h"
|
||||
@ -55,10 +56,11 @@ WidgetType palette_view_type()
|
||||
return type;
|
||||
}
|
||||
|
||||
PaletteView::PaletteView(bool editable, PaletteViewDelegate* delegate, int boxsize)
|
||||
PaletteView::PaletteView(bool editable, PaletteViewStyle style, PaletteViewDelegate* delegate, int boxsize)
|
||||
: Widget(palette_view_type())
|
||||
, m_state(State::WAITING)
|
||||
, m_editable(editable)
|
||||
, m_style(style)
|
||||
, m_delegate(delegate)
|
||||
, m_columns(16)
|
||||
, m_boxsize(boxsize)
|
||||
@ -395,6 +397,13 @@ void PaletteView::onPaint(ui::PaintEvent& ev)
|
||||
ui::Graphics* g = ev.getGraphics();
|
||||
gfx::Rect bounds = getClientBounds();
|
||||
Palette* palette = get_current_palette();
|
||||
int fgIndex = -1;
|
||||
int bgIndex = -1;
|
||||
|
||||
if (m_style == FgBgColors) {
|
||||
fgIndex = findExactIndex(ColorBar::instance()->getFgColor());
|
||||
bgIndex = findExactIndex(ColorBar::instance()->getBgColor());
|
||||
}
|
||||
|
||||
g->fillRect(gfx::rgba(0, 0, 0), bounds);
|
||||
|
||||
@ -408,9 +417,28 @@ void PaletteView::onPaint(ui::PaintEvent& ev)
|
||||
|
||||
g->fillRect(color, box);
|
||||
|
||||
if (m_currentEntry == i)
|
||||
g->fillRect(color_utils::blackandwhite_neg(color),
|
||||
gfx::Rect(box.getCenter(), gfx::Size(1, 1)));
|
||||
switch (m_style) {
|
||||
|
||||
case SelectOneColor:
|
||||
if (m_currentEntry == i)
|
||||
g->fillRect(color_utils::blackandwhite_neg(color),
|
||||
gfx::Rect(box.getCenter(), gfx::Size(1, 1)));
|
||||
break;
|
||||
|
||||
case FgBgColors:
|
||||
if (fgIndex == i) {
|
||||
gfx::Color neg = color_utils::blackandwhite_neg(color);
|
||||
for (int i=0; i<m_boxsize/2; ++i)
|
||||
g->drawHLine(neg, box.x, box.y+i, m_boxsize/2-i);
|
||||
}
|
||||
|
||||
if (bgIndex == i) {
|
||||
gfx::Color neg = color_utils::blackandwhite_neg(color);
|
||||
for (int i=0; i<m_boxsize/4; ++i)
|
||||
g->drawHLine(neg, box.x+box.w-(i+1), box.y+box.h-m_boxsize/4+i, i+1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Draw selected entries
|
||||
@ -735,4 +763,24 @@ void PaletteView::setCursor()
|
||||
ui::set_mouse_cursor(kArrowCursor);
|
||||
}
|
||||
|
||||
int PaletteView::findExactIndex(const app::Color& color) const
|
||||
{
|
||||
switch (color.getType()) {
|
||||
|
||||
case Color::MaskType:
|
||||
return (current_editor ? current_editor->sprite()->transparentColor(): -1);
|
||||
|
||||
case Color::RgbType:
|
||||
case Color::HsvType:
|
||||
case Color::GrayType:
|
||||
return get_current_palette()->findExactMatch(color.getRed(), color.getGreen(), color.getBlue());
|
||||
|
||||
case Color::IndexType:
|
||||
return color.getIndex();
|
||||
}
|
||||
|
||||
ASSERT(false);
|
||||
return -1;
|
||||
}
|
||||
|
||||
} // namespace app
|
||||
|
@ -39,7 +39,12 @@ namespace app {
|
||||
class PaletteView : public ui::Widget
|
||||
, public MarchingAnts {
|
||||
public:
|
||||
PaletteView(bool editable, PaletteViewDelegate* delegate, int boxsize);
|
||||
enum PaletteViewStyle {
|
||||
SelectOneColor,
|
||||
FgBgColors
|
||||
};
|
||||
|
||||
PaletteView(bool editable, PaletteViewStyle style, PaletteViewDelegate* delegate, int boxsize);
|
||||
|
||||
bool isEditable() const { return m_editable; }
|
||||
|
||||
@ -118,9 +123,11 @@ namespace app {
|
||||
bool pickedXY(const doc::PalettePicks& entries, int i, int dx, int dy) const;
|
||||
void updateCopyFlag(ui::Message* msg);
|
||||
void setCursor();
|
||||
int findExactIndex(const app::Color& color) const;
|
||||
|
||||
State m_state;
|
||||
bool m_editable;
|
||||
PaletteViewStyle m_style;
|
||||
PaletteViewDelegate* m_delegate;
|
||||
int m_columns;
|
||||
int m_boxsize;
|
||||
|
Loading…
x
Reference in New Issue
Block a user