Browse Source

Add Color::plus/minus utils

Signed-off-by: falkTX <falktx@falktx.com>
pull/409/head
falkTX 2 years ago
parent
commit
878a183b59
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
2 changed files with 67 additions and 1 deletions
  1. +25
    -1
      dgl/Color.hpp
  2. +42
    -0
      dgl/src/Color.cpp

+ 25
- 1
dgl/Color.hpp View File

@@ -1,6 +1,6 @@
/* /*
* DISTRHO Plugin Framework (DPF) * DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2012-2022 Filipe Coelho <falktx@falktx.com>
* *
* Permission to use, copy, modify, and/or distribute this software for any purpose with * Permission to use, copy, modify, and/or distribute this software for any purpose with
* or without fee is hereby granted, provided that the above copyright notice and this * or without fee is hereby granted, provided that the above copyright notice and this
@@ -70,6 +70,30 @@ struct Color {
*/ */
Color withAlpha(float alpha) const noexcept; Color withAlpha(float alpha) const noexcept;


/**
Create a new color based on this one but with subtracted numeric value on all elements.
Value must be in [0..255] range.
*/
Color minus(int value) const noexcept;

/**
Create a new color based on this one but with subtracted floating-point value on all elements.
Value must be in [0..1] range.
*/
Color minus(float value) const noexcept;

/**
Create a new color based on this one but with added numeric value on all elements.
Value must be in [0..255] range.
*/
Color plus(int value) const noexcept;

/**
Create a new color based on this one but with added floating-point value on all elements.
Value must be in [0..1] range.
*/
Color plus(float value) const noexcept;

/** /**
Create a color specified by hue, saturation and lightness. Create a color specified by hue, saturation and lightness.
Values must in [0..1] range. Values must in [0..1] range.


+ 42
- 0
dgl/src/Color.cpp View File

@@ -121,6 +121,48 @@ Color Color::withAlpha(const float alpha2) const noexcept
return color; return color;
} }


Color Color::minus(const int value) const noexcept
{
const float fvalue = static_cast<float>(value)/255.f;
Color color(*this);
color.red -= fvalue;
color.green -= fvalue;
color.blue -= fvalue;
color.fixBounds();
return color;
}

Color Color::minus(const float value) const noexcept
{
Color color(*this);
color.red -= value;
color.green -= value;
color.blue -= value;
color.fixBounds();
return color;
}

Color Color::plus(const int value) const noexcept
{
const float fvalue = static_cast<float>(value)/255.f;
Color color(*this);
color.red += fvalue;
color.green += fvalue;
color.blue += fvalue;
color.fixBounds();
return color;
}

Color Color::plus(const float value) const noexcept
{
Color color(*this);
color.red += value;
color.green += value;
color.blue += value;
color.fixBounds();
return color;
}

Color Color::fromHSL(float hue, float saturation, float lightness, float alpha) Color Color::fromHSL(float hue, float saturation, float lightness, float alpha)
{ {
float m1, m2; float m1, m2;


Loading…
Cancel
Save