blob: d9534bc82acecfee73599902e7796fcdf349761e [file] [log] [blame]
Florin Malita54f65c42018-01-16 17:04:30 -05001/*
2 * Copyright 2017 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SkottieSlide_DEFINED
9#define SkottieSlide_DEFINED
10
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "tools/viewer/Slide.h"
Florin Malita3d856bd2018-05-26 09:49:28 -040012
13#if defined(SK_ENABLE_SKOTTIE)
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#include "modules/skottie/include/Skottie.h"
Florin Malita00d4f532019-07-22 12:05:41 -040015#include "modules/sksg/include/SkSGInvalidationController.h"
Florin Malita54f65c42018-01-16 17:04:30 -050016
Florin Malita15ee9702019-12-10 14:23:32 -050017#include <vector>
18
Florin Malitabcd07232018-01-31 11:08:58 -050019namespace sksg { class Scene; }
Florin Malita54f65c42018-01-16 17:04:30 -050020
21class SkottieSlide : public Slide {
22public:
23 SkottieSlide(const SkString& name, const SkString& path);
24 ~SkottieSlide() override = default;
25
26 void load(SkScalar winWidth, SkScalar winHeight) override;
27 void unload() override;
Florin Malitac4f6e022019-12-10 13:38:45 -050028 void resize(SkScalar, SkScalar) override;
Florin Malita54f65c42018-01-16 17:04:30 -050029
30 SkISize getDimensions() const override;
31
32 void draw(SkCanvas*) override;
Hal Canary41248072019-07-11 16:32:53 -040033 bool animate(double) override;
Florin Malita54f65c42018-01-16 17:04:30 -050034
35 bool onChar(SkUnichar) override;
Hal Canaryb1f411a2019-08-29 10:39:22 -040036 bool onMouse(SkScalar x, SkScalar y, skui::InputState, skui::ModifierKey modifiers) override;
Florin Malita54f65c42018-01-16 17:04:30 -050037
38private:
Florin Malitac4f6e022019-12-10 13:38:45 -050039 SkRect UIArea() const;
40 void renderUI();
41
42 const SkString fPath;
43
Florin Malita40c37422018-08-22 20:37:04 -040044 sk_sp<skottie::Animation> fAnimation;
45 skottie::Animation::Builder::Stats fAnimationStats;
Florin Malita00d4f532019-07-22 12:05:41 -040046 sksg::InvalidationController fInvalController;
Florin Malita15ee9702019-12-10 14:23:32 -050047 std::vector<float> fFrameTimes;
Florin Malitac4f6e022019-12-10 13:38:45 -050048 SkSize fWinSize = SkSize::MakeEmpty();
Florin Malita1bb3a6d2019-12-11 08:55:46 -050049 double fTimeBase = 0,
50 fFrameRate = 0;
51 const char* fFrameRateLabel = nullptr;
Florin Malitac4f6e022019-12-10 13:38:45 -050052 float fCurrentFrame = 0;
Florin Malita40c37422018-08-22 20:37:04 -040053 bool fShowAnimationInval = false,
Florin Malitac4f6e022019-12-10 13:38:45 -050054 fShowAnimationStats = false,
55 fShowUI = false,
Florin Malita67ff5412020-05-20 17:04:21 -040056 fDraggingProgress = false,
57 fPreferGlyphPaths = false;
Florin Malita54f65c42018-01-16 17:04:30 -050058
John Stiles7571f9e2020-09-02 22:42:33 -040059 using INHERITED = Slide;
Florin Malita54f65c42018-01-16 17:04:30 -050060};
61
Florin Malita3d856bd2018-05-26 09:49:28 -040062#endif // SK_ENABLE_SKOTTIE
63
Florin Malita54f65c42018-01-16 17:04:30 -050064#endif // SkottieSlide_DEFINED