00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
#ifndef UCOLOR_HPP
00029
#define UCOLOR_HPP
00030
00031
#include "../uobject.hpp"
00032
#include "../ufo_types.hpp"
00033
00034
namespace ufo {
00035
00047 class UFO_EXPORT UColor {
00048
00049
public:
00050
static const UColor red;
00051
static const UColor green;
00052
static const UColor blue;
00053
00054
static const UColor darkRed;
00055
static const UColor darkGreen;
00056
static const UColor darkBlue;
00057
00058
static const UColor white;
00059
static const UColor black;
00060
00061
static const UColor gray;
00062
static const UColor darkGray;
00063
static const UColor lightGray;
00064
00065
static const UColor cyan;
00066
static const UColor magenta;
00067
static const UColor yellow;
00068
00069
static const UColor darkCyan;
00070
static const UColor darkMagenta;
00071
static const UColor darkYellow;
00072
00073
00074
00075
00076
public:
00078 UColor();
00079 UColor(
const UColor & col);
00089
explicit UColor(
const std::string & colorString);
00090
explicit UColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255);
00091
explicit UColor(
const uint8_t rgba[],
bool hasAlpha =
false);
00092
explicit UColor(
int r,
int g,
int b,
int a = 255);
00093
explicit UColor(
const int rgba[],
bool hasAlpha =
false);
00094
explicit UColor(
float r,
float g,
float b,
float a = 1.0f);
00095
explicit UColor(
const float rgba[],
bool hasAlpha =
false);
00096
explicit UColor(
double r,
double g,
double b,
double a = 1.0);
00097
explicit UColor(
const double rgba[],
bool hasAlpha =
false);
00098
00102
const float * getFloat()
const;
00106
float * getFloat();
00107
00108
float getRed()
const;
00109
float getGreen()
const;
00110
float getBlue()
const;
00111
float getAlpha()
const;
00112
00113 uint32_t getArgb()
const;
00114 uint32_t getRgba()
const;
00115
00119 UColor darker()
const;
00123 UColor brighter()
const;
00124
00126
bool isBlack()
const;
00128
bool isWhite()
const;
00129
00130
public:
00131
friend bool operator==(
const UColor & col1,
const UColor & col2);
00132
friend bool operator!=(
const UColor & col1,
const UColor & col2);
00133
00134
friend std::ostream & operator<<(std::ostream & os,
const UColor & col);
00135
00136
private:
00140
float m_farr[4];
00141
00143
static const float FACTOR;
00144
static const float MIN_VAL;
00145 };
00146
00147
00153 class UFO_EXPORT UColorObject :
public UColor,
public UObject {
00154 UFO_DECLARE_DYNAMIC_CLASS(UColorObject)
00155
public:
00156 UColorObject();
00157
explicit UColorObject(
const std::string & colorString);
00158
explicit UColorObject(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255);
00159
explicit UColorObject(
const uint8_t rgba[],
bool hasAlpha =
false);
00160
explicit UColorObject(
int r,
int g,
int b,
int a = 255);
00161
explicit UColorObject(
const int rgba[],
bool hasAlpha =
false);
00162
explicit UColorObject(
float r,
float g,
float b,
float a = 1.0f);
00163
explicit UColorObject(
const float rgba[],
bool hasAlpha =
false);
00164
explicit UColorObject(
double r,
double g,
double b,
double a = 1.0);
00165
explicit UColorObject(
const double rgba[],
bool hasAlpha =
false);
00166
00167
public:
00168
virtual unsigned int hashCode()
const;
00169
virtual bool equals(
const UObject * obj);
00170
virtual bool equals(
const UColorObject * obj);
00171
virtual UObject * clone()
const;
00172
00173
protected:
00174
virtual std::ostream & paramString(std::ostream & os)
const;
00175 };
00176
00177
00178
00179
00180
00181
00182
00183
inline const float *
00184 UColor::getFloat()
const {
00185
return m_farr;
00186 }
00187
00188
inline float *
00189 UColor::getFloat() {
00190
return m_farr;
00191 }
00192
00193
inline float
00194 UColor::getRed()
const {
00195
return m_farr[0];
00196 }
00197
00198
inline float
00199 UColor::getGreen()
const {
00200
return m_farr[1];
00201 }
00202
00203
inline float
00204 UColor::getBlue()
const {
00205
return m_farr[2];
00206 }
00207
00208
inline float
00209 UColor::getAlpha()
const {
00210
return m_farr[3];
00211 }
00212
00213
inline bool
00214 UColor::isBlack()
const {
00215
return ((m_farr[0] == 0.f) && (m_farr[1] == 0.f) && (m_farr[2] == 0.f));
00216 }
00217
00218
inline bool
00219 UColor::isWhite()
const {
00220
return ((m_farr[0] == 1.f) && (m_farr[1] == 1.f) && (m_farr[2] == 1.f));
00221 }
00222
00223
00224
inline bool operator==(
const UColor & col1,
const UColor & col2) {
00225
return ((col1.
m_farr[0] == col2.
m_farr[0]) &&
00226 (col1.
m_farr[1] == col2.
m_farr[1]) &&
00227 (col1.
m_farr[2] == col2.
m_farr[2]) &&
00228 (col1.
m_farr[3] == col2.
m_farr[3])
00229 );
00230 }
00231
00232
inline bool operator!=(
const UColor & col1,
const UColor & col2) {
00233
return !(operator==(col1, col2));
00234 }
00235
00236
inline std::ostream &
00237 operator<<(std::ostream & os,
const UColor & col) {
00238
return os <<
"UColor["
00239 << col.m_farr[0] <<
","
00240 << col.m_farr[1] <<
","
00241 << col.m_farr[2] <<
","
00242 << col.m_farr[3]
00243 <<
"]";
00244 }
00245
00246
00247
00248
00249
00250
00251
inline
00252 UColorObject::UColorObject() {}
00253
00254
inline
00255 UColorObject::UColorObject(
const std::string & colorString)
00256 : UColor(colorString)
00257 {}
00258
00259
inline
00260 UColorObject::UColorObject(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
00261 : UColor(r, g, b, a)
00262 {}
00263
00264
inline
00265 UColorObject::UColorObject(
const uint8_t rgba[],
bool hasAlpha)
00266 : UColor(rgba, hasAlpha)
00267 {}
00268
00269
inline
00270 UColorObject::UColorObject(
int r,
int g,
int b,
int a)
00271 : UColor(r, g, b, a)
00272 {}
00273
00274
inline
00275 UColorObject::UColorObject(
const int rgba[],
bool hasAlpha)
00276 : UColor(rgba, hasAlpha)
00277 {}
00278
00279
inline
00280 UColorObject::UColorObject(
float r,
float g,
float b,
float a)
00281 : UColor(r, g, b, a)
00282 {}
00283
00284
inline
00285 UColorObject::UColorObject(
const float rgba[],
bool hasAlpha)
00286 : UColor(rgba, hasAlpha)
00287 {}
00288
00289
inline
00290 UColorObject::UColorObject(
double r,
double g,
double b,
double a)
00291 : UColor(r, g, b, a)
00292 {}
00293
00294
inline
00295 UColorObject::UColorObject(
const double rgba[],
bool hasAlpha)
00296 : UColor(rgba, hasAlpha)
00297 {}
00298
00299 }
00300
00301
#endif // UCOLOR_HPP