YSTest: ColorPicker.cpp 源文件

YSTest PreAlpha_b700_20160611 The YSLib Test Project

- 首页
- 相关页面
- 模块
- 命名空间
- 类
- 文件

- 文件列表
- 文件成员

ColorPicker.cpp
浏览该文件的文档.
1 /*
2 © 2012-2015 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
28 #include "ColorPicker.h"
29 #include YFM_YSLib_UI_Border
30
31 namespace YSLib
32 {
33
34 namespace UI
35 {
36
37 namespace
38 {
39 yconstexpr const Size track_size(112, 16);
40 yconstexpr const Size label_size(44, 20);
41 }
42
43 ColorBox::ColorBox(const Point& pt, Color c)
44 : DialogPanel({pt, 200, 96}),
45 ctlColorArea({164, 32, 32, 32}, MakeBlankBrush()),
46 trRed({4, 24, track_size}), trGreen({4, 48, track_size}),
47 trBlue({4, 72, track_size}), lblRed({120, 24, label_size}),
48 lblGreen({120, 48, label_size}), lblBlue({120, 72, label_size})
49 {
50 const auto update_color([this]{
51 SetColor(Color(trRed.GetValue(), trGreen.GetValue(),
52 trBlue.GetValue()));
53 });
54
55 AddWidgets(*this, ctlColorArea, trRed, trGreen, trBlue, lblRed, lblGreen,
56 lblBlue),
57 trRed.SetMaxValue(255),
58 trGreen.SetMaxValue(255),
59 trBlue.SetMaxValue(255),
60 yunseq(
61 FetchEvent<Paint>(ctlColorArea).Add(BorderBrush(), BoundaryPriority),
62 trRed.Scroll += update_color,
63 trGreen.Scroll += update_color,
64 trBlue.Scroll += update_color
65 );
66 SetColor(c);
67 }
68 ImplDeDtor(ColorBox)
69
70 Color&
71 ColorBox::GetColorRef() const
72 {
73 const auto p(ctlColorArea.Background.target<SolidBrush>());
74
75 if(!p)
76 throw LoggedEvent("Invalid brush found @ ColorBox::GetColor");
77 return p->Color;
78 }
79
80 void
81 ColorBox::SetColor(Color c)
82 {
83 GetColorRef() = c,
84 trRed.SetValue(c.GetR()),
85 trGreen.SetValue(c.GetG()),
86 trBlue.SetValue(c.GetB());
87 yunseq(lblRed.Text = "R: " + to_string(c.GetR()),
88 lblGreen.Text = "G: " + to_string(c.GetG()),
89 lblBlue.Text = "B: " + to_string(c.GetB()));
90 Invalidate(ctlColorArea),
91 Invalidate(trRed), Invalidate(trGreen), Invalidate(trBlue),
92 Invalidate(lblRed), Invalidate(lblGreen), Invalidate(lblBlue);
93 }
94
95 } // namespace UI;
96
97 } // namespace YSLib;
98
platform::p
while p p
Definition: YCLib/FileSystem.h:225
ystdex::to_string
std::string to_string(const std::thread::id &)
转换 thread::id 为字符串表示。
yconstexpr
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:653
YSLib::UI::ColorBox::trRed
HorizontalTrack trRed
颜色分量轨道。
Definition: ColorPicker.h:61
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:45
platform::Color
颜色。
Definition: Video.h:451
YSLib::UI::DialogPanel
对话面板。
Definition: UIContainerEx.h:78
YSLib::LoggedEvent
记录日志的异常事件类。
Definition: YException.h:49
YSLib::UI::ColorBox::SetColor
void SetColor(Color)
取当前选定的颜色。
Color
Pixel Color
Definition: CharRenderer.cpp:58
YSLib::UI::AddWidgets
void AddWidgets(_tCon &con, _tWidgets &...wgts)
向部件容器添加子部件。
Definition: YUIContainer.h:443
CHRLib::c
c
Definition: CharacterProcessing.h:81
YSLib::UI::ColorBox::ColorBox
ColorBox(const Point &, Color c=ColorSpace::White)
Definition: ColorPicker.cpp:43
YSLib::UI::ColorBox::trBlue
HorizontalTrack trBlue
Definition: ColorPicker.h:61
YSLib::UI::ImplDeDtor
ImplDeDtor(Thumb) void DecorateAsCloseButton(Thumb &tmb)
Definition: Button.cpp:125
YSLib::UI::Invalidate
YF_API void Invalidate(IWidget &, const Rect &)
无效化：使相对部件的指定区域在直接和间接的窗口缓冲区中无效。
Definition: YWidget.cpp:108
YSLib::UI::ColorBox::lblGreen
Label lblGreen
Definition: ColorPicker.h:66
YSLib::UI::ColorBox::lblRed
Label lblRed
颜色分量标签。
Definition: ColorPicker.h:66
YSLib::UI::ATrack::SetValue
void SetValue(ValueType)
设置滚动事件关联值。
Definition: Scroll.cpp:170
YSLib::UI::ColorBox::trGreen
HorizontalTrack trGreen
Definition: ColorPicker.h:61
YSLib::UI::ColorBox::lblBlue
Label lblBlue
Definition: ColorPicker.h:66
YSLib::UI::ColorBox
拾色框。
Definition: ColorPicker.h:45
yunseq
#define yunseq
无序列依赖表达式组求值。
Definition: ydef.h:996
YSLib::UI::ColorBox::ctlColorArea
Control ctlColorArea
颜色区域。
Definition: ColorPicker.h:56
YSLib::Drawing::SolidBrush
单色画刷。
Definition: YBrush.h:58
ColorPicker.h
拾色器。
UI
YSLib::UI::BoundaryPriority
yconstexpr const EventPriority BoundaryPriority(0x60)
YSLib::UI::MLabel::Text
String Text
标签文本。
Definition: Label.h:94
YSLib::Drawing::GBinaryGroup< SPos >