1/*
2* Copyright 2019 Google LLC
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 ParticlesSlide_DEFINED
9#define ParticlesSlide_DEFINED
10
11#include "tools/viewer/Slide.h"
12
13#include "include/core/SkPath.h"
14#include "include/private/SkTArray.h"
15#include "include/utils/SkRandom.h"
16
17class SkParticleEffect;
18class SkParticleEffectParams;
19
20namespace skresources { class ResourceProvider; }
21
22class ParticlesSlide : public Slide {
23public:
24    ParticlesSlide();
25
26    // TODO: We need a way for primarily interactive slides to always be as large as the window
27    SkISize getDimensions() const override { return SkISize::MakeEmpty(); }
28
29    void load(SkScalar winWidth, SkScalar winHeight) override;
30    void draw(SkCanvas* canvas) override;
31    bool animate(double) override;
32
33    bool onMouse(SkScalar x, SkScalar y, skui::InputState state,
34                 skui::ModifierKey modifiers) override;
35
36private:
37    void loadEffects(const char* dirname);
38
39    SkRandom fRandom;
40    bool fAnimated = false;
41    double fAnimationTime = 0;
42    SkPoint fMousePos = { 0, 0 };
43
44    struct LoadedEffect {
45        SkString fName;
46        sk_sp<SkParticleEffectParams> fParams;
47    };
48    SkTArray<LoadedEffect> fLoaded;
49
50    struct RunningEffect {
51        SkString fName;
52        sk_sp<SkParticleEffect> fEffect;
53        bool fTrackMouse;
54    };
55    SkTArray<RunningEffect> fRunning;
56
57    sk_sp<skresources::ResourceProvider> fResourceProvider;
58};
59
60#endif
61