YSTest  PreAlpha_b400_20130424
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
ywidget.h
浏览该文件的文档.
1 /*
2  Copyright by FrankHB 2009 - 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 #ifndef YSL_INC_UI_ywidget_h_
29 #define YSL_INC_UI_ywidget_h_ 1
30 
31 #include "ycomp.h"
32 #include "yfocus.h"
33 #include "ywgtview.h"
34 #include <ystdex/any_iterator.hpp> // for ystdex::any_input_iterator;
35 
37 
39 
40 
44 typedef ystdex::any_input_iterator<IWidget> WidgetIterator;
49 typedef pair<WidgetIterator, WidgetIterator> WidgetRange;
50 
51 
60  DeclIEntry(Renderer& GetRenderer() const)
65  DeclIEntry(View& GetView() const)
69  DeclIEntry(AController& GetController() const)
75  DeclIEntry(WidgetRange GetChildren())
76 EndDecl
77 
78 
83 inline bool
84 IsVisible(const IWidget& wgt)
85 {
86  return wgt.GetView().IsVisible();
87 }
88 
93 bool
94 YF_API Contains(const IWidget&, SPos, SPos);
99 inline bool
100 Contains(const IWidget& wgt, const Point& pt)
101 {
102  return Contains(wgt, pt.X, pt.Y);
103 }
104 
109 bool
110 YF_API ContainsVisible(const IWidget& wgt, SPos x, SPos y);
115 inline bool
116 ContainsVisible(const IWidget& wgt, const Point& pt)
117 {
118  return ContainsVisible(wgt, pt.X, pt.Y);
119 }
120 
121 
128 inline IWidget*
130 {
131  return wgt.GetView().ContainerPtr;
132 }
133 
140 inline IWidget*
142 {
143  return wgt.GetView().FocusingPtr;
144 }
145 
151 inline const Point&
153 {
154  return wgt.GetView().GetLocation();
155 }
156 
162 inline const Size&
163 GetSizeOf(const IWidget& wgt)
164 {
165  return wgt.GetView().GetSize();
166 }
167 
172 inline Rect
173 GetBoundsOf(const IWidget& wgt)
174 {
175  return Rect(GetLocationOf(wgt), GetSizeOf(wgt));
176 }
177 
182 YF_API void
183 SetBoundsOf(IWidget&, const Rect&);
184 
189 inline void
191 {
192  wgt.GetView().ContainerPtr = pCon;
193 }
194 
199 YF_API void
200 SetInvalidationOf(IWidget&);
201 
207 YF_API void
208 SetInvalidationToParent(IWidget&);
209 
214 YF_API void
215 SetLocationOf(IWidget&, const Point&);
216 
217 /*
218 \brief 设置部件大小。
219 \since build 259
220 */
221 YF_API void
222 SetSizeOf(IWidget&, const Size&);
223 
228 inline void
229 SetVisibleOf(IWidget& wgt, bool b)
230 {
231  wgt.GetView().SetVisible(b);
232 }
233 
234 
241 YF_API void
242 Close(IWidget&);
243 
248 YF_API void
249 DrawArrow(PaintEventArgs&&, IWidget&, SDst = 4, Drawing::Rotation
251 
257 YF_API void
258 Hide(IWidget&);
259 
264 YF_API void
265 Invalidate(IWidget&);
270 YF_API void
271 Invalidate(IWidget&, const Rect&);
272 
273 /*
274 \brief 调用指定子部件的 Paint 事件绘制参数指定的事件发送者。
275 \see Renderer::Paint 。
276 \since build 263
277 
278 以 e.Sender() 作为绘制目标,判断其边界是否和区域 e.ClipArea 相交,
279 若相交区域非空则调用 wgt 的渲染器的 Paint 方法绘制 。
280 调用中, e.Location 被修改为相对子部件的坐标, e.ClipArea 被覆盖为相交区域。
281 之后, e 可继续被 e.GetSender() 的渲染器的 Paint 方法修改。
282 */
283 YF_API void
284 PaintChild(IWidget& wgt, PaintEventArgs&& e);
285 /*
286 \brief 调用指定子部件的 Paint 事件绘制指定子部件。
287 \return 实际绘制的区域。
288 \note 使用指定子部件作为事件发送者并复制参数。
289 \since build 294
290 
291 以 wgt 作为绘制目标,判断其边界是否和区域 pc.ClipArea 相交,
292 若相交区域非空则调用 wgt 的渲染器的 Paint 方法绘制 。
293 */
294 YF_API Rect
295 PaintChild(IWidget& wgt, const PaintContext& pc);
296 
297 
303 YF_API void
304 RequestToTop(IWidget&);
305 
306 
313 YF_API void
314 Show(IWidget&);
315 
316 
322 {
323 public:
329  {};
330 
331 private:
337  unique_ptr<View> view_ptr;
338  unique_ptr<Renderer> renderer_ptr;
339  unique_ptr<AController> controller_ptr;
340 
341 
342 public:
349 
351  explicit
361  template<typename _tView, typename _tRenderer, typename _tController>
362  explicit inline
363  Widget(_tView&& pView_ = make_unique<View>(),
364  _tRenderer&& pRenderer_ = make_unique<Renderer>(),
365  _tController&& pController_ = {})
366  : view_ptr(yforward(pView_)), renderer_ptr(yforward(pRenderer_)),
367  controller_ptr(yforward(pController_)),
368  Background(), ForeColor(Drawing::ColorSpace::Black)
369  {
370  YAssert(bool(view_ptr) && bool(renderer_ptr), "Null pointer found.");
371 
372  InitializeEvents();
373  }
377  Widget(const Widget&);
378  DefDeMoveCtor(Widget)
385  virtual
386  ~Widget();
387 
388 private:
393  void
394  InitializeEvents();
395 
396 public:
397  DefGetterMem(const ynothrow, SPos, X, GetView())
398  DefGetterMem(const ynothrow, SPos, Y, GetView())
399  DefGetterMem(const ynothrow, SDst, Width, GetView())
400  DefGetterMem(const ynothrow, SDst, Height, GetView())
401  ImplI(IWidget) DefGetter(const ynothrow, Renderer&, Renderer, *renderer_ptr)
402  ImplI(IWidget) DefGetter(const ynothrow, View&, View, *view_ptr)
404  GetController() const override;
406  ImplI(IWidget) DefGetter(override, WidgetRange, Children, WidgetRange())
407 
408  DefSetterMem(SDst, X, GetView())
409  DefSetterMem(SDst, Y, GetView())
410  DefSetterMem(SDst, Width, GetView())
411  DefSetterMem(SDst, Height, GetView())
417  void
418  SetRenderer(unique_ptr<Renderer>&&);
424  void
425  SetView(unique_ptr<View>&&);
426 
438  ImplI(IWidget) void
439  Refresh(PaintEventArgs&&);
440 };
441 
443 
444 YSL_END
445 
446 #endif
447