Tulip  4.3.0
Better Visualization Through Research
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Groups Pages
Color.h
1 /*
2  *
3  * This file is part of Tulip (www.tulip-software.org)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux 1 and Inria Bordeaux - Sud Ouest
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 ///@cond DOXYGEN_HIDDEN
20 
21 #ifndef _COLOR_H
22 #define _COLOR_H
23 #include <tulip/Vector.h>
24 
25 ///
26 namespace tlp {
27 
28 class TLP_SCOPE Color : public tlp::Vector<unsigned char,4> {
29 public:
30  ///
31  inline Color(const tlp::Vector<unsigned char,4>&);
32  ///
33  inline Color(const unsigned char red=0 ,const unsigned char green=0 ,const unsigned char blue=0,const unsigned char alpha=255);
34  ///
35  inline void set(const unsigned char red=0,const unsigned char green=0 ,const unsigned char blue=0, const unsigned char alpha=255);
36  ///
37  inline float getRGL()const;
38  ///
39  inline float getGGL()const;
40  ///
41  inline float getBGL()const;
42  ///
43  inline float getAGL()const;
44  ///
45  inline float* getGL()const;
46  ///
47  inline unsigned char getR()const;
48  ///
49  inline unsigned char getG()const;
50  ///
51  inline unsigned char getB()const;
52  ///
53  inline unsigned char getA()const;
54  ///
55  inline void setR(const unsigned char red);
56  ///
57  inline void setG(const unsigned char green);
58  ///
59  inline void setB(const unsigned char blue);
60  ///
61  inline void setA(const unsigned char alpha);
62  ///
63  long getTrueColor();
64  ///
65  int getH() const;
66  ///
67  int getS() const;
68  ///
69  int getV() const;
70  ///
71  void setH(int );
72  ///
73  void setS(int );
74  ///
75  void setV(int );
76 
77  static const Color Amaranth;
78  static const Color Amber;
79  static const Color Apricot;
80  static const Color Aquamarine;
81  static const Color Azure;
82  static const Color BabyBlue;
83  static const Color Beige;
84  static const Color Black;
85  static const Color Blue;
86  static const Color BlueGreen;
87  static const Color BlueViolet;
88  static const Color Blush;
89  static const Color Bronze;
90  static const Color Brown;
91  static const Color Burgundy;
92  static const Color Byzantium;
93  static const Color Carmine;
94  static const Color Cerise;
95  static const Color Cerulean;
96  static const Color Champagne;
97  static const Color ChartreuseGreen;
98  static const Color Chocolate;
99  static const Color Coffee;
100  static const Color Copper;
101  static const Color Coral;
102  static const Color Crimson;
103  static const Color Cyan;
104  static const Color DesertSand;
105  static const Color ElectricBlue;
106  static const Color Erin;
107  static const Color Gold;
108  static const Color Gray;
109  static const Color Green;
110  static const Color Harlequin;
111  static const Color Indigo;
112  static const Color Ivory;
113  static const Color Jade;
114  static const Color JungleGreen;
115  static const Color Lavender;
116  static const Color Lemon;
117  static const Color Lilac;
118  static const Color Lime;
119  static const Color Magenta;
120  static const Color MagentaRose;
121  static const Color Maroon;
122  static const Color Mauve;
123  static const Color NavyBlue;
124  static const Color Olive;
125  static const Color Orange;
126  static const Color OrangeRed;
127  static const Color Orchid;
128  static const Color Peach;
129  static const Color Pear;
130  static const Color Periwinkle;
131  static const Color PersianBlue;
132  static const Color Pink;
133  static const Color Plum;
134  static const Color PrussianBlue;
135  static const Color Puce;
136  static const Color Purple;
137  static const Color Raspberry;
138  static const Color Red;
139  static const Color RedViolet;
140  static const Color Rose;
141  static const Color Salmon;
142  static const Color Sapphire;
143  static const Color Scarlet;
144  static const Color Silver;
145  static const Color SlateGray;
146  static const Color SpringBud;
147  static const Color SpringGreen;
148  static const Color Tan;
149  static const Color Taupe;
150  static const Color Teal;
151  static const Color Turquoise;
152  static const Color Violet;
153  static const Color Viridian;
154  static const Color White;
155  static const Color Yellow;
156 
157 };
158 
159 TLP_SCOPE std::ostream& operator<<(std::ostream &os,const tlp::Color &);
160 TLP_SCOPE std::istream& operator>>(std::istream &is, tlp::Color &);
161 
162 }
163 
164 tlp::Color::Color(const tlp::Vector<unsigned char,4> &v) : tlp::Vector<unsigned char,4>(v) {}
165 
166 tlp::Color::Color(const unsigned char red ,const unsigned char green ,const unsigned char blue,const unsigned char alpha) {
167  array[0]=red;
168  array[1]=green;
169  array[2]=blue;
170  array[3]=alpha;
171 }
172 void tlp::Color::set(unsigned char red,unsigned char green,unsigned char blue, unsigned char alpha) {
173  array[0]=red;
174  array[1]=green;
175  array[2]=blue;
176  array[3]=alpha;
177 }
178 
179 unsigned char tlp::Color::getR()const {
180  return array[0];
181 }
182 unsigned char tlp::Color::getG()const {
183  return array[1];
184 }
185 unsigned char tlp::Color::getB()const {
186  return array[2];
187 }
188 unsigned char tlp::Color::getA()const {
189  return array[3];
190 }
191 
192 float tlp::Color::getRGL()const {
193  return (float)array[0]/255.0;
194 }
195 float tlp::Color::getGGL()const {
196  return (float)array[1]/255.0;
197 }
198 float tlp::Color::getBGL()const {
199  return (float)array[2]/255.0;
200 }
201 float tlp::Color::getAGL()const {
202  return (float)array[3]/255.0;
203 }
204 float* tlp::Color::getGL()const {
205  float *result=new float[4];
206  result[0]=getRGL();
207  result[1]=getGGL();
208  result[2]=getBGL();
209  result[3]=getAGL();
210  return result;
211 }
212 
213 void tlp::Color::setR(unsigned char red) {
214  array[0]=red;
215 }
216 void tlp::Color::setG(unsigned char green) {
217  array[1]=green;
218 }
219 void tlp::Color::setB(unsigned char blue) {
220  array[2]=blue;
221 }
222 void tlp::Color::setA(unsigned char alpha) {
223  array[3]=alpha;
224 }
225 
226 TLP_BEGIN_HASH_NAMESPACE {
227  template <>
228  struct hash<tlp::Color> {
229  inline std::size_t operator()(const tlp::Color &c) const {
230  return hash_vector(c);
231  }
232  };
233 } TLP_END_HASH_NAMESPACE
234 
235 #endif
236 
237 ///@endcond