neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
hsv_color.hpp
Go to the documentation of this file.
1// hsv_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>
23
24namespace neogfx
25{
26 template <color_space ColorSpace, typename BaseComponent, typename ViewComponent, typename Derived>
27 class basic_rgb_color;
28
30 {
31 public:
33 hsv_color(double aHue, double aSaturation, double aValue, double aAlpha = 1.0);
34 template <color_space ColorSpace, typename BaseComponent, typename ViewComponent = BaseComponent, typename Derived = void>
37 public:
38 double hue() const;
39 double saturation() const;
40 double value() const;
41 double brightness() const;
42 double alpha() const;
43 void set_hue(double aHue);
44 void set_saturation(double aSaturation);
45 void set_value(double aValue);
46 void set_brightness(double aBrightness);
47 void set_alpha(double aAlpha);
48 bool hue_undefined() const;
49 public:
50 hsv_color with_hue(double aNewHue) const;
51 hsv_color with_saturation(double aNewSaturation) const;
52 hsv_color with_value(double aNewValue) const;
53 hsv_color with_brightness(double aNewLightness) const;
54 hsv_color brighter(double aDelta) const;
55 hsv_color brighter(double aCoeffecient, 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 hsv_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 hsv_color& aOther) const;
79 bool operator!=(const hsv_color& aOther) const;
80 bool operator<(const hsv_color& aOther) const;
81 private:
82 double iHue;
83 double iSaturation;
84 double iValue;
85 double iAlpha;
86 };
87}
void set_alpha(double aAlpha)
RgbColor::return_type to_rgb() const
Definition hsv_color.hpp:58
bool operator<(const hsv_color &aOther) const
double hue() const
static hsv_color from_rgb(const basic_rgb_color< ColorSpace, BaseComponent, ViewComponent, Derived > &aColor)
Definition hsv_color.hpp:71
double value() const
void set_hue(double aHue)
hsv_color brighter(double aCoeffecient, double aDelta) const
hsv_color with_hue(double aNewHue) const
static double undefined_hue()
double saturation() const
double alpha() const
void to_rgb(scalar &aRed, scalar &aGreen, scalar &aBlue, scalar &aAlpha) const
hsv_color with_value(double aNewValue) const
hsv_color brighter(double aDelta) const
double brightness() const
hsv_color with_brightness(double aNewLightness) const
hsv_color with_saturation(double aNewSaturation) const
void set_brightness(double aBrightness)
bool operator==(const hsv_color &aOther) const
void set_value(double aValue)
bool operator!=(const hsv_color &aOther) const
hsv_color(double aHue, double aSaturation, double aValue, double aAlpha=1.0)
hsv_color(const basic_rgb_color< ColorSpace, BaseComponent, ViewComponent, Derived > &aColor)
Definition hsv_color.hpp:35
bool hue_undefined() const
static hsv_color from_rgb(scalar aRed, scalar aGreen, scalar aBlue, scalar aAlpha=1.0)
void set_saturation(double aSaturation)
double scalar
Definition numerical.hpp:63