ESPHome 2025.5.0
Loading...
Searching...
No Matches
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#include <map>
11
12namespace esphome {
13namespace sdl {
14
15constexpr static const char *const TAG = "sdl";
16
17class Sdl : public display::Display {
18 public:
20 void update() override;
21 void loop() override;
22 void setup() override;
23 void draw_pixels_at(int x_start, int y_start, int w, int h, const uint8_t *ptr, display::ColorOrder order,
24 display::ColorBitness bitness, bool big_endian, int x_offset, int y_offset, int x_pad) override;
25 void draw_pixel_at(int x, int y, Color color) override;
26 void process_key(uint32_t keycode, bool down);
27 void set_dimensions(uint16_t width, uint16_t height) {
28 this->width_ = width;
29 this->height_ = height;
30 }
31 int get_width() override { return this->width_; }
32 int get_height() override { return this->height_; }
33 float get_setup_priority() const override { return setup_priority::HARDWARE; }
34 void dump_config() override { LOG_DISPLAY("", "SDL", this); }
35 void add_key_listener(int32_t keycode, std::function<void(bool)> &&callback) {
36 if (!this->key_callbacks_.count(keycode)) {
38 }
39 this->key_callbacks_[keycode].add(std::move(callback));
40 }
41
42 int mouse_x{};
43 int mouse_y{};
44 bool mouse_down{};
45
46 protected:
47 int get_width_internal() override { return this->width_; }
48 int get_height_internal() override { return this->height_; }
49 void redraw_(SDL_Rect &rect);
50 int width_{};
51 int height_{};
52 SDL_Renderer *renderer_{};
53 SDL_Window *window_{};
54 SDL_Texture *texture_{};
55 uint16_t x_low_{0};
56 uint16_t y_low_{0};
57 uint16_t x_high_{0};
58 uint16_t y_high_{0};
59 std::map<int32_t, CallbackManager<void(bool)>> key_callbacks_{};
60};
61} // namespace sdl
62} // namespace esphome
63
64#endif
uint8_t h
Definition bl0906.h:2
void setup() override
int get_width() override
Definition sdl_esphome.h:31
void add_key_listener(int32_t keycode, std::function< void(bool)> &&callback)
Definition sdl_esphome.h:35
int get_height() override
Definition sdl_esphome.h:32
SDL_Renderer * renderer_
Definition sdl_esphome.h:52
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
int get_height_internal() override
Definition sdl_esphome.h:48
void process_key(uint32_t keycode, bool down)
SDL_Texture * texture_
Definition sdl_esphome.h:54
void set_dimensions(uint16_t width, uint16_t height)
Definition sdl_esphome.h:27
void redraw_(SDL_Rect &rect)
void loop() override
void dump_config() override
Definition sdl_esphome.h:34
void draw_pixel_at(int x, int y, Color color) override
int get_width_internal() override
Definition sdl_esphome.h:47
void update() override
float get_setup_priority() const override
Definition sdl_esphome.h:33
display::DisplayType get_display_type() override
Definition sdl_esphome.h:19
SDL_Window * window_
Definition sdl_esphome.h:53
std::map< int32_t, CallbackManager< void(bool)> > key_callbacks_
Definition sdl_esphome.h:59
const float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
Definition component.cpp:18
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
uint16_t x
Definition tt21100.cpp:5
uint16_t y
Definition tt21100.cpp:6