xcal
基于 C++23 的现代图形渲染引擎
载入中...
搜索中...
未找到
color.hpp
浏览该文件的文档.
1#pragma once
2#include <xcal/public.h>
3
4#include <string>
6#include <xcmath/xcmath.hpp>
7
8namespace xcal::property {
9
16class XCAL_API Color : public MProperty {
18 public:
20
21 private:
22 Proxy<data_t> data_{this, {0.0f, 0.0, 0.0, 1.0}};
23
24 public:
30
39 : MProperty(), data_{this, {r, g, b, a}} {}
40
45 const float_t &r() const { return data_[0]; }
46
51 const float_t &g() const { return data_[1]; }
52
57 const float_t &b() const { return data_[2]; }
58
63 const float_t &a() const { return data_[3]; }
64
69 float_t &r() { return data_[0]; }
70
75 float_t &g() { return data_[1]; }
76
81 float_t &b() { return data_[2]; }
82
87 float_t &a() { return data_[3]; }
88
94 size_t to_hex() {
95 return ((size_t(data_[0] * 255) << 16) | (size_t(data_[1] * 255) << 8) |
96 size_t(data_[2] * 255));
97 }
98
103 std::string to_hex_string() {
104 return "#" + std::string(std::to_string(to_hex()));
105 }
106
113 static Color from_hex(uint32_t hex);
114
121 static Color from_name(const std::string &name);
122
129 static Color from_hex(const std::string &hex);
130
131 Color &operator=(const data_t &other) {
132 data_ = other;
133 return *this;
134 }
140 // NOLINTNEXTLINE(google-explicit-constructor)
141 operator data_t &() { return data_; }
142
148 // NOLINTNEXTLINE(google-explicit-constructor)
149 operator const data_t &() const { return data_; }
150
151 const data_t &value() const { return data_; }
152 public:
153 Color(const Color &) = delete;
154 Color(Color &&) = delete;
155 Color &operator=(const Color &) = delete;
156 Color &operator=(Color &&) = delete;
157};
158
159} // namespace xcal::property
颜色属性类
Definition color.hpp:16
const float_t & r() const
获取红色分量(只读)
Definition color.hpp:45
Color & operator=(const Color &)=delete
Color(const Color &)=delete
float_t & r()
获取红色分量(可修改)
Definition color.hpp:69
Color(float_t r, float_t g, float_t b, float_t a=1.0)
构造函数
Definition color.hpp:38
Color()
默认构造函数
Definition color.hpp:29
const float_t & a() const
获取透明度分量(只读)
Definition color.hpp:63
Color(Color &&)=delete
const data_t & value() const
Definition color.hpp:151
float_t & a()
获取透明度分量(可修改)
Definition color.hpp:87
Color & operator=(const data_t &other)
Definition color.hpp:131
float_t & b()
获取蓝色分量(可修改)
Definition color.hpp:81
size_t to_hex()
将颜色转换为十六进制数值
Definition color.hpp:94
Color & operator=(Color &&)=delete
float_t & g()
获取绿色分量(可修改)
Definition color.hpp:75
std::string to_hex_string()
将颜色转换为十六进制字符串
Definition color.hpp:103
const float_t & g() const
获取绿色分量(只读)
Definition color.hpp:51
const float_t & b() const
获取蓝色分量(只读)
Definition color.hpp:57
Vector class template
Definition vec.hpp:206
float float_t
Definition public.h:27
#define XCAL_PROPERTY_TYPE(type)
Definition property.hpp:6
#define XCAL_API
Definition public.h:69