ASPiK SDK
ccolor.h
1 // This file is part of VSTGUI. It is subject to the license terms
2 // in the LICENSE file found in the top-level directory of this
3 // distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
4 
5 #ifndef __ccolor__
6 #define __ccolor__
7 
8 #include "vstguibase.h"
9 
10 namespace VSTGUI {
11 
12 //-----------------------------------------------------------------------------
14 //-----------------------------------------------------------------------------
15 struct CColor
16 {
17  CColor () = default;
18  CColor (uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = 255)
19  : red (red), green (green), blue (blue), alpha (alpha)
20  {}
21 
22  CColor (const CColor& inColor)
23  : red (inColor.red), green (inColor.green), blue (inColor.blue), alpha (inColor.alpha)
24  {}
25 
26  //-----------------------------------------------------------------------------
28  //-----------------------------------------------------------------------------
30  CColor& operator() (uint8_t _red, uint8_t _green, uint8_t _blue, uint8_t _alpha)
31  {
32  red = _red;
33  green = _green;
34  blue = _blue;
35  alpha = _alpha;
36  return *this;
37  }
38 
39  CColor& operator= (const CColor& newColor)
40  {
41  red = newColor.red;
42  green = newColor.green;
43  blue = newColor.blue;
44  alpha = newColor.alpha;
45  return *this;
46  }
47 
48  bool operator!= (const CColor &other) const
49  { return (red != other.red || green != other.green || blue != other.blue || alpha != other.alpha); }
50 
51  bool operator== (const CColor &other) const
52  { return (red == other.red && green == other.green && blue == other.blue && alpha == other.alpha); }
54 
55  //-----------------------------------------------------------------------------
57  //-----------------------------------------------------------------------------
59 
65  void toHSV (double& hue, double& saturation, double& value) const;
72  void fromHSV (double hue, double saturation, double value);
73 
80  void toHSL (double& hue, double& saturation, double& lightness) const;
87  void fromHSL (double hue, double saturation, double lightness);
88 
90  uint8_t getLuma () const { return (uint8_t)((float)red * 0.3f + (float)green * 0.59f + (float)blue * 0.11f); }
92  uint8_t getLightness () const;
94 
95  uint8_t red {255};
96  uint8_t green {255};
97  uint8_t blue {255};
98  uint8_t alpha {255};
99 };
100 
101 inline CColor MakeCColor (uint8_t red = 0, uint8_t green = 0, uint8_t blue = 0, uint8_t alpha = 255)
102 {
103  return CColor (red, green, blue, alpha);
104 }
105 
106 // define some basic colors
107 extern const CColor kTransparentCColor;
108 extern const CColor kBlackCColor;
109 extern const CColor kWhiteCColor;
110 extern const CColor kGreyCColor;
111 extern const CColor kRedCColor;
112 extern const CColor kGreenCColor;
113 extern const CColor kBlueCColor;
114 extern const CColor kYellowCColor;
115 extern const CColor kCyanCColor;
116 extern const CColor kMagentaCColor;
117 
118 
119 } // namespace
120 
121 #endif
RGBA Color structure.
Definition: ccolor.h:15
uint8_t getLightness() const
Definition: ccolor.cpp:42
void toHSL(double &hue, double &saturation, double &lightness) const
convert to hue, saturation and lightness
Definition: ccolor.cpp:48
void fromHSL(double hue, double saturation, double lightness)
convert from hue, saturation and lightness
Definition: ccolor.cpp:84
uint8_t blue
blue component [0..255]
Definition: ccolor.h:97
Definition: customcontrols.cpp:8
uint8_t green
green component [0..255]
Definition: ccolor.h:96
void toHSV(double &hue, double &saturation, double &value) const
convert to hue, saturation and value
Definition: ccolor.cpp:140
void fromHSV(double hue, double saturation, double value)
convert from hue, saturation and value
Definition: ccolor.cpp:190
uint8_t alpha
alpha component [0..255]
Definition: ccolor.h:98
uint8_t red
red component [0..255]
Definition: ccolor.h:95
uint8_t getLuma() const
Definition: ccolor.h:90