Skip to content

Commit

Permalink
Set alpha=255 if the current color is MaskType when picking colors fr…
Browse files Browse the repository at this point in the history
…om ColorSelectors

This is a little UI improvement: If we've just picked the mask color,
and click a color selector, generally we would like to use the opaque
version of that color (instead of the completely transparent version
of that color, alpha=0, which is an useless option).
  • Loading branch information
dacap committed Apr 7, 2020
1 parent ed5deb9 commit fd651c4
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
10 changes: 9 additions & 1 deletion src/app/ui/color_selector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ bool ColorSelector::onProcessMessage(ui::Message* msg)
newHue,
m_color.getHsvSaturation(),
m_color.getHsvValue(),
m_color.getAlpha());
getCurrentAlphaForNewColor());

ColorChange(newColor, kButtonNone);
}
Expand Down Expand Up @@ -490,6 +490,14 @@ void ColorSelector::paintColorIndicator(ui::Graphics* g,
pos.y-icon->height()/2);
}

int ColorSelector::getCurrentAlphaForNewColor() const
{
if (m_color.getType() != Color::MaskType)
return m_color.getAlpha();
else
return 255;
}

gfx::Rect ColorSelector::bottomBarBounds() const
{
SkinTheme* theme = static_cast<SkinTheme*>(this->theme());
Expand Down
6 changes: 5 additions & 1 deletion src/app/ui/color_selector.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Aseprite
// Copyright (c) 2018-2020 Igara Studio S.A.
// Copyright (C) 2018-2020 Igara Studio S.A.
// Copyright (C) 2016-2018 David Capello
//
// This program is distributed under the terms of
Expand Down Expand Up @@ -78,6 +78,10 @@ namespace app {
const gfx::Point& pos,
const bool white);

// Returns the 255 if m_color is the mask color, or the
// m_color.getAlpha() if it's really a color.
int getCurrentAlphaForNewColor() const;

app::Color m_color;

// These flags indicate which areas must be redrawed in the
Expand Down
4 changes: 2 additions & 2 deletions src/app/ui/color_spectrum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ app::Color ColorSpectrum::getMainAreaColor(const int u, const int umax,
MID(0.0, hue, 360.0),
m_color.getHslSaturation(),
MID(0.0, lit, 1.0),
m_color.getAlpha());
getCurrentAlphaForNewColor());
}

app::Color ColorSpectrum::getBottomBarColor(const int u, const int umax)
Expand All @@ -51,7 +51,7 @@ app::Color ColorSpectrum::getBottomBarColor(const int u, const int umax)
m_color.getHslHue(),
MID(0.0, sat, 1.0),
m_color.getHslLightness(),
m_color.getAlpha());
getCurrentAlphaForNewColor());
}

void ColorSpectrum::onPaintMainArea(ui::Graphics* g, const gfx::Rect& rc)
Expand Down
11 changes: 6 additions & 5 deletions src/app/ui/color_tint_shade_tone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include "app/color_utils.h"
#include "app/ui/skin/skin_theme.h"
#include "base/clamp.h"
#include "ui/graphics.h"

namespace app {
Expand All @@ -32,19 +33,19 @@ app::Color ColorTintShadeTone::getMainAreaColor(const int u, const int umax,
double val = (1.0 - double(v) / double(vmax));
return app::Color::fromHsv(
m_color.getHsvHue(),
MID(0.0, sat, 1.0),
MID(0.0, val, 1.0),
m_color.getAlpha());
base::clamp(sat, 0.0, 1.0),
base::clamp(val, 0.0, 1.0),
getCurrentAlphaForNewColor());
}

app::Color ColorTintShadeTone::getBottomBarColor(const int u, const int umax)
{
double hue = (360.0 * u / umax);
return app::Color::fromHsv(
MID(0.0, hue, 360.0),
base::clamp(hue, 0.0, 360.0),
m_color.getHsvSaturation(),
m_color.getHsvValue(),
m_color.getAlpha());
getCurrentAlphaForNewColor());
}

void ColorTintShadeTone::onPaintMainArea(ui::Graphics* g, const gfx::Rect& rc)
Expand Down
13 changes: 7 additions & 6 deletions src/app/ui/color_wheel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "app/ui/skin/skin_theme.h"
#include "app/ui/status_bar.h"
#include "base/bind.h"
#include "base/clamp.h"
#include "base/pi.h"
#include "filters/color_curve.h"
#include "os/surface.h"
Expand Down Expand Up @@ -132,10 +133,10 @@ app::Color ColorWheel::getMainAreaColor(const int _u, const int umax,
}

return app::Color::fromHsv(
MID(0, hue, 360),
MID(0, sat / 100.0, 1.0),
m_color.getHsvValue(),
m_color.getAlpha());
base::clamp(hue, 0, 360),
base::clamp(sat / 100.0, 0.0, 1.0),
(m_color.getType() != Color::MaskType ? m_color.getHsvValue(): 1.0),
getCurrentAlphaForNewColor());
}

// Pick harmonies
Expand Down Expand Up @@ -170,8 +171,8 @@ app::Color ColorWheel::getBottomBarColor(const int u, const int umax)
return app::Color::fromHsv(
m_color.getHsvHue(),
m_color.getHsvSaturation(),
MID(0.0, val, 1.0),
m_color.getAlpha());
base::clamp(val, 0.0, 1.0),
getCurrentAlphaForNewColor());
}

void ColorWheel::onPaintMainArea(ui::Graphics* g, const gfx::Rect& rc)
Expand Down

0 comments on commit fd651c4

Please sign in to comment.