OpenLexocad  27.1
Color.h
Go to the documentation of this file.
1 #pragma once
2 
3 #pragma warning(push)
4 #pragma warning(disable : 4251)
5 
6 #include <list>
7 #include <map>
8 #include <memory>
9 #include <string>
10 #include <vector>
11 
12 class CA_ColorP;
13 
14 // Smart pointer to private implementation of Color
15 typedef std::unique_ptr<CA_ColorP> pCA_ColorP;
16 
17 namespace Base
18 {
19 class Color;
20 
21 class LX_BASE_EXPORT MColor
22 {
23 public:
24  MColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
25  MColor();
26  explicit MColor(const Base::Color& c);
27 
28  unsigned char red() const;
29  unsigned char green() const;
30  unsigned char blue() const;
31  unsigned char alpha() const;
32 
33  unsigned char r;
34  unsigned char g;
35  unsigned char b;
36  unsigned char a;
37 
38  bool operator==(const MColor& c) const;
39  bool operator!=(const MColor& c) const;
40 
41  size_t hash() const;
42 };
43 
44 
45 class LX_BASE_EXPORT Color
46 {
47 public:
49  // //
50  // --------------------- BEGIN API --------------------- //
51  // //
52  // ATTENTION: DO NOT CHANGE ANY SIGNATURES IN THE API ! //
53  // //
55 
56  enum Spec
57  {
59  Rgb,
60  Hsv,
61  Cmyk
62  };
63  enum Origin
64  {
66  Cadwork
67  };
68 
69  Color();
70  Color(const Base::MColor& c);
71  Color(int r, int g, int b, int a = 255);
72  Color(const std::string& name);
73  Color(const char* name);
74  Color(const Color& rhs);
75  Color(Spec spec);
76  ~Color();
77 
78  bool isValid() const;
79 
80  std::string name() const;
81  void setNamedColor(const std::string& name);
82 
83  static std::list<std::string> colorNames();
84 
85  Spec spec() const;
86 
87  void setOrigin(Origin o);
88  Origin origin() const;
89 
90  int alpha() const;
91  void setAlpha(int alpha);
92 
93  double alphaF() const;
94  void setAlphaF(double alpha);
95 
96  int red() const;
97  int green() const;
98  int blue() const;
99  void setRed(int red);
100  void setGreen(int green);
101  void setBlue(int blue);
102 
103  double redF() const;
104  double greenF() const;
105  double blueF() const;
106  void setRedF(double red);
107  void setGreenF(double green);
108  void setBlueF(double blue);
109 
110  void getRgb(int* r, int* g, int* b, int* a = 0) const;
111  void setRgb(int r, int g, int b, int a = 255);
112 
113  void getRgbF(double* r, double* g, double* b, double* a = 0) const;
114  void setRgbF(double r, double g, double b, double a = 1.0);
115 
116  int hue() const; // 0 <= hue < 360
117  int saturation() const;
118  int value() const;
119 
120  double hueF() const; // 0.0 <= hueF < 360.0
121  double saturationF() const;
122  double valueF() const;
123 
124  void getHsv(int* h, int* s, int* v, int* a = 0) const;
125  void setHsv(int h, int s, int v, int a = 255);
126 
127  void getHsvF(double* h, double* s, double* v, double* a = 0) const;
128  void setHsvF(double h, double s, double v, double a = 1.0);
129 
130  int cyan() const;
131  int magenta() const;
132  int yellow() const;
133  int black() const;
134 
135  double cyanF() const;
136  double magentaF() const;
137  double yellowF() const;
138  double blackF() const;
139 
140  void getCmyk(int* c, int* m, int* y, int* k, int* a = 0);
141  void setCmyk(int c, int m, int y, int k, int a = 255);
142 
143  void getCmykF(double* c, double* m, double* y, double* k, double* a = 0);
144  void setCmykF(double c, double m, double y, double k, double a = 1.0);
145 
146  Color toRgb() const;
147  Color toHsv() const;
148  Color toCmyk() const;
149 
150  Color convertTo(Spec colorSpec) const;
151 
152  static Color fromRgb(int r, int g, int b, int a = 255);
153  static Color fromRgbF(double r, double g, double b, double a = 1.0);
154 
155  static Color fromHsv(int h, int s, int v, int a = 255);
156  static Color fromHsvF(double h, double s, double v, double a = 1.0);
157 
158  static Color fromCmyk(int c, int m, int y, int k, int a = 255);
159  static Color fromCmykF(double c, double m, double y, double k, double a = 1.0);
160 
161  Color light(int f = 150) const;
162  Color lighter(int f = 150) const;
163  Color dark(int f = 200) const;
164  Color darker(int f = 200) const;
165 
166  Color& operator=(const Color&);
167 
168  bool isEqualIgnoreOrigin(const Color& c) const;
169  bool operator==(const Color& c) const;
170  bool operator!=(const Color& c) const;
171  bool operator<(const Color& c) const;
172 
174  static int toCdwkColor(const Color& color, bool* isPrecise = NULL);
176  static Color fromCdwkColor(const int index);
178  static int maximumCdwkColorNumber();
179 
181  bool isLcc() const;
183  bool isMainLcc() const;
186  bool isLccSubColor() const;
187 
188  friend std::size_t hash_value(const Color& b) { return b.hash(); }
189 
190  size_t hash() const;
191 
193  // //
194  // ---------------------- END API ---------------------- //
195  // //
197 
198  Color toCdwkOrigin() const; // return color with Cadwork origin, if color exists in cadwork palette, otherwise return original color
199  unsigned int rgb() const;
200  unsigned int rgba() const;
201 
202  friend LX_BASE_EXPORT std::ostream& operator<<(std::ostream& o, const Base::Color& color);
203 
204 private:
205  pCA_ColorP _pimpl;
206 };
207 
208 }; // namespace Base
209 
210 
211 #pragma warning(pop)
unsigned char b
Definition: Color.h:35
Definition: Color.h:45
unsigned char g
Definition: Color.h:34
unsigned char r
Definition: Color.h:33
std::unique_ptr< CA_ColorP > pCA_ColorP
Definition: Color.h:12
_Vec1 convertTo(const _Vec2 &v)
Definition: Converter.h:96
constexpr bool operator!=(const basic_hashed_string< Char > &lhs, const basic_hashed_string< Char > &rhs) ENTT_NOEXCEPT
Compares two hashed strings.
Definition: entt.hpp:570
Definition: Color.h:59
Core::PropertyText name
Definition: CoreDocument.h:167
Origin
Definition: Color.h:63
friend std::size_t hash_value(const Color &b)
Definition: Color.h:188
Definition: Color.h:58
size_t hash() const
Definition: Color.h:60
Definition: AbstractConstraint.h:6
Definition: Color.h:65
Definition: Color.h:21
unsigned char a
Definition: Color.h:36
Definition: AbstractXMLReader.h:5
Spec
Definition: Color.h:56
LX_GEOM_EXPORT std::ostream & operator<<(std::ostream &o, const Geom::Vec &vec)