YSTest  PreAlpha_b400_20130424
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
progress.cpp
浏览该文件的文档.
1 /*
2  Copyright by FrankHB 2011 - 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 "YSLib/UI/progress.h"
29 #include "YSLib/UI/ygui.h"
30 #include "YSLib/UI/YBrush.h"
31 
33 
35 
36 ProgressBar::ProgressBar(const Rect& r, ValueType m)
37  : Control(r, NoBackgroundTag()), GMRange<float>(m == 0 ? 1 : m, 0)
38 {
39  auto& pal(FetchGUIState().Colors);
40  BorderStyle style;
41 
42  style.ActiveColor = pal[Styles::InactiveBorder];
43  yunseq(
44  Background = SolidBrush(pal[Styles::Track]),
45  ForeColor = pal[Styles::HotTracking],
46  FetchEvent<Paint>(*this).Add(BorderBrush(style), BoundaryPriority)
47  );
48 }
49 
50 void
51 ProgressBar::SetMaxValue(ValueType m)
52 {
53  if(YB_LIKELY(m > 0))
54  {
55  if(YB_LIKELY(value > m))
56  value = m;
57  max_value = m;
58  }
59 }
60 
61 void
62 ProgressBar::Refresh(PaintEventArgs&& e)
63 {
64  const auto& g(e.Target);
65  auto pt(e.Location);
66  Size s(GetSizeOf(*this));
67 
68  e.ClipArea = Rect(pt, s);
69  if(YB_LIKELY(s.Width > 2 && s.Height > 2))
70  {
71  yunseq(s.Width -= 2, s.Height -= 2, pt.X += 1, pt.Y += 1);
72 
73  const SDst w_bar(round(value * s.Width / max_value));
74 
75  FillRect(g, pt, Size(w_bar, s.Height), ForeColor);
76  pt.X += w_bar;
77  if(s.Width > w_bar)
78  // TODO: Finish drawing with non-solid brushes.
79  if(const auto p = Background.target<SolidBrush>())
80  FillRect(g, pt, Size(s.Width - w_bar, s.Height), p->Color);
81  }
82 }
83 
85 
86 YSL_END
87