Skip to content

Commit

Permalink
clang-tidy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Charlie-83 committed Mar 7, 2024
1 parent 65d5c42 commit 1590bcb
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 36 deletions.
25 changes: 24 additions & 1 deletion src/app/ui/color_selector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,11 +585,34 @@ void ColorSelector::paintColorIndicator(ui::Graphics* g,

g->drawColoredRgbaSurface(
icon,
white ? gfx::rgba(255, 255, 255, alpha): gfx::rgba(0, 0, 0, alpha),
white ? gfx::rgba(255, 255, 255): gfx::rgba(0, 0, 0),
pos.x-icon->width()/2,
pos.y-icon->height()/2);
}

void ColorSelector::paintColorIndicatorChain(ui::Graphics* g,
const std::vector<gfx::Point>& positions,
const std::vector<bool> white,
const int current)
{
auto theme = SkinTheme::get(this);
os::Surface* icon = theme->parts.colorWheelIndicator()->bitmap(0);

for (int i=0; i<positions.size(); i++)
{
int alpha = i == current ? 255 : 50;
auto color =
white.at(i) ? gfx::rgba(255, 255, 255, alpha): gfx::rgba(0, 0, 0, alpha);
g->drawColoredRgbaSurface(
icon,
color,
positions.at(i).x-icon->width()/2,
positions.at(i).y-icon->height()/2);
if (i < positions.size()-1)
g->drawLine(color, positions.at(i), positions.at(i+1));
}
}

int ColorSelector::getCurrentAlphaForNewColor() const
{
if (m_color.getType() != Color::MaskType)
Expand Down
10 changes: 7 additions & 3 deletions src/app/ui/color_selector.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,13 @@ namespace app {
virtual bool subColorPicked() { return false; }

void paintColorIndicator(ui::Graphics* g,
const gfx::Point& pos,
const bool white,
const int alpha=255);
gfx::Point& pos,
bool white,
int alpha=255);
void paintColorIndicatorChain(ui::Graphics* g,
std::vector<gfx::Point>& positions,
std::vector<bool> white,
int current);

// Returns the 255 if m_color is the mask color, or the
// m_color.getAlpha() if it's really a color.
Expand Down
66 changes: 34 additions & 32 deletions src/app/ui/color_spectrum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,29 +106,33 @@ void ColorSpectrum::onPaintMainArea(ui::Graphics* g, const gfx::Rect& rc)
{
doc::PalettePicks picks;
ColorBar::instance()->getPaletteView()->getSelectedEntries(picks);
if (picks.picks() > 1)
{
if (picks.picks() > 1) {
std::vector<gfx::Point> positions;
std::vector<bool> white;
int current;
for (int i = 0; i<picks.size(); i++) {
if (!picks[i])
if (picks[i] == 0)
continue;
Color color = app::Color::fromIndex(i);
Color const color = app::Color::fromIndex(i);
if (color.getType() != app::Color::MaskType) {
double hue = color.getHslHue();
double lit = color.getHslLightness();
gfx::Point pos(rc.x + int(hue * rc.w / 360.0),
double const hue = color.getHslHue();
double const lit = color.getHslLightness();
gfx::Point const pos(rc.x + int(hue * rc.w / 360.0),
rc.y + rc.h - int(lit * rc.h));

int alpha = color == m_color ? 255 : 100;
paintColorIndicator(g, pos, lit < 0.5, alpha);
if (color == m_color)
current = positions.size();
positions.push_back(pos);
white.push_back(lit < 0.5);
}
}
paintColorIndicatorChain(g, positions, white, current);
}
else
{
else {
if (m_color.getType() != app::Color::MaskType) {
double hue = m_color.getHslHue();
double lit = m_color.getHslLightness();
gfx::Point pos(rc.x + int(hue * rc.w / 360.0),
double const hue = m_color.getHslHue();
double const lit = m_color.getHslLightness();
gfx::Point const pos(rc.x + int(hue * rc.w / 360.0),
rc.y + rc.h - int(lit * rc.h));

paintColorIndicator(g, pos, lit < 0.5);
Expand All @@ -140,32 +144,30 @@ void ColorSpectrum::onPaintBottomBar(ui::Graphics* g, const gfx::Rect& rc)
{
doc::PalettePicks picks;
ColorBar::instance()->getPaletteView()->getSelectedEntries(picks);
if (picks.picks() > 1)
{
if (picks.picks() > 1) {
for (int i = 0; i<picks.size(); i++) {
if (!picks[i])
if (picks[i] == 0)
continue;
Color color = app::Color::fromIndex(i);
double lit = color.getHslLightness();
Color const color = app::Color::fromIndex(i);
double const lit = color.getHslLightness();
if (color.getType() != app::Color::MaskType) {
double sat = color.getHslSaturation();
gfx::Point pos(rc.x + int(double(rc.w) * sat),
double const sat = color.getHslSaturation();
gfx::Point const pos(rc.x + int(double(rc.w) * sat),
rc.y + rc.h/2);
int alpha = color == m_color ? 255 : 100;
int alpha = color == m_color ? 255 : 50;
paintColorIndicator(g, pos, lit < 0.5, alpha);
}
}
}
else
{
double lit = m_color.getHslLightness();
if (m_color.getType() != app::Color::MaskType) {
double sat = m_color.getHslSaturation();
gfx::Point pos(rc.x + int(double(rc.w) * sat),
rc.y + rc.h/2);
paintColorIndicator(g, pos, lit < 0.5);
}
}
else {
double const lit = m_color.getHslLightness();
if (m_color.getType() != app::Color::MaskType) {
double const sat = m_color.getHslSaturation();
gfx::Point const pos(rc.x + int(double(rc.w) * sat),
rc.y + rc.h/2);
paintColorIndicator(g, pos, lit < 0.5);
}
}
}

void ColorSpectrum::onPaintSurfaceInBgThread(
Expand Down

0 comments on commit 1590bcb

Please sign in to comment.