YSTest: ColorPicker.cpp 源文件

YSTest PreAlpha_b500_20140530 The YSLib Test Project

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

- 文件列表
- 文件成员

全部 类 命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义 组 页
ColorPicker.cpp
浏览该文件的文档.
1 /*
2 © 2012-2014 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 Size track_size(112, 16);
40 yconstexpr 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.GetScroll() += update_color,
63 trGreen.GetScroll() += update_color,
64 trBlue.GetScroll() += update_color
65 );
66 SetColor(c);
67 }
68
69 Color&
70 ColorBox::GetColorRef() const
71 {
72 const auto p(ctlColorArea.Background.target<SolidBrush>());
73
74 if(!p)
75 throw LoggedEvent("Invalid brush found @ ColorBox::GetColor");
76 return p->Color;
77 }
78
79 void
80 ColorBox::SetColor(Color c)
81 {
82 GetColorRef() = c,
83 trRed.SetValue(c.GetR()),
84 trGreen.SetValue(c.GetG()),
85 trBlue.SetValue(c.GetB());
86 yunseq(lblRed.Text = "R: " + to_string(c.GetR()),
87 lblGreen.Text = "G: " + to_string(c.GetG()),
88 lblBlue.Text = "B: " + to_string(c.GetB()));
89 Invalidate(ctlColorArea),
90 Invalidate(trRed), Invalidate(trGreen), Invalidate(trBlue),
91 Invalidate(lblRed), Invalidate(lblGreen), Invalidate(lblBlue);
92 }
93
94 } // namespace UI;
95
96 } // namespace YSLib;
97
YSLib::UI::ColorBox::lblRed
Label lblRed
颜色分量标签。
Definition: ColorPicker.h:66
YSLib::UI::ColorBox::ctlColorArea
Control ctlColorArea
颜色区域。
Definition: ColorPicker.h:56
YSLib::UI::ColorBox::ColorBox
ColorBox(const Point &, Color c=ColorSpace::White)
Definition: ColorPicker.cpp:43
YSLib::UI::ColorBox::lblBlue
Label lblBlue
Definition: ColorPicker.h:66
YSLib::UI::Invalidate
YF_API void Invalidate(IWidget &, const Rect &)
无效化：使相对于部件的指定区域在直接和间接的窗口缓冲区中无效。
Definition: ywidget.cpp:111
YSLib::UI::ColorBox::SetColor
void SetColor(Color)
取当前选定的颜色。
Definition: ColorPicker.cpp:80
YSLib::UI::BoundaryPriority
yconstexpr EventPriority BoundaryPriority(0x60)
YSLib::UI::ColorBox::lblGreen
Label lblGreen
Definition: ColorPicker.h:66
YSLib::UI::AddWidgets
void AddWidgets(_tCon &con, _tWidgets &...wgts)
向部件容器添加子部件。
Definition: yuicont.h:400
YSLib::UI::MLabel::Text
String Text
标签文本。
Definition: label.h:76
YSLib::UI::Widget::Background
HBrush Background
背景。
Definition: ywidget.h:374
yunseq
#define yunseq
无序列依赖表达式组求值。
Definition: ydef.h:748
YSLib::Drawing::GBinaryGroup< SPos >
YSLib::UI::ColorBox::trGreen
HorizontalTrack trGreen
Definition: ColorPicker.h:61
YSLib::UI::ColorBox::trRed
HorizontalTrack trRed
颜色分量轨道。
Definition: ColorPicker.h:61
ystdex::to_string
std::string to_string(unsigned char val)
转换为字符串。
Definition: string.hpp:353
platform::Consoles::Color
Color
控制台颜色枚举。
Definition: Video.h:458
yconstexpr
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:462
YSLib::UI::ColorBox::trBlue
HorizontalTrack trBlue
Definition: ColorPicker.h:61
CHRLib::c
c
Definition: chrproc.h:76
ColorPicker.h
拾色器。
YSLib::UI::DialogPanel
对话面板。
Definition: uicontx.h:73