• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "SkParticleData.h"
14 #include "SkPoint.h"
15 
16 struct SkColorCurve;
17 struct SkCurve;
18 
19 class SkParticleAffector : public SkReflected {
20 public:
21     REFLECTED_ABSTRACT(SkParticleAffector, SkReflected)
22 
23     void apply(const SkParticleUpdateParams& params, SkParticleState ps[], int count);
24     void visitFields(SkFieldVisitor* v) override;
25 
26     static void RegisterAffectorTypes();
27 
28     // Affectors that can set the linear or angular velocity. Both have a 'force' option to apply
29     // the resulting value as a force, rather than directly setting the velocity.
30     static sk_sp<SkParticleAffector> MakeLinearVelocity(const SkCurve& angle,
31                                                         const SkCurve& strength,
32                                                         bool force,
33                                                         SkParticleFrame frame);
34     static sk_sp<SkParticleAffector> MakeAngularVelocity(const SkCurve& strength,
35                                                          bool force);
36 
37     // Set the orientation of a particle, relative to the world, local, or velocity frame.
38     static sk_sp<SkParticleAffector> MakeOrientation(const SkCurve& angle,
39                                                      SkParticleFrame frame);
40 
41     static sk_sp<SkParticleAffector> MakePointForce(SkPoint point, SkScalar constant,
42                                                     SkScalar invSquare);
43 
44     static sk_sp<SkParticleAffector> MakeSize(const SkCurve& curve);
45     static sk_sp<SkParticleAffector> MakeFrame(const SkCurve& curve);
46     static sk_sp<SkParticleAffector> MakeColor(const SkColorCurve& curve);
47 
48 private:
49     virtual void onApply(const SkParticleUpdateParams& params, SkParticleState ps[], int count) = 0;
50 
51     bool fEnabled = true;
52 };
53 
54 #endif // SkParticleAffector_DEFINED
55