neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
hsl_color.hpp
Go to the documentation of this file.
1// hsl_color.hpp
2/*
3 neogfx C++ App/Game Engine
4 Copyright (c) 2015, 2020 Leigh Johnston. All Rights Reserved.
5
6 This program is free software: you can redistribute it and / or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#pragma once
21
22#include <neogfx/neogfx.hpp>
24
25namespace neogfx
26{
27 template <color_space ColorSpace, typename BaseComponent, typename ViewComponent, typename Derived>
28 class basic_rgb_color;
29
31 {
32 public:
34 hsl_color(double aHue, double aSaturation, double aLightness, double aAlpha = 1.0);
35 template <color_space ColorSpace, typename BaseComponent, typename ViewComponent = BaseComponent, typename Derived = void>
38 public:
39 double hue() const;
40 double saturation() const;
41 double lightness() const;
42 double alpha() const;
43 void set_hue(double aHue);
44 void set_saturation(double aSaturation);
45 void set_lightness(double aLightness);
46 void set_alpha(double aAlpha);
47 bool hue_undefined() const;
48 public:
49 hsl_color with_hue(double aNewHue) const;
50 hsl_color with_saturation(double aNewSaturation) const;
51 hsl_color with_lightness(double aNewLightness) const;
52 hsl_color lighter(double aDelta) const;
53 hsl_color lighter(double aCoeffecient, double aDelta) const;
54 hsl_color shade(double aDelta) const;
55 hsl_color unshade(double aDelta) const;
56 void to_rgb(scalar& aRed, scalar& aGreen, scalar& aBlue, scalar& aAlpha) const;
57 template <typename RgbColor>
58 typename RgbColor::return_type to_rgb() const
59 {
60 vec4 components;
61 to_rgb(components.x, components.y, components.z, components[3]);
62 typename RgbColor::return_type result;
63 result.set_red<scalar>(components.x);
64 result.set_green<scalar>(components.y);
65 result.set_blue<scalar>(components.z);
66 result.set_alpha<scalar>(components[3]);
67 return result;
68 }
69 static hsl_color from_rgb(scalar aRed, scalar aGreen, scalar aBlue, scalar aAlpha = 1.0);
70 template <color_space ColorSpace, typename BaseComponent, typename ViewComponent = BaseComponent, typename Derived = void>
72 {
73 return from_rgb(aColor.template red<scalar>(), aColor.template green<scalar>(), aColor.template blue<scalar>(), aColor.template alpha<scalar>());
74 }
75 public:
76 static double undefined_hue();
77 public:
78 bool operator==(const hsl_color& aOther) const;
79 bool operator!=(const hsl_color& aOther) const;
80 bool operator<(const hsl_color& aOther) const;
81 private:
82 double iHue;
83 double iSaturation;
84 double iLightness;
85 double iAlpha;
86 };
87}
hsl_color unshade(double aDelta) const
static double undefined_hue()
hsl_color shade(double aDelta) const
hsl_color(const basic_rgb_color< ColorSpace, BaseComponent, ViewComponent, Derived > &aColor)
Definition hsl_color.hpp:36
static hsl_color from_rgb(const basic_rgb_color< ColorSpace, BaseComponent, ViewComponent, Derived > &aColor)
Definition hsl_color.hpp:71
void set_lightness(double aLightness)
void set_hue(double aHue)
double hue() const
bool operator!=(const hsl_color &aOther) const
double alpha() const
hsl_color with_hue(double aNewHue) const
hsl_color lighter(double aCoeffecient, double aDelta) const
void set_alpha(double aAlpha)
double saturation() const
hsl_color with_saturation(double aNewSaturation) const
void set_saturation(double aSaturation)
double lightness() const
hsl_color lighter(double aDelta) const
hsl_color with_lightness(double aNewLightness) const
static hsl_color from_rgb(scalar aRed, scalar aGreen, scalar aBlue, scalar aAlpha=1.0)
bool operator<(const hsl_color &aOther) const
bool operator==(const hsl_color &aOther) const
hsl_color(double aHue, double aSaturation, double aLightness, double aAlpha=1.0)
void to_rgb(scalar &aRed, scalar &aGreen, scalar &aBlue, scalar &aAlpha) const
bool hue_undefined() const
RgbColor::return_type to_rgb() const
Definition hsl_color.hpp:58
double scalar
Definition numerical.hpp:63