1 /*
2 * Copyright (c) 2023 - 2024 the ThorVG project. All rights reserved.
3
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10
11 * The above copyright notice and this permission notice shall be included in all
12 * copies or substantial portions of the Software.
13
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 #include "../../lv_conf_internal.h"
24 #if LV_USE_THORVG_INTERNAL
25
26 #include "tvgFrameModule.h"
27 #include "tvgAnimation.h"
28
29 /************************************************************************/
30 /* Internal Class Implementation */
31 /************************************************************************/
32
33 /************************************************************************/
34 /* External Class Implementation */
35 /************************************************************************/
36
~Animation()37 Animation::~Animation()
38 {
39 delete(pImpl);
40 }
41
42
Animation()43 Animation::Animation() : pImpl(new Impl)
44 {
45 }
46
47
frame(float no)48 Result Animation::frame(float no) noexcept
49 {
50 auto loader = pImpl->picture->pImpl->loader;
51
52 if (!loader) return Result::InsufficientCondition;
53 if (!loader->animatable()) return Result::NonSupport;
54
55 if (static_cast<FrameModule*>(loader)->frame(no)) return Result::Success;
56 return Result::InsufficientCondition;
57 }
58
59
picture() const60 Picture* Animation::picture() const noexcept
61 {
62 return pImpl->picture;
63 }
64
65
curFrame() const66 float Animation::curFrame() const noexcept
67 {
68 auto loader = pImpl->picture->pImpl->loader;
69
70 if (!loader) return 0;
71 if (!loader->animatable()) return 0;
72
73 return static_cast<FrameModule*>(loader)->curFrame();
74 }
75
76
totalFrame() const77 float Animation::totalFrame() const noexcept
78 {
79 auto loader = pImpl->picture->pImpl->loader;
80
81 if (!loader) return 0;
82 if (!loader->animatable()) return 0;
83
84 return static_cast<FrameModule*>(loader)->totalFrame();
85 }
86
87
duration() const88 float Animation::duration() const noexcept
89 {
90 auto loader = pImpl->picture->pImpl->loader;
91
92 if (!loader) return 0;
93 if (!loader->animatable()) return 0;
94
95 return static_cast<FrameModule*>(loader)->duration();
96 }
97
98
segment(float begin,float end)99 Result Animation::segment(float begin, float end) noexcept
100 {
101 if (begin < 0.0 || end > 1.0 || begin > end) return Result::InvalidArguments;
102
103 auto loader = pImpl->picture->pImpl->loader;
104 if (!loader) return Result::InsufficientCondition;
105 if (!loader->animatable()) return Result::NonSupport;
106
107 static_cast<FrameModule*>(loader)->segment(begin, end);
108
109 return Result::Success;
110 }
111
112
segment(float * begin,float * end)113 Result Animation::segment(float *begin, float *end) noexcept
114 {
115 auto loader = pImpl->picture->pImpl->loader;
116 if (!loader) return Result::InsufficientCondition;
117 if (!loader->animatable()) return Result::NonSupport;
118 if (!begin && !end) return Result::InvalidArguments;
119
120 static_cast<FrameModule*>(loader)->segment(begin, end);
121
122 return Result::Success;
123 }
124
125
gen()126 unique_ptr<Animation> Animation::gen() noexcept
127 {
128 return unique_ptr<Animation>(new Animation);
129 }
130
131 #endif /* LV_USE_THORVG_INTERNAL */
132
133