YSTest  PreAlpha_b400_20130424
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
ColorPicker.cpp
浏览该文件的文档.
1 /*
2  Copyright by FrankHB 2012 - 2013.
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 <YSLib/UI/YBrush.h>
30 
32 
34 
35 namespace
36 {
37  yconstexpr Size track_size(112, 16);
38  yconstexpr Size label_size(44, 20);
39 }
40 
42  : DialogPanel({pt, 200, 96}),
43  ctlColorArea({164, 32, 32, 32}), trRed({4, 24, track_size}),
44  trGreen({4, 48, track_size}), trBlue({4, 72, track_size}),
45  lblRed({120, 24, label_size}), lblGreen({120, 48, label_size}),
46  lblBlue({120, 72, label_size})
47 {
48  const auto update_color([this](ScrollEventArgs&&){
49  SetColor(Color(trRed.GetValue(), trGreen.GetValue(),
50  trBlue.GetValue()));
51  });
52 
54  lblBlue),
55  trRed.SetMaxValue(255),
56  trGreen.SetMaxValue(255),
57  trBlue.SetMaxValue(255),
58  yunseq(
59  FetchEvent<Paint>(ctlColorArea).Add(BorderBrush(), BoundaryPriority),
60  trRed.GetScroll() += update_color,
61  trGreen.GetScroll() += update_color,
62  trBlue.GetScroll() += update_color
63  );
64  SetColor(c);
65 }
66 
67 Color&
68 ColorBox::GetColorRef() const
69 {
70  const auto p(ctlColorArea.Background.target<SolidBrush>());
71 
72  if(!p)
73  throw LoggedEvent("Invalid brush found @ ColorBox::GetColor");
74  return p->Color;
75 }
76 
77 void
79 {
80  GetColorRef() = c,
81  trRed.SetValue(c.GetR()),
82  trGreen.SetValue(c.GetG()),
83  trBlue.SetValue(c.GetB());
84  yunseq(lblRed.Text = "R: " + to_string(c.GetR()),
85  lblGreen.Text = "G: " + to_string(c.GetG()),
86  lblBlue.Text = "B: " + to_string(c.GetB()));
90 }
91 
93 
94 YSL_END
95