diff --git a/dgl/Color.hpp b/dgl/Color.hpp index 42094950..fbce9cc2 100644 --- a/dgl/Color.hpp +++ b/dgl/Color.hpp @@ -65,6 +65,11 @@ struct Color { */ 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. Values must in [0..1] range. diff --git a/dgl/src/Color.cpp b/dgl/src/Color.cpp index 07036490..4aa6b45d 100644 --- a/dgl/src/Color.cpp +++ b/dgl/src/Color.cpp @@ -114,6 +114,13 @@ Color::Color(const Color& color1, const Color& color2, const float u) noexcept 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) { float m1, m2;