g4tools  5.4.0
colorf
Go to the documentation of this file.
1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
2 // See the file tools.license for terms.
3 
4 #ifndef tools_colorf
5 #define tools_colorf
6 
7 #include "lina/vec4f"
8 
9 namespace tools {
10 
11 class colorf : public vec4f {
12  typedef vec4f parent;
13 public: //for SWIG
14  typedef unsigned char uchar;
15 public:
16  TOOLS_SCLASS(tools::colorf) //for stype()
17 public:
18  colorf():parent(0,0,0,1){}
19 #ifdef TOOLS_MEM
20  colorf(float a_r,float a_g,float a_b,float a_a = 1,bool a_inc = true):parent(a_r,a_g,a_b,a_a,a_inc){}
21 #else
22  colorf(float a_r,float a_g,float a_b,float a_a = 1):parent(a_r,a_g,a_b,a_a){}
23 #endif
24  virtual ~colorf() {}
25 public:
26  colorf(const colorf& a_from):parent(a_from){}
27  colorf& operator=(const colorf& a_from){
28  parent::operator=(a_from);
29  return *this;
30  }
31 public:
32  float r() const {return v0();}
33  float g() const {return v1();}
34  float b() const {return v2();}
35  float a() const {return v3();}
36 
37  void set_r(float a_v) {m_data[0] = a_v;}
38  void set_g(float a_v) {m_data[1] = a_v;}
39  void set_b(float a_v) {m_data[2] = a_v;}
40  void set_a(float a_v) {m_data[3] = a_v;}
41 
42  uchar ruchar() const {return uchar(255.0f*m_data[0]);}
43  uchar guchar() const {return uchar(255.0f*m_data[1]);}
44  uchar buchar() const {return uchar(255.0f*m_data[2]);}
45  uchar auchar() const {return uchar(255.0f*m_data[3]);}
46 
47 #ifdef tools_colorf
48  // deprecated, use the upper ones.
49  uchar rchar() const {return uchar(255.0f*m_data[0]);}
50  uchar gchar() const {return uchar(255.0f*m_data[1]);}
51  uchar bchar() const {return uchar(255.0f*m_data[2]);}
52 #endif
53 
54 public:
55 //#define tools_stat_colorfs
56 #ifdef tools_stat_colorfs
57  //NOTE : the below are deprecated, use functions in inlib/colorfs.
58  // colorf::white() replaced by colorf_white()
59 
60  // our forever 65 named colors taken long time ago from X11.
61 
62  //NOTE : don't handle a static object because of mem balance.
63  //0-9
64  static colorf aquamarine() {return colorf(0.496101F,0.996109F,0.828138F);}
65  static colorf mediumaquamarine() {return colorf(0.398444F,0.800793F,0.664073F);}
66  static colorf black() {return colorf(0,0,0);}
67  static colorf blue() {return colorf(0,0,1);}
68  static colorf cadetblue() {return colorf(0.371099F,0.617197F,0.62501F);}
69  static colorf cornflowerblue() {return colorf(0.390631F,0.58204F,0.925795F);}
70  static colorf darkslateblue() {return colorf(0.281254F,0.238285F,0.542977F);}
71  static colorf lightblue() {return colorf(0.675792F,0.843763F,0.898451F);}
72  static colorf lightsteelblue() {return colorf(0.68751F,0.765637F,0.867201F);}
73  static colorf mediumblue() {return colorf(0,0,0.800793F);}
74 
75  //10-19
76  static colorf mediumslateblue() {return colorf(0.480476F,0.406256F,0.929702F);}
77  static colorf midnightblue() {return colorf(0.0976577F,0.0976577F,0.437507F);}
78  static colorf navyblue() {return colorf(0,0,0.500008F);}
79  static colorf navy() {return colorf(0,0,0.500008F);}
80  static colorf skyblue() {return colorf(0.527352F,0.8047F,0.917983F);}
81  static colorf slateblue() {return colorf(0.414069F,0.351568F,0.800793F);}
82  static colorf steelblue() {return colorf(0.273442F,0.50782F,0.703136F);}
83  static colorf coral() {return colorf(0.996109F,0.496101F,0.312505F);}
84  static colorf cyan() {return colorf(0,1,1);}
85  static colorf firebrick() {return colorf(0.695323F,0.132815F,0.132815F);}
86 
87  //20-29
88  static colorf brown() {return colorf(0.644541F,0.164065F,0.164065F);}
89  static colorf gold() {return colorf(0.996109F,0.839857F,0);}
90  static colorf goldenrod() {return colorf(0.851575F,0.644541F,0.125002F);}
91  static colorf green() {return colorf(0,1,0);}
92  static colorf darkgreen() {return colorf(0,0.390631F,0);}
93  static colorf darkolivegreen() {return colorf(0.332036F,0.417975F,0.183597F);}
94  static colorf forestgreen() {return colorf(0.132815F,0.542977F,0.132815F);}
95  static colorf limegreen() {return colorf(0.195315F,0.800793F,0.195315F);}
96  static colorf mediumseagreen() {return colorf(0.234379F,0.699229F,0.441413F);}
97  static colorf mediumspringgreen() {return colorf(0,0.976577F,0.601572F);}
98 
99  //30-39
100  static colorf palegreen() {return colorf(0.593759F,0.980484F,0.593759F);}
101  static colorf seagreen() {return colorf(0.17969F,0.542977F,0.339849F);}
102  static colorf springgreen() {return colorf(0,0.996109F,0.496101F);}
103  static colorf yellowgreen() {return colorf(0.601572F,0.800793F,0.195315F);}
104  static colorf darkslategrey() {return colorf(0.183597F,0.308598F,0.308598F);}
105  static colorf dimgrey() {return colorf(0.410163F,0.410163F,0.410163F);}
106  static colorf lightgrey() {return colorf(0.824231F,0.824231F,0.824231F);}
107  static colorf grey() {return colorf(0.750011F,0.750011F,0.750011F);}
108  static colorf khaki() {return colorf(0.937514F,0.898451F,0.546883F);}
109  static colorf magenta() {return colorf(1,0,1);}
110 
111  //40-49
112  static colorf maroon() {return colorf(0.68751F,0.187503F,0.375006F);}
113  static colorf orange() {return colorf(0.996109F,0.644541F,0);}
114  static colorf orchid() {return colorf(0.851575F,0.437507F,0.83595F);}
115  static colorf darkorchid() {return colorf(0.597665F,0.195315F,0.796887F);}
116  static colorf mediumorchid() {return colorf(0.726574F,0.332036F,0.824231F);}
117  static colorf pink() {return colorf(0.996109F,0.750011F,0.792981F);}
118  static colorf plum() {return colorf(0.863294F,0.62501F,0.863294F);}
119  static colorf red() {return colorf(1,0,0);}
120  static colorf indianred() {return colorf(0.800793F,0.35938F,0.35938F);}
121  static colorf mediumvioletred() {return colorf(0.777356F,0.0820325F,0.519539F);}
122 
123  //50-59
124  static colorf orangered() {return colorf(0.996109F,0.269535F,0);}
125  static colorf violetred() {return colorf(0.812512F,0.125002F,0.562509F);}
126  static colorf salmon() {return colorf(0.976577F,0.500008F,0.445319F);}
127  static colorf sienna() {return colorf(0.62501F,0.320317F,0.175784F);}
128  static colorf tan() {return colorf(0.820325F,0.703136F,0.546883F);}
129  static colorf thistle() {return colorf(0.843763F,0.746105F,0.843763F);}
130  static colorf turquoise() {return colorf(0.250004F,0.875013F,0.812512F);}
131  static colorf darkturquoise() {return colorf(0,0.8047F,0.816419F);}
132  static colorf mediumturquoise() {return colorf(0.281254F,0.816419F,0.796887F);}
133  static colorf violet() {return colorf(0.929702F,0.50782F,0.929702F);}
134 
135  //60-64
136  static colorf blueviolet() {return colorf(0.539071F,0.167971F,0.882826F);}
137  static colorf wheat() {return colorf(0.957046F,0.867201F,0.699229F);}
138  static colorf white() {return colorf(1,1,1);}
139  static colorf yellow() {return colorf(1,1,0);}
140  static colorf greenyellow() {return colorf(0.675792F,0.996109F,0.18359F);}
141 #endif
142 };
143 
144 struct cmp_colorf {
145  bool operator()(const colorf& a_a,const colorf& a_b) const {
146  // x :
147  if(a_a.v0()<a_b.v0()) return true;
148  if(a_a.v0()>a_b.v0()) return false;
149  // y :
150  if(a_a.v1()<a_b.v1()) return true;
151  if(a_a.v1()>a_b.v1()) return false;
152  // z :
153  if(a_a.v2()<a_b.v2()) return true;
154  return false;
155  }
156 };
157 
158 #if defined(TOOLS_MEM) && !defined(TOOLS_MEM_ATEXIT)
159 inline const colorf& colorf_default() {static const colorf s_v(0.8f,0.8f,0.8f,1,false);return s_v;}
160 #else
161 inline const colorf& colorf_default() {static const colorf s_v(0.8f,0.8f,0.8f,1);return s_v;}
162 #endif
163 
164 }
165 
166 #endif
tools::colorf::set_b
void set_b(float a_v)
Definition: colorf:39
tools::vec4< float >::v1
const float & v1() const
Definition: vec4:86
tools::colorf::set_g
void set_g(float a_v)
Definition: colorf:38
tools::colorf::guchar
uchar guchar() const
Definition: colorf:43
tools::colorf::operator=
colorf & operator=(const colorf &a_from)
Definition: colorf:27
tools::colorf::TOOLS_SCLASS
TOOLS_SCLASS(tools::colorf) public
Definition: colorf:16
tools::colorf::gchar
uchar gchar() const
Definition: colorf:50
tools::vec4< float >::m_data
float m_data[4]
Definition: vec4:262
tools::colorf
Definition: colorf:11
tools::colorf_default
const colorf & colorf_default()
Definition: colorf:161
tools::colorf::g
float g() const
Definition: colorf:33
tools::vec4< float >::v0
const float & v0() const
Definition: vec4:85
tools::colorf::set_r
void set_r(float a_v)
Definition: colorf:37
tools::colorf::colorf
colorf(float a_r, float a_g, float a_b, float a_a=1)
Definition: colorf:22
tools::colorf::colorf
colorf(const colorf &a_from)
Definition: colorf:26
tools::colorf::uchar
unsigned char uchar
Definition: colorf:14
tools::colorf::a
float a() const
Definition: colorf:35
tools::vec4< float >::v2
const float & v2() const
Definition: vec4:87
tools::colorf::bchar
uchar bchar() const
Definition: colorf:51
tools
inlined C code : ///////////////////////////////////
Definition: aida_ntuple:26
tools::cmp_colorf
Definition: colorf:144
tools::cmp_colorf::operator()
bool operator()(const colorf &a_a, const colorf &a_b) const
Definition: colorf:145
tools::colorf::auchar
uchar auchar() const
Definition: colorf:45
tools::colorf::rchar
uchar rchar() const
Definition: colorf:49
tools::vec4f::operator=
vec4f & operator=(const vec4f &a_from)
Definition: vec4f:28
tools::vec4< float >::v3
const float & v3() const
Definition: vec4:88
tools::colorf::buchar
uchar buchar() const
Definition: colorf:44
tools::colorf::r
float r() const
Definition: colorf:32
tools::colorf::set_a
void set_a(float a_v)
Definition: colorf:40
vec4f
tools::colorf::ruchar
uchar ruchar() const
Definition: colorf:42
tools::vec4f
Definition: vec4f:13
tools::colorf::~colorf
virtual ~colorf()
Definition: colorf:24
tools::colorf::b
float b() const
Definition: colorf:34