YSTest  PreAlpha_b500_20140530
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
ywidget.cpp
浏览该文件的文档.
1 /*
2  © 2009-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_YDesktop
30 #include YFM_YSLib_UI_YBrush
31 #include YFM_YSLib_UI_YGUI
32 
33 namespace YSLib
34 {
35 
36 namespace UI
37 {
38 
39 bool
40 Contains(const IWidget& wgt, SPos x, SPos y)
41 {
42  return GetBoundsOf(wgt).Contains(x, y);
43 }
44 
45 bool
46 ContainsVisible(const IWidget& wgt, SPos x, SPos y)
47 {
48  return IsVisible(wgt) && Contains(wgt, x, y);
49 }
50 
51 
52 void
53 SetBoundsOf(IWidget& wgt, const Rect& r)
54 {
55  SetLocationOf(wgt, r.GetPoint()),
56  SetSizeOf(wgt, r.GetSize());
57 }
58 
59 void
61 {
62  wgt.GetRenderer().CommitInvalidation(Rect(GetSizeOf(wgt)));
63 }
64 
65 void
67 {
68  if(const auto p_con = FetchContainerPtr(wgt))
69  p_con->GetRenderer().CommitInvalidation(GetBoundsOf(wgt));
70 }
71 
72 void
73 SetLocationOf(IWidget& wgt, const Point& pt)
74 {
75  if(GetLocationOf(wgt) != pt)
76  {
77  wgt.GetView().SetLocation(pt);
78  CallEvent<Move>(wgt, UIEventArgs(wgt));
79  }
80 }
81 
82 void
83 SetSizeOf(IWidget& wgt, const Size& s)
84 {
85  if(GetSizeOf(wgt) != s)
86  {
87  wgt.GetRenderer().SetSize(s);
88  wgt.GetView().SetSize(s);
89  CallEvent<Resize>(wgt, UIEventArgs(wgt));
90  }
91 }
92 
93 
94 void
95 Close(IWidget& wgt)
96 {
97  Hide(wgt);
98  if(const auto pCon = FetchContainerPtr(wgt))
99  ClearFocusingOf(*pCon);
100 }
101 
102 void
103 Hide(IWidget& wgt)
104 {
105  SetVisibleOf(wgt, false);
106  ReleaseFocus(wgt);
107  Invalidate(wgt);
108 }
109 
110 void
111 Invalidate(IWidget& wgt, const Rect& bounds)
112 {
113  auto p_wgt(&wgt);
114  Rect r(bounds);
115 
116  do
117  {
118  r = p_wgt->GetRenderer().CommitInvalidation(r);
119  r.GetPointRef() += GetLocationOf(*p_wgt);
120  }while((p_wgt = FetchContainerPtr(*p_wgt)));
121 }
122 
123 void
124 InvalidateAll(IWidget& wgt, const Rect& bounds)
125 {
126  InvalidateChildren(wgt, bounds);
127  Invalidate(wgt, bounds);
128 }
129 
130 void
132 {
133  Rect r(wgt.GetRenderer().CommitInvalidation(bounds));
134 
135  for(auto pr(wgt.GetChildren()); pr.first != pr.second; ++pr.first)
136  {
137  auto& child(*pr.first);
138 
139  InvalidateChildren(child, Rect(r - GetLocationOf(child)));
140  }
141 }
142 
143 void
145 {
146  if(const auto p_con = FetchContainerPtr(wgt))
147  Invalidate(*p_con, GetBoundsOf(wgt));
148 }
149 
150 void
151 InvalidateVisible(IWidget& wgt, const Rect& bounds)
152 {
153  auto p_wgt(&wgt);
154  Rect r(bounds);
155 
156  while(IsVisible(*p_wgt))
157  {
158  r = p_wgt->GetRenderer().CommitInvalidation(r);
159  r.GetPointRef() += GetLocationOf(*p_wgt);
160  if(!(p_wgt = FetchContainerPtr(*p_wgt)))
161  break;
162  }
163 }
164 
165 void
167 {
168  if(IsVisible(wgt))
169  if(const auto p_con = FetchContainerPtr(wgt))
170  InvalidateVisible(*p_con, GetBoundsOf(wgt));
171 }
172 
173 void
175 {
176  auto& sender(e.GetSender());
177 
178  if(Clip(e.ClipArea, Rect(e.Location += GetLocationOf(sender),
179  GetSizeOf(sender))))
180  wgt.GetRenderer().Paint(sender, std::move(e));
181 }
182 Rect
183 PaintChild(IWidget& wgt, const PaintContext& pc)
184 {
185  PaintEventArgs e(wgt, pc);
186 
187  PaintChild(wgt, std::move(e));
188  return e.ClipArea;
189 }
190 
191 void
193 {
194  if(IsVisible(wgt))
195  e.ClipArea |= PaintChild(wgt, e);
196 }
197 
198 void
200 {
201  if(const auto p_pnl = dynamic_cast<Panel*>(FetchContainerPtr(wgt)))
202  p_pnl->MoveToFront(wgt);
203 }
204 
205 void
206 Show(IWidget& wgt)
207 {
208  SetVisibleOf(wgt, true);
209  RequestFocus(wgt);
210  Invalidate(wgt);
211 }
212 
213 
215  : view_ptr(new View(r)), renderer_ptr(new Renderer()),
216  controller_ptr(new WidgetController(false)), Background()
217 {
219 }
221  : view_ptr(new View(r)), renderer_ptr(new Renderer()),
222  controller_ptr(new WidgetController(false)), Background(b), ForeColor(f)
223 {
225 }
227  : view_ptr(ClonePolymorphic(wgt.view_ptr)),
228  renderer_ptr(ClonePolymorphic(wgt.renderer_ptr)),
229  controller_ptr(ClonePolymorphic(wgt.controller_ptr)),
230  Background(wgt.Background), ForeColor(wgt.ForeColor)
231 {}
232 Widget::~Widget()
233 {
235 }
236 
237 void
239 {
240  (FetchEvent<Paint>(*this).Add(std::ref(Background), BackgroundPriority))
241  += std::bind(&Widget::Refresh, this, std::placeholders::_1);
242 }
243 
244 HBrush
245 Widget::MakeBlankBrush()
246 {
248 }
249 
250 void
251 Widget::SetRenderer(unique_ptr<Renderer> p)
252 {
253  renderer_ptr = p ? std::move(p) : make_unique<Renderer>();
254  renderer_ptr->SetSize(GetSizeOf(*this));
255 }
256 void
257 Widget::SetView(unique_ptr<View>&& p)
258 {
259  view_ptr = p ? std::move(p)
260  : unique_ptr<View>(new View(GetBoundsOf(*this)));
261 }
262 
263 void
265 {
266  if(!e.ClipArea.IsUnstrictlyEmpty())
267  for(auto pr(GetChildren()); pr.first != pr.second; ++pr.first)
268  PaintVisibleChild(*pr.first, e);
269 }
270 
271 } // namespace UI;
272 
273 } // namespace YSLib;
274 
void InitializeEvents()
初始化事件组。
Definition: ywidget.cpp:238
void InvalidateParent(IWidget &wgt)
Definition: ywidget.cpp:144
bool Clip(Rect &x, const Rect &y)
剪切操作:取标准矩形交集并判断是否严格非空。
Definition: ygdi.h:134
pt pt Y const IWidget &wgt const IWidget &wgt GetSizeOf
无效化:使相对于部件的子部件的指定区域在直接和间接的窗口缓冲区中无效。
Definition: ywidget.h:156
pt pt Y const IWidget &wgt GetLocationOf
Definition: ywidget.h:148
YF_API void SetLocationOf(IWidget &, const Point &)
设置部件左上角所在位置(相对于容器的偏移坐标)。
Definition: ywidget.cpp:73
YF_API GUIState & FetchGUIState()
取默认图形用户界面公共状态。
Definition: ygui.cpp:442
void SetBoundsOf(IWidget &wgt, const Rect &r)
Definition: ywidget.cpp:53
auto ClonePolymorphic(const _type &p) -> decltype(&*p)
使用 clone 成员函数复制指定指针指向的多态类类型对象。
Definition: ycutil.h:479
YF_API void Invalidate(IWidget &, const Rect &)
无效化:使相对于部件的指定区域在直接和间接的窗口缓冲区中无效。
Definition: ywidget.cpp:111
void InvalidateAll(IWidget &wgt, const Rect &bounds)
Definition: ywidget.cpp:124
部件渲染器。
Definition: yrender.h:46
AController *controller_ptr Renderer *renderer_ptr View View
Definition: ywidget.h:440
部件绘制参数。
Definition: ywgtevt.h:276
YF_API void PaintChild(IWidget &wgt, PaintEventArgs &&e)
调用指定子部件的 Paint 事件绘制参数指定的事件发送者。
Definition: ywidget.cpp:174
unique_ptr< View > view_ptr
部件视图指针。
Definition: ywidget.h:364
void SetInvalidationOf(IWidget &wgt)
Definition: ywidget.cpp:60
YF_API void SetSizeOf(IWidget &, const Size &)
设置部件大小。
Definition: ywidget.cpp:83
void InvalidateVisibleParent(IWidget &wgt)
Definition: ywidget.cpp:166
YF_API void Hide(IWidget &)
隐藏部件。
Definition: ywidget.cpp:103
用户界面事件参数基类。
Definition: ywgtevt.h:59
YF_API void Show(IWidget &)
显示部件。
Definition: ywidget.cpp:206
YF_API void PaintVisibleChild(IWidget &, PaintEventArgs &)
调用 PaintChild 指定子部件并合并参数的重绘区域。
Definition: ywidget.cpp:192
YF_API void InvalidateVisible(IWidget &, const Rect &)
无效化:使相对于可见的部件的指定区域在直接和间接的窗口缓冲区中无效。
Definition: ywidget.cpp:151
HBrush Background
背景。
Definition: ywidget.h:374
pt pt Y bool YF_API ContainsVisible(const IWidget &wgt, SPos x, SPos y)
判断点是否在可见部件的可视区域内。
Definition: ywidget.cpp:46
pt pt Y const IWidget &wgt const IWidget &wgt const IWidget &wgt GetBoundsOf
Definition: ywidget.h:163
_tWidget & wgt
Definition: ywgtevt.h:596
屏幕标准矩形:表示屏幕矩形区域。
Definition: ygdibase.h:416
部件控制器。
Definition: ywgtevt.h:608
const IWidget &wgt SPos
Definition: ywidget.h:104
std::function< void(PaintEventArgs &&)> HBrush
画刷回调函数。
Definition: YComponent.h:104
_tWidget _fCallable && f
Definition: ywgtevt.h:597
wgt wgt YF_API void ClearFocusingOf(IWidget &)
清除焦点指针并以此部件作为事件源调用被清除焦点部件的 LostFocus 事件。
Definition: yfocus.cpp:112
部件视图。
Definition: ywgtview.h:137
void CleanupReferences(IWidget &)
清除状态对指定部件的引用。
Definition: ygui.cpp:162
Selected const shared_ptr< ListType > const pair< Color, Color > viewer Contains
Definition: textlist.h:124
Color
控制台颜色枚举。
Definition: Video.h:458
YF_API void SetInvalidationToParent(IWidget &)
在容器设置部件的无效区域。
Definition: ywidget.cpp:66
YF_API void RequestToFront(IWidget &)
请求提升至容器前端。
Definition: ywidget.cpp:199
单色画刷。
Definition: YBrush.h:46
bounds & r
Definition: ydraw.h:220
void SetView(unique_ptr< View > &&)
设置渲染器为指定指针指向的对象,同时更新渲染器状态。
Definition: ywidget.cpp:257
void InvalidateChildren(IWidget &wgt, const Rect &bounds)
Definition: ywidget.cpp:131
virtual void Refresh(PaintEventArgs &&)
刷新:按指定参数绘制界面并更新状态。
Definition: ywidget.cpp:264
屏幕区域大小。
Definition: ygdibase.h:249
enable_if_t<!is_array< _type >::value, std::unique_ptr< _type > > make_unique(_tParams &&...args)
使用 new 和指定参数构造指定类型的 std::unique_ptr 实例。
Definition: memory.hpp:213
部件。
Definition: ywidget.h:356
void Close(IWidget &wgt)
Definition: ywidget.cpp:95
unique_ptr< Renderer > renderer_ptr
渲染器指针。
Definition: ywidget.h:365
yconstexpr EventPriority BackgroundPriority(0xC0)
用户界面绘制优先级。
Widget(const Rect &={})
Definition: ywidget.cpp:214