Browse Source

Add convenience Color::withAlpha method

Signed-off-by: falkTX <falktx@falktx.com>
pull/293/head
falkTX 3 years ago
parent
commit
6d57f75c6a
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
2 changed files with 12 additions and 0 deletions
  1. +5
    -0
      dgl/Color.hpp
  2. +7
    -0
      dgl/src/Color.cpp

+ 5
- 0
dgl/Color.hpp View File

@@ -65,6 +65,11 @@ struct Color {
*/ */
Color(const Color& color1, const Color& color2, float u) noexcept; Color(const Color& color1, const Color& color2, float u) noexcept;


/**
Create a new color based on this one but with a different alpha value.
*/
Color withAlpha(float alpha) 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.


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

@@ -114,6 +114,13 @@ Color::Color(const Color& color1, const Color& color2, const float u) noexcept
interpolate(color2, u); interpolate(color2, u);
} }


Color Color::withAlpha(const float alpha) noexcept
{
Color color(*this);
color.alpha = alpha;
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