FlightGear next
FGColor.hxx
Go to the documentation of this file.
1#ifndef FG_GUI_COLOR_HXX
2#define FG_GUI_COLOR_HXX
3
4// forward decls
5class SGPropertyNode;
6
7class FGColor {
8public:
9 FGColor() { clear(); }
10 FGColor(float r, float g, float b, float a = 1.0f) { set(r, g, b, a); }
11 FGColor(const SGPropertyNode *prop) { set(prop); }
13 if (c) set(c->_red, c->_green, c->_blue, c->_alpha);
14 }
15
16 inline void clear() { _red = _green = _blue = _alpha = -1.0f; }
17 // merges in non-negative components from property with children <red> etc.
18 bool merge(const SGPropertyNode *prop);
19 bool merge(const FGColor *color);
20
21 bool set(const SGPropertyNode *prop) { clear(); return merge(prop); };
22 bool set(const FGColor *color) { clear(); return merge(color); }
23 bool set(float r, float g, float b, float a = 1.0f) {
24 _red = r, _green = g, _blue = b, _alpha = a;
25 return true;
26 }
27 bool isValid() const {
28 return _red >= 0.0 && _green >= 0.0 && _blue >= 0.0;
29 }
30 void print() const;
31
32 inline void setRed(float red) { _red = red; }
33 inline void setGreen(float green) { _green = green; }
34 inline void setBlue(float blue) { _blue = blue; }
35 inline void setAlpha(float alpha) { _alpha = alpha; }
36
37 inline float red() const { return clamp(_red); }
38 inline float green() const { return clamp(_green); }
39 inline float blue() const { return clamp(_blue); }
40 inline float alpha() const { return _alpha < 0.0 ? 1.0f : clamp(_alpha); }
41
42protected:
44
45private:
46 float clamp(float f) const { return f < 0.0 ? 0.0f : f > 1.0 ? 1.0f : f; }
47};
48
49#endif
bool merge(const SGPropertyNode *prop)
Definition FGColor.cxx:22
FGColor(float r, float g, float b, float a=1.0f)
Definition FGColor.hxx:10
void setGreen(float green)
Definition FGColor.hxx:33
float green() const
Definition FGColor.hxx:38
bool set(const FGColor *color)
Definition FGColor.hxx:22
void print() const
Definition FGColor.cxx:16
float _alpha
Definition FGColor.hxx:43
void setBlue(float blue)
Definition FGColor.hxx:34
bool set(float r, float g, float b, float a=1.0f)
Definition FGColor.hxx:23
FGColor(const SGPropertyNode *prop)
Definition FGColor.hxx:11
FGColor()
Definition FGColor.hxx:9
bool isValid() const
Definition FGColor.hxx:27
float alpha() const
Definition FGColor.hxx:40
float blue() const
Definition FGColor.hxx:39
float red() const
Definition FGColor.hxx:37
float _blue
Definition FGColor.hxx:43
void setAlpha(float alpha)
Definition FGColor.hxx:35
float _green
Definition FGColor.hxx:43
void clear()
Definition FGColor.hxx:16
FGColor(FGColor *c)
Definition FGColor.hxx:12
float _red
Definition FGColor.hxx:43
void setRed(float red)
Definition FGColor.hxx:32
bool set(const SGPropertyNode *prop)
Definition FGColor.hxx:21