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 SkParticleAffector_DEFINED |
| 9 | #define SkParticleAffector_DEFINED |
| 10 | |
| 11 | #include "SkReflected.h" |
| 12 | |
| 13 | #include "SkPoint.h" |
| 14 | |
Brian Osman | 125daa4 | 2019-02-20 12:25:20 -0500 | [diff] [blame] | 15 | struct SkColorCurve; |
Brian Osman | 8b6283f | 2019-02-14 16:55:21 -0500 | [diff] [blame] | 16 | struct SkCurve; |
Brian Osman | 125daa4 | 2019-02-20 12:25:20 -0500 | [diff] [blame] | 17 | struct SkParticleState; |
Brian Osman | 7c979f5 | 2019-02-12 13:27:51 -0500 | [diff] [blame] | 18 | struct SkParticleUpdateParams; |
| 19 | |
Brian Osman | 0c48681 | 2019-02-26 10:02:15 -0500 | [diff] [blame^] | 20 | enum SkParticleFrame { |
| 21 | kWorld_ParticleFrame, // "Up" is { 0, -1 } |
| 22 | kLocal_ParticleFrame, // "Up" is particle's heading |
| 23 | kVelocity_ParticleFrame, // "Up" is particle's direction of travel |
| 24 | }; |
| 25 | |
Brian Osman | 7c979f5 | 2019-02-12 13:27:51 -0500 | [diff] [blame] | 26 | class SkParticleAffector : public SkReflected { |
| 27 | public: |
| 28 | REFLECTED_ABSTRACT(SkParticleAffector, SkReflected) |
| 29 | |
Brian Osman | 14a67a3 | 2019-02-25 14:30:44 -0500 | [diff] [blame] | 30 | void apply(SkParticleUpdateParams& params, SkParticleState ps[], int count); |
Brian Osman | 1b20cd8 | 2019-02-25 14:15:02 -0500 | [diff] [blame] | 31 | void visitFields(SkFieldVisitor* v) override; |
Brian Osman | 7c979f5 | 2019-02-12 13:27:51 -0500 | [diff] [blame] | 32 | |
| 33 | static void RegisterAffectorTypes(); |
| 34 | |
Brian Osman | 0c48681 | 2019-02-26 10:02:15 -0500 | [diff] [blame^] | 35 | // Affectors that can set the linear or angular velocity. Both have a 'force' option to apply |
| 36 | // the resulting value as a force, rather than directly setting the velocity. |
Brian Osman | 8b6283f | 2019-02-14 16:55:21 -0500 | [diff] [blame] | 37 | static sk_sp<SkParticleAffector> MakeLinearVelocity(const SkCurve& angle, |
| 38 | const SkCurve& strength, |
Brian Osman | d5c57fe | 2019-02-22 11:48:18 -0500 | [diff] [blame] | 39 | bool force, |
Brian Osman | 0c48681 | 2019-02-26 10:02:15 -0500 | [diff] [blame^] | 40 | SkParticleFrame frame); |
| 41 | static sk_sp<SkParticleAffector> MakeAngularVelocity(const SkCurve& strength, |
| 42 | bool force); |
| 43 | |
| 44 | // Set the orientation of a particle, relative to the world, local, or velocity frame. |
| 45 | static sk_sp<SkParticleAffector> MakeOrientation(const SkCurve& angle, |
| 46 | SkParticleFrame frame); |
| 47 | |
Brian Osman | 7c979f5 | 2019-02-12 13:27:51 -0500 | [diff] [blame] | 48 | static sk_sp<SkParticleAffector> MakePointForce(SkPoint point, SkScalar constant, |
| 49 | SkScalar invSquare); |
Brian Osman | 8b6283f | 2019-02-14 16:55:21 -0500 | [diff] [blame] | 50 | |
Brian Osman | 125daa4 | 2019-02-20 12:25:20 -0500 | [diff] [blame] | 51 | static sk_sp<SkParticleAffector> MakeSize(const SkCurve& curve); |
| 52 | static sk_sp<SkParticleAffector> MakeFrame(const SkCurve& curve); |
| 53 | static sk_sp<SkParticleAffector> MakeColor(const SkColorCurve& curve); |
Brian Osman | 1b20cd8 | 2019-02-25 14:15:02 -0500 | [diff] [blame] | 54 | |
| 55 | private: |
Brian Osman | 14a67a3 | 2019-02-25 14:30:44 -0500 | [diff] [blame] | 56 | virtual void onApply(SkParticleUpdateParams& params, SkParticleState ps[], int count) = 0; |
Brian Osman | 1b20cd8 | 2019-02-25 14:15:02 -0500 | [diff] [blame] | 57 | |
| 58 | bool fEnabled = true; |
Brian Osman | 7c979f5 | 2019-02-12 13:27:51 -0500 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | #endif // SkParticleAffector_DEFINED |