| 1 |
/*************************************************************************** |
| 2 |
* Copyright (C) 2005-2019 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 |
|
| 43 |
/** Constructor. |
| 44 |
* |
| 45 |
* @param r Red channel value. |
| 46 |
* @param g Green channel value. |
| 47 |
* @param b Blue channel value. |
| 48 |
* @param alpha Alpha channel value. |
| 49 |
*/ |
| 50 |
Color(uint8_t r = 0, uint8_t g = 0, uint8_t b = 0, uint8_t alpha = 255); |
| 51 |
|
| 52 |
/** Destructor |
| 53 |
*/ |
| 54 |
~Color(); |
| 55 |
|
| 56 |
/** Compares equality of two colors |
| 57 |
*/ |
| 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 |
|
| 62 |
/** Compares unequality of two colors |
| 63 |
*/ |
| 64 |
inline bool operator!=(const Color& color) const { |
| 65 |
return !(*this == color); |
| 66 |
} |
| 67 |
|
| 68 |
/** Overload less operator |
| 69 |
*/ |
| 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 |
|
| 81 |
/** Set all color channel values. |
| 82 |
* |
| 83 |
* @param r Red channel value. |
| 84 |
* @param g Green channel value. |
| 85 |
* @param b Blue channel value. |
| 86 |
* @param alpha Alpha channel value. |
| 87 |
*/ |
| 88 |
void set(uint8_t r, uint8_t g, uint8_t b, uint8_t alpha); |
| 89 |
|
| 90 |
/** Set red channel value. |
| 91 |
* |
| 92 |
* @param r New value. |
| 93 |
*/ |
| 94 |
void setR(uint8_t r); |
| 95 |
|
| 96 |
/** Set green channel value. |
| 97 |
* |
| 98 |
* @param g New value. |
| 99 |
*/ |
| 100 |
void setG(uint8_t g); |
| 101 |
|
| 102 |
/** Set blue channel value. |
| 103 |
* |
| 104 |
* @param b New value. |
| 105 |
*/ |
| 106 |
void setB(uint8_t b); |
| 107 |
|
| 108 |
/** Set alpha channel value. |
| 109 |
* |
| 110 |
* @param alpha New value. |
| 111 |
*/ |
| 112 |
void setAlpha(uint8_t alpha); |
| 113 |
|
| 114 |
/** @return Red channel value. |
| 115 |
*/ |
| 116 |
uint8_t getR() const; |
| 117 |
|
| 118 |
/** @return Green channel value. |
| 119 |
*/ |
| 120 |
uint8_t getG() const; |
| 121 |
|
| 122 |
/** @return Blue channel value. |
| 123 |
*/ |
| 124 |
uint8_t getB() const; |
| 125 |
|
| 126 |
/** @return Alpha channel value. |
| 127 |
*/ |
| 128 |
uint8_t getAlpha() const; |
| 129 |
|
| 130 |
private: |
| 131 |
|
| 132 |
uint8_t m_r; |
| 133 |
uint8_t m_g; |
| 134 |
uint8_t m_b; |
| 135 |
uint8_t m_a; |
| 136 |
}; |
| 137 |
} |
| 138 |
|
| 139 |
#endif //FIFE_VIDEO_COLOR_H |