blob: be3d48f4b1af0497841e3db112561837d87e8980 [file] [log] [blame]
Brian Osman7c979f52019-02-12 13:27:51 -05001/*
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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "modules/particles/include/SkReflected.h"
Brian Osman7c979f52019-02-12 13:27:51 -050012
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "include/core/SkPoint.h"
14#include "modules/particles/include/SkParticleData.h"
Brian Osman7c979f52019-02-12 13:27:51 -050015
Brian Osman125daa42019-02-20 12:25:20 -050016struct SkColorCurve;
Brian Osman8b6283f2019-02-14 16:55:21 -050017struct SkCurve;
Brian Osman0c486812019-02-26 10:02:15 -050018
Brian Osman7c979f52019-02-12 13:27:51 -050019class SkParticleAffector : public SkReflected {
20public:
21 REFLECTED_ABSTRACT(SkParticleAffector, SkReflected)
22
Brian Osmanbdcdf1a2019-03-04 10:55:22 -050023 void apply(const SkParticleUpdateParams& params, SkParticleState ps[], int count);
Brian Osman1b20cd82019-02-25 14:15:02 -050024 void visitFields(SkFieldVisitor* v) override;
Brian Osman7c979f52019-02-12 13:27:51 -050025
26 static void RegisterAffectorTypes();
27
Brian Osman0c486812019-02-26 10:02:15 -050028 // 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.
Brian Osman8b6283f2019-02-14 16:55:21 -050030 static sk_sp<SkParticleAffector> MakeLinearVelocity(const SkCurve& angle,
31 const SkCurve& strength,
Brian Osmand5c57fe2019-02-22 11:48:18 -050032 bool force,
Brian Osman0c486812019-02-26 10:02:15 -050033 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
Brian Osman7c979f52019-02-12 13:27:51 -050041 static sk_sp<SkParticleAffector> MakePointForce(SkPoint point, SkScalar constant,
42 SkScalar invSquare);
Brian Osman8b6283f2019-02-14 16:55:21 -050043
Brian Osman125daa42019-02-20 12:25:20 -050044 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);
Brian Osman1b20cd82019-02-25 14:15:02 -050047
48private:
Brian Osmanbdcdf1a2019-03-04 10:55:22 -050049 virtual void onApply(const SkParticleUpdateParams& params, SkParticleState ps[], int count) = 0;
Brian Osman1b20cd82019-02-25 14:15:02 -050050
51 bool fEnabled = true;
Brian Osman7c979f52019-02-12 13:27:51 -050052};
53
54#endif // SkParticleAffector_DEFINED