ESPHome  2024.11.2
sdl_esphome.h
Go to the documentation of this file.
1 #pragma once
2 
3 #ifdef USE_HOST
5 #include "esphome/core/log.h"
8 #define SDL_MAIN_HANDLED
9 #include "SDL.h"
10 
11 namespace esphome {
12 namespace sdl {
13 
14 constexpr static const char *const TAG = "sdl";
15 
16 class Sdl : public display::Display {
17  public:
19  void update() override;
20  void loop() override;
21  void setup() override;
22  void draw_pixels_at(int x_start, int y_start, int w, int h, const uint8_t *ptr, display::ColorOrder order,
23  display::ColorBitness bitness, bool big_endian, int x_offset, int y_offset, int x_pad) override;
24  void draw_pixel_at(int x, int y, Color color) override;
25  void set_dimensions(uint16_t width, uint16_t height) {
26  this->width_ = width;
27  this->height_ = height;
28  }
29  int get_width() override { return this->width_; }
30  int get_height() override { return this->height_; }
31  float get_setup_priority() const override { return setup_priority::HARDWARE; }
32  void dump_config() override { LOG_DISPLAY("", "SDL", this); }
33 
34  int mouse_x{};
35  int mouse_y{};
36  bool mouse_down{};
37 
38  protected:
39  int get_width_internal() override { return this->width_; }
40  int get_height_internal() override { return this->height_; }
41  void redraw_(SDL_Rect &rect);
42  int width_{};
43  int height_{};
44  SDL_Renderer *renderer_{};
45  SDL_Window *window_{};
46  SDL_Texture *texture_{};
47  uint16_t x_low_{0};
48  uint16_t y_low_{0};
49  uint16_t x_high_{0};
50  uint16_t y_high_{0};
51 };
52 } // namespace sdl
53 } // namespace esphome
54 
55 #endif
void setup() override
Definition: sdl_esphome.cpp:8
display::DisplayType get_display_type() override
Definition: sdl_esphome.h:18
uint16_t x_high_
Definition: sdl_esphome.h:49
uint16_t x
Definition: tt21100.cpp:17
SDL_Window * window_
Definition: sdl_esphome.h:45
int get_width() override
Definition: sdl_esphome.h:29
void draw_pixels_at(int x_start, int y_start, int w, int h, const uint8_t *ptr, display::ColorOrder order, display::ColorBitness bitness, bool big_endian, int x_offset, int y_offset, int x_pad) override
Definition: sdl_esphome.cpp:37
int get_height_internal() override
Definition: sdl_esphome.h:40
uint8_t h
Definition: bl0906.h:209
void set_dimensions(uint16_t width, uint16_t height)
Definition: sdl_esphome.h:25
uint16_t y
Definition: tt21100.cpp:18
SDL_Renderer * renderer_
Definition: sdl_esphome.h:44
void dump_config() override
Definition: sdl_esphome.h:32
void redraw_(SDL_Rect &rect)
Definition: sdl_esphome.cpp:32
float get_setup_priority() const override
Definition: sdl_esphome.h:31
void update() override
Definition: sdl_esphome.cpp:20
void draw_pixel_at(int x, int y, Color color) override
Definition: sdl_esphome.cpp:50
const float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
Definition: component.cpp:18
int get_width_internal() override
Definition: sdl_esphome.h:39
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
SDL_Texture * texture_
Definition: sdl_esphome.h:46
uint16_t y_high_
Definition: sdl_esphome.h:50
int get_height() override
Definition: sdl_esphome.h:30
void loop() override
Definition: sdl_esphome.cpp:64