YSTest: Progress.cpp 源文件

YSTest PreAlpha_b800_20170810 The YSLib Test Project

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

- 文件列表
- 文件成员

Progress.cpp
浏览该文件的文档.
1 /*
2 © 2011-2015 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_Service_YBrush
32 #include YFM_YSLib_UI_Border
33
34 namespace YSLib
35 {
36
37 namespace UI
38 {
39
40 ProgressBar::ProgressBar(const Rect& r, ValueType m)
41 : Control(r), GMRange<float>(std::isnormal(m) ? m : 1.F, 0)
42 {
43 const auto invalidator([this]{
44 Invalidate(*this);
45 });
46 auto& pal(FetchGUIConfiguration().Colors);
47
48 yunseq(
49 Background = Drawing::SolidBrush(pal[Styles::Track]),
50 ForeColor = pal[Styles::HotTracking],
51 FetchEvent<Paint>(*this).Add(BorderBrush(
52 BorderStyle(pal[Styles::InactiveBorder])), 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
70 ProgressBar::Refresh(PaintEventArgs&& e)
71 {
72 const auto& g(e.Target);
73 auto pt(e.Location);
74 const Rect& bounds(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, bounds, {pt, w_bar, s.Height}, ForeColor);
84 // XXX: Conversion to 'SPos' might be implementation-defined.
85 pt.X += SPos(w_bar);
86 if(s.Width > w_bar)
87 // TODO: Finish drawing with non-solid brushes.
88 if(const auto p = Background.target<Drawing::SolidBrush>())
89 FillRect(g, bounds, Rect(pt, s.Width - w_bar, s.Height),
90 p->Color);
91 }
92 }
93
94 } // namespace UI;
95
96 } // namespace YSLib;
97
YSLib::UI::FetchGUIConfiguration
GUIConfiguration & FetchGUIConfiguration()
Definition: YGUI.cpp:519
YSLib::UI::ProgressBar::Refresh
void Refresh(PaintEventArgs &&) override
刷新：按指定参数绘制界面并更新状态。
Definition: Progress.cpp:70
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:45
YSLib::UI::BorderStyle
边框样式。
Definition: Border.h:46
UI
YSLib::Drawing::r
The boundary is out of the const Graphics const Rect const Point const Point Color c const Rect const Rect & r
Definition: YDraw.h:174
YSLib::UI::BorderBrush
边框画刷。
Definition: Border.h:68
YSLib::UI::Styles::InactiveBorder
不活动边框背景。
Definition: YStyle.h:322
yunseq
#define yunseq
无序列依赖表达式组求值。
Definition: ydef.h:1022
YSLib::Drawing::FillRect
c YF_API void FillRect(const Graphics &g, const Rect &r, Color c)
填充标准矩形。
Definition: YDraw.cpp:150
YSLib::UI::Invalidate
YF_API void Invalidate(IWidget &, const Rect &)
无效化：使相对部件的指定区域在直接和间接的窗口缓冲区中无效。
Definition: YWidget.cpp:108
YSLib::UI::Styles::HotTracking
Definition: YStyle.h:333
YSLib::UI::Widget::SPos
Renderer AView SPos
Definition: YWidget.h:459
YSLib::Drawing::Size::Width
SDst Width
Definition: YGDIBase.h:302
platform::SDst
std::uint16_t SDst
屏幕坐标距离。
Definition: Video.h:44
YSLib::Drawing::g
The boundary is out of the const Graphics & g
Definition: YDraw.h:161
YSLib::GMRange< float >::max_value
ValueType max_value
最大取值。
Definition: YObject.h:1072
CHRLib::s
_tDst const _tSrc * s
Definition: CharacterProcessing.h:140
YSLib::GMRange< float >::value
ValueType value
值。
Definition: YObject.h:1073
YSLib::UI::PaintEventArgs
部件绘制参数。
Definition: YWidgetEvent.h:323
YSLib::UI::ProgressBar::ForeColor
Color ForeColor
默认前景色。
Definition: Progress.h:53
YSLib::UI::e
void e
Definition: YWidget.h:352
YSLib::UI::Styles::Track
滚动条背景。
Definition: YStyle.h:313
YSLib::UI::BoundaryPriority
yconstexpr const EventPriority BoundaryPriority(0x60)
YModules.h
YSLib::Drawing::Rect
屏幕标准矩形：表示屏幕矩形区域。
Definition: YGDIBase.h:540
YSLib::Drawing::Size::Height
SDst Height
宽和高。
Definition: YGDIBase.h:302
std
Definition: memory.hpp:1183
YSLib::UI::Control
控件。
Definition: YControl.h:275
YSLib::UI::Widget::Background
HBrush Background
背景。
Definition: YWidget.h:391
YSLib::Drawing::Size
屏幕区域大小。
Definition: YGDIBase.h:293
YSLib::GMRange< float >::ValueType
float ValueType
Definition: YObject.h:1069
YSLib::Drawing::SolidBrush
单色画刷。
Definition: YBrush.h:58
YSLib::Drawing::bounds
The boundary is out of the const Rect & bounds
Definition: YDraw.h:127
YB_LIKELY
#define YB_LIKELY(_expr)
Definition: ydef.h:463
YSLib::GMRange
判断是否持有相同对象。
Definition: YObject.h:1066
YSLib::UI::GetSizeOf
pt pt Y const IWidget &wgt const IWidget &wgt GetSizeOf
无效化：使相对部件的子部件的指定区域在直接和间接的窗口缓冲区中无效。
Definition: YWidget.h:161
YSLib::UI::ProgressBar::ProgressBar
ProgressBar(const Rect &={}, ValueType=0xFF)
Definition: Progress.cpp:40
CHRLib::p
const auto p(d)