SCV  4.2.1
Simple Components for Visual
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Color4f.h
Go to the documentation of this file.
1 #ifndef __SCV_COLOR_4F_H__
2 #define __SCV_COLOR_4F_H__
3 
4 namespace scv {
5 
6 class ColorRGBA;
7 
11 class Color4f {
12 public:
13  explicit Color4f(void);
14  Color4f(float r, float g, float b, float a = 1.f);
15  Color4f(const ColorRGBA &rhs);
16 
17  Color4f operator+(float w) const;
18  Color4f operator-(float w) const;
19  Color4f& operator+=(float w);
20  Color4f& operator-=(float w);
21 
22  inline float& operator[](int index);
23  inline const float& operator[](int index) const;
24 
25  friend std::ostream& operator<<(std::ostream &stream, const Color4f& rhs);
26 
27  static Color4f fromByte(unsigned char r, unsigned char g, unsigned char b, unsigned char a = 255)
28  {
29  return Color4f(r / 255.f, g / 255.f, b / 255.f, a / 255.f);
30  }
31 
32 private:
33  float data[4];
34 };
35 
36 float& Color4f::operator[](int index) {
37  assert(index >= 0 && index < 4);
38  return data[index];
39 }
40 
41 const float& Color4f::operator[](int index) const {
42  assert(index >= 0 && index < 4);
43  return data[index];
44 }
45 
46 } // namespace scv
47 
48 #endif // __SCV_COLOR_4F_H__