TinyGPU
Loading...
Searching...
No Matches
LCDBoardsSDL.h
Go to the documentation of this file.
1#pragma once
2/**
3 * @file LCDBoardsSDL.h
4 * @brief LCDBoard for the SDL2 desktop backend - renders to a window via
5 * DisplayDriverSDL and maps the mouse to touch via TouchDriverSDL, so
6 * sketches written against the LCDBoard interface can run unmodified on a
7 * desktop for testing/debugging without any physical hardware.
8 *
9 * See LCDBoardsCommon.h for the platform-independent LCDBoard interface this
10 * implements, and LCDBoardsESP32.h for the ESP32 hardware boards.
11 */
12#include "TinyGPU/Boards/LCDBoardsCommon.h"
13#include "TinyGPU/Drivers/DisplayDriverSDL.h"
14#include "TinyGPU/Input/TouchDriverSDL.h"
15
16namespace tinygpu {
17
18/**
19 * @brief Desktop SDL2 window standing in for a physical LCD board. Window
20 * size is set at construction time (default 320x240) since - unlike the
21 * hardware boards in LCDBoardsESP32.h - there is no fixed panel to match.
22 *
23 * The left mouse button stands in for a finger (see TouchDriverSDL).
24 * There is no backlight/I2S/LED hardware on this backend, so i2s()/led()
25 * report "not present" (every field -1) and backlightPin() is -1.
26 */
28 public:
29 LCDBoardDesktopSDL(size_t width = 320, size_t height = 240)
31
32 /// Size of the window as a multiple of the display, e.g. 1.5 or 2 (before
33 /// begin()); the environment variable TINYGPU_SDL_SCALE takes precedence.
34 void setScale(float scale) { display_.setScale(scale); }
35
36 /// Title of the window (before begin()).
37 void setTitle(const char* title) { display_.setTitle(title); }
38
39 /// Opens the SDL window and starts mouse-as-touch tracking.
40 bool begin() override {
41 if (!display_.begin()) return false;
42 return touch_.begin();
43 }
44
45 /// Window width in pixels.
46 size_t width() const override { return width_; }
47 /// Window height in pixels.
48 size_t height() const override { return height_; }
49
50 /// The board's display driver.
51 DisplayDriverSDL<RGB565>& display() override { return display_; }
52 /// The board's touch controller (mouse-mapped).
53 TouchDriver* touch() override { return &touch_; }
54 /// No I2S bus on this backend - every field is -1.
55 const I2SPins& i2s() const override { return i2s_; }
56 /// No LED on this backend - every field is -1.
57 const LEDPins& led() const override { return led_; }
58
59 private:
60 size_t width_;
61 size_t height_;
62 DisplayDriverSDL<RGB565> display_;
63 TouchDriverSDL touch_;
64 I2SPins i2s_{};
65 LEDPins led_{};
66};
67
68using DesktopSDL = LCDBoardDesktopSDL;
69
70} // namespace tinygpu
Display class for rendering a Surface<RGB565> using the SDL2 library. This class can be used to displ...
Definition: DisplayDriverSDL.h:33
Desktop SDL2 window standing in for a physical LCD board. Window size is set at construction time (de...
Definition: LCDBoardsSDL.h:27
DisplayDriverSDL< RGB565 > & display() override
The board's display driver.
Definition: LCDBoardsSDL.h:51
size_t height() const override
Window height in pixels.
Definition: LCDBoardsSDL.h:48
const I2SPins & i2s() const override
No I2S bus on this backend - every field is -1.
Definition: LCDBoardsSDL.h:55
TouchDriver * touch() override
The board's touch controller (mouse-mapped).
Definition: LCDBoardsSDL.h:53
size_t width() const override
Window width in pixels.
Definition: LCDBoardsSDL.h:46
bool begin() override
Opens the SDL window and starts mouse-as-touch tracking.
Definition: LCDBoardsSDL.h:40
void setTitle(const char *title)
Title of the window (before begin()).
Definition: LCDBoardsSDL.h:37
void setScale(float scale)
Definition: LCDBoardsSDL.h:34
const LEDPins & led() const override
No LED on this backend - every field is -1.
Definition: LCDBoardsSDL.h:57
LCDBoardDesktopSDL(size_t width=320, size_t height=240)
Definition: LCDBoardsSDL.h:29
Definition: LCDBoardsCommon.h:62
RGB color stored in 16-bit RGB565 format, byte-swapped from the conventional bit layout.
Definition: RGB565.h:24
Maps the desktop mouse to a TouchDriver, for exercising touch-driven UI (buttons, sliders,...
Definition: TouchDriverSDL.h:28
bool begin() override
Initialize the controller.
Definition: TouchDriverSDL.h:32
Base class for touch controllers.
Definition: TouchDriverCommon.h:72
Definition: DSIBusESP32.h:19
Definition: LCDBoardsCommon.h:28
Definition: LCDBoardsCommon.h:49