YSTest: Animation.h 源文件

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
45 yconstexpr Messaging::Priority AnimationPriority(0x20);
46
47
49
50 template<typename _fCallable>
52 void
53 AnimateTask(_fCallable update,
54 Messaging::Priority prior = UI::AnimationPriority)
55 {
56 Messaging::Renew(update, prior);
57 }
58
60 template<typename _fCallable>
61 void
62 AnimateConnection(const shared_ptr<_fCallable>& conn,
63 Messaging::Priority prior = UI::AnimationPriority)
64 {
65 YAssertNonnull(conn);
66 AnimateTask([=]{
67 return (*conn)();
68 }, prior);
69 }
70
75 template<typename _fCallable>
76 void
77 Animate(_fCallable f, Messaging::Priority prior = UI::AnimationPriority)
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:
88 using Connection = ystdex::decay_t<_tCallable>;
89 using ConnectionPtr = shared_ptr<Connection>;
90
91 private:
92 ConnectionPtr conn;
93
94 public:
95 DefDeCtor(GAnimationSession)
97 ~GAnimationSession()
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
112 ImplExpr(AnimateConnection(conn))
113
114 DefGetter(const ynothrow, Connection&, ConnectionRef,
115 (YAssertNonnull(conn), *conn))
116 DefGetter(const ynothrow, const ConnectionPtr&, ConnectionPtr, conn)
117 };
118
119
124 class YF_API InvalidationUpdater
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
YModules.h
YSLib::UI::GAnimationSession::YAssertNonnull
Connection YAssertNonnull(conn)
YSLib::UI::InvalidationUpdater::WidgetPtr
IWidget * WidgetPtr
Definition: Animation.h:129
YSLib::UI::GAnimationSession
动画会话。
Definition: Animation.h:85
YSLib::UI::args
yconstfn const string _tParams && args
Definition: Loader.h:111
YSLib::UI::Invalidate
YF_API void Invalidate(IWidget &, const Rect &)
无效化：使相对于部件的指定区域在直接和间接的窗口缓冲区中无效。
Definition: ywidget.cpp:111
YSLib::UI::InvalidationUpdater::InvalidationUpdater
InvalidationUpdater(IWidget *p_wgt={}, bool ready={})
Definition: Animation.h:141
YSLib::UI::AnimateTask
void AnimateTask(_fCallable update, Messaging::Priority prior=UI::AnimationPriority)
按更新条件和优先级通过消息队列部署动画任务。
Definition: Animation.h:53
YF_API
#define YF_API
Definition: Platform.h:64
YSLib::UI::Animate
void Animate(_fCallable f, Messaging::Priority prior=UI::AnimationPriority)
按指定的可调用对象初始化为连接对象更新动画任务。
Definition: Animation.h:77
YSLib::UI::AnimationPriority
yconstexpr Messaging::Priority AnimationPriority(0x20)
默认背景动画任务消息优先级。
ystdex::decay_t
typename decay< _type >::type decay_t
Definition: type_op.hpp:271
YSLib::UI::GAnimationSession::PDefH
PDefH(void, Start,) const ImplExpr(AnimateConnection(conn)) DefGetter(const ynothrow
使用 ADL 调用 AnimateConnection 开始动画。
YSLib::UI::Restart
_fCallable void Restart(_tAnimation &ani, IWidget &wgt, _fCallable f)
Definition: Animation.h:177
yforward
#define yforward(_expr)
根据参数类型使用 std::forward 传递对应参数。
Definition: ydef.h:722
DefGetter
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:180
YSLib::UI::GAnimationSession< YSLib::UI::InvalidationUpdater >::ConnectionPtr
shared_ptr< Connection > ConnectionPtr
Definition: Animation.h:89
YSLib::UI::GAnimationSession::DefDeCtor
DefDeCtor(GAnimationSession)~GAnimationSession()
使用 ADL 调用 ResetState 函数复位连接对象状态以确保安全。
Definition: Animation.h:95
ImplExpr
#define ImplExpr(...)
Definition: YBaseMacro.h:93
YSLib::UI::wgt
_tWidget & wgt
Definition: ywgtevt.h:596
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:514
YSLib::Messaging::Renew
void Renew(_fCallable update, Priority prior=Messaging::NormalPriority)
按更新条件和优先级通过消息队列部署任务。
Definition: Task.h:57
YAssertNonnull
#define YAssertNonnull(_expr)
Definition: cassert.h:81
YSLib::UI::f
_tWidget _fCallable && f
Definition: ywgtevt.h:597
YSLib::UI::InvalidationUpdater
无效状态更新器。
Definition: Animation.h:124
YSLib::UI::AnimateConnection
void AnimateConnection(const shared_ptr< _fCallable > &conn, Messaging::Priority prior=UI::AnimationPriority)
按指定的连接对象更新动画任务。
Definition: Animation.h:62
YSLib::UI::SetupByTimer
void SetupByTimer(_tAnimation &ani, IWidget &wgt, _tTimer &&timer, _fCallable f)
安装以计时器控制的动画效果。
Definition: Animation.h:210
YSLib::UI::InvalidationUpdater::Ready
bool Ready
准备和最后持续状态：更新函数的最后结果。
Definition: Animation.h:131
yconstexpr
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:462
YSLib::UI::InvalidationUpdater::Invalidator
std::function< bool(IWidget &)> Invalidator
Definition: Animation.h:128
YSLib::UI::GAnimationSession::ConnectionRef
Connection ConnectionRef
Definition: Animation.h:114
YSLib::UI::GAnimationSession::conn
ConnectionPtr conn
Definition: Animation.h:92
YSLib::UI::Setup
void Setup(_tAnimation &ani, IWidget &wgt, _fCallable f)
安装动画效果。
Definition: Animation.h:188
YSLib::UI::GAnimationSession< YSLib::UI::InvalidationUpdater >::Connection
ystdex::decay_t< YSLib::UI::InvalidationUpdater > Connection
Definition: Animation.h:88
YSLib::Messaging::Priority
u8 Priority
消息优先级。
Definition: ymsg.h:52
YSLib::UI::GAnimationSession::Reset
void Reset(_tParams &&...args)
Definition: Animation.h:105