OpenLexocad  27.0
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 <Base/base_defines.h>
7 
8 #include <list>
9 #include <map>
10 #include <memory>
11 #include <string>
12 #include <vector>
13 
14 class CA_ColorP;
15 
16 // Smart pointer to private implementation of Color
17 typedef std::unique_ptr<CA_ColorP> pCA_ColorP;
18 
19 namespace Base
20 {
21 class Color;
22 
24 {
25 public:
26  MColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
27  MColor();
28  explicit MColor(const Base::Color& c);
29 
30  unsigned char red() const;
31  unsigned char green() const;
32  unsigned char blue() const;
33  unsigned char alpha() const;
34 
35  unsigned char r;
36  unsigned char g;
37  unsigned char b;
38  unsigned char a;
39 
40  bool operator==(const MColor& c) const;
41  bool operator!=(const MColor& c) const;
42 
43  size_t hash() const;
44 };
45 
46 
48 {
49 public:
51  // //
52  // --------------------- BEGIN API --------------------- //
53  // //
54  // ATTENTION: DO NOT CHANGE ANY SIGNATURES IN THE API ! //
55  // //
57 
58  enum Spec
59  {
61  Rgb,
62  Hsv,
63  Cmyk
64  };
65  enum Origin
66  {
69  Greyscale
70  };
71 
72  Color();
73  Color(const Base::MColor& c);
74  Color(int r, int g, int b, int a = 255);
75  Color(const std::string& name);
76  Color(const char* name);
77  Color(const Color& rhs);
78  Color(Spec spec);
79  ~Color();
80 
81  bool isValid() const;
82 
83  std::string name() const;
84  void setNamedColor(const std::string& name);
85 
86  static std::list<std::string> colorNames();
87 
88  Spec spec() const;
89 
90  void setOrigin(Origin o);
91  Origin origin() const;
92 
93  int alpha() const;
94  void setAlpha(int alpha);
95 
96  double alphaF() const;
97  void setAlphaF(double alpha);
98 
99  int red() const;
100  int green() const;
101  int blue() const;
102  void setRed(int red);
103  void setGreen(int green);
104  void setBlue(int blue);
105 
106  double redF() const;
107  double greenF() const;
108  double blueF() const;
109  void setRedF(double red);
110  void setGreenF(double green);
111  void setBlueF(double blue);
112 
113  void getRgb(int* r, int* g, int* b, int* a = 0) const;
114  void setRgb(int r, int g, int b, int a = 255);
115 
116  void getRgbF(double* r, double* g, double* b, double* a = 0) const;
117  void setRgbF(double r, double g, double b, double a = 1.0);
118 
119  int hue() const; // 0 <= hue < 360
120  int saturation() const;
121  int value() const;
122 
123  double hueF() const; // 0.0 <= hueF < 360.0
124  double saturationF() const;
125  double valueF() const;
126 
127  void getHsv(int* h, int* s, int* v, int* a = 0) const;
128  void setHsv(int h, int s, int v, int a = 255);
129 
130  void getHsvF(double* h, double* s, double* v, double* a = 0) const;
131  void setHsvF(double h, double s, double v, double a = 1.0);
132 
133  int cyan() const;
134  int magenta() const;
135  int yellow() const;
136  int black() const;
137 
138  double cyanF() const;
139  double magentaF() const;
140  double yellowF() const;
141  double blackF() const;
142 
143  void getCmyk(int* c, int* m, int* y, int* k, int* a = 0);
144  void setCmyk(int c, int m, int y, int k, int a = 255);
145 
146  void getCmykF(double* c, double* m, double* y, double* k, double* a = 0);
147  void setCmykF(double c, double m, double y, double k, double a = 1.0);
148 
149  Color toRgb() const;
150  Color toHsv() const;
151  Color toCmyk() const;
152 
153  Color convertTo(Spec colorSpec) const;
154 
155  static Color fromRgb(int r, int g, int b, int a = 255);
156  static Color fromRgbF(double r, double g, double b, double a = 1.0);
157 
158  static Color fromHsv(int h, int s, int v, int a = 255);
159  static Color fromHsvF(double h, double s, double v, double a = 1.0);
160 
161  static Color fromCmyk(int c, int m, int y, int k, int a = 255);
162  static Color fromCmykF(double c, double m, double y, double k, double a = 1.0);
163 
164  Color light(int f = 150) const;
165  Color lighter(int f = 150) const;
166  Color dark(int f = 200) const;
167  Color darker(int f = 200) const;
168 
169  Color& operator=(const Color&);
170 
171  bool isEqualIgnoreOrigin(const Color& c) const;
172  bool operator==(const Color& c) const;
173  bool operator!=(const Color& c) const;
174  bool operator<(const Color& c) const;
175 
177  static int toCdwkColor(const Color& color, bool* isPrecise = NULL);
179  static Color fromCdwkColor(const int index);
181  static int maximumCdwkColorNumber();
182 
184  static int toGreyscaleColor(const Color& color, bool* isPrecise = NULL);
186  static Color fromGreyscaleColor(const int index);
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 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:37
Definition: Color.h:47
unsigned char g
Definition: Color.h:36
unsigned char r
Definition: Color.h:35
std::unique_ptr< CA_ColorP > pCA_ColorP
Definition: Color.h:14
#define BASE_EXPORT
Definition: base_defines.h:12
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:61
Core::PropertyText name
Definition: CoreDocument.h:143
Origin
Definition: Color.h:65
friend std::size_t hash_value(const Color &b)
Definition: Color.h:188
Definition: Color.h:60
size_t hash() const
Definition: Color.h:68
GEOM_EXPORT std::ostream & operator<<(std::ostream &o, const Geom::Vec &vec)
Definition: Color.h:62
Definition: Color.h:67
Definition: Color.h:23
unsigned char a
Definition: Color.h:38
Definition: AbstractXMLReader.h:8
Spec
Definition: Color.h:58