C++ main module for emicrom 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 
36  //default color string
37  static const tString DEFAULT_COLORS[];
38  //number of default color
40  //default color index
42 
43  //value of the color
45 
46  //opacity of the color
48 
49  //factor for darker or lighter transformation
50  static tFloat FACTOR;
51 
52  // ASSOCIATIONS
53 
54 
55 public:
56  // METHODS
57 
58  // CONSTRUCTORS
59 
61  CORE_Color(const tUChar& r,const tUChar& g,const tUChar& b);
63  CORE_Color(const tUChar& r,const tUChar& g,const tUChar& b,const tUChar& a);
65  CORE_Color(const tUInt& rgb);
68  CORE_Color(const tString& str);
70  CORE_Color();
71 
72 
73  // DESTRUCTORS
74 
75 
78  virtual ~CORE_Color(void);
79 
80 public:
81 
83  inline static SP::CORE_Color New(const tUChar& r,const tUChar& g,const tUChar& b){
84  SP::CORE_Color p(new CORE_Color(r,g,b),CORE_Color::Delete());
85  p->setThis(p);
86  return p;
87  };
88 
90  inline static SP::CORE_Color New(const tUChar& r,const tUChar& g,const tUChar& b,const tUChar& a){
91  SP::CORE_Color p(new CORE_Color(r,g,b,a),CORE_Color::Delete());
92  p->setThis(p);
93  return p;
94  };
96  inline static SP::CORE_Color New(const tUInt& rgb){
97  SP::CORE_Color p(new CORE_Color(rgb),CORE_Color::Delete());
98  p->setThis(p);
99  return p;
100  };
102  inline static SP::CORE_Color New(){
103  SP::CORE_Color p(new CORE_Color(),CORE_Color::Delete());
104  p->setThis(p);
105  return p;
106  };
107 
109  inline static SP::CORE_Color New(const tString& value){
110  SP::CORE_Color p(new CORE_Color(value),CORE_Color::Delete());
111  p->setThis(p);
112  return p;
113  };
115  inline static SP::CORE_Color New(const CORE_Color& c){
116  SP::CORE_Color p(new CORE_Color(c.getRed(),c.getGreen(),c.getBlue()),CORE_Color::Delete());
117  p->setThis(p);
118  return p;
119  };
122  inline static SP::CORE_Color NewDefaultColor(const tBoolean& variing) {
123  return New(getDefaultColorString(variing));
124 
125  };
128  inline static SP::CORE_Color NewDefaultColor() {
129  return NewDefaultColor(false);
130  };
133  inline static SP::CORE_Color NewDefaultColor(const tFlag& index,
134  const tBoolean& variing) {
135  return New(getDefaultColorString(index,
136  variing));
137  };
138 
139 
142  inline void setBlack() {setColor((tUChar)0,(tUChar)0,(tUChar)0);};
145  inline void setWhite() {setColor((tUChar)255,(tUChar)255,(tUChar)255);};
148  inline void setRed() {setColor((tUChar)255,(tUChar)0,(tUChar)0);};
151  inline void setGreen() {setColor((tUChar)0,(tUChar)255,(tUChar)0);};
154  inline void setBlue() {setColor((tUChar)0,(tUChar)0,(tUChar)255);};
157  inline void setOrange() { setColor((tUChar)255,(tUChar)108,(tUChar)0);};
160  inline void setYellow() { setColor("#ffff00");};
163  inline void setCyan() { setColor("#00ffff");};
166  inline void setPurple() { setColor("#800080");};
169  inline void setPink() { setColor("#FD6C9E");};
170 
171 
172  // OPERATORS
173 
177  tBoolean isEquals(const SPC::CORE_Color& x) {
178  return (x->getRGB()==getRGB());
179  }
180 
181  // SET methosd
186  inline void setOpacity(const tUChar& opacity) {mOpacity=opacity;}
187 
191  void setColor(const SPC::CORE_Color& c);
195  void setColor(const SPC::CORE_Color* c){
196  if (c!=null) setColor(*c);
197  };
201  inline void setColor(const CORE_Color& c) {
202  setColor(c.toString());
203  };
205  inline void setColor(const CORE_Color* c) {
206  if (c!=null) setColor(c->toString());
207  };
211  void setColor(const tString& c);
212 
218  void setColor(const SPC::CORE_Color& c0,const SPC::CORE_Color& c1,const tFloat& f);
224  void setColor(const tUChar& r,const tUChar& g,const tUChar& b);
230  inline void setColor(const tFloat& r,const tFloat& g,const tFloat& b) {
231  setColor((tUChar) (r*255),(tUChar) (g*255),(tUChar) (b*255));
232  };
233 
237  inline void setRGB(const tUInt& rgb) {
238  mValue = 0xff000000 | rgb;
239  };
245  inline void toColor(const tFloat& tau,
246  const SPC::CORE_Color& fromColor,
247  const SP::CORE_Color& color) const {
248  toColor(tau,*fromColor.get(),*color.get());
249  };
255  void toColor(const tFloat& tau,
256  const CORE_Color& fromColor,
257  CORE_Color& color) const;
258 
259  // GET methods
260 
261 
265  inline const tUChar& getOpacity() const {return mOpacity;};
266 
272  inline static tString getDefaultColorString(const tBoolean& variing) {
273  tString c=DEFAULT_COLORS[DEFAULT_COLOR_INDEX];
274  if (variing)
275  DEFAULT_COLOR_INDEX=(DEFAULT_COLOR_INDEX+1)%DEFAULT_COLORS_NUMBER;
276  return c;
277  };
278 
283  inline static tString getDefaultColorString(const tFlag& index) {
284  return getDefaultColorString(index,false);
285 
286  };
292  inline static tString getDefaultColorString(const tFlag& index,
293  const tBoolean& variing) {
294  DEFAULT_COLOR_INDEX=index%DEFAULT_COLORS_NUMBER;
295  return getDefaultColorString(variing);
296 
297  };
301  inline static tString getDefaultColorString() {
302  return getDefaultColorString(false);
303  };
304 
305 
306 
312  tUChar getRed() const;
318  tUChar getGreen() const;
324  tUChar getBlue() const;
329  tUChar getAlpha() const;
339  inline const tUInt& getRGB() const {
340  return mValue;
341  }
342 
348  inline void getRGBColor(double& r,double& g,double& b) const {
349  r=((double)getRed())/((double)255.0);
350  b=((double)getBlue())/((double)255.0);
351  g=((double)getGreen())/((double) 255.0);
352  };
358  inline void getRGBColor(tUChar& r,tUChar& g,tUChar& b) const {
359  r=getRed();
360  b=getBlue();
361  g=getGreen();
362  };
369  inline void getRGBColor(tUChar& r,tUChar& g,tUChar& b,tUChar& opacity) const {
370  r=getRed();
371  b=getBlue();
372  g=getGreen();
373  opacity=getOpacity();
374  };
375 
376 
377 
378  // OTHERS methods
394  void darker(const SP::CORE_Color& color) const;
409  void brighter(const SP::CORE_Color& color) const;
413  inline string name() const {
414  return toString("color[r,g,b,a]");
415  }
416 
420  virtual string toString() const {
421  return toString("color[r,g,b]");
422  }
423 
424 
428  string toString(const tString& format) const;
429 
430 
431 
432 
433 
434 
435 
436 
437 };
438 
439 #endif
void setOpacity(const tUChar &opacity)
set the opacity in [0,100]
Definition: CORE_Color.h:186
void setColor(const CORE_Color &c)
set the color to color
Definition: CORE_Color.h:201
void setCyan()
set color to Cyan
Definition: CORE_Color.h:163
string name() const
return the string representation of the color
Definition: CORE_Color.h:413
tUChar getRed() const
Returns the red component in the range 0-255 in the default sRGB space.
Definition: CORE_Color.cpp:71
static SP::CORE_Color NewDefaultColor(const tBoolean &variing)
create a new default color
Definition: CORE_Color.h:122
virtual string toString() const
return the string representation of the color
Definition: CORE_Color.h:420
#define DEFINE_SPTR(X)
Definition: CORE_Pointers.h:191
const tUInt & getRGB() const
Returns the RGB value representing the color in the default sRGB (Bits 24-31 are alpha, 16-23 are red, 8-15 are green, 0-7 are blue).
Definition: CORE_Color.h:339
static SP::CORE_Color New(const tUChar &r, const tUChar &g, const tUChar &b, const tUChar &a)
create a color with rgb value in the a base
Definition: CORE_Color.h:90
static tString getDefaultColorString()
Definition: CORE_Color.h:301
void setOrange()
set color to orange ff6c00
Definition: CORE_Color.h:157
void getRGBColor(tUChar &r, tUChar &g, tUChar &b) const
get the rgdb color
Definition: CORE_Color.h:358
void setPink()
set color to Pink
Definition: CORE_Color.h:169
tUInt mValue
Definition: CORE_Color.h:44
void getRGBColor(double &r, double &g, double &b) const
get the rgdb color
Definition: CORE_Color.h:348
static SP::CORE_Color New(const tUInt &rgb)
create a color with rgb value
Definition: CORE_Color.h:96
void setGreen()
set color to green 00ff00
Definition: CORE_Color.h:151
void setRGB(const tUInt &rgb)
set rgb
Definition: CORE_Color.h:237
#define tFloat
Definition: types.h:50
void setBlack()
set color to black 000000
Definition: CORE_Color.h:142
static SP::CORE_Color NewDefaultColor()
create a new default color
Definition: CORE_Color.h:128
#define tBoolean
Definition: types.h:139
void setRed()
set color to red ff0000
Definition: CORE_Color.h:148
static const tFlag DEFAULT_COLORS_NUMBER
Definition: CORE_Color.h:39
tUChar mOpacity
Definition: CORE_Color.h:47
#define null
Definition: types.h:144
static tFloat FACTOR
Definition: CORE_Color.h:50
static SP::CORE_Color New()
create a color
Definition: CORE_Color.h:102
void setWhite()
set color to white ffffff
Definition: CORE_Color.h:145
#define SP_OBJECT(X)
Definition: CORE_Pointers.h:203
static tFlag DEFAULT_COLOR_INDEX
Definition: CORE_Color.h:41
static tString getDefaultColorString(const tFlag &index)
Definition: CORE_Color.h:283
static SP::CORE_Color New(const tString &value)
create a color
Definition: CORE_Color.h:109
void setPurple()
set color to Purple
Definition: CORE_Color.h:166
const tUChar & getOpacity() const
get opacity
Definition: CORE_Color.h:265
void getRGBColor(tUChar &r, tUChar &g, tUChar &b, tUChar &opacity) const
get the rgdb color
Definition: CORE_Color.h:369
#define tUChar
Definition: types.h:20
#define tUInt
Definition: types.h:33
void setColor(const CORE_Color *c)
set the color to color
Definition: CORE_Color.h:205
tUChar getGreen() const
Returns the green component in the range 0-255 in the default sRGB space.
Definition: CORE_Color.cpp:76
static SP::CORE_Color New(const tUChar &r, const tUChar &g, const tUChar &b)
create a color with rgb value
Definition: CORE_Color.h:83
static SP::CORE_Color NewDefaultColor(const tFlag &index, const tBoolean &variing)
create a new default color
Definition: CORE_Color.h:133
static tString getDefaultColorString(const tBoolean &variing)
get default color string
Definition: CORE_Color.h:272
abstract base class for most classes.
Definition: CORE_Object.h:53
#define tString
Definition: types.h:135
this class describes color
Definition: CORE_Color.h:28
void setColor(const tFloat &r, const tFloat &g, const tFloat &b)
set color
Definition: CORE_Color.h:230
void setBlue()
set color to blue 0000ff
Definition: CORE_Color.h:154
static SP::CORE_Color New(const CORE_Color &c)
copy a color
Definition: CORE_Color.h:115
void setColor(const SPC::CORE_Color *c)
set the color to color
Definition: CORE_Color.h:195
static tString getDefaultColorString(const tFlag &index, const tBoolean &variing)
Definition: CORE_Color.h:292
void toColor(const tFloat &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:245
void setYellow()
set color to yellow
Definition: CORE_Color.h:160
tBoolean isEquals(const SPC::CORE_Color &x)
test if This & x color are identical
Definition: CORE_Color.h:177
tUChar getBlue() const
Returns the blue component in the range 0-255 in the default sRGB space.
Definition: CORE_Color.cpp:81
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:141
#define tFlag
Definition: types.h:74