18#ifndef BIMHOMEAPP_APP_COLOR_H
19#define BIMHOMEAPP_APP_COLOR_H
44 explicit Color(
float R = 0.0,
float G = 0.0,
float B = 0.0,
float A = 0.0)
45 : r(
R), g(
G), b(
B), a(
A) {}
63 : r(c.r), g(c.g), b(c.b), a(c.a) {}
84 return !operator==(c);
95 void set(
float R,
float G,
float B,
float A = 0.0)
97 r =
R; g =
G; b =
B; a =
A;
108 r = c.
r; g = c.
g; b = c.
b; a = c.
a;
120 this->set((rgba >> 24) / 255.0f,
121 ((rgba >> 16) & 0xff) / 255.0f,
122 ((rgba >> 8) & 0xff) / 255.0f,
123 (rgba & 0xff) / 255.0f);
134 return (
static_cast<uint32_t
>(r * 255.0f + 0.5f) << 24 |
135 static_cast<uint32_t
>(g * 255.0f + 0.5f) << 16 |
136 static_cast<uint32_t
>(b * 255.0f + 0.5f) << 8 |
137 static_cast<uint32_t
>(a * 255.0f + 0.5f));
145 template <
typename T>
148 set(q.redF(), q.greenF(), q.blueF());
166 template <
typename T>
168 return T(
int(r * 255.0f),
int(g * 255.0f),
int(b * 255.0f));
177 std::stringstream ss;
178 ss <<
"#" << std::hex << std::uppercase << std::setfill(
'0') << std::setw(2) << int(r * 255.0f)
179 << std::setw(2) << int(g * 255.0f)
180 << std::setw(2) << int(b * 255.0f);
190 return asHexString();
200 if (hex.size() < 7 || hex[0] !=
'#')
203 if (hex.size() == 7) {
204 std::stringstream ss(hex);
208 ss >> c >> std::hex >> rgb;
209 int rc = (rgb >> 16) & 0xff;
210 int gc = (rgb >> 8) & 0xff;
220 if (hex.size() == 9) {
221 std::stringstream ss(hex);
225 ss >> c >> std::hex >> rgba;
226 int rc = (rgba >> 24) & 0xff;
227 int gc = (rgba >> 16) & 0xff;
228 int bc = (rgba >> 8) & 0xff;
229 int ac = rgba & 0xff;
A
Definition ISnapProcessedBase.h:49
G
Definition ISnapProcessedBase.h:49
B
Definition ISnapProcessedBase.h:49
R
Definition ISnapProcessedBase.h:49
T
Definition ISnapProcessedBase.h:49
Color & setPackedValue(uint32_t rgba)
设置颜色值
Definition Color.h:118
std::string asHexString() const
将颜色转换为十六进制字符串
Definition Color.h:176
Color & operator=(const Color &c)
赋值运算符
Definition Color.h:106
void setValue(const Color &q)
从 Color 类型设置颜色值
Definition Color.h:156
float r
颜色值,公共可访问
Definition Color.h:243
float a
Definition Color.h:243
void setValue(const T &q)
从模板类型设置颜色值
Definition Color.h:146
Color(uint32_t rgba)
构造颜色对象
Definition Color.h:52
bool fromHexString(const std::string &hex)
从十六进制字符串设置颜色
Definition Color.h:199
float b
Definition Color.h:243
Color(float R=0.0, float G=0.0, float B=0.0, float A=0.0)
构造颜色对象
Definition Color.h:44
T asValue() const
将颜色转换为模板类型
Definition Color.h:167
float g
Definition Color.h:243
bool operator==(const Color &c) const
比较两个颜色对象是否相等
Definition Color.h:71
bool operator!=(const Color &c) const
比较两个颜色对象是否不相等
Definition Color.h:82
uint32_t getPackedValue() const
获取颜色的打包值
Definition Color.h:132
void set(float R, float G, float B, float A=0.0)
设置颜色分量
Definition Color.h:95
std::string asCSSString() const
将颜色转换为 CSS 样式的字符串
Definition Color.h:189
Color(const Color &c)
复制构造函数
Definition Color.h:62
表示颜色的类
Definition Color.h:34
Definition BaseFigureFactory.h:28