xcal
基于 C++23 的现代图形渲染引擎
载入中...
搜索中...
未找到
xcal
property
color.cc
浏览该文件的文档.
1
#include "
./color.hpp
"
2
3
xcal::property::Color
xcal::property::Color::from_hex
(
const
std::string &hex) {
4
if
(hex.size() != 7 || hex[0] !=
'#'
)
return
Color
(0.0, 0.0, 0.0);
5
uint32_t
value
= std::stoul(hex.substr(1),
nullptr
, 16);
6
return
from_hex
(
value
);
7
}
8
xcal::property::Color
xcal::property::Color::from_hex
(uint32_t hex) {
9
return
Color
(((hex >> 16) & 0xff) / 255.0, ((hex >> 8) & 0xff) / 255.0,
10
(hex & 0xff) / 255.0);
11
}
12
13
xcal::property::Color
xcal::property::Color::from_name
(
14
const
std::string &name) {
15
if
(name ==
"red"
)
16
return
Color
(1.0, 0.0, 0.0);
17
else
if
(name ==
"green"
)
18
return
Color
(0.0, 1.0, 0.0);
19
else
if
(name ==
"blue"
)
20
return
Color
(0.0, 0.0, 1.0);
21
else
if
(name ==
"white"
)
22
return
Color
(1.0, 1.0, 1.0);
23
else
if
(name ==
"black"
)
24
return
Color
(0.0, 0.0, 0.0);
25
else
if
(name ==
"yellow"
)
26
return
Color
(1.0, 1.0, 0.0);
27
else
if
(name ==
"cyan"
)
28
return
Color
(0.0, 1.0, 1.0);
29
else
if
(name ==
"magenta"
)
30
return
Color
(1.0, 0.0, 1.0);
31
else
if
(name ==
"gray"
)
32
return
Color
(0.5, 0.5, 0.5);
33
else
34
return
Color
(0.0, 0.0, 0.0);
35
}
xcal::property::Color
颜色属性类
Definition
color.hpp:16
xcal::property::Color::from_name
static Color from_name(const std::string &name)
从颜色名称创建颜色
Definition
color.cc:13
xcal::property::Color::Color
Color()
默认构造函数
Definition
color.hpp:29
xcal::property::Color::value
const data_t & value() const
Definition
color.hpp:151
xcal::property::Color::from_hex
static Color from_hex(uint32_t hex)
从十六进制数值创建颜色
Definition
color.cc:8
color.hpp
生成于 2025年 九月 19日 星期五 21:12:12 , 为 xcal使用
1.9.8