LibreCAD
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
icolor.h
Go to the documentation of this file.
1 #pragma once
2 #include "color.h"
3 #include "metacolor.h"
4 
5 namespace lc {
6 
14  class iColor {
15  public:
16  iColor();
17 
18  virtual ~iColor() {}
19 
20  // Given a specific DXF color ID return a MetaCOlor shared pointer
21  // Codes <0 and > 255 will return nullptr
22  std::shared_ptr<lc::MetaColorByValue> intToColor(int code) const {
23  if (code < 0 || code > 255) {
24  return nullptr;
25  }
26 
27  return _intToCol[code];
28  }
29 
34  int colorToInt(const lc::Color& col) const {
35  for (int i = 0; i < 256; i++) {
36  if (_intToCol[i]->color() == col) {
37  return i;
38  }
39  }
40 
41  return -1;
42  }
43 
49  inline int colorToInt(std::shared_ptr<const lc::MetaColorByValue>& col) const {
50  for (int i = 0; i < 256; i++) {
51  if (_intToCol[i] == col) {
52  return i;
53  }
54  }
55 
56  return -1;
57  }
58 
59  public:
60  lc::MetaColorByValue_SPtr _intToCol[256];
61  };
62 
63 
64 }
65 
66 
67 
int colorToInt(const lc::Color &col) const
Definition: icolor.h:34
int colorToInt(std::shared_ptr< const lc::MetaColorByValue > &col) const
Definition: icolor.h:49
Definition: cadentity.h:12
iColor()
Definition: icolor.cpp:5
lc::MetaColorByValue_SPtr _intToCol[256]
Definition: icolor.h:60
virtual ~iColor()
Definition: icolor.h:18
std::shared_ptr< lc::MetaColorByValue > intToColor(int code) const
Definition: icolor.h:22