Skip to content
0.2.0-dev Download ZIP
109 lines ·3.1 KB Raw
1/*
2 * Copyright (c) 2023 - 2026 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 "tvgLoader.h"
24#include "tvgAnimation.h"
25
26
27Animation::~Animation()
28{
29 delete(pImpl);
30}
31
32
33Animation::Animation() : pImpl(new Impl)
34{
35}
36
37
38Result Animation::frame(float no) noexcept
39{
40 auto loader = to<PictureImpl>(pImpl->picture)->loader;
41
42 if (!loader) return Result::InsufficientCondition;
43 if (!loader->playable) return Result::NonSupport;
44
45 if (static_cast<AnimLoader*>(loader)->frame(no)) {
46 PAINT(pImpl->picture)->mark(RenderUpdateFlag::Children);
47 return Result::Success;
48 }
49 return Result::InsufficientCondition;
50}
51
52
53Picture* Animation::picture() const noexcept
54{
55 return pImpl->picture;
56}
57
58
59float Animation::curFrame() const noexcept
60{
61 auto loader = to<PictureImpl>(pImpl->picture)->loader;
62 if (!loader || !loader->playable) return 0;
63 return static_cast<AnimLoader*>(loader)->curFrame();
64}
65
66
67float Animation::totalFrame() const noexcept
68{
69 auto loader = to<PictureImpl>(pImpl->picture)->loader;
70 if (!loader || !loader->playable) return 0;
71 return static_cast<AnimLoader*>(loader)->totalFrame();
72}
73
74
75float Animation::duration() const noexcept
76{
77 auto loader = to<PictureImpl>(pImpl->picture)->loader;
78 if (!loader || !loader->playable) return 0;
79 return static_cast<AnimLoader*>(loader)->duration();
80}
81
82
83Result Animation::segment(float begin, float end) noexcept
84{
85 auto loader = to<PictureImpl>(pImpl->picture)->loader;
86 if (!loader) return Result::InsufficientCondition;
87 if (!loader->playable) return Result::NonSupport;
88
89 return static_cast<AnimLoader*>(loader)->segment(begin, end);
90}
91
92
93Result Animation::segment(float *begin, float *end) noexcept
94{
95 auto loader = to<PictureImpl>(pImpl->picture)->loader;
96 if (!loader) return Result::InsufficientCondition;
97 if (!loader->playable) return Result::NonSupport;
98 if (!begin && !end) return Result::InvalidArguments;
99
100 static_cast<AnimLoader*>(loader)->segment(begin, end);
101
102 return Result::Success;
103}
104
105
106Animation* Animation::gen() noexcept
107{
108 return new Animation;
109}