Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
lottie_view.hpp
Go to the documentation of this file.
1#pragma once
2
15
16#include <memory>
17#include <string>
18
19#include <pulp/view/view.hpp>
20
21namespace pulp::canvas { class LottieAnimation; }
22
23namespace pulp::view {
24
25class LottieView : public View {
26public:
28 ~LottieView() override;
29
31 static bool supported();
32
33 bool set_source_file(const std::string& path);
34 bool set_source_json(const std::string& json);
35 bool valid() const;
36
37 void set_playing(bool playing);
38 bool playing() const { return playing_; }
39 void set_looping(bool looping) { looping_ = looping; }
40 bool looping() const { return looping_; }
41 void set_speed(float speed) { speed_ = speed < 0.0f ? 0.0f : speed; }
42 float speed() const { return speed_; }
43
44 void seek(double seconds);
45 double time() const { return time_; }
46 double duration() const;
47
51 void advance(float dt);
52
53 void paint(canvas::Canvas& canvas) override;
54 void on_attached() override;
55 void on_detached() override;
56 void on_frame_clock_changed() override;
57
58private:
59 void subscribe_clock();
60 void unsubscribe_clock();
61 // Paint a bordered "Lottie unavailable" placeholder when Lottie is compiled
62 // out of this build, so a disabled build reads as intentionally-unavailable
63 // rather than a silently blank box (mirrors the ImageView missing-image
64 // placeholder). Logs the reason once per view instance.
65 void paint_unsupported_placeholder(canvas::Canvas& canvas);
66
67 std::unique_ptr<canvas::LottieAnimation> animation_;
68 double time_ = 0.0;
69 float speed_ = 1.0f;
70 bool playing_ = true;
71 bool looping_ = true;
72 int clock_subscription_ = -1;
73 // frame_clock() becomes null after detachment; retain the actual clock so
74 // a descendant subscription can always be removed from its old host.
75 FrameClock* subscription_clock_ = nullptr;
76 bool unsupported_logged_ = false;
77};
78
79} // namespace pulp::view
Definition canvas.hpp:240
Definition lottie_animation.hpp:25
Definition frame_clock.hpp:14
void set_playing(bool playing)
void on_frame_clock_changed() override
The FrameClock reachable from this view (via frame_clock()) may have changed — a clock was installed ...
void set_speed(float speed)
Definition lottie_view.hpp:41
bool looping() const
Definition lottie_view.hpp:40
void set_looping(bool looping)
Definition lottie_view.hpp:39
bool set_source_file(const std::string &path)
bool playing() const
Definition lottie_view.hpp:38
float speed() const
Definition lottie_view.hpp:42
void on_attached() override
void advance(float dt)
Advance the playhead by dt seconds (scaled by speed, looped/clamped).
void paint(canvas::Canvas &canvas) override
void seek(double seconds)
void on_detached() override
double time() const
Definition lottie_view.hpp:45
double duration() const
bool set_source_json(const std::string &json)
static bool supported()
True when Lottie support is compiled in (PULP_LOTTIE / PULP_HAS_LOTTIE).
Definition affine_transform.hpp:24
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
@ path
Definition anchor_strategy.hpp:42