OpenLexocad  28.0
Color.h
Go to the documentation of this file.
1 #pragma once
2 #include <Base/String.h>
3 #include <list>
4 #include <map>
5 #include <memory>
6 
7 
8 class CA_ColorP;
9 
10 namespace Base
11 {
12 class Color;
13 
14 class LX_BASE_EXPORT MColor
15 {
16 public:
17  MColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
18  MColor();
19  explicit MColor(const Base::Color& c);
20 
21  unsigned char red() const;
22  unsigned char green() const;
23  unsigned char blue() const;
24  unsigned char alpha() const;
25 
26  unsigned char r;
27  unsigned char g;
28  unsigned char b;
29  unsigned char a;
30 
31  bool operator==(const MColor& c) const;
32  bool operator!=(const MColor& c) const;
33 
34  size_t hash() const;
35 };
36 
37 
38 class LX_BASE_EXPORT Color
39 {
40 public:
42  // //
43  // --------------------- BEGIN API --------------------- //
44  // //
45  // ATTENTION: DO NOT CHANGE ANY SIGNATURES IN THE API ! //
46  // //
48 
49  enum Spec
50  {
52  Rgb,
53  Hsv,
54  Cmyk
55  };
56 
57  Color();
58  Color(const Base::MColor& c);
59  Color(int r, int g, int b, int a = 255);
60  Color(const std::string& name);
61  Color(const char* name);
62  Color(const Color& rhs);
63  Color(Spec spec);
64 
65  bool isValid() const;
66 
67  std::string name() const;
68  void setNamedColor(const std::string& name);
69 
70  static std::list<std::string> colorNames();
71 
72  Spec spec() const;
73 
74  int alpha() const;
75  void setAlpha(int alpha);
76 
77  double alphaF() const;
78  void setAlphaF(double alpha);
79 
80  int red() const;
81  int green() const;
82  int blue() const;
83  void setRed(int red);
84  void setGreen(int green);
85  void setBlue(int blue);
86 
87  double redF() const;
88  double greenF() const;
89  double blueF() const;
90  void setRedF(double red);
91  void setGreenF(double green);
92  void setBlueF(double blue);
93 
94  void getRgb(int* r, int* g, int* b, int* a = nullptr) const;
95  void setRgb(int r, int g, int b, int a = 255);
96 
97  void getRgbF(double* r, double* g, double* b, double* a = nullptr) const;
98  void setRgbF(double r, double g, double b, double a = 1.0);
99 
100  int hue() const; // 0 <= hue < 360
101  int saturation() const;
102  int value() const;
103 
104  double hueF() const; // 0.0 <= hueF < 360.0
105  double saturationF() const;
106  double valueF() const;
107 
108  void getHsv(int* h, int* s, int* v, int* a = nullptr) const;
109  void setHsv(int h, int s, int v, int a = 255);
110 
111  void getHsvF(double* h, double* s, double* v, double* a = nullptr) const;
112  void setHsvF(double h, double s, double v, double a = 1.0);
113 
114  int cyan() const;
115  int magenta() const;
116  int yellow() const;
117  int black() const;
118 
119  double cyanF() const;
120  double magentaF() const;
121  double yellowF() const;
122  double blackF() const;
123 
124  void getCmyk(int* c, int* m, int* y, int* k, int* a = nullptr);
125  void setCmyk(int c, int m, int y, int k, int a = 255);
126 
127  void getCmykF(double* c, double* m, double* y, double* k, double* a = nullptr);
128  void setCmykF(double c, double m, double y, double k, double a = 1.0);
129 
130  Color toRgb() const;
131  Color toHsv() const;
132  Color toCmyk() const;
133 
134  Color convertTo(Spec colorSpec) const;
135 
136  static Color fromRgb(int r, int g, int b, int a = 255);
137  static Color fromRgbF(double r, double g, double b, double a = 1.0);
138 
139  static Color fromHsv(int h, int s, int v, int a = 255);
140  static Color fromHsvF(double h, double s, double v, double a = 1.0);
141 
142  static Color fromCmyk(int c, int m, int y, int k, int a = 255);
143  static Color fromCmykF(double c, double m, double y, double k, double a = 1.0);
144 
145  Color light(int f = 150) const;
146  Color lighter(int f = 150) const;
147  Color dark(int f = 200) const;
148  Color darker(int f = 200) const;
149 
151 
152  bool operator==(const Color& c) const;
153  bool operator!=(const Color& c) const;
154  bool operator<(const Color& c) const;
155 
157  static const std::map<std::pair<unsigned int, unsigned int>, Base::Color>& getCdwkPalette();
159  static std::pair<unsigned int, unsigned int> toCdwkColor(const Color& color, bool* isPrecise = nullptr);
161  static Color fromCdwkColor(const unsigned int integerPart, const unsigned int decimalPart = 0);
163  static unsigned int maximumCdwkColorIntegerNumber();
165  static unsigned int maximumDecimalPartNumber();
167  static Base::String getToolTip(const Base::Color& color);
168 
170  static void loadLccColors(const Base::String& filename, bool user = false);
172  static void setLccColors(const std::map<int, Base::Color>& colors, const std::map<Base::Color, Base::String>& tooltips);
173 
175  bool isLcc() const;
177  bool isMainLcc() const;
178 
179  friend std::size_t hash_value(const Color& b) { return b.hash(); }
180 
181  size_t hash() const;
182 
184  // //
185  // ---------------------- END API ---------------------- //
186  // //
188 
189  Color(unsigned int rgb);
191 
192  unsigned int rgb() const;
193  unsigned int rgba() const;
194 
195  friend LX_BASE_EXPORT std::ostream& operator<<(std::ostream& o, const Base::Color& color);
196 
197 private:
198  std::unique_ptr<CA_ColorP> _pimpl;
199 };
200 LX_BASE_EXPORT std::ostream& operator<<(std::ostream& o, const Base::Color& color);
201 }; // namespace Base
Base::Color::getCdwkPalette
static const std::map< std::pair< unsigned int, unsigned int >, Base::Color > & getCdwkPalette()
Provides access to the cadwork palette.
Base::Color::blackF
double blackF() const
Base::Color::setAlphaF
void setAlphaF(double alpha)
Base::Color
Definition: Color.h:39
Base::Color::setAlpha
void setAlpha(int alpha)
Base::MColor::MColor
MColor(const Base::Color &c)
Base::Color::Color
Color(Spec spec)
Base::Color::magentaF
double magentaF() const
Base::Color::colorNames
static std::list< std::string > colorNames()
Base::Color::operator<<
friend LX_BASE_EXPORT std::ostream & operator<<(std::ostream &o, const Base::Color &color)
Base::Color::Color
Color(const Base::MColor &c)
Base::Color::fromHsvF
static Color fromHsvF(double h, double s, double v, double a=1.0)
Base::Color::toCdwkColor
static std::pair< unsigned int, unsigned int > toCdwkColor(const Color &color, bool *isPrecise=nullptr)
Converts a Color to a cadwork color.
Base::MColor
Definition: Color.h:15
Base::MColor::hash
size_t hash() const
Base::Color::cyanF
double cyanF() const
Base::Color::toHsv
Color toHsv() const
Base::MColor::green
unsigned char green() const
Base::MColor::b
unsigned char b
Definition: Color.h:28
Base::Color::operator=
Color & operator=(const Color &)
Base::Color::isMainLcc
bool isMainLcc() const
Returns true if the color is intended to be used for main Lcc elements/components.
Base::Color::rgba
unsigned int rgba() const
Base::Color::Invalid
@ Invalid
Definition: Color.h:51
Base::Color::setRed
void setRed(int red)
Base::Color::maximumCdwkColorIntegerNumber
static unsigned int maximumCdwkColorIntegerNumber()
Returns maximum number in cadwork palette. Classic cadwork palette has numbers [1-256].
Base::Color::getCmykF
void getCmykF(double *c, double *m, double *y, double *k, double *a=nullptr)
Base::MColor::g
unsigned char g
Definition: Color.h:27
Base::Color::saturationF
double saturationF() const
Base::Color::Rgb
@ Rgb
Definition: Color.h:52
Base::Color::alpha
int alpha() const
Base::MColor::red
unsigned char red() const
Base::MColor::r
unsigned char r
Definition: Color.h:26
Base::Color::isValid
bool isValid() const
Base::Color::alphaF
double alphaF() const
Base::Color::getRgb
void getRgb(int *r, int *g, int *b, int *a=nullptr) const
Base::Color::setRedF
void setRedF(double red)
Base::Color::blueF
double blueF() const
Base::Color::setNamedColor
void setNamedColor(const std::string &name)
Base::Color::toRgb
Color toRgb() const
Base::MColor::MColor
MColor()
Base::Color::Color
Color(const std::string &name)
Base::Color::lighter
Color lighter(int f=150) const
Base::Color::setHsvF
void setHsvF(double h, double s, double v, double a=1.0)
Base::Color::redF
double redF() const
Base::Color::hue
int hue() const
Base::Color::blue
int blue() const
Base::Color::setRgb
void setRgb(int r, int g, int b, int a=255)
Base::MColor::alpha
unsigned char alpha() const
Base::Color::red
int red() const
Base::Color::fromRgb
static Color fromRgb(int r, int g, int b, int a=255)
Base::Color::magenta
int magenta() const
Base::Color::getHsvF
void getHsvF(double *h, double *s, double *v, double *a=nullptr) const
Base::Color::setBlue
void setBlue(int blue)
Base::Color::Hsv
@ Hsv
Definition: Color.h:53
Base::Color::saturation
int saturation() const
Base::Color::hash
size_t hash() const
Base::Color::fromCdwkColor
static Color fromCdwkColor(const unsigned int integerPart, const unsigned int decimalPart=0)
Converts a cadwork color to a Color.
Base::MColor::blue
unsigned char blue() const
Base::Color::Color
Color()
Base::Color::toCmyk
Color toCmyk() const
Base::Color::getHsv
void getHsv(int *h, int *s, int *v, int *a=nullptr) const
Base::Color::isLcc
bool isLcc() const
Returns true if the color is intended to be used for Lcc elements/components.
Base::Color::Spec
Spec
Definition: Color.h:50
Base::Color::valueF
double valueF() const
Base::Color::setCmyk
void setCmyk(int c, int m, int y, int k, int a=255)
Base::Color::setBlueF
void setBlueF(double blue)
Base::Color::greenF
double greenF() const
String.h
Base::Color::value
int value() const
Base::Color::operator!=
bool operator!=(const Color &c) const
Base::Color::Color
Color(unsigned int rgb)
Base::Color::getToolTip
static Base::String getToolTip(const Base::Color &color)
Returns tooltip for given color.
Base::Color::hueF
double hueF() const
Base::Color::~Color
~Color()
Base::Color::cyan
int cyan() const
Base::Color::fromCmykF
static Color fromCmykF(double c, double m, double y, double k, double a=1.0)
Base::Color::spec
Spec spec() const
Base::MColor::a
unsigned char a
Definition: Color.h:29
Base::Color::setGreenF
void setGreenF(double green)
Base::Color::operator==
bool operator==(const Color &c) const
Base::Color::fromRgbF
static Color fromRgbF(double r, double g, double b, double a=1.0)
Base::Color::setRgbF
void setRgbF(double r, double g, double b, double a=1.0)
Base::operator<<
LX_BASE_EXPORT std::ostream & operator<<(std::ostream &o, const Base::Color &color)
Base::Color::Color
Color(const Color &rhs)
Base::MColor::MColor
MColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
Base::Color::rgb
unsigned int rgb() const
Base::Color::loadLccColors
static void loadLccColors(const Base::String &filename, bool user=false)
Reloads Lcc colors from the file.
Base::Color::operator<
bool operator<(const Color &c) const
Base::Color::green
int green() const
Base::Color::darker
Color darker(int f=200) const
Base::Color::Color
Color(const char *name)
Base::Color::getRgbF
void getRgbF(double *r, double *g, double *b, double *a=nullptr) const
Base::Color::setCmykF
void setCmykF(double c, double m, double y, double k, double a=1.0)
Base::Color::hash_value
friend std::size_t hash_value(const Color &b)
Definition: Color.h:179
Base::Color::light
Color light(int f=150) const
Base::Color::maximumDecimalPartNumber
static unsigned int maximumDecimalPartNumber()
Returns maximum number that is available in decimal part.
Base::MColor::operator!=
bool operator!=(const MColor &c) const
Base::Color::convertTo
Color convertTo(Spec colorSpec) const
Base::Color::getCmyk
void getCmyk(int *c, int *m, int *y, int *k, int *a=nullptr)
Base::String
A Utf-16 (windows) or ucs4 (unix) encoded string class.
Definition: String.h:18
Base::Color::yellowF
double yellowF() const
Base::Color::setHsv
void setHsv(int h, int s, int v, int a=255)
Base::Color::dark
Color dark(int f=200) const
Base::MColor::operator==
bool operator==(const MColor &c) const
Base::Color::setGreen
void setGreen(int green)
Base::Color::name
std::string name() const
Base::Color::yellow
int yellow() const
Base::Color::fromCmyk
static Color fromCmyk(int c, int m, int y, int k, int a=255)
Base::Color::setLccColors
static void setLccColors(const std::map< int, Base::Color > &colors, const std::map< Base::Color, Base::String > &tooltips)
Sets Lcc colors from the map.
Base::Color::fromHsv
static Color fromHsv(int h, int s, int v, int a=255)
Base
Definition: AbstractXMLReader.h:5
Base::Color::black
int black() const
Base::Color::Color
Color(int r, int g, int b, int a=255)