YSTest  PreAlpha_b500_20140530
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
ExStyle.cpp
浏览该文件的文档.
1 /*
2  © 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 "YSLib/UI/YModules.h"
29 #include YFM_YSLib_UI_ExStyle
30 #include YFM_YSLib_UI_YGUI
31 #include YFM_YSLib_Service_YBlit
32 #include YFM_YSLib_UI_Button
33 #include YFM_YSLib_UI_Selector
34 #include <ystdex/cast.hpp>
35 
36 namespace YSLib
37 {
38 
39 using namespace Drawing;
40 
41 namespace UI
42 {
43 
44 namespace Styles
45 {
46 
47 namespace
48 {
49 
51 void
52 RectDrawButton_Aoi(const PaintContext& pc, Size s, Hue base_hue,
53  CursorState cursor_state, bool is_enabled, bool is_focused)
54 {
55  const bool inside(cursor_state != CursorState::Outside);
56  const auto roll([=](bool b, MonoType gr, const hsl_t& hsl){
57  return MakeGrayOrColor(RollColor(hsl, base_hue), gr, inside || b);
58  });
59  const auto& g(pc.Target);
60 
61  DrawRectRoundCorner(pc, s, is_enabled ? roll(is_focused, 112, {25.640625F,
62  0.493671F, 0.462891F}) : FetchGUIState().Colors[Styles::Workspace]);
63  if(YB_LIKELY(s.Width > 2 && s.Height > 2))
64  {
65  auto pt(pc.Location);
66  const auto& bounds(pc.ClipArea);
67 
68  yunseq(pt.X += 1, pt.Y += 1, s.Width -= 2, s.Height -= 2);
69  FillRect(g, bounds, {pt, s}, is_enabled ? roll(is_focused, 243,
70  {11.304688F, 0.990431F, 0.591797F}) : MakeGray(244));
71  if(is_enabled)
72  {
73  if(s.Width > 2 && s.Height > 2)
74  {
75  Rect rp(pt.X + 1, pt.Y + 1, s.Width - 2, (s.Height - 2) / 2);
76 
77  FillRect(g, bounds, rp,
78  roll({}, 239, {39.132872F, 0.920000F, 0.951172F}));
79  rp.Y += rp.Height;
80  if(s.Height % 2 != 0)
81  ++rp.Height;
82  FillRect(g, bounds, rp,
83  roll({}, 214, {29.523438F, 0.969231F, 0.873047F}));
84  }
85  if(cursor_state == CursorState::Pressed)
86  {
87  const Color tc(RollColor({165, 0.4F, 0.16F}, base_hue));
88 
89  TransformRect(g, bounds & Rect(pt, s), [=](BitmapPtr dst){
90  const Color d(*dst);
91 
92  *dst = Color(d.GetR() ^ tc.GetR(), d.GetG() ^ tc.GetG(),
93  d.GetB() ^ tc.GetB());
94  });
95  }
96  }
97  }
98 }
99 
100 
102 
103 enum SelectorIndex_Aoi
104 {
105  SelectorIndex_Aoi_C1 = 4,
106  SelectorIndex_Aoi_C2 = 8,
107  SelectorIndex_Aoi_C3 = 11,
108  SelectorIndex_Aoi_End = 14
109 };
110 
111 enum ControlState : yimpl(size_t)
112 {
113  ControlState_Focused = 0,
114  ControlState_Enabled = 1,
115  ControlState_Locked = 2,
116  ControlState_Ticked = 3
117 };
118 
119 
120 void
121 RectDrawSelector_Aoi(void(*f)(const PaintContext&, const Size&, const bool[],
122  const Color[], size_t), const PaintContext& pc, Thumb& tmb, bool is_ticked)
123 {
124  const Hue base_hue(tmb.GetHue());
125  const auto roll([=](float h, float s, float l){
126  return RollColor({h, s, l}, base_hue);
127  });
128  const Color colors[]{MakeGray(177), MakeGray(143), roll(2.3F, .315F, .486F),
129  roll(25.9F, .519F, .359F), MakeGray(246), MakeGray(244),
130  roll(2.1F, .737F, .925F), roll(20.8F, .743F, .863F),
131  roll(32.7F, .073F, .704F), roll(23.9F, .914F, .725F),
132  roll(25.5F, .905F, .669F), MakeGray(232), roll(20.F, .934F, .88F),
133  roll(20.8F, .923F, .847F)};
134  const bool ctl_states[]{IsFocused(tmb), IsEnabled(tmb),
135  IsFocusedByShell(tmb), is_ticked};
136 
137  f(pc, GetSizeOf(tmb), ctl_states, colors, [](CursorState s)->size_t{
138  switch(s)
139  {
140  case CursorState::Outside:
141  return 1;
142  case CursorState::Over:
143  return 2;
145  return 3;
146  default:
147  YAssert(false, "Invalid state found.");
148  };
149  return 0;
150  }(tmb.GetCursorState()));
151 }
152 
153 
154 void
155 RectDrawCheckBox_Aoi(const PaintContext& pc, CheckBox& cb)
156 {
157  RectDrawSelector_Aoi([](const PaintContext& pc, const Size& s,
158  const bool cst[], const Color ccs[], size_t c_idx){
159  const auto& g(pc.Target);
160  const auto& pt(pc.Location);
161  const auto& bounds(pc.ClipArea);
162  const Rect r(pt, s);
163  const bool is_enabled(cst[ControlState_Enabled]);
164 
165  DrawRect(g, bounds, r, ccs[is_enabled ? c_idx : 0]);
166  // XXX: Minimal size.
167  if(YB_LIKELY(r.Width > 10 && r.Height > 10))
168  {
169  Rect rt(r);
170 
171  Diminish(rt);
172  FillRect(g, bounds, rt, ccs[SelectorIndex_Aoi_C1
173  + (cst[ControlState_Locked] || cst[ControlState_Focused]
174  ? 2 : is_enabled ? c_idx : 0)]);
175  if(is_enabled)
176  {
177  --c_idx;
178  Diminish(rt);
179  DrawRect(g, bounds, rt, ccs[SelectorIndex_Aoi_C2 + c_idx]);
180  Diminish(rt);
181  FillRect(g, bounds, rt, ccs[SelectorIndex_Aoi_C3 + c_idx]);
182  }
183  }
184  if(cst[ControlState_Ticked])
185  DrawTick(g, bounds, r, is_enabled ? Color(4, 34, 113)
186  : MakeGray(190), is_enabled ? Color(108, 166, 208)
187  : MakeGray(199));
188  }, pc, cb, cb.IsTicked());
189 }
190 
191 void
192 RectDrawRadioBox_Aoi(const PaintContext& pc, RadioBox& rb)
193 {
194  RectDrawSelector_Aoi([](const PaintContext& pc, const Size& s,
195  const bool cst[], const Color ccs[], size_t c_idx){
196  const auto& g(pc.Target);
197  const SDst rad(min(s.Width / 2, s.Height / 2));
198  const auto pt(pc.Location + Size(rad, rad));
199  const auto& bounds(pc.ClipArea);
200  const Rect r(pc.Location, s);
201  const bool is_enabled(cst[ControlState_Enabled]);
202 
203  DrawCircle(g, bounds, pt, rad, ccs[is_enabled ? c_idx : 0]);
204  // XXX: Minimal size.
205  if(YB_LIKELY(r.Width > 10 && r.Height > 10))
206  {
207  SDst radt(rad);
208 
209  FillCircle(g, bounds, pt, --radt, ccs[SelectorIndex_Aoi_C1
210  + (cst[ControlState_Locked] || cst[ControlState_Focused]
211  ? 2 : is_enabled ? c_idx : 0)]);
212  if(is_enabled)
213  {
214  --c_idx;
215  DrawCircle(g, bounds, pt, --radt,
216  ccs[SelectorIndex_Aoi_C2 + c_idx]);
217  DrawCircle(g, bounds, pt, --radt,
218  ccs[SelectorIndex_Aoi_C3 + c_idx]);
219  }
220  }
221  if(cst[ControlState_Ticked])
222  FillCircle(g, bounds, pt, rad - 2, is_enabled ? Color(11, 130, 199)
223  : MakeGray(190));
224  }, pc, rb, rb.IsSelected());
225 }
227 
228 } // unnamed namespace;
229 
230 
231 void
233 {
234  HandlerTable ht;
235 
236  AddHandlers<Thumb>(ht, {{Thumb::ThumbBackground,
237  [](PaintEventArgs&& e){
238  const auto&
239  tmb(ystdex::polymorphic_downcast<Thumb&>(e.GetSender()));
240 
241  RectDrawButton_Aoi(e, GetSizeOf(tmb), tmb.GetHue(),
242  tmb.GetCursorState(), IsEnabled(tmb), IsFocused(tmb));
243  }
244  }}),
245  AddHandlers<CheckBox>(ht, {{CheckBox::CheckBoxBackground,
246  [](PaintEventArgs&& e){
247  RectDrawCheckBox_Aoi(e,
248  ystdex::polymorphic_downcast<CheckBox&>(e.GetSender()));
249  }
250  }}),
251  AddHandlers<RadioBox>(ht, {{CheckBox::CheckBoxBackground,
252  [](PaintEventArgs&& e){
253  RectDrawRadioBox_Aoi(e,
254  ystdex::polymorphic_downcast<RadioBox&>(e.GetSender()));
255  }
256  }});
257  FetchGUIState().Styles.Add("Aoi", std::move(ht));
258 }
259 
260 } // namespace Styles;
261 
262 } // namespace UI;
263 
264 } // namespace YSLib;
265 
pt pt Y const IWidget &wgt const IWidget &wgt GetSizeOf
无效化:使相对于部件的子部件的指定区域在直接和间接的窗口缓冲区中无效。
Definition: ywidget.h:156
YF_API void FillCircle(const Graphics &, const Rect &, const Point &, SDst, Color c)
填充圆形。
Definition: ydraw.cpp:195
YF_API GUIState & FetchGUIState()
取默认图形用户界面公共状态。
Definition: ygui.cpp:442
YF_API void FillRect(const Graphics &g, const Rect &, Color c)
填充标准矩形。
Definition: ydraw.cpp:146
部件绘制参数。
Definition: ywgtevt.h:276
bool IsFocusedByShell(const IWidget &wgt, const GUIState &st=FetchGUIState())
判断指定部件是否被句柄指定的图形用户界面状态锁定为独立焦点。
Definition: ygui.h:318
YF_API void DrawRectRoundCorner(const PaintContext &pc, const Size &s, Color)
绘制部件边框用空心标准矩形。
Definition: ystyle.cpp:42
std::uint16_t SDst
屏幕坐标距离。
Definition: Video.h:39
#define yimpl(...)
实现标签。
Definition: ydef.h:177
YF_API void DrawTick(const Graphics &, const Rect &, const Rect &, Color, Color)
Definition: ystyle.cpp:138
C++ 转换模板。
CursorState
指针设备光标相对于控件的状态。
Definition: ycontrol.h:345
bounds c YF_API void DrawCircle(const Graphics &, const Rect &, const Point &, SDst, Color c)
描画圆形。
Definition: ydraw.cpp:173
#define yunseq
无序列依赖表达式组求值。
Definition: ydef.h:748
YF_API bool IsFocused(const IWidget &)
判断部件是否取得焦点。
Definition: yfocus.cpp:38
unordered_map< Key, Handler, ystdex::combined_hash< Key >> HandlerTable
样式处理器表。
Definition: ystyle.h:259
ystdex::octet MonoType
Definition: Video.h:185
_tWidget _fCallable && f
Definition: ywgtevt.h:597
bool IsEnabled(const IWidget &wgt)
判断部件是否为可用的控件。
Definition: ycontrol.h:86
应用程序工作区背景。
Definition: ystyle.h:185
YF_API void InitExStyles()
初始化扩展样式。
Definition: ExStyle.cpp:232
Color
控制台颜色枚举。
Definition: Video.h:458
PixelType * BitmapPtr
Definition: Video.h:295
bounds & r
Definition: ydraw.h:220
bool TransformRect(const Graphics &g, const Point &pt, const Size &s, _fTransformPixel tp)
以像素为单位变换标准矩形。
Definition: yblit.h:529
c yconstfn g
Definition: ystyle.h:104
#define YB_LIKELY(expr)
Definition: ydef.h:297
YF_API Color RollColor(hsl_t, Hue)
色调偏移。
Definition: ystyle.cpp:238
Styles::StyleMap Styles
样式映射。
Definition: ygui.h:129
p1 p1 p2 p2 c YF_API void DrawRect(const Graphics &g, const Rect &bounds, const Point &pt, const Size &s, Color c)
描画标准矩形。
Definition: ydraw.cpp:131
#define YAssert(_expr, _msg)
Definition: cassert.h:73