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 
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
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()));
92 }
93 
94 } // namespace UI;
95 
96 } // namespace YSLib;
97 
Label lblRed
颜色分量标签。
Definition: ColorPicker.h:66
Control ctlColorArea
颜色区域。
Definition: ColorPicker.h:56
ColorBox(const Point &, Color c=ColorSpace::White)
Definition: ColorPicker.cpp:43
YF_API void Invalidate(IWidget &, const Rect &)
无效化:使相对于部件的指定区域在直接和间接的窗口缓冲区中无效。
Definition: ywidget.cpp:111
void SetColor(Color)
取当前选定的颜色。
Definition: ColorPicker.cpp:80
yconstexpr EventPriority BoundaryPriority(0x60)
void AddWidgets(_tCon &con, _tWidgets &...wgts)
向部件容器添加子部件。
Definition: yuicont.h:400
String Text
标签文本。
Definition: label.h:76
HBrush Background
背景。
Definition: ywidget.h:374
#define yunseq
无序列依赖表达式组求值。
Definition: ydef.h:748
HorizontalTrack trGreen
Definition: ColorPicker.h:61
HorizontalTrack trRed
颜色分量轨道。
Definition: ColorPicker.h:61
std::string to_string(unsigned char val)
转换为字符串。
Definition: string.hpp:353
Color
控制台颜色枚举。
Definition: Video.h:458
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:462
HorizontalTrack trBlue
Definition: ColorPicker.h:61
拾色器。
对话面板。
Definition: uicontx.h:73