Show current color indicator in the color wheel

This commit is contained in:
David Capello 2015-08-21 12:34:06 -03:00
parent be0a944cd8
commit b0877df0cb
5 changed files with 34 additions and 2 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

View File

@ -397,6 +397,7 @@
<part id="icon_black" x="48" y="256" w="16" h="16" />
<part id="icon_white" x="64" y="256" w="16" h="16" />
<part id="icon_transparent" x="80" y="256" w="16" h="16" />
<part id="color_wheel_indicator" x="48" y="192" w="4" h="4" />
</parts>
<stylesheet>

View File

@ -328,6 +328,7 @@ void ColorBar::setColorSelector(ColorSelector selector)
if (!m_wheel) {
m_wheel = new ColorWheel;
m_wheel->setExpansive(true);
m_wheel->selectColor(m_fgColor.getColor());
m_wheel->ColorChange.connect(&ColorBar::onPickSpectrum, this);
m_selectorPlaceholder.addChild(m_wheel);
}
@ -769,6 +770,9 @@ void ColorBar::onColorButtonChange(const app::Color& color)
// palette view fg/bg indicators.
m_paletteView.invalidate();
}
if (m_wheel && m_wheel->isVisible())
m_wheel->selectColor(color);
}
void ColorBar::onPickSpectrum(const app::Color& color, ui::MouseButtons buttons)

View File

@ -18,6 +18,7 @@
#include "app/ui/status_bar.h"
#include "base/bind.h"
#include "base/pi.h"
#include "she/surface.h"
#include "ui/graphics.h"
#include "ui/menu.h"
#include "ui/message.h"
@ -62,7 +63,7 @@ app::Color ColorWheel::pickColor(const gfx::Point& pos) const
int v = (pos.y - (m_wheelBounds.y+m_wheelBounds.h/2));
double d = std::sqrt(u*u + v*v);
if (d < m_wheelRadius) {
if (d < m_wheelRadius+2*guiscale()) {
double a = std::atan2(-v, u);
int hue = (int(180.0 * a / PI)
@ -76,11 +77,15 @@ app::Color ColorWheel::pickColor(const gfx::Point& pos) const
}
hue %= 360; // To leave hue in [0,360) range
int sat = int(120.0 * d / m_wheelRadius);
int sat;
if (m_discrete) {
sat = int(120.0 * d / m_wheelRadius);
sat /= 20;
sat *= 20;
}
else {
sat = int(100.0 * d / m_wheelRadius);
}
return app::Color::fromHsv(
MID(0, hue, 360),
@ -92,6 +97,12 @@ app::Color ColorWheel::pickColor(const gfx::Point& pos) const
}
}
void ColorWheel::selectColor(const app::Color& color)
{
m_mainColor = color;
invalidate();
}
void ColorWheel::setDiscrete(bool state)
{
m_discrete = state;
@ -153,6 +164,20 @@ void ColorWheel::onPaint(ui::PaintEvent& ev)
g->putPixel(color, x, y);
}
}
if (m_mainColor.getAlpha() > 0) {
int hue = m_mainColor.getHue()-30;
int sat = m_mainColor.getSaturation();
gfx::Point pos =
m_wheelBounds.getCenter() +
gfx::Point(int(+std::cos(PI*hue/180)*double(m_wheelRadius)*sat/100.0),
int(-std::sin(PI*hue/180)*double(m_wheelRadius)*sat/100.0));
she::Surface* icon = theme->parts.colorWheelIndicator()->getBitmap(0);
g->drawRgbaSurface(icon,
pos.x-icon->width()/2,
pos.y-icon->height()/2);
}
}
bool ColorWheel::onProcessMessage(ui::Message* msg)

View File

@ -23,6 +23,7 @@ namespace app {
~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);
@ -42,6 +43,7 @@ namespace app {
int m_wheelRadius;
bool m_discrete;
ui::ButtonBase m_options;
app::Color m_mainColor;
};
} // namespace app