Merge branch 'main' into beta

This commit is contained in:
David Capello 2021-06-04 13:31:51 -03:00
commit d618bada49
5 changed files with 47 additions and 35 deletions

View File

@ -142,4 +142,4 @@ We are using some modern C++ (C++11, C++14, etc.) features, mainly:
* You can use `<atomic>`, `<thread>`, `<mutex>`, and `<condition_variable>`
* Prefer `using T = ...;` instead of `typedef ... T`
* We use gcc 9.2 or clang 9.0 on Linux, so check the features available in
https://developer.mozilla.org/en-US/docs/Mozilla/Using_CXX_in_Mozilla_code
https://en.cppreference.com/w/cpp/compiler_support

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
@ -222,8 +222,6 @@ ColorSelector::ColorSelector()
: Widget(kGenericWidget)
, m_paintFlags(AllAreasFlag)
, m_lockColor(false)
, m_capturedInBottom(false)
, m_capturedInAlpha(false)
, m_timer(100, this)
{
initTheme();
@ -308,6 +306,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);
@ -325,6 +326,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);
@ -94,7 +123,7 @@ app::Color ColorWheel::getMainAreaColor(const int _u, const int umax,
int r = 128 + di*std::cos(a);
int g = 128 + di*std::sin(a);
int b = 255 - di;
if (d < m_wheelRadius+2*guiscale()) {
if (d <= m_wheelRadius) {
return app::Color::fromRgb(
base::clamp(r, 0, 255),
base::clamp(g, 0, 255),
@ -106,7 +135,7 @@ app::Color ColorWheel::getMainAreaColor(const int _u, const int umax,
}
// Pick from the wheel
if (d < m_wheelRadius+2*guiscale()) {
if (d <= m_wheelRadius) {
double a = std::atan2(-v, u);
int hue = (int(180.0 * a / PI)
@ -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();
}
@ -178,8 +184,8 @@ void ColorWheel::onPaintMainArea(ui::Graphics* g, const gfx::Rect& rc)
{
bool oldHarmonyPicked = m_harmonyPicked;
int r = std::min(rc.w/2, rc.h/2);
m_wheelRadius = r;
double r = std::max(1.0, std::min(rc.w, rc.h) / 2.0);
m_wheelRadius = r-0.1;
m_wheelBounds = gfx::Rect(rc.x+rc.w/2-r,
rc.y+rc.h/2-r,
r*2, r*2);

View File

@ -1,4 +1,5 @@
// Aseprite
// Copyright (C) 2021 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -68,7 +69,7 @@ namespace app {
gfx::Rect m_wheelBounds;
gfx::Color m_bgColor;
int m_wheelRadius;
double m_wheelRadius;
bool m_discrete;
ColorModel m_colorModel;
Harmony m_harmony;