FIFE  6e1afdbeda11afe9ac53e6023a4be96ef88f1dc6
color.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2017 by the FIFE team *
3  * http://www.fifengine.net *
4  * This file is part of FIFE. *
5  * *
6  * FIFE is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU Lesser General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2.1 of the License, or (at your option) any later version. *
10  * *
11  * This library 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 GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20  ***************************************************************************/
21 
22 #ifndef FIFE_VIDEO_COLOR_H
23 #define FIFE_VIDEO_COLOR_H
24 
25 // Standard C++ library includes
26 #include <string>
27 #include <vector>
28 
29 // Platform specific includes
30 #include "util/base/fife_stdint.h"
31 
32 // 3rd party library includes
33 
34 // FIFE includes
35 // These includes are split up in two parts, separated by one empty line
36 // First block: files included from the FIFE root src directory
37 // Second block: files included from the same folder
38 
39 namespace FIFE {
40  class Color {
41  public:
42 
50  Color(uint8_t r = 0, uint8_t g = 0, uint8_t b = 0, uint8_t alpha = 255);
51 
54  ~Color();
55 
58  inline bool operator==(const Color& color) const {
59  return (m_r == color.m_r && m_g == color.m_g && m_b == color.m_b && m_a == color.m_a);
60  }
61 
64  inline bool operator!=(const Color& color) const {
65  return !(*this == color);
66  }
67 
70  inline bool operator<(const Color& rhs) const {
71  if (m_r != rhs.m_r) {
72  return m_r < rhs.m_r;
73  } else if (m_g != rhs.m_g) {
74  return m_g < rhs.m_g;
75  } else if (m_b != rhs.m_b) {
76  return m_b < rhs.m_b;
77  }
78  return m_a < rhs.m_a;
79  }
80 
88  void set(uint8_t r, uint8_t g, uint8_t b, uint8_t alpha);
89 
94  void setR(uint8_t r);
95 
100  void setG(uint8_t g);
101 
106  void setB(uint8_t b);
107 
112  void setAlpha(uint8_t alpha);
113 
116  uint8_t getR() const;
117 
120  uint8_t getG() const;
121 
124  uint8_t getB() const;
125 
128  uint8_t getAlpha() const;
129 
130  private:
131 
136  };
137 }
138 
139 #endif //FIFE_VIDEO_COLOR_H
uint8_t getG() const
Definition: color.cpp:76
bool operator<(const Color &rhs) const
Overload less operator.
Definition: color.h:70
bool operator==(const Color &color) const
Compares equality of two colors.
Definition: color.h:58
uint8_t getB() const
Definition: color.cpp:80
void setG(uint8_t g)
Set green channel value.
Definition: color.cpp:60
uint8_t getAlpha() const
Definition: color.cpp:84
void setB(uint8_t b)
Set blue channel value.
Definition: color.cpp:64
void setAlpha(uint8_t alpha)
Set alpha channel value.
Definition: color.cpp:68
~Color()
Destructor.
Definition: color.cpp:46
bool operator!=(const Color &color) const
Compares unequality of two colors.
Definition: color.h:64
unsigned char uint8_t
Definition: core.h:38
uint8_t getR() const
Definition: color.cpp:72
uint8_t m_g
Definition: color.h:133
Color(uint8_t r=0, uint8_t g=0, uint8_t b=0, uint8_t alpha=255)
Constructor.
Definition: color.cpp:38
void setR(uint8_t r)
Set red channel value.
Definition: color.cpp:56
uint8_t m_b
Definition: color.h:134
uint8_t m_a
Definition: color.h:135
uint8_t m_r
Definition: color.h:132