FastLED 3.9.3
Loading...
Searching...
No Matches
fx.h
1#pragma once
2
3#include <stdint.h>
4
5#include "crgb.h"
6#include "namespace.h"
7#include "ref.h"
8#include "detail/draw_context.h"
9#include "detail/transition.h"
10
11FASTLED_NAMESPACE_BEGIN
12
13FASTLED_SMART_REF(Fx);
14
15// Abstract base class for effects on a strip/grid of LEDs.
16class Fx : public Referent {
17 public:
18 // Alias DrawContext for use within Fx
20
21 Fx(uint16_t numLeds) : mNumLeds(numLeds) {}
22
26 virtual void draw(DrawContext context) = 0; // This is the only function that needs to be implemented
27 // everything else is optional.
28
29 // capabilities
30 virtual bool hasAlphaChannel() const { return false; }
31
32 // If true then this fx has a fixed frame rate and the fps parameter will be
33 // set to the frame rate.
34 virtual bool hasFixedFrameRate(float *fps) const { *fps = 30; return true; }
35
36 // Get the name of the current fx. This is the class name if there is only one.
37 // -1 means to get the current fx name if there are multiple fx.
38 virtual const char * fxName(int which = -1) const = 0;
39 // Optionally implement these for multi fx classes.
40 virtual int fxNum() const {
41 return 1;
42 }; // Return 1 if you only have one fx managed by this class.
43 virtual void fxSet(int fx) {}; // Set the current fx number.
44
45 // Negative numbers are allowed. -1 means previous fx.
46 virtual void fxNext(int fx = 1) {};
47 virtual int fxGet() const { return 0; }; // Get the current fx number.
48
49 virtual void pause() {
50 } // Called when the fx is paused, usually when a transition has finished.
51 virtual void resume() {} // Called when the fx is resumed after a pause,
52 // usually when a transition has started.
53
54 virtual void destroy() {
55 delete this;
56 } // Public virtual destructor function
57 virtual void lazyInit() {}
58 uint16_t getNumLeds() const { return mNumLeds; }
59
60 protected:
61 virtual ~Fx() {} // Protected destructor
62 uint16_t mNumLeds;
63};
64
65FASTLED_NAMESPACE_END
Definition fx.h:16
virtual void draw(DrawContext context)=0