LibreCAD
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
metacolor.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "cad/const.h"
5 #include "cad/meta/color.h"
6 
7 #include <cmath>
8 
9 namespace lc {
13  class MetaColor : public EntityMetaType {
14  protected:
16 
17  }
18 
19  public:
20  virtual const std::string metaTypeID() const override {
21  return LCMETANAME();
22  }
23  static const std::string LCMETANAME() {
24  return "_COLOR";
25  }
26  };
27 
28  class MetaColorByValue : public MetaColor {
29  public:
30 
31  MetaColorByValue() : MetaColor(), _color(1., 1., 1., 1.) {
32  }
33 
34  MetaColorByValue(const MetaColorByValue& other) : MetaColor(), _color(other.color()) {
35  }
36 
37  MetaColorByValue(const Color& other) : MetaColor(), _color(other) {
38  }
39 
40  MetaColorByValue(double r, double g, double b, double a = 1.) : MetaColor(), _color(r, g, b, a) {
41  }
42 
43  virtual ~MetaColorByValue() = default;
44 
45  virtual const std::string id() const override {
46  // TODO create proper ID
47  return LCMETANAME() + "_" + std::to_string(red()) + "_" + std::to_string(green()) + "_" + std::to_string(blue());
48  }
49 
50  Color color() const {
51  return _color;
52  }
53 
54  inline double red() const {
55  return _color.red();
56  }
57 
58  inline double green() const {
59  return _color.green();
60  }
61 
62  inline double blue() const {
63  return _color.blue();
64  }
65 
66  inline double alpha() const {
67  return _color.alpha();
68  }
69 
70  inline unsigned char redI() const {
71  return _color.redI();
72  }
73 
74  inline unsigned char greenI() const {
75  return _color.greenI();
76  }
77 
78  inline unsigned char blueI() const {
79  return _color.blueI();
80  }
81 
82  inline unsigned char alphaI() const {
83  return _color.alphaI();
84  }
85 
86  private:
88 
89  friend std::ostream& operator<<(std::ostream& os, const MetaColorByValue& metaColor) {
90  os << "MetaColorByValue(red=" << metaColor.red() << " green=" << metaColor.green() << " blue=" << metaColor.blue() << " alpha" << metaColor.alpha() << ")";
91  return os;
92  }
93  };
94 
95  class MetaColorByBlock : public MetaColor {
96  public:
98 
99  }
100 
101  virtual const std::string id() const override {
102  return LCMETANAME() + "_BYBLOCK";
103  }
104  };
105 
106  DECLARE_SHORT_SHARED_PTR(MetaColor)
107  DECLARE_SHORT_SHARED_PTR(MetaColorByValue)
108  DECLARE_SHORT_SHARED_PTR(MetaColorByBlock)
109 }
110 
double alpha() const
Definition: color.h:50
double blue() const
Definition: color.h:47
unsigned char alphaI() const
Definition: color.h:63
unsigned char redI() const
Definition: color.h:54
double green() const
Definition: color.h:44
Color color() const
Definition: metacolor.h:50
static const std::string LCMETANAME()
Definition: metacolor.h:23
double red() const
Definition: color.h:41
MetaColorByValue(const Color &other)
Definition: metacolor.h:37
MetaColorByValue(double r, double g, double b, double a=1.)
Definition: metacolor.h:40
friend std::ostream & operator<<(std::ostream &os, const MetaColorByValue &metaColor)
Definition: metacolor.h:89
unsigned char redI() const
Definition: metacolor.h:70
DECLARE_SHORT_SHARED_PTR(Document)
virtual const std::string id() const override
Definition: metacolor.h:101
double green() const
Definition: metacolor.h:58
Definition: cadentity.h:12
unsigned char greenI() const
Definition: metacolor.h:74
virtual ~MetaColorByValue()=default
double red() const
Definition: metacolor.h:54
double blue() const
Definition: metacolor.h:62
virtual const std::string id() const override
Definition: metacolor.h:45
unsigned char blueI() const
Definition: metacolor.h:78
unsigned char blueI() const
Definition: color.h:60
unsigned char greenI() const
Definition: color.h:57
virtual const std::string metaTypeID() const override
Definition: metacolor.h:20
MetaColorByValue(const MetaColorByValue &other)
Definition: metacolor.h:34
unsigned char alphaI() const
Definition: metacolor.h:82
double alpha() const
Definition: metacolor.h:66