mirror of
https://github.com/aseprite/aseprite.git
synced 2025-02-22 06:41:08 +00:00
Add new app::ColorSelector to share behavior between ColorTintShadeTone/ColorSpectrum/ColorWheel
This commit is contained in:
parent
1209037b02
commit
449ae1d9e4
@ -338,6 +338,7 @@ add_library(app-lib
|
||||
ui/color_bar.cpp
|
||||
ui/color_button.cpp
|
||||
ui/color_popup.cpp
|
||||
ui/color_selector.cpp
|
||||
ui/color_sliders.cpp
|
||||
ui/color_spectrum.cpp
|
||||
ui/color_tint_shade_tone.cpp
|
||||
|
41
src/app/ui/color_selector.cpp
Normal file
41
src/app/ui/color_selector.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 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
|
||||
// published by the Free Software Foundation.
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/ui/color_selector.h"
|
||||
|
||||
#include "ui/size_hint_event.h"
|
||||
#include "ui/theme.h"
|
||||
|
||||
namespace app {
|
||||
|
||||
using namespace ui;
|
||||
|
||||
ColorSelector::ColorSelector()
|
||||
: Widget(kGenericWidget)
|
||||
, m_lockColor(false)
|
||||
{
|
||||
}
|
||||
|
||||
void ColorSelector::selectColor(const app::Color& color)
|
||||
{
|
||||
if (m_lockColor)
|
||||
return;
|
||||
|
||||
m_color = color;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
void ColorSelector::onSizeHint(SizeHintEvent& ev)
|
||||
{
|
||||
ev.setSizeHint(gfx::Size(32*ui::guiscale(), 32*ui::guiscale()));
|
||||
}
|
||||
|
||||
} // namespace app
|
41
src/app/ui/color_selector.h
Normal file
41
src/app/ui/color_selector.h
Normal file
@ -0,0 +1,41 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 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
|
||||
// published by the Free Software Foundation.
|
||||
|
||||
#ifndef APP_UI_COLOR_SELECTOR_H_INCLUDED
|
||||
#define APP_UI_COLOR_SELECTOR_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/color.h"
|
||||
#include "base/signal.h"
|
||||
#include "ui/mouse_buttons.h"
|
||||
#include "ui/widget.h"
|
||||
|
||||
namespace app {
|
||||
|
||||
class ColorSelector : public ui::Widget {
|
||||
public:
|
||||
ColorSelector();
|
||||
|
||||
void selectColor(const app::Color& color);
|
||||
|
||||
// Signals
|
||||
base::Signal2<void, const app::Color&, ui::MouseButtons> ColorChange;
|
||||
|
||||
protected:
|
||||
void onSizeHint(ui::SizeHintEvent& ev) override;
|
||||
|
||||
app::Color m_color;
|
||||
|
||||
// Internal flag used to lock the modification of m_color.
|
||||
// E.g. When the user picks a color harmony, we don't want to
|
||||
// change the main color.
|
||||
bool m_lockColor;
|
||||
};
|
||||
|
||||
} // namespace app
|
||||
|
||||
#endif
|
@ -29,16 +29,11 @@ using namespace gfx;
|
||||
using namespace ui;
|
||||
|
||||
ColorSpectrum::ColorSpectrum()
|
||||
: Widget(kGenericWidget)
|
||||
{
|
||||
setAlign(HORIZONTAL);
|
||||
setBorder(gfx::Border(3*ui::guiscale()));
|
||||
}
|
||||
|
||||
ColorSpectrum::~ColorSpectrum()
|
||||
{
|
||||
}
|
||||
|
||||
app::Color ColorSpectrum::pickColor(const gfx::Point& pos) const
|
||||
{
|
||||
gfx::Rect rc = childrenBounds();
|
||||
@ -70,22 +65,6 @@ app::Color ColorSpectrum::pickColor(const gfx::Point& pos) const
|
||||
MID(0.0, val, 100.0));
|
||||
}
|
||||
|
||||
void ColorSpectrum::selectColor(const app::Color& color)
|
||||
{
|
||||
m_color = color;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
void ColorSpectrum::onSizeHint(SizeHintEvent& ev)
|
||||
{
|
||||
ev.setSizeHint(gfx::Size(32*ui::guiscale(), 32*ui::guiscale()));
|
||||
}
|
||||
|
||||
void ColorSpectrum::onResize(ui::ResizeEvent& ev)
|
||||
{
|
||||
Widget::onResize(ev);
|
||||
}
|
||||
|
||||
void ColorSpectrum::onPaint(ui::PaintEvent& ev)
|
||||
{
|
||||
ui::Graphics* g = ev.graphics();
|
||||
|
@ -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
|
||||
@ -9,32 +9,20 @@
|
||||
#define APP_UI_COLOR_SPECTRUM_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/color.h"
|
||||
#include "base/signal.h"
|
||||
#include "ui/mouse_buttons.h"
|
||||
#include "ui/widget.h"
|
||||
#include "app/ui/color_selector.h"
|
||||
#include "ui/button.h"
|
||||
|
||||
namespace app {
|
||||
|
||||
class ColorSpectrum : public ui::Widget {
|
||||
class ColorSpectrum : public ColorSelector {
|
||||
public:
|
||||
ColorSpectrum();
|
||||
~ColorSpectrum();
|
||||
|
||||
app::Color pickColor(const gfx::Point& pos) const;
|
||||
void selectColor(const app::Color& color);
|
||||
|
||||
// Signals
|
||||
base::Signal2<void, const app::Color&, ui::MouseButtons> ColorChange;
|
||||
|
||||
protected:
|
||||
void onSizeHint(ui::SizeHintEvent& ev) override;
|
||||
void onResize(ui::ResizeEvent& ev) override;
|
||||
void onPaint(ui::PaintEvent& ev) override;
|
||||
bool onProcessMessage(ui::Message* msg) override;
|
||||
|
||||
private:
|
||||
app::Color m_color;
|
||||
};
|
||||
|
||||
} // namespace app
|
||||
|
@ -29,16 +29,11 @@ using namespace gfx;
|
||||
using namespace ui;
|
||||
|
||||
ColorTintShadeTone::ColorTintShadeTone()
|
||||
: Widget(kGenericWidget)
|
||||
, m_capturedInHue(false)
|
||||
: m_capturedInHue(false)
|
||||
{
|
||||
setBorder(gfx::Border(3*ui::guiscale()));
|
||||
}
|
||||
|
||||
ColorTintShadeTone::~ColorTintShadeTone()
|
||||
{
|
||||
}
|
||||
|
||||
app::Color ColorTintShadeTone::pickColor(const gfx::Point& pos) const
|
||||
{
|
||||
gfx::Rect rc = childrenBounds();
|
||||
@ -71,22 +66,6 @@ app::Color ColorTintShadeTone::pickColor(const gfx::Point& pos) const
|
||||
MID(0.0, val, 100.0));
|
||||
}
|
||||
|
||||
void ColorTintShadeTone::selectColor(const app::Color& color)
|
||||
{
|
||||
m_color = color;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
void ColorTintShadeTone::onSizeHint(SizeHintEvent& ev)
|
||||
{
|
||||
ev.setSizeHint(gfx::Size(32*ui::guiscale(), 32*ui::guiscale()));
|
||||
}
|
||||
|
||||
void ColorTintShadeTone::onResize(ui::ResizeEvent& ev)
|
||||
{
|
||||
Widget::onResize(ev);
|
||||
}
|
||||
|
||||
void ColorTintShadeTone::onPaint(ui::PaintEvent& ev)
|
||||
{
|
||||
ui::Graphics* g = ev.graphics();
|
||||
|
@ -9,26 +9,15 @@
|
||||
#define APP_UI_COLOR_TINT_SHADE_TONE_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/color.h"
|
||||
#include "base/signal.h"
|
||||
#include "ui/mouse_buttons.h"
|
||||
#include "ui/widget.h"
|
||||
#include "app/ui/color_selector.h"
|
||||
|
||||
namespace app {
|
||||
|
||||
class ColorTintShadeTone : public ui::Widget {
|
||||
class ColorTintShadeTone : public ColorSelector {
|
||||
public:
|
||||
ColorTintShadeTone();
|
||||
~ColorTintShadeTone();
|
||||
|
||||
void selectColor(const app::Color& color);
|
||||
|
||||
// Signals
|
||||
base::Signal2<void, const app::Color&, ui::MouseButtons> ColorChange;
|
||||
|
||||
protected:
|
||||
void onSizeHint(ui::SizeHintEvent& ev) override;
|
||||
void onResize(ui::ResizeEvent& ev) override;
|
||||
void onPaint(ui::PaintEvent& ev) override;
|
||||
bool onProcessMessage(ui::Message* msg) override;
|
||||
|
||||
@ -37,8 +26,6 @@ namespace app {
|
||||
bool inHueBarArea(const gfx::Point& pos) const;
|
||||
int getHueBarSize() const;
|
||||
|
||||
app::Color m_color;
|
||||
|
||||
// True when the user pressed the mouse button in the hue slider.
|
||||
// It's used to avoid swapping in both areas (tint/shades/tones
|
||||
// area vs hue slider) when we drag the mouse above this widget.
|
||||
|
@ -51,13 +51,11 @@ static struct {
|
||||
};
|
||||
|
||||
ColorWheel::ColorWheel()
|
||||
: Widget(kGenericWidget)
|
||||
, m_discrete(Preferences::instance().colorBar.discreteWheel())
|
||||
: m_discrete(Preferences::instance().colorBar.discreteWheel())
|
||||
, m_colorModel((ColorModel)Preferences::instance().colorBar.wheelModel())
|
||||
, m_harmony((Harmony)Preferences::instance().colorBar.harmony())
|
||||
, m_options("", kButtonWidget, kButtonWidget, kCheckWidget)
|
||||
, m_harmonyPicked(false)
|
||||
, m_lockColor(false)
|
||||
{
|
||||
SkinTheme* theme = SkinTheme::instance();
|
||||
|
||||
@ -74,10 +72,6 @@ ColorWheel::ColorWheel()
|
||||
addChild(&m_options);
|
||||
}
|
||||
|
||||
ColorWheel::~ColorWheel()
|
||||
{
|
||||
}
|
||||
|
||||
app::Color ColorWheel::pickColor(const gfx::Point& pos) const
|
||||
{
|
||||
m_harmonyPicked = false;
|
||||
@ -119,7 +113,7 @@ app::Color ColorWheel::pickColor(const gfx::Point& pos) const
|
||||
}
|
||||
|
||||
// Pick harmonies
|
||||
if (m_mainColor.getAlpha() > 0) {
|
||||
if (m_color.getAlpha() > 0) {
|
||||
const gfx::Rect& rc = m_clientBounds;
|
||||
int n = getHarmonies();
|
||||
int boxsize = MIN(rc.w/10, rc.h/10);
|
||||
@ -143,15 +137,6 @@ app::Color ColorWheel::pickColor(const gfx::Point& pos) const
|
||||
return app::Color::fromMask();
|
||||
}
|
||||
|
||||
void ColorWheel::selectColor(const app::Color& color)
|
||||
{
|
||||
if (m_lockColor)
|
||||
return;
|
||||
|
||||
m_mainColor = color;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
void ColorWheel::setDiscrete(bool state)
|
||||
{
|
||||
m_discrete = state;
|
||||
@ -186,21 +171,16 @@ app::Color ColorWheel::getColorInHarmony(int j) const
|
||||
{
|
||||
int i = MID(0, (int)m_harmony, (int)Harmony::LAST);
|
||||
j = MID(0, j, harmonies[i].n-1);
|
||||
double hue = convertHueAngle(int(m_mainColor.getHue()), -1) + harmonies[i].hues[j];
|
||||
double sat = m_mainColor.getSaturation() * harmonies[i].sats[j] / 100.0;
|
||||
double hue = convertHueAngle(int(m_color.getHue()), -1) + harmonies[i].hues[j];
|
||||
double sat = m_color.getSaturation() * harmonies[i].sats[j] / 100.0;
|
||||
return app::Color::fromHsv(std::fmod(hue, 360),
|
||||
MID(0.0, sat, 100.0),
|
||||
m_mainColor.getValue());
|
||||
}
|
||||
|
||||
void ColorWheel::onSizeHint(SizeHintEvent& ev)
|
||||
{
|
||||
ev.setSizeHint(gfx::Size(32*ui::guiscale(), 32*ui::guiscale()));
|
||||
m_color.getValue());
|
||||
}
|
||||
|
||||
void ColorWheel::onResize(ui::ResizeEvent& ev)
|
||||
{
|
||||
Widget::onResize(ev);
|
||||
ColorSelector::onResize(ev);
|
||||
|
||||
gfx::Rect rc = clientChildrenBounds();
|
||||
int r = MIN(rc.w/2, rc.h/2);
|
||||
@ -247,7 +227,7 @@ void ColorWheel::onPaint(ui::PaintEvent& ev)
|
||||
}
|
||||
}
|
||||
|
||||
if (m_mainColor.getAlpha() > 0) {
|
||||
if (m_color.getAlpha() > 0) {
|
||||
int n = getHarmonies();
|
||||
int boxsize = MIN(rc.w/10, rc.h/10);
|
||||
|
||||
|
@ -9,15 +9,12 @@
|
||||
#define APP_UI_COLOR_WHEEL_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/color.h"
|
||||
#include "base/signal.h"
|
||||
#include "app/ui/color_selector.h"
|
||||
#include "ui/button.h"
|
||||
#include "ui/mouse_buttons.h"
|
||||
#include "ui/widget.h"
|
||||
|
||||
namespace app {
|
||||
|
||||
class ColorWheel : public ui::Widget {
|
||||
class ColorWheel : public ColorSelector {
|
||||
public:
|
||||
enum class ColorModel {
|
||||
RGB,
|
||||
@ -37,10 +34,8 @@ namespace app {
|
||||
};
|
||||
|
||||
ColorWheel();
|
||||
~ColorWheel();
|
||||
|
||||
app::Color pickColor(const gfx::Point& pos) const;
|
||||
void selectColor(const app::Color& color);
|
||||
|
||||
bool isDiscrete() const { return m_discrete; }
|
||||
void setDiscrete(bool state);
|
||||
@ -48,11 +43,7 @@ namespace app {
|
||||
void setColorModel(ColorModel colorModel);
|
||||
void setHarmony(Harmony harmony);
|
||||
|
||||
// Signals
|
||||
base::Signal2<void, const app::Color&, ui::MouseButtons> ColorChange;
|
||||
|
||||
private:
|
||||
void onSizeHint(ui::SizeHintEvent& ev) override;
|
||||
void onResize(ui::ResizeEvent& ev) override;
|
||||
void onPaint(ui::PaintEvent& ev) override;
|
||||
bool onProcessMessage(ui::Message* msg) override;
|
||||
@ -72,16 +63,10 @@ namespace app {
|
||||
ColorModel m_colorModel;
|
||||
Harmony m_harmony;
|
||||
ui::ButtonBase m_options;
|
||||
app::Color m_mainColor;
|
||||
|
||||
// Internal flag used to know if after pickColor() we selected an
|
||||
// harmony.
|
||||
mutable bool m_harmonyPicked;
|
||||
|
||||
// Internal flag used to lock the modification of m_mainColor.
|
||||
// When the user picks a color harmony, we don't want to change
|
||||
// the main color.
|
||||
bool m_lockColor;
|
||||
};
|
||||
|
||||
} // namespace app
|
||||
|
Loading…
x
Reference in New Issue
Block a user