YSTest  PreAlpha_b500_20140530
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
progress.cpp
浏览该文件的文档.
1 /*
2  © 2011-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_Progress
30 #include YFM_YSLib_UI_YGUI
31 #include YFM_YSLib_UI_Border
32 
33 namespace YSLib
34 {
35 
36 namespace UI
37 {
38 
40  : Control(r), GMRange<float>(m == 0 ? 1 : m, 0)
41 {
42  const auto invalidator([this]{
43  Invalidate(*this);
44  });
45  auto& pal(FetchGUIState().Colors);
46  BorderStyle style;
47 
49  yunseq(
52  FetchEvent<Paint>(*this).Add(BorderBrush(style), BoundaryPriority),
53  FetchEvent<GotFocus>(*this) += invalidator,
54  FetchEvent<LostFocus>(*this) += invalidator
55  );
56 }
57 
58 void
59 ProgressBar::SetMaxValue(ValueType m)
60 {
61  if(YB_LIKELY(m > 0))
62  {
63  if(YB_LIKELY(value > m))
64  value = m;
65  max_value = m;
66  }
67 }
68 
69 void
71 {
72  const auto& g(e.Target);
73  auto pt(e.Location);
74  auto& r(e.ClipArea);
75  Size s(GetSizeOf(*this));
76 
77  if(YB_LIKELY(s.Width > 2 && s.Height > 2))
78  {
79  yunseq(s.Width -= 2, s.Height -= 2, pt.X += 1, pt.Y += 1);
80 
81  const SDst w_bar(round(value * s.Width / max_value));
82 
83  FillRect(g, r, {pt, w_bar, s.Height}, ForeColor);
84  pt.X += w_bar;
85  if(s.Width > w_bar)
86  // TODO: Finish drawing with non-solid brushes.
87  if(const auto p = Background.target<SolidBrush>())
88  FillRect(g, r, Rect(pt, s.Width - w_bar, s.Height), p->Color);
89  }
90 }
91 
92 } // namespace UI;
93 
94 } // namespace YSLib;
95 
范围模块类。
Definition: yobject.h:532
pt pt Y const IWidget &wgt const IWidget &wgt GetSizeOf
无效化:使相对于部件的子部件的指定区域在直接和间接的窗口缓冲区中无效。
Definition: ywidget.h:156
YF_API GUIState & FetchGUIState()
取默认图形用户界面公共状态。
Definition: ygui.cpp:442
YF_API void FillRect(const Graphics &g, const Rect &, Color c)
填充标准矩形。
Definition: ydraw.cpp:146
YF_API void Invalidate(IWidget &, const Rect &)
无效化:使相对于部件的指定区域在直接和间接的窗口缓冲区中无效。
Definition: ywidget.cpp:111
ProgressBar(const Rect &={}, ValueType=0xFF)
Definition: progress.cpp:39
部件绘制参数。
Definition: ywgtevt.h:276
ValueType max_value
最大取值。
Definition: yobject.h:538
SDst Height
宽和高。
Definition: ygdibase.h:258
不活动边框背景。
Definition: ystyle.h:193
yconstexpr EventPriority BoundaryPriority(0x60)
std::uint16_t SDst
屏幕坐标距离。
Definition: Video.h:39
控件。
Definition: ycontrol.h:275
边框样式。
Definition: Border.h:45
边框画刷。
Definition: Border.h:59
HBrush Background
背景。
Definition: ywidget.h:374
#define yunseq
无序列依赖表达式组求值。
Definition: ydef.h:748
屏幕标准矩形:表示屏幕矩形区域。
Definition: ygdibase.h:416
ValueType value
值。
Definition: yobject.h:539
单色画刷。
Definition: YBrush.h:46
bounds & r
Definition: ydraw.h:220
c yconstfn g
Definition: ystyle.h:104
#define YB_LIKELY(expr)
Definition: ydef.h:297
Color ForeColor
默认前景色。
Definition: ywidget.h:375
滚动条背景。
Definition: ystyle.h:184
屏幕区域大小。
Definition: ygdibase.h:249
void Refresh(PaintEventArgs &&) override
刷新:按指定参数绘制界面并更新状态。
Definition: progress.cpp:70