YSTest  PreAlpha_b500_20140530
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
Animation.h
浏览该文件的文档.
1 /*
2  © 2013-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_Animation_h_
29 #define YSL_INC_UI_Animation_h_ 1
30 
31 #include "YModules.h"
32 #include YFM_YSLib_UI_YWidget
33 #include YFM_YSLib_Core_Task
34 
35 namespace YSLib
36 {
37 
38 namespace UI
39 {
40 
46 
47 
49 
50 template<typename _fCallable>
52 void
53 AnimateTask(_fCallable update,
55 {
56  Messaging::Renew(update, prior);
57 }
58 
60 template<typename _fCallable>
61 void
62 AnimateConnection(const shared_ptr<_fCallable>& conn,
64 {
65  YAssertNonnull(conn);
66  AnimateTask([=]{
67  return (*conn)();
68  }, prior);
69 }
70 
75 template<typename _fCallable>
76 void
78 {
79  AnimateConnection(ystdex::make_shared<_fCallable>(f), prior);
80 }
81 
82 
84 template<typename _tCallable = std::function<bool()>>
85 class GAnimationSession final
86 {
87 public:
89  using ConnectionPtr = shared_ptr<Connection>;
90 
91 private:
93 
94 public:
98  {
99  if(conn)
100  ResetState(*conn);
101  }
102 
103  template<typename... _tParams>
104  void
105  Reset(_tParams&&... args)
106  {
107  conn.reset(new Connection(yforward(args)...));
108  }
109 
111  PDefH(void, Start, ) const
113 
115  (YAssertNonnull(conn), *conn))
116  DefGetter(const ynothrow, const ConnectionPtr&, ConnectionPtr, conn)
117 };
118 
119 
125 {
126 public:
128  using Invalidator = std::function<bool(IWidget&)>;
129  IWidget* WidgetPtr;
131  mutable bool Ready;
132 
138  Invalidator Invalidate{DefaultInvalidate};
139 
140 public:
141  InvalidationUpdater(IWidget* p_wgt = {}, bool ready = {})
142  : WidgetPtr(p_wgt), Ready(ready)
143  {}
144 
146  bool
147  operator()() const;
148 
154  static bool
155  DefaultInvalidate(IWidget&);
156 
162  static bool
163  DefaultInvalidateControl(IWidget&);
164 };
165 
167 inline PDefH(void, ResetState, InvalidationUpdater& updater)
168  ImplExpr(updater.WidgetPtr = {})
170 
171 
172 
174 template<class _tAnimation, typename _fCallable>
176 inline void
177 Restart(_tAnimation& ani, IWidget& wgt, _fCallable f)
178 {
179  ani.Reset(&wgt, true);
180  ani.GetConnectionRef().Invalidate = f;
181  ani.Start();
182 }
183 
185 
186 template<class _tAnimation, typename _fCallable>
187 void
188 Setup(_tAnimation& ani, IWidget& wgt, _fCallable f)
189 {
190  UI::Restart(ani, wgt, [f](IWidget&){
191  f();
192  return true;
193  });
194 }
195 template<class _tAnimation, typename _fCallable, typename _fCond>
196 void
197 Setup(_tAnimation& ani, IWidget& wgt, _fCond cond, _fCallable f)
198 {
199  UI::Restart(ani, wgt, [cond, f](IWidget&){
200  if(cond())
201  f();
202  return true;
203  });
204 }
206 
208 template<class _tAnimation, typename _fCallable, typename _tTimer>
209 void
210 SetupByTimer(_tAnimation& ani, IWidget& wgt, _tTimer&& timer,
211  _fCallable f)
212 {
213  UI::Setup(ani, wgt, [&]{
214  return timer.Refresh();
215  }, f);
216 }
218 
219 } // namespace UI;
220 
221 } // namespace YSLib;
222 
223 #endif
224 
Connection YAssertNonnull(conn)
动画会话。
Definition: Animation.h:85
yconstfn const string _tParams && args
Definition: Loader.h:111
YF_API void Invalidate(IWidget &, const Rect &)
无效化:使相对于部件的指定区域在直接和间接的窗口缓冲区中无效。
Definition: ywidget.cpp:111
InvalidationUpdater(IWidget *p_wgt={}, bool ready={})
Definition: Animation.h:141
void AnimateTask(_fCallable update, Messaging::Priority prior=UI::AnimationPriority)
按更新条件和优先级通过消息队列部署动画任务。
Definition: Animation.h:53
#define YF_API
Definition: Platform.h:64
void Animate(_fCallable f, Messaging::Priority prior=UI::AnimationPriority)
按指定的可调用对象初始化为连接对象更新动画任务。
Definition: Animation.h:77
yconstexpr Messaging::Priority AnimationPriority(0x20)
默认背景动画任务消息优先级。
typename decay< _type >::type decay_t
Definition: type_op.hpp:271
PDefH(void, Start,) const ImplExpr(AnimateConnection(conn)) DefGetter(const ynothrow
使用 ADL 调用 AnimateConnection 开始动画。
_fCallable void Restart(_tAnimation &ani, IWidget &wgt, _fCallable f)
Definition: Animation.h:177
#define yforward(_expr)
根据参数类型使用 std::forward 传递对应参数。
Definition: ydef.h:722
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:180
DefDeCtor(GAnimationSession)~GAnimationSession()
使用 ADL 调用 ResetState 函数复位连接对象状态以确保安全。
Definition: Animation.h:95
#define ImplExpr(...)
Definition: YBaseMacro.h:93
_tWidget & wgt
Definition: ywgtevt.h:596
#define ynothrow
YSLib 无异常抛出保证:若支持 noexcept 关键字, 指定特定的 noexcept 异常规范。
Definition: ydef.h:514
void Renew(_fCallable update, Priority prior=Messaging::NormalPriority)
按更新条件和优先级通过消息队列部署任务。
Definition: Task.h:57
#define YAssertNonnull(_expr)
Definition: cassert.h:81
_tWidget _fCallable && f
Definition: ywgtevt.h:597
无效状态更新器。
Definition: Animation.h:124
void AnimateConnection(const shared_ptr< _fCallable > &conn, Messaging::Priority prior=UI::AnimationPriority)
按指定的连接对象更新动画任务。
Definition: Animation.h:62
void SetupByTimer(_tAnimation &ani, IWidget &wgt, _tTimer &&timer, _fCallable f)
安装以计时器控制的动画效果。
Definition: Animation.h:210
bool Ready
准备和最后持续状态:更新函数的最后结果。
Definition: Animation.h:131
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:462
std::function< bool(IWidget &)> Invalidator
Definition: Animation.h:128
void Setup(_tAnimation &ani, IWidget &wgt, _fCallable f)
安装动画效果。
Definition: Animation.h:188
ystdex::decay_t< YSLib::UI::InvalidationUpdater > Connection
Definition: Animation.h:88
u8 Priority
消息优先级。
Definition: ymsg.h:52
void Reset(_tParams &&...args)
Definition: Animation.h:105