Brian Osman | 7c979f5 | 2019-02-12 13:27:51 -0500 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "tools/viewer/Slide.h" |
Brian Osman | 7c979f5 | 2019-02-12 13:27:51 -0500 | [diff] [blame] | 12 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "include/core/SkPath.h" |
| 14 | #include "include/private/SkTArray.h" |
| 15 | #include "include/utils/SkRandom.h" |
Brian Osman | 7c979f5 | 2019-02-12 13:27:51 -0500 | [diff] [blame] | 16 | |
| 17 | class SkParticleEffect; |
Brian Osman | b77d502 | 2019-03-06 11:08:48 -0500 | [diff] [blame] | 18 | class SkParticleEffectParams; |
Brian Osman | 7c979f5 | 2019-02-12 13:27:51 -0500 | [diff] [blame] | 19 | |
Brian Osman | d12f278 | 2019-11-27 10:34:18 -0500 | [diff] [blame] | 20 | namespace skresources { class ResourceProvider; } |
| 21 | |
Brian Osman | 7c979f5 | 2019-02-12 13:27:51 -0500 | [diff] [blame] | 22 | class ParticlesSlide : public Slide { |
| 23 | public: |
| 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 | |
Ben Wagner | a57d868 | 2019-02-14 13:22:43 -0500 | [diff] [blame] | 29 | void load(SkScalar winWidth, SkScalar winHeight) override; |
Brian Osman | 7c979f5 | 2019-02-12 13:27:51 -0500 | [diff] [blame] | 30 | void draw(SkCanvas* canvas) override; |
Hal Canary | 4124807 | 2019-07-11 16:32:53 -0400 | [diff] [blame] | 31 | bool animate(double) override; |
Brian Osman | 7c979f5 | 2019-02-12 13:27:51 -0500 | [diff] [blame] | 32 | |
Hal Canary | b1f411a | 2019-08-29 10:39:22 -0400 | [diff] [blame] | 33 | bool onMouse(SkScalar x, SkScalar y, skui::InputState state, |
| 34 | skui::ModifierKey modifiers) override; |
Brian Osman | 7c979f5 | 2019-02-12 13:27:51 -0500 | [diff] [blame] | 35 | |
| 36 | private: |
Brian Osman | b77d502 | 2019-03-06 11:08:48 -0500 | [diff] [blame] | 37 | void loadEffects(const char* dirname); |
| 38 | |
Brian Osman | 7c979f5 | 2019-02-12 13:27:51 -0500 | [diff] [blame] | 39 | SkRandom fRandom; |
Hal Canary | 4124807 | 2019-07-11 16:32:53 -0400 | [diff] [blame] | 40 | bool fAnimated = false; |
| 41 | double fAnimationTime = 0; |
Brian Osman | ffbfd1b | 2019-12-05 14:38:14 -0500 | [diff] [blame] | 42 | SkPoint fMousePos = { 0, 0 }; |
Brian Osman | b77d502 | 2019-03-06 11:08:48 -0500 | [diff] [blame] | 43 | |
| 44 | struct LoadedEffect { |
| 45 | SkString fName; |
| 46 | sk_sp<SkParticleEffectParams> fParams; |
| 47 | }; |
| 48 | SkTArray<LoadedEffect> fLoaded; |
| 49 | |
| 50 | struct RunningEffect { |
Brian Osman | b77d502 | 2019-03-06 11:08:48 -0500 | [diff] [blame] | 51 | SkString fName; |
| 52 | sk_sp<SkParticleEffect> fEffect; |
Brian Osman | df18296 | 2019-10-15 10:27:59 -0400 | [diff] [blame] | 53 | bool fTrackMouse; |
Brian Osman | b77d502 | 2019-03-06 11:08:48 -0500 | [diff] [blame] | 54 | }; |
| 55 | SkTArray<RunningEffect> fRunning; |
Brian Osman | d12f278 | 2019-11-27 10:34:18 -0500 | [diff] [blame] | 56 | |
| 57 | sk_sp<skresources::ResourceProvider> fResourceProvider; |
Brian Osman | 7c979f5 | 2019-02-12 13:27:51 -0500 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | #endif |