bWidgets
Core widget toolkit designed for Blender
bwColor.h
Go to the documentation of this file.
1#pragma once
2
3namespace bWidgets {
4
5class bwColor {
6 public:
7 bwColor(float red, float green, float blue, float alpha = 1.0f);
8 bwColor(float rgb, float alpha = 1.0f);
9 bwColor(unsigned int red, unsigned int green, unsigned int blue, unsigned int alpha = 255);
10 bwColor(unsigned int rgb, unsigned int alpha = 255);
11 bwColor() = default;
12 ~bwColor() = default;
13 bwColor(const bwColor&);
14
15 auto shade(float rgb_shade, float alpha_shade = 0.0f) -> bwColor&;
16 auto shade(unsigned int rgb_shade, unsigned int alpha_shade = 0.0f) -> bwColor&;
17
18 void setColor(float red, float green, float blue, float alpha = 1.0f);
19 void setColor(float rgb, float alpha = 1.0f);
20 void setColor(const float rgba[4]);
21 auto getColor() const -> const float*;
22 auto operator=(const float* rgb) -> bwColor&;
23 auto operator=(const bwColor& other_color) -> bwColor&;
24
25 auto operator==(const bwColor& compare_color) const -> bool;
26 auto operator[](const int index) -> float&;
27 // Implicit conversion to float*
28 operator const float*() const;
29
30 private:
31 enum class Component {
32 RED = 0,
33 GREEN = 1,
34 BLUE = 2,
35 ALPHA = 3,
36 };
37
38 auto operator[](const Component component) -> float&
39 {
40 return rgba[static_cast<int>(component)];
41 }
42
43 void clamp(const Component component);
44
45 float rgba[4]{0, 0, 0, 1};
46};
47
48} // namespace bWidgets
Definition: bwColor.h:5
~bwColor()=default
void setColor(float red, float green, float blue, float alpha=1.0f)
Definition: bwColor.cc:66
auto getColor() const -> const float *
Definition: bwColor.cc:86
auto operator[](const int index) -> float &
Definition: bwColor.cc:108
auto shade(float rgb_shade, float alpha_shade=0.0f) -> bwColor &
Definition: bwColor.cc:40
Definition: bwContext.h:3