-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathColorPickerCustom.h
170 lines (136 loc) · 4.17 KB
/
ColorPickerCustom.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#ifndef UI_CONTROL_COLORPICKER_CUSTOM_H_
#define UI_CONTROL_COLORPICKER_CUSTOM_H_
#include "duilib/Core/Box.h"
#include "duilib/Control/ColorControl.h"
#include "duilib/Control/ColorSlider.h"
#include "duilib/Control/RichEdit.h"
namespace ui
{
/** 颜色选择器:自定义颜色
*/
class RichEdit;
class ColorPickerRegular;
class ColorPickerCustom : public Box
{
typedef Box BaseClass;
public:
explicit ColorPickerCustom(Window* pWindow);
/** 获取控件类型
*/
virtual DString GetType() const override;
/** 选择一个颜色
*/
void SelectColor(const UiColor& color);
/** 设置控件位置
*/
virtual void SetPos(UiRect rc) override;
/** 监听选择颜色的事件
* @param[in] callback 选择颜色变化时的回调函数
* 参数说明:
wParam: 当前新选择的颜色值,可以用UiColor((uint32_t)wParam)生成颜色
lParam: 原来旧选择的颜色值,可以用UiColor((uint32_t)lParam)生成颜色
*/
void AttachSelectColor(const EventCallback& callback) { AttachEvent(kEventSelectColor, callback); }
private:
/** 颜色变化的原因
*/
enum class ChangeReason
{
ColorUpdate, //颜色值从其他页面更新
ColorSpectrum, //颜色光谱图
ColorRegular, //标准颜色表
NewColorEdit, //新颜色的可编辑框
ColorARGB_A, //ARGB颜色变化
ColorARGB_R, //ARGB颜色变化
ColorARGB_G, //ARGB颜色变化
ColorARGB_B, //ARGB颜色变化
ColorHSV_H, //HSV颜色变化
ColorHSV_S, //HSV颜色变化
ColorHSV_V, //HSV颜色变化
ColorHSL_H, //HSL颜色变化
ColorHSL_S, //HSL颜色变化
ColorHSL_L, //HSL颜色变化
};
/** 初始化
*/
void InitPicker();
/** 颜色发生变化
*/
void OnColorChanged(WPARAM wParam, LPARAM lParam, ChangeReason reason);
/** 判断输入是否为合法的颜色字符串,格式如"#FF123456"
*/
bool IsValidColorString(const DString& colorText) const;
private:
/** 一个颜色通道的界面控件
*/
struct ColorUI
{
//颜色值显示控件
RichEdit* m_pColorEdit = nullptr;
//颜色值调整控件
ColorSlider* m_pColorSlider = nullptr;
};
/** 初始化一个RGB通道
*/
void InitRGB(const ColorUI& colorUI, ChangeReason reason);
/** 初始化一个HSV通道
*/
void InitHSV(const ColorUI& colorUI, int32_t maxValue, ChangeReason reason);
/** 初始化一个HSL通道
*/
void InitHSL(const ColorUI& colorUI, int32_t maxValue, ChangeReason reason);
/** 更新RGB
* @param [in] flag: 0 - A, 1 - R, 2 - G, 3 - B
*/
void UpdateRGB(const ColorUI& colorUI, const UiColor& color, int32_t flag);
/** 更新HSV
*/
void UpdateHSV(const ColorUI& colorUIH, const ColorUI& colorUIS, const ColorUI& colorUIV, const UiColor& color, ChangeReason reason);
/** 更新HSL
*/
void UpdateHSL(const ColorUI& colorUIH, const ColorUI& colorUIS, const ColorUI& colorUIL, const UiColor& color, ChangeReason reason);
/** RGB颜色发生变化
*/
void OnRGBChanged(ChangeReason reason);
/** HSV颜色发生变化
*/
void OnHSVChanged(ChangeReason reason);
/** HSL颜色发生变化
*/
void OnHSLChanged(ChangeReason reason);
private:
/** 是否已经完成初始化
*/
bool m_bPickerInited;
/** 旧的颜色
*/
UiColor m_oldColor;
/** 标准颜色控件接口
*/
ColorPickerRegular* m_pRegularPicker;
/** 色谱控件
*/
ColorControl* m_pSpectrumControl;
/** 新选择的颜色控件文本框接口
*/
RichEdit* m_pNewColorEdit;
private:
/** RGB颜色调整控件
*/
ColorUI m_rgbA;
ColorUI m_rgbR;
ColorUI m_rgbG;
ColorUI m_rgbB;
/** HSV颜色调整控件
*/
ColorUI m_hsvH;
ColorUI m_hsvS;
ColorUI m_hsvV;
/** HSL颜色调整控件
*/
ColorUI m_hslH;
ColorUI m_hslS;
ColorUI m_hslL;
};
}//namespace ui
#endif //UI_CONTROL_COLORPICKER_CUSTOM_H_