SUMO - Simulation of Urban MObility
RGBColor.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // A RGB-color definition
20 /****************************************************************************/
21 #ifndef RGBColor_h
22 #define RGBColor_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <iostream>
36 
37 
38 // ===========================================================================
39 // class definitions
40 // ===========================================================================
46 class RGBColor {
47 public:
50  RGBColor();
51 
57  RGBColor(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha = 255);
58 
60  RGBColor(const RGBColor& col);
61 
63  ~RGBColor();
64 
68  unsigned char red() const {
69  return myRed;
70  }
71 
75  unsigned char green() const {
76  return myGreen;
77  }
78 
82  unsigned char blue() const {
83  return myBlue;
84  }
85 
89  unsigned char alpha() const {
90  return myAlpha;
91  }
92 
99  void set(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
100 
106  RGBColor changedBrightness(int change, int toChange = 3) const;
107 
109  RGBColor invertedColor() const;
110 
122  static RGBColor parseColor(std::string coldef);
123 
139  static RGBColor parseColorReporting(const std::string& coldef, const std::string& objecttype,
140  const char* objectid, bool report, bool& ok);
141 
152  static RGBColor interpolate(const RGBColor& minColor, const RGBColor& maxColor, double weight);
153 
161  static RGBColor fromHSV(double h, double s, double v);
162 
168  friend std::ostream& operator<<(std::ostream& os, const RGBColor& col);
169 
170  // @brief Equality operator
171  bool operator==(const RGBColor& c) const;
172 
173  // @brief Inequality operator
174  bool operator!=(const RGBColor& c) const;
175 
178  static const RGBColor RED;
179  static const RGBColor GREEN;
180  static const RGBColor BLUE;
181  static const RGBColor YELLOW;
182  static const RGBColor CYAN;
183  static const RGBColor MAGENTA;
184  static const RGBColor ORANGE;
185  static const RGBColor WHITE;
186  static const RGBColor BLACK;
187  static const RGBColor GREY;
189 
191  static const RGBColor DEFAULT_COLOR;
192 
194  static const std::string DEFAULT_COLOR_STRING;
195 
196 private:
198  unsigned char myRed, myGreen, myBlue, myAlpha;
199 };
200 
201 
202 #endif
203 
204 /****************************************************************************/
205 
static const RGBColor BLUE
Definition: RGBColor.h:180
static RGBColor parseColor(std::string coldef)
Parses a color information.
Definition: RGBColor.cpp:179
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition: RGBColor.cpp:156
~RGBColor()
Destructor.
Definition: RGBColor.cpp:78
static RGBColor fromHSV(double h, double s, double v)
Converts the given hsv-triplet to rgb.
Definition: RGBColor.cpp:301
static const RGBColor WHITE
Definition: RGBColor.h:185
static RGBColor parseColorReporting(const std::string &coldef, const std::string &objecttype, const char *objectid, bool report, bool &ok)
Parses a color information.
Definition: RGBColor.cpp:259
unsigned char alpha() const
Returns the alpha-amount of the color.
Definition: RGBColor.h:89
static const RGBColor ORANGE
Definition: RGBColor.h:184
unsigned char blue() const
Returns the blue-amount of the color.
Definition: RGBColor.h:82
friend std::ostream & operator<<(std::ostream &os, const RGBColor &col)
Writes the color to the given stream.
Definition: RGBColor.cpp:91
static const RGBColor BLACK
Definition: RGBColor.h:186
bool operator==(const RGBColor &c) const
Definition: RGBColor.cpp:133
RGBColor invertedColor() const
obtain inverted of current RGBColor
Definition: RGBColor.cpp:145
bool operator!=(const RGBColor &c) const
Definition: RGBColor.cpp:139
static const RGBColor GREEN
Definition: RGBColor.h:179
static const RGBColor GREY
Definition: RGBColor.h:187
unsigned char myAlpha
Definition: RGBColor.h:198
unsigned char myRed
The color amounts.
Definition: RGBColor.h:198
static const RGBColor DEFAULT_COLOR
The default color (for vehicle types and vehicles)
Definition: RGBColor.h:191
unsigned char myGreen
Definition: RGBColor.h:198
static const RGBColor MAGENTA
Definition: RGBColor.h:183
static const RGBColor YELLOW
Definition: RGBColor.h:181
static const RGBColor RED
named colors
Definition: RGBColor.h:178
static const RGBColor CYAN
Definition: RGBColor.h:182
unsigned char green() const
Returns the green-amount of the color.
Definition: RGBColor.h:75
unsigned char myBlue
Definition: RGBColor.h:198
unsigned char red() const
Returns the red-amount of the color.
Definition: RGBColor.h:68
RGBColor()
Constructor.
Definition: RGBColor.cpp:66
static RGBColor interpolate(const RGBColor &minColor, const RGBColor &maxColor, double weight)
Interpolates between two colors.
Definition: RGBColor.cpp:285
static const std::string DEFAULT_COLOR_STRING
The string description of the default color.
Definition: RGBColor.h:194