Allow to drag mouse outside color wheel to select colors at the circumference

This commit is contained in:
David Capello 2021-05-31 15:00:21 -03:00
parent 779bf09893
commit f6ba8d9ae0
3 changed files with 40 additions and 29 deletions

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018-2020 Igara Studio S.A.
// Copyright (C) 2018-2021 Igara Studio S.A.
// Copyright (C) 2016-2018 David Capello
//
// This program is distributed under the terms of
@ -226,8 +226,6 @@ ColorSelector::ColorSelector()
: Widget(kGenericWidget)
, m_paintFlags(AllAreasFlag)
, m_lockColor(false)
, m_capturedInBottom(false)
, m_capturedInAlpha(false)
, m_timer(100, this)
{
initTheme();
@ -312,6 +310,9 @@ bool ColorSelector::onProcessMessage(ui::Message* msg)
if (msg->type() == kMouseDownMessage) {
m_capturedInBottom = bottomBarBounds().contains(pos);
m_capturedInAlpha = alphaBarBounds().contains(pos);
m_capturedInMain = (hasCapture() &&
!m_capturedInMain &&
!m_capturedInBottom);
}
app::Color color = getColorByPosition(pos);
@ -329,6 +330,7 @@ bool ColorSelector::onProcessMessage(ui::Message* msg)
if (hasCapture()) {
m_capturedInBottom = false;
m_capturedInAlpha = false;
m_capturedInMain = false;
releaseMouse();
}
return true;

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018-2020 Igara Studio S.A.
// Copyright (C) 2018-2021 Igara Studio S.A.
// Copyright (C) 2016-2018 David Capello
//
// This program is distributed under the terms of
@ -82,6 +82,8 @@ namespace app {
// m_color.getAlpha() if it's really a color.
int getCurrentAlphaForNewColor() const;
bool hasCaptureInMainArea() const { return m_capturedInMain; }
app::Color m_color;
// These flags indicate which areas must be redrawed in the
@ -108,8 +110,9 @@ namespace app {
// slider. It's used to avoid swapping in both areas (main color
// area vs bottom slider) when we drag the mouse above this
// widget.
bool m_capturedInBottom;
bool m_capturedInAlpha;
bool m_capturedInBottom = false;
bool m_capturedInAlpha = false;
bool m_capturedInMain = false;
ui::Timer m_timer;

View File

@ -74,8 +74,37 @@ app::Color ColorWheel::getMainAreaColor(const int _u, const int umax,
int u = _u - umax/2;
int v = _v - vmax/2;
// Pick harmonies
if (m_color.getAlpha() > 0) {
const gfx::Point pos(_u, _v);
int n = getHarmonies();
int boxsize = std::min(umax/10, vmax/10);
for (int i=0; i<n; ++i) {
app::Color color = getColorInHarmony(i);
if (gfx::Rect(umax-(n-i)*boxsize,
vmax-boxsize,
boxsize, boxsize).contains(pos)) {
m_harmonyPicked = true;
color = app::Color::fromHsv(convertHueAngle(int(color.getHsvHue()), 1),
color.getHsvSaturation(),
color.getHsvValue(),
m_color.getAlpha());
return color;
}
}
}
double d = std::sqrt(u*u + v*v);
// When we click the main area we can limit the distance to the
// wheel radius to pick colors even outside the wheel radius.
if (hasCaptureInMainArea() && d > m_wheelRadius)
d = m_wheelRadius;
if (m_colorModel == ColorModel::NORMAL_MAP) {
double a = std::atan2(-v, u);
int di = int(128.0 * d / m_wheelRadius);
@ -138,29 +167,6 @@ app::Color ColorWheel::getMainAreaColor(const int _u, const int umax,
getCurrentAlphaForNewColor());
}
// Pick harmonies
if (m_color.getAlpha() > 0) {
const gfx::Point pos(_u, _v);
int n = getHarmonies();
int boxsize = std::min(umax/10, vmax/10);
for (int i=0; i<n; ++i) {
app::Color color = getColorInHarmony(i);
if (gfx::Rect(umax-(n-i)*boxsize,
vmax-boxsize,
boxsize, boxsize).contains(pos)) {
m_harmonyPicked = true;
color = app::Color::fromHsv(convertHueAngle(int(color.getHsvHue()), 1),
color.getHsvSaturation(),
color.getHsvValue(),
m_color.getAlpha());
return color;
}
}
}
return app::Color::fromMask();
}