YSTest  PreAlpha_b500_20140530
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
ycontrol.h
浏览该文件的文档.
1 /*
2  © 2010-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 #ifndef YSL_INC_UI_ycontrol_h_
29 #define YSL_INC_UI_ycontrol_h_ 1
30 
31 #include "YModules.h"
32 #include YFM_YSLib_UI_YWidget
33 #include YFM_YSLib_UI_YWidgetEvent
34 
35 namespace YSLib
36 {
37 
38 namespace UI
39 {
40 
46 using namespace Drawing;
47 
54 {
55 protected:
57 
58 public:
59  explicit
60  Controller(bool b)
61  : AController(b), EventMap()
62  {}
64  template<typename... _tParams>
65  Controller(bool b, _tParams&&... args)
66  : AController(b), EventMap(yforward(args)...)
67  {}
68 
69  ImplI(AController) PDefH(EventMapping::ItemType&, GetItem,
70  const VisualEvent& id)
71  ImplRet(EventMap.at(id))
72  EventMapping::ItemType&
73  GetItemRef(const VisualEvent&, EventMapping::MappedType(&)()) override;
74  DefGetter(const ynothrow, EventMapping::MapType&, EventMap, EventMap) \
76 
78  ImplI(AController) DefClone(const override, Controller)
79 };
80 
81 
85 inline bool
86 IsEnabled(const IWidget& wgt)
87 {
88  try
89  {
90  return wgt.GetController().IsEnabled();
91  }
92  catch(BadEvent&)
93  {}
94  return false;
95 }
96 
100 inline void
101 SetEnabledOf(IWidget& wgt, bool b)
102 {
103  try
104  {
105  wgt.GetController().SetEnabled(b);
106  }
107  catch(BadEvent&)
108  {}
109 }
110 
116 YF_API bool
117 Enable(IWidget&, bool = true);
118 
119 
130 template<VisualEvent _vID>
132 FetchEvent(IWidget& wgt)
133 {
134  return FetchEvent<_vID>(wgt.GetController());
135 }
136 
142 template<VisualEvent _vID, typename _tEventArgs>
143 inline size_t
144 CallEvent(IWidget& wgt, _tEventArgs&& e)
145 {
146  using HandlerType = typename EventTypeMapping<_vID>::HandlerType;
147  static_assert(std::is_convertible<ystdex::remove_reference_t<_tEventArgs>,
148  ystdex::remove_reference_t<typename EventArgsHead<typename
149  HandlerType::TupleType>::type>>::value,
150  "Invalid event argument type found @ CallEvent;");
151 
152  try
153  {
154  return DoEvent<HandlerType>(wgt.GetController(), _vID, std::move(e));
155  }
156  catch(BadEvent&)
157  {}
158  return 0;
159 }
160 
161 
162 //公共事件处理器。
163 
171 template<VisualEvent _vID, class _tEventArgs>
172 inline void
173 OnEvent_Call(_tEventArgs&& e)
174 {
175  CallEvent<_vID>(e.GetSender(), e);
176 }
177 
178 /*
179 \brief 处理事件:停止事件路由。
180 \since build 285
181 */
182 template<class _tEventArgs>
183 inline void
184 OnEvent_StopRouting(_tEventArgs&& e)
185 {
186  e.Handled = true;
187 }
188 
189 
194 YF_API void
196 
197 
201 YF_API void
203 
213 YF_API void
215 
221 YF_API void
223 
229 YF_API void
231 
237 YF_API void
239 
240 
248 YF_API void
250 
258 YF_API void
260 
267 YF_API void
269 
270 
275 class YF_API Control : public Widget
276 {
277 protected:
283  DefExtendEventMap(YF_API ControlEventMap, VisualEventMap)
284 
285 public:
286  //标准控件事件见 VisualEvent 。
287 
288  //其它扩展控件事件示例。
289 // DeclEvent(H1Event, Ext1) //!< 扩展事件 1 。
290 // DeclEvent(H2Event, Ext2) //!< 扩展事件 2 。
291 
292  //事件组映射。
299  std::function<IWidget*(const KeyInput&)> BoundControlPtr;
300 
309  explicit
310  Control(const Rect& = {});
316  explicit
321  Control(const Control&);
322  DefDeMoveCtor(Control)
323 
324 
327  virtual PDefH(IWidget*, GetBoundControlPtr, const KeyInput&)
328  ImplRet(nullptr)
329 
336  void
337  OnTouch_Close(CursorEventArgs&&);
338 };
339 
340 
345 enum class CursorState
346 {
347  Outside,
348  Over,
349  Pressed
350 };
351 
352 } // namespace UI;
353 
354 } // namespace YSLib;
355 
356 #endif
357 
YF_API void OnKeyHeld(KeyEventArgs &&)
处理键接触保持事件。
Definition: ycontrol.cpp:108
YF_API void OnKey_Bound_TouchDown(KeyEventArgs &&)
处理按键事件:按键-指针设备接触开始。
Definition: ycontrol.cpp:171
控制器抽象类。
Definition: ywgtevt.h:468
Controller(bool b, _tParams &&...args)
Definition: ycontrol.h:65
GEventPointerWrapper< UIEventArgs && > MappedType
映射项类型。
Definition: ywgtevt.h:423
typename remove_reference< _type >::type remove_reference_t
Definition: type_op.hpp:234
按键输入事件参数类。
Definition: ywgtevt.h:167
yconstfn const string _tParams && args
Definition: Loader.h:111
#define DefExtendEventMap(_n, _b)
定义扩展事件映射类。
Definition: yevt.hpp:852
#define YF_API
Definition: Platform.h:64
GIHEvent< UIEventArgs && > ItemType
Definition: ywgtevt.h:424
EventT(typename EventTypeMapping< _vID >::HandlerType)&FetchEvent(IWidget &wgt)
取部件事件。
Definition: ycontrol.h:131
YF_API void OnTouchHeld_DraggingRaw(CursorEventArgs &&, IWidget &)
处理屏幕接触移动事件:拖放指定部件。
Definition: ycontrol.cpp:151
YF_API bool Enable(IWidget &, bool=true)
设置部件可用性,且当可用性改变时无效化部件区域。
Definition: ycontrol.cpp:90
YF_API void OnTouchHeld_Dragging(CursorEventArgs &&)
处理屏幕接触移动事件:拖放按下部件。
Definition: ycontrol.cpp:144
用户界面事件参数基类。
Definition: ywgtevt.h:59
#define yforward(_expr)
根据参数类型使用 std::forward 传递对应参数。
Definition: ydef.h:722
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:180
#define ImplI(...)
Definition: YBaseMacro.h:308
控件。
Definition: ycontrol.h:275
void SetEnabledOf(IWidget &wgt, bool b)
设置部件可用性。
Definition: ycontrol.h:101
map< VisualEvent, MappedType > MapType
映射表类型。
Definition: ywgtevt.h:426
YF_API void OnTouchHeld(CursorEventArgs &&)
处理屏幕接触保持事件。
Definition: ycontrol.cpp:131
PDefH(void, Activate, Console &console, Drawing::Color fc=Drawing::ColorSpace::White) ImplExpr(Activate(console
激活:使用指定屏幕、有效性、前景色和默认背景色。
CursorState
指针设备光标相对于控件的状态。
Definition: ycontrol.h:345
_tWidget & wgt
Definition: ywgtevt.h:596
#define ynothrow
YSLib 无异常抛出保证:若支持 noexcept 关键字, 指定特定的 noexcept 异常规范。
Definition: ydef.h:514
部件控制器。
Definition: ycontrol.h:53
YF_API void OnTouchDown_RequestToFrontFocused(CursorEventArgs &&)
处理屏幕接触开始事件:使用一般接触策略。
Definition: ycontrol.cpp:118
屏幕标准矩形:表示屏幕矩形区域。
Definition: ygdibase.h:416
EventMapping::MapType VisualEventMap
Definition: ywgtevt.h:432
std::function< void(PaintEventArgs &&)> HBrush
画刷回调函数。
Definition: YComponent.h:104
void OnEvent_Call(_tEventArgs &&e)
处理事件:直接转发至发送者。
Definition: ycontrol.h:173
void OnEvent_StopRouting(_tEventArgs &&e)
Definition: ycontrol.h:184
bool IsEnabled(const IWidget &wgt)
判断部件是否为可用的控件。
Definition: ycontrol.h:86
错误或不存在的部件事件异常。
Definition: ywgtevt.h:440
#define DefClone(_q, _t)
动态复制。
Definition: YBaseMacro.h:221
EventMapping::MapType EventMap
事件映射表。
Definition: ycontrol.h:56
const IWidget &wgt ImplRet(wgt.GetView().IsVisible()) bool YF_API Contains(const IWidget &
判断点是否在部件的可视区域内。
YF_API void OnKey_Bound_TouchUp(KeyEventArgs &&)
处理按键事件:按键-指针设备接触结束。
Definition: ycontrol.cpp:159
Selected const shared_ptr< ListType > const pair< Color, Color > & DefDeMoveCtor(TextList) DefPredMem(const ynothrow
YF_API void OnKey_Bound_Click(KeyEventArgs &&)
处理按键事件:按键-指针设备按下。
Definition: ycontrol.cpp:183
size_t CallEvent(IWidget &wgt, _tEventArgs &&e)
调用部件事件,并忽略 BadEvent 异常。
Definition: ycontrol.h:144
颜色。
Definition: Video.h:339
部件。
Definition: ywidget.h:356
指针设备输入事件参数类。
Definition: ywgtevt.h:183
std::bitset< KeyBitsetWidth > KeyInput
按键并行位宽。
Definition: Keys.h:68
YF_API void OnUIEvent_Invalidate(UIEventArgs &&)
处理用户界面事件:无效化发送者。
Definition: ycontrol.cpp:102