PCB Environment 2
Loading...
Searching...
No Matches
Color.hpp
1
2#ifndef GYM_PCB_COLOR_H
3#define GYM_PCB_COLOR_H
4
5#include "Defs.hpp"
6#include <string_view>
7
8class Color
9{
10public:
11 Color() { }
12 Color(std::string_view);
13 constexpr Color(uint32_t abgr) : mABGR(abgr) { }
14 constexpr Color(uint8_t R, uint8_t G, uint8_t B, uint8_t A = 255) : mABGR((A << 24) | (B << 16) | (G << 8) | R) { }
15 uint32_t ABGR8() const { return mABGR; }
16 Color& operator=(const Color &c) { mABGR = c.mABGR; return *this; }
17 bool operator==(const Color &c) const { return mABGR == c.mABGR; }
18 bool isVisible() const { return mABGR & 0xff000000; }
19 void getFloat4(float *) const;
20 Color withAlpha(float a) const { return Color((mABGR & 0xffffff) | (uint(a * 255.0f) << 24)); }
21 std::string str() const;
22 static Color HSV(int h, float s, float v, float a = 1.0f);
23 static Color RGBA(float r, float g, float b, float a);
24 static const Color TRANSPARENT;
25 static const Color BLACK;
26 static const Color WHITE;
27 static const Color RED;
28 static const Color GREEN;
29 static const Color BLUE;
30 static const Color CYAN;
31 static const Color MAGENTA;
32 static const Color YELLOW;
33 static const Color ORANGE;
34 static const Color PINK;
35 static const Color POISON;
36 static const Color MINT;
37 static const Color SKY;
38private:
39 uint32_t mABGR{0};
40};
41
42constexpr const Color Color::TRANSPARENT(0x00000000);
43constexpr const Color Color::BLACK(0xff000000);
44constexpr const Color Color::WHITE(0xffffffff);
45constexpr const Color Color::RED(0xff0000ff);
46constexpr const Color Color::GREEN(0xff00ff00);
47constexpr const Color Color::BLUE(0xffff0000);
48constexpr const Color Color::CYAN(0xffffff00);
49constexpr const Color Color::MAGENTA(0xffff00ff);
50constexpr const Color Color::YELLOW(0xff00ffff);
51constexpr const Color Color::ORANGE(0xff0080ff);
52constexpr const Color Color::PINK(0xff8000ff);
53constexpr const Color Color::POISON(0xff00ff80);
54constexpr const Color Color::MINT(0xff80ff00);
55constexpr const Color Color::SKY(0xffff8000);
56
57class Palette
58{
59 constexpr static const uint MaxColors = 1024;
60public:
61 Palette() { }
62 Palette(const Color *, uint);
63
64 void setColor(uint, Color);
65
66 uint size() const { return mColors.size(); }
67
68 Color operator[](uint i) const { return mColors[i % static_cast<uint>(mColors.size())]; }
69public:
70 static Color FootprintLine[2];
71 static Color FootprintFill[2];
72 static Color PinLine[2][2]; // [-+net][z]
73 static Color PinFill[2][2]; // [-+net][z]
74 static Color PowerNet;
75 static Color GroundNet;
76 static Palette Nets;
77 static Palette Tracks;
78 static const uint Hues[16];
79private:
80 std::vector<Color> mColors;
81};
82
83inline Color Color::RGBA(float r, float g, float b, float a)
84{
85 int32_t R = r * 255.0f;
86 int32_t G = g * 255.0f;
87 int32_t B = b * 255.0f;
88 int32_t A = a * 255.0f;
89 return Color((A << 24) | (B << 16) | (G << 8) | R);
90};
91
92#endif // GYM_PCB_COLOR_H
Definition Color.hpp:9