Debian Codegraph @

thirdparty/thorvg/src/renderer/tvgAnimation.cpp

raw symbols SCIP
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 "tvgFrameModule.h"
24 #include "tvgAnimation.h"
25
26 /************************************************************************/
27 /* Internal Class Implementation */
28 /************************************************************************/
29
30 /************************************************************************/
31 /* External Class Implementation */
32 /************************************************************************/
33
34 Animation::~Animation()
35 {
36 delete(pImpl);
37 }
38
39
40 Animation::Animation() : pImpl(new Impl)
41 {
42 }
43
44
45 Result Animation::frame(float no) noexcept
46 {
47 auto loader = pImpl->picture->pImpl->loader;
48
49 if (!loader) return Result::InsufficientCondition;
50 if (!loader->animatable()) return Result::NonSupport;
51
52 if (static_cast<FrameModule*>(loader)->frame(no)) return Result::Success;
53 return Result::InsufficientCondition;
54 }
55
56
57 Picture* Animation::picture() const noexcept
58 {
59 return pImpl->picture;
60 }
61
62
63 float Animation::curFrame() const noexcept
64 {
65 auto loader = pImpl->picture->pImpl->loader;
66
67 if (!loader) return 0;
68 if (!loader->animatable()) return 0;
69
70 return static_cast<FrameModule*>(loader)->curFrame();
71 }
72
73
74 float Animation::totalFrame() const noexcept
75 {
76 auto loader = pImpl->picture->pImpl->loader;
77
78 if (!loader) return 0;
79 if (!loader->animatable()) return 0;
80
81 return static_cast<FrameModule*>(loader)->totalFrame();
82 }
83
84
85 float Animation::duration() const noexcept
86 {
87 auto loader = pImpl->picture->pImpl->loader;
88
89 if (!loader) return 0;
90 if (!loader->animatable()) return 0;
91
92 return static_cast<FrameModule*>(loader)->duration();
93 }
94
95
96 Result Animation::segment(float begin, float end) noexcept
97 {
98 if (begin < 0.0f || end > 1.0f || begin > end) return Result::InvalidArguments;
99
100 auto loader = pImpl->picture->pImpl->loader;
101 if (!loader) return Result::InsufficientCondition;
102 if (!loader->animatable()) return Result::NonSupport;
103
104 static_cast<FrameModule*>(loader)->segment(begin, end);
105
106 return Result::Success;
107 }
108
109
110 Result Animation::segment(float *begin, float *end) noexcept
111 {
112 auto loader = pImpl->picture->pImpl->loader;
113 if (!loader) return Result::InsufficientCondition;
114 if (!loader->animatable()) return Result::NonSupport;
115 if (!begin && !end) return Result::InvalidArguments;
116
117 static_cast<FrameModule*>(loader)->segment(begin, end);
118
119 return Result::Success;
120 }
121
122
123 unique_ptr<Animation> Animation::gen() noexcept
124 {
125 return unique_ptr<Animation>(new Animation);
126 }