ESPHome  2025.2.0
animation.h
Go to the documentation of this file.
1 #pragma once
3 
5 
6 namespace esphome {
7 namespace animation {
8 
9 class Animation : public image::Image {
10  public:
11  Animation(const uint8_t *data_start, int width, int height, uint32_t animation_frame_count, image::ImageType type,
12  image::Transparency transparent);
13 
14  uint32_t get_animation_frame_count() const;
15  int get_current_frame() const;
16  void next_frame();
17  void prev_frame();
18 
23  void set_frame(int frame);
24 
25  void set_loop(uint32_t start_frame, uint32_t end_frame, int count);
26 
27  protected:
28  void update_data_start_();
29 
30  const uint8_t *animation_data_start_;
34  uint32_t loop_end_frame_;
37 };
38 
39 template<typename... Ts> class AnimationNextFrameAction : public Action<Ts...> {
40  public:
41  AnimationNextFrameAction(Animation *parent) : parent_(parent) {}
42  void play(Ts... x) override { this->parent_->next_frame(); }
43 
44  protected:
46 };
47 
48 template<typename... Ts> class AnimationPrevFrameAction : public Action<Ts...> {
49  public:
50  AnimationPrevFrameAction(Animation *parent) : parent_(parent) {}
51  void play(Ts... x) override { this->parent_->prev_frame(); }
52 
53  protected:
55 };
56 
57 template<typename... Ts> class AnimationSetFrameAction : public Action<Ts...> {
58  public:
59  AnimationSetFrameAction(Animation *parent) : parent_(parent) {}
60  TEMPLATABLE_VALUE(uint16_t, frame)
61  void play(Ts... x) override { this->parent_->set_frame(this->frame_.value(x...)); }
62 
63  protected:
65 };
66 
67 } // namespace animation
68 } // namespace esphome
void set_frame(int frame)
Selects a specific frame within the animation.
Definition: animation.cpp:50
uint16_t x
Definition: tt21100.cpp:17
uint32_t get_animation_frame_count() const
Definition: animation.cpp:25
TEMPLATABLE_VALUE(uint16_t, frame) void play(Ts... x) override
Definition: animation.h:60
const uint8_t * animation_data_start_
Definition: animation.h:30
void set_loop(uint32_t start_frame, uint32_t end_frame, int count)
Definition: animation.cpp:18
uint8_t type
Animation(const uint8_t *data_start, int width, int height, uint32_t animation_frame_count, image::ImageType type, image::Transparency transparent)
Definition: animation.cpp:8
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7