YSTest: Animation.h 源文件

YSTest PreAlpha_b800_20170810 The YSLib Test Project

- 首页
- 相关页面
- 模块
- 命名空间
- 类
- 文件

- 文件列表
- 文件成员

Animation.h
浏览该文件的文档.
1 /*
2 © 2013-2017 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 #include YFM_YSLib_Service_YTimer // for Timers::TimeSpan;
35
36 namespace YSLib
37 {
38
39 namespace UI
40 {
41
46 yconstexpr const Messaging::Priority AnimationPriority(0x20);
47
48
50
51 template<typename _fUpdater>
53 void
54 AnimateTask(_fUpdater update, Messaging::Priority prior = UI::AnimationPriority)
55 {
56 Messaging::Renew(update, prior);
57 }
58
60 template<typename _fUpdater>
61 void
62 AnimateConnection(const shared_ptr<_fUpdater>& conn,
63 Messaging::Priority prior = UI::AnimationPriority)
64 {
65 YAssertNonnull(conn);
66 AnimateTask([=]{
67 return (*conn)();
68 }, prior);
69 }
70
75 template<typename _fUpdater>
76 void
77 Animate(_fUpdater f, Messaging::Priority prior = UI::AnimationPriority)
78 {
79 AnimateConnection(share_copy(f), prior);
80 }
81
82
84 template<typename _fUpdater = std::function<bool()>>
85 class GAnimationSession final
86 {
87 public:
88 using Connection = ystdex::decay_t<_fUpdater>;
89 using ConnectionPtr = shared_ptr<Connection>;
90
91 private:
92 ConnectionPtr conn;
93
94 public:
95 DefDeCtor(GAnimationSession)
100 ~GAnimationSession()
101 {
102 if(conn)
103 ResetState(*conn);
104 }
105
106 template<typename... _tParams>
107 void
108 Reset(_tParams&&... args)
109 {
110 conn.reset(new Connection(yforward(args)...));
111 }
112
114 PDefH(void, Start, ) const
115 ImplExpr(AnimateConnection(conn))
116
117 DefGetter(const ynothrow, Connection&, ConnectionRef, Deref(conn))
118 DefGetter(const ynothrow, const ConnectionPtr&, ConnectionPtr, conn)
119 };
120
121
126 class YF_API InvalidationUpdater
127 {
128 public:
130 using Invalidator = std::function<bool(IWidget&)>;
132 observer_ptr<IWidget> WidgetPtr;
134 mutable bool Ready;
135
141 Invalidator Invalidate{DefaultInvalidate};
142
143 public:
145 InvalidationUpdater(observer_ptr<IWidget> p_wgt = {}, bool ready = {})
146 : WidgetPtr(p_wgt), Ready(ready)
147 {}
148
150 bool
151 operator()() const;
152
158 static bool
159 DefaultInvalidate(IWidget&);
160
166 static bool
167 DefaultInvalidateControl(IWidget&);
168 };
169
174 inline PDefH(void, ResetState, InvalidationUpdater& updater) ynothrow
175 ImplExpr(updater.WidgetPtr = {})
177
178
179
181 template<class _tAnimation, typename _fCallable>
183 inline void
184 Restart(_tAnimation& ani, IWidget& wgt, _fCallable f)
185 {
186 ani.Reset(make_observer(&wgt), true);
187 ani.GetConnectionRef().Invalidate = f;
188 ani.Start();
189 }
190
192
193 template<class _tAnimation, typename _func>
194 void
195 Setup(_tAnimation& ani, IWidget& wgt, _func f)
196 {
197 UI::Restart(ani, wgt, [f](IWidget&) ynoexcept_spec(f()){
198 f();
199 return true;
200 });
201 }
202 template<class _tAnimation, typename _func, typename _fCond>
203 void
204 Setup(_tAnimation& ani, IWidget& wgt, _fCond cond, _func f)
205 {
206 UI::Restart(ani, wgt,
207 [cond, f](IWidget&) ynoexcept(noexcept(cond()) && noexcept(f())){
208 if(cond())
209 f();
210 return true;
211 });
212 }
214
216 template<class _tAnimation, typename _func, typename _tTimer>
217 void
218 SetupByTimer(_tAnimation& ani, IWidget& wgt, _tTimer&& timer, _func f)
219 {
220 UI::Setup(ani, wgt, [&]() ynoexcept_spec(timer.Refresh()){
221 return timer.Refresh();
222 }, f);
223 }
225
226
231 YF_API void
232 ActAfter(IWidget&, Timers::TimeSpan);
233
238 inline PDefH(void, DisplayFor, IWidget& wgt, Timers::TimeSpan delay)
239 ImplExpr(Show(wgt), ActAfter(wgt, delay))
240
241 } // namespace UI;
242
243 } // namespace YSLib;
244
245 #endif
246
YSLib::UI::ynothrow
AView &y ynothrow
Definition: YWidgetView.cpp:47
YSLib::UI::args
yconstfn const string _tParams && args
Definition: Loader.h:131
platform::KeyCodes::DS::Start
Definition: Keys.h:218
YSLib::Messaging::Priority
std::uint8_t Priority
消息优先级。
Definition: YMessage.h:51
ystdex::share_copy
std::shared_ptr< decay_t< _type > > share_copy(const _tValue &v)
复制值创建对应的 std::shared_ptr 实例的对象。
Definition: memory.hpp:971
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:45
UI
ystdex::make_observer
observer_ptr< _type > make_observer(_type *p)
Definition: pointer.hpp:326
YSLib::UI::InvalidationUpdater::WidgetPtr
observer_ptr< IWidget > WidgetPtr
Definition: Animation.h:132
YSLib::UI::AnimateConnection
void AnimateConnection(const shared_ptr< _fUpdater > &conn, Messaging::Priority prior=UI::AnimationPriority)
按指定的连接对象更新动画任务。
Definition: Animation.h:62
YSLib::UI::GAnimationSession< InvalidationUpdater >::Connection
ystdex::decay_t< InvalidationUpdater > Connection
Definition: Animation.h:88
CHRLib::f
f(d, s)
YSLib::UI::InvalidationUpdater::InvalidationUpdater
InvalidationUpdater(observer_ptr< IWidget > p_wgt={}, bool ready={})
Definition: Animation.h:145
ynoexcept_spec
#define ynoexcept_spec(...)
表达式 noexcept 异常规范。
Definition: ydef.h:794
YSLib::UI::wgt
IWidget & wgt
Definition: YControl.h:112
YAssertNonnull
#define YAssertNonnull(_expr)
Definition: cassert.h:120
yconstexpr
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:679
YSLib::UI::GAnimationSession::Deref
Connection Deref(conn)) DefGetter(const ynothrow
YSLib::UI::Invalidate
YF_API void Invalidate(IWidget &, const Rect &)
无效化：使相对部件的指定区域在直接和间接的窗口缓冲区中无效。
Definition: YWidget.cpp:108
YSLib::UI::GAnimationSession::DefDeCtor
DefDeCtor(GAnimationSession)~GAnimationSession()
使用 ADL 调用 ResetState 函数复位连接对象状态以确保安全。
Definition: Animation.h:95
YSLib::UI::GAnimationSession::Reset
void Reset(_tParams &&...args)
Definition: Animation.h:108
YSLib::UI::ActAfter
YF_API void ActAfter(IWidget &, Timers::TimeSpan)
在一定时间后对部件进行操作。
Definition: Animation.cpp:63
YSLib::UI::InvalidationUpdater::Invalidator
std::function< bool(IWidget &)> Invalidator
Definition: Animation.h:130
YSLib::UI::AnimationPriority
yconstexpr const Messaging::Priority AnimationPriority(0x20)
默认背景动画任务消息优先级。
YSLib::UI::Setup
void Setup(_tAnimation &ani, IWidget &wgt, _func f)
安装动画效果。
Definition: Animation.h:195
YF_API
#define YF_API
Definition: Platform.h:56
YSLib::UI::GAnimationSession::ConnectionRef
Connection ConnectionRef
Definition: Animation.h:117
YSLib::UI::InvalidationUpdater::Ready
bool Ready
准备和最后持续状态：更新函数的最后结果。
Definition: Animation.h:134
YModules.h
YSLib::UI::Show
YF_API void Show(IWidget &)
显示部件。
Definition: YWidget.cpp:202
YSLib::UI::Restart
_fCallable void Restart(_tAnimation &ani, IWidget &wgt, _fCallable f)
Definition: Animation.h:184
YSLib::UI::GAnimationSession::conn
ConnectionPtr conn
Definition: Animation.h:92
DefGetter
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:241
YSLib::UI::ImplExpr
IWidget bool b ImplExpr(wgt.GetController().SetEnabled(b)) YF_API bool Enable(IWidget &
设置部件可用性，且当可用性改变时无效化部件区域。
yforward
#define yforward(_expr)
根据参数类型使用 std::forward 传递对应参数。
Definition: ydef.h:995
YSLib::UI::GAnimationSession< InvalidationUpdater >::ConnectionPtr
shared_ptr< Connection > ConnectionPtr
Definition: Animation.h:89
YSLib::Messaging::Renew
void Renew(_fUpdater update, Priority prior=Messaging::NormalPriority)
按更新条件和优先级通过消息队列部署任务。
Definition: Task.h:57
YSLib::UI::AnimateTask
void AnimateTask(_fUpdater update, Messaging::Priority prior=UI::AnimationPriority)
按更新条件和优先级通过消息队列部署动画任务。
Definition: Animation.h:54
YSLib::UI::Animate
void Animate(_fUpdater f, Messaging::Priority prior=UI::AnimationPriority)
按指定的可调用对象初始化为连接对象更新动画任务。
Definition: Animation.h:77
YSLib::UI::GAnimationSession::PDefH
PDefH(void, Start,) const ImplExpr(AnimateConnection(conn)) DefGetter(const ynothrow
使用 ADL 调用 AnimateConnection 开始动画。
YSLib::UI::SetupByTimer
void SetupByTimer(_tAnimation &ani, IWidget &wgt, _tTimer &&timer, _func f)
安装以计时器控制的动画效果。
Definition: Animation.h:218
YSLib::UI::InvalidationUpdater
无效状态更新器。
Definition: Animation.h:126
YSLib::Timers::TimeSpan
std::chrono::duration< Duration::rep, std::milli > TimeSpan
低精度时间间隔。
Definition: YClock.h:81
YSLib::UI::GAnimationSession
动画会话。
Definition: Animation.h:85
ynoexcept
#define ynoexcept(...)
YSLib 无异常抛出保证：指定特定的异常规范。
Definition: ydef.h:746