C++ main module for gpm Package  1.0
CORE_Color.h
Go to the documentation of this file.
1 #ifndef CORE_Color_H
2 #define CORE_Color_H
3 
4 
5 #include <string>
6 #include "CORE_Object.h"
7 #include "CORE_Pointers.h"
8 #include "CORE_ListPointers.h"
9 #include "types.h"
10 
11 
28 class CORE_Color : public CORE_Object {
30 
31 
32 
33 private:
34  // ATTRIBUTES
35  static const tString DEFAULT_COLORS[];
36  static const int DEFAULT_COLORS_NUMBER;
37  static int DEFAULT_COLOR_INDEX;
38 
39  int mValue;
40  int mOpacity;
41  static double FACTOR;
42  // ASSOCIATIONS
43 
44 
45 public:
46  // METHODS
47 
48  // CONSTRUCTORS
49 
51  CORE_Color(int r,int g,int b);
53  CORE_Color(int r,int g,int b,int a);
55  CORE_Color(int rgb);
58  CORE_Color(const tString& str);
60  CORE_Color();
61 
62 
63  // DESTRUCTORS
64 
65 
68  virtual ~CORE_Color(void);
69 
70 public:
71 
73  inline static SP::CORE_Color New(int r,int g,int b){
74  SP::CORE_Color p(new CORE_Color(r,g,b),CORE_Color::Delete());
75  p->setThis(p);
76  return p;
77  };
78 
80  inline static SP::CORE_Color New(int r,int g,int b,int a){
81  SP::CORE_Color p(new CORE_Color(r,g,b,a),CORE_Color::Delete());
82  p->setThis(p);
83  return p;
84  };
86  inline static SP::CORE_Color New(int rgb){
87  SP::CORE_Color p(new CORE_Color(rgb),CORE_Color::Delete());
88  p->setThis(p);
89  return p;
90  };
92  inline static SP::CORE_Color New(){
93  SP::CORE_Color p(new CORE_Color(),CORE_Color::Delete());
94  p->setThis(p);
95  return p;
96  };
98  inline static SP::CORE_Color New(const tString& value){
99  SP::CORE_Color p(new CORE_Color(value),CORE_Color::Delete());
100  p->setThis(p);
101  return p;
102  };
104  inline static SP::CORE_Color New(const CORE_Color& c){
105  SP::CORE_Color p(new CORE_Color(c.getRed(),c.getGreen(),c.getBlue()),CORE_Color::Delete());
106  p->setThis(p);
107  return p;
108  };
111  inline static SP::CORE_Color NewDefaultColor(const tBoolean& variing) {
112  return New(getDefaultColorString(variing));
113 
114  };
117  inline static SP::CORE_Color NewDefaultColor() {
118  return NewDefaultColor(false);
119  };
122  inline static SP::CORE_Color NewDefaultColor(const int& index,
123  const tBoolean& variing) {
124  return New(getDefaultColorString(index,
125  variing));
126  };
127 
128 
131  inline void setBlack() {setColor(0,0,0);};
134  inline void setWhite() {setColor(255,255,255);};
137  inline void setRed() {setColor(255,0,0);};
140  inline void setGreen() {setColor(0,255,0);};
143  inline void setBlue() {setColor(0,0,255);};
146  inline void setOrange() { setColor(255,108,0);};
149  inline void setYellow() { setColor("#ffff00");};
152  inline void setCyan() { setColor("#00ffff");};
155  inline void setPurple() { setColor("#800080");};
158  inline void setPink() { setColor("#FD6C9E");};
159 
160 
161  // OPERATORS
162 
165  tBoolean isEquals(const SPC::CORE_Color& x) {
166  return (x->getRGB()==getRGB());
167  }
168 
169  // SET methosd
172  inline void setOpacity(const int& opacity) {mOpacity=opacity;}
173 
174 
175  // GET methods
176 
177 
180  inline int getOpacity() const {return mOpacity;};
181 
184  inline static tString getDefaultColorString(const tBoolean& variing) {
185  tString c=DEFAULT_COLORS[DEFAULT_COLOR_INDEX];
186  if (variing)
187  DEFAULT_COLOR_INDEX=(DEFAULT_COLOR_INDEX+1)%DEFAULT_COLORS_NUMBER;
188  return c;
189  };
190 
193  inline static tString getDefaultColorString(const int& index) {
194  return getDefaultColorString(index,false);
195 
196  };
199  inline static tString getDefaultColorString(const int& index,
200  const tBoolean& variing) {
201  DEFAULT_COLOR_INDEX=index%DEFAULT_COLORS_NUMBER;
202  return getDefaultColorString(variing);
203 
204  };
207  inline static tString getDefaultColorString() {
208  return getDefaultColorString(false);
209  };
210 
211 
212 
215  unsigned char * getRGBToArray() const;
221  int getRed() const;
227  int getGreen() const;
233  int getBlue() const;
238  int getAlpha() const;
248  int getRGB() const;
249 
252  inline void getRGBColor(double& r,double& g,double& b) const {
253  r=((double)getRed())/((double)255.0);
254  b=((double)getBlue())/((double)255.0);
255  g=((double)getGreen())/((double) 255.0);
256  };
259  inline void getRGBColor(int& r,int& g,int& b) const {
260  r=getRed();
261  b=getBlue();
262  g=getGreen();
263  };
266  inline void getRGBColor(int& r,int& g,int& b,int& opacity) const {
267  r=getRed();
268  b=getBlue();
269  g=getGreen();
270  opacity=getOpacity();
271  };
272 
273 
274 
275  // OTHERS methods
291  void darker(const SP::CORE_Color& color) const;
306  void brighter(const SP::CORE_Color& color) const;
307 
311  virtual string toString() const {
312  return toString("color[r,g,b]");
313  }
317  inline string name() const {
318  return toString("color[r,g,b,a]");
319  }
320 
324  string toString(const tString& format) const;
325 
327  void setColor(const SPC::CORE_Color& c);
329  void setColor(const SPC::CORE_Color* c){
330  if (c!=null) setColor(*c);
331  };
333  inline void setColor(const CORE_Color& c) {
334  setColor(c.toString());
335  };
337  inline void setColor(const CORE_Color* c) {
338  if (c!=null) setColor(c->toString());
339  };
341  void setColor(const tString& c);
342 
345  void setColor(const SPC::CORE_Color& c0,const SPC::CORE_Color& c1,float f);
348  void setColor(int r,int g,int b);
351  inline void setColor(double r,double g,double b) {
352  setColor((int) r*255,(int) g*255,(int) b*255);
353  };
356  inline void setRGB(const int& rgb) {
357  mValue = 0xff000000 | rgb;
358  };
361  inline void toColor(const tReal& tau,
362  const SPC::CORE_Color& fromColor,
363  const SP::CORE_Color& color) const {
364  toColor(tau,*fromColor.get(),*color.get());
365  };
368  void toColor(const tReal& tau,
369  const CORE_Color& fromColor,
370  CORE_Color& color) const;
371 
372 
373 
374 private:
382  static tBoolean testColorValueRange(int r, int g, int b, int a);
383 
384 
385 
386 
387 };
388 
389 #endif
void setColor(const CORE_Color &c)
set the color to color
Definition: CORE_Color.h:333
void setCyan()
set color to Cyan
Definition: CORE_Color.h:152
static SP::CORE_Color NewDefaultColor(const tBoolean &variing)
create a new default color
Definition: CORE_Color.h:111
#define DEFINE_SPTR(X)
Definition: CORE_Pointers.h:164
static tString getDefaultColorString()
Definition: CORE_Color.h:207
void setOrange()
set color to orange #ff6c00
Definition: CORE_Color.h:146
void setPink()
set color to Pink
Definition: CORE_Color.h:158
void getRGBColor(double &r, double &g, double &b) const
get the rgdb color
Definition: CORE_Color.h:252
void setGreen()
set color to green #00ff00
Definition: CORE_Color.h:140
int getOpacity() const
get opacity
Definition: CORE_Color.h:180
void setBlack()
set color to black #000000
Definition: CORE_Color.h:131
static SP::CORE_Color NewDefaultColor()
create a new default color
Definition: CORE_Color.h:117
static tString getDefaultColorString(const int &index, const tBoolean &variing)
Definition: CORE_Color.h:199
static SP::CORE_Color New(int rgb)
create a color with rgb value
Definition: CORE_Color.h:86
#define tBoolean
Definition: types.h:35
void setRed()
set color to red #ff0000
Definition: CORE_Color.h:137
int getGreen() const
Returns the green component in the range 0-255 in the default sRGB space.
Definition: CORE_Color.cpp:104
string name() const
return the string representation of the color
Definition: CORE_Color.h:317
#define null
Definition: types.h:13
static SP::CORE_Color NewDefaultColor(const int &index, const tBoolean &variing)
create a new default color
Definition: CORE_Color.h:122
static SP::CORE_Color New()
create a color
Definition: CORE_Color.h:92
static SP::CORE_Color New(int r, int g, int b)
create a color with rgb value
Definition: CORE_Color.h:73
void setWhite()
set color to white #ffffff
Definition: CORE_Color.h:134
#define SP_OBJECT(X)
Definition: CORE_Pointers.h:176
static SP::CORE_Color New(const tString &value)
create a color
Definition: CORE_Color.h:98
void setPurple()
set color to Purple
Definition: CORE_Color.h:155
void setOpacity(const int &opacity)
set the opacity in [0,100]
Definition: CORE_Color.h:172
void setColor(double r, double g, double b)
interpolate the color : c=c0+(f-1)*(c1-co)
Definition: CORE_Color.h:351
static tString getDefaultColorString(const int &index)
Definition: CORE_Color.h:193
void setColor(const CORE_Color *c)
set the color to color
Definition: CORE_Color.h:337
void getRGBColor(int &r, int &g, int &b) const
get the rgdb color
Definition: CORE_Color.h:259
static tString getDefaultColorString(const tBoolean &variing)
Definition: CORE_Color.h:184
void getRGBColor(int &r, int &g, int &b, int &opacity) const
get the rgdb color
Definition: CORE_Color.h:266
void toColor(const tReal &tau, const SPC::CORE_Color &fromColor, const SP::CORE_Color &color) const
set the color as an intermediare between from color and this color
Definition: CORE_Color.h:361
abstract base class for most classes.
Definition: CORE_Object.h:30
#define tString
Definition: types.h:36
this class describes color
Definition: CORE_Color.h:28
void setBlue()
set color to blue #0000ff
Definition: CORE_Color.h:143
static SP::CORE_Color New(const CORE_Color &c)
copy a color
Definition: CORE_Color.h:104
void setColor(const SPC::CORE_Color *c)
set the color to color
Definition: CORE_Color.h:329
void setRGB(const int &rgb)
set rgb
Definition: CORE_Color.h:356
int getRed() const
Returns the red component in the range 0-255 in the default sRGB space.
Definition: CORE_Color.cpp:99
static SP::CORE_Color New(int r, int g, int b, int a)
create a color with rgb value in the a base
Definition: CORE_Color.h:80
void setYellow()
set color to yellow
Definition: CORE_Color.h:149
#define tReal
Definition: types.h:18
virtual string toString() const
return the string representation of the color
Definition: CORE_Color.h:311
tBoolean isEquals(const SPC::CORE_Color &x)
test if two color are identical
Definition: CORE_Color.h:165
int getBlue() const
Returns the blue component in the range 0-255 in the default sRGB space.
Definition: CORE_Color.cpp:109
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:106