Use color sliders for Hue/Saturation dialog

This commit is contained in:
David Capello 2017-05-26 15:40:21 -03:00
parent 9c39b4ad7a
commit b69e791207
5 changed files with 57 additions and 35 deletions

View File

@ -173,11 +173,6 @@ recent_files = Recent files:
recent_folders = Recent folders:
news = News:
[hue_saturation]
h = H:
s = S:
l = L:
[import_sprite_sheet]
title = Import Sprite Sheet
select_file = Select File

View File

@ -1,11 +0,0 @@
<!-- Aseprite -->
<!-- Copyright (C) 2017 by David Capello -->
<gui>
<vbox expansive="true" id="hue_saturation">
<grid expansive="true" columns="2">
<label text="@.h" /><slider min="-180" max="180" id="hue" width="128" />
<label text="@.s" /><slider min="-100" max="100" id="saturation" />
<label text="@.l" /><slider min="-100" max="100" id="lightness" />
</grid>
</vbox>
</gui>

View File

@ -16,6 +16,7 @@
#include "app/ini_file.h"
#include "app/modules/gui.h"
#include "app/ui/color_button.h"
#include "app/ui/color_sliders.h"
#include "base/bind.h"
#include "doc/image.h"
#include "doc/mask.h"
@ -27,8 +28,6 @@
#include "ui/widget.h"
#include "ui/window.h"
#include "hue_saturation.xml.h"
namespace app {
static const char* ConfigSection = "HueSaturation";
@ -42,29 +41,23 @@ public:
WithoutTiledCheckBox)
, m_filter(filter)
{
getContainer()->addChild(&m_controls);
m_controls.hue()->setValue(0);
m_controls.saturation()->setValue(0);
m_controls.lightness()->setValue(0);
m_controls.hue()->Change.connect(base::Bind(&HueSaturationWindow::onChangeControls, this));
m_controls.saturation()->Change.connect(base::Bind(&HueSaturationWindow::onChangeControls, this));
m_controls.lightness()->Change.connect(base::Bind(&HueSaturationWindow::onChangeControls, this));
getContainer()->addChild(&m_sliders);
m_sliders.setMode(ColorSliders::Relative);
m_sliders.ColorChange.connect(base::Bind<void>(&HueSaturationWindow::onChangeControls, this));
}
private:
void onChangeControls() {
m_filter.setHue(double(m_controls.hue()->getValue()));
m_filter.setSaturation(m_controls.saturation()->getValue() / 100.0);
m_filter.setLightness(m_controls.lightness()->getValue() / 100.0);
m_filter.setHue(double(m_sliders.getRelSliderValue(0)));
m_filter.setSaturation(m_sliders.getRelSliderValue(1) / 100.0);
m_filter.setLightness(m_sliders.getRelSliderValue(2) / 100.0);
restartPreview();
}
HueSaturationFilter& m_filter;
app::gen::HueSaturation m_controls;
HslSliders m_sliders;
};
class HueSaturationCommand : public Command {

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2001-2016 David Capello
// Copyright (C) 2001-2017 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
@ -14,6 +14,8 @@
#include "app/ui/skin/skin_theme.h"
#include "base/bind.h"
#include "base/scoped_value.h"
#include "gfx/hsl.h"
#include "gfx/rgb.h"
#include "ui/box.h"
#include "ui/entry.h"
#include "ui/graphics.h"
@ -407,6 +409,39 @@ app::Color HsvSliders::getColorFromSliders()
getAbsSliderValue(3));
}
//////////////////////////////////////////////////////////////////////
// HslSliders
HslSliders::HslSliders()
: ColorSliders()
{
addSlider(Hue, "H", 0, 180);
addSlider(Saturation, "S", 0, 100);
addSlider(Value, "L", 0, 100);
}
void HslSliders::onSetColor(const app::Color& color)
{
gfx::Hsl hsl(gfx::Rgb(color.getRed(),
color.getGreen(),
color.getBlue()));
setAbsSliderValue(0, hsl.hue());
setAbsSliderValue(1, hsl.saturation() * 100.0);
setAbsSliderValue(2, hsl.lightness() * 100.0);
}
app::Color HslSliders::getColorFromSliders()
{
gfx::Hsl hsl(getAbsSliderValue(0),
getAbsSliderValue(1) / 100.0,
getAbsSliderValue(2) / 100.0);
gfx::Rgb rgb(hsl);
return app::Color::fromRgb(rgb.red(),
rgb.green(),
rgb.blue(), 255);
}
//////////////////////////////////////////////////////////////////////
// GraySlider

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2001-2016 David Capello
// Copyright (C) 2001-2017 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
@ -41,6 +41,9 @@ namespace app {
void setMode(Mode mode);
void resetRelativeSliders();
int getAbsSliderValue(int sliderIndex) const;
int getRelSliderValue(int sliderIndex) const;
// Signals
obs::signal<void(ColorSlidersChangeEvent&)> ColorChange;
@ -50,8 +53,6 @@ namespace app {
// For derived classes
void addSlider(Channel channel, const char* labelText, int min, int max);
void setAbsSliderValue(int sliderIndex, int value);
int getAbsSliderValue(int sliderIndex) const;
int getRelSliderValue(int sliderIndex) const;
virtual void onSetColor(const app::Color& color) = 0;
virtual app::Color getColorFromSliders() = 0;
@ -96,6 +97,15 @@ namespace app {
virtual app::Color getColorFromSliders() override;
};
class HslSliders : public ColorSliders {
public:
HslSliders();
private:
virtual void onSetColor(const app::Color& color) override;
virtual app::Color getColorFromSliders() override;
};
class GraySlider : public ColorSliders {
public:
GraySlider();