Prepare for render re-write

This commit is contained in:
Rasmus Rasmussen 2026-01-09 18:16:44 +01:00
parent 9b118b2d80
commit 740c8e01c1
13 changed files with 89 additions and 69 deletions

View File

@ -20,8 +20,8 @@ enum CLICK_EVENTS {
}; };
struct CLICK_EVENT { struct CLICK_EVENT {
int x; short int x;
int y; short int y;
CLICK_EVENTS event; CLICK_EVENTS event;
}; };
@ -32,7 +32,7 @@ enum class ApplicationEventState {
}; };
struct APPLICATION_EVENT { struct APPLICATION_EVENT {
int id; short int id;
ApplicationEventState state; ApplicationEventState state;
char title[64]; char title[64];
}; };

View File

@ -92,9 +92,13 @@ public:
void run() override { void run() override {
_window->x += 150; _window->x += 150;
_window->width -= 50; _window->width -= 50;
//_window->sprite.setPsram(true); _window->sprite.setPsram(false);
//_window->sprite.createSprite(10, 10); _window->sprite.createSprite(10, 10);
//_window->sprite.setColorDepth(16); _window->sprite.setColorDepth(16);
_window->sprite.fillScreen(TFT_BLACK);
_window->sprite.fillCircle(50, 50, 40, TFT_RED);
_window->hasSprite = true;
//_window->sprite.pushSprite(0, 0);
Serial.println("Settings started!"); Serial.println("Settings started!");
WindowContentText ram_usage; WindowContentText ram_usage;

View File

@ -1,9 +1,9 @@
#pragma once #pragma once
struct Mouse_Icon { struct Mouse_Icon {
int x; short int x;
int y; short int y;
int size_x; short int size_x;
int size_y; short int size_y;
int color; short int color;
}; };

View File

@ -23,7 +23,7 @@ void InputManager::init(DISPLAY_STATE* display_state, TFT_Handler* tf) {
void InputManager::update() { void InputManager::update() {
for (int i = 0; i < NUM_BUTTONS; i++) { for (int i = 0; i < NUM_BUTTONS; i++) {
int reading = digitalRead(BUTTON_PINS[i]); short int reading = digitalRead(BUTTON_PINS[i]);
if (reading != lastButtonState[i]) { if (reading != lastButtonState[i]) {
lastDebounceTime[i] = millis(); lastDebounceTime[i] = millis();
@ -43,7 +43,7 @@ void InputManager::update() {
} }
} }
void InputManager::handle_button_press(int buttonIndex) { void InputManager::handle_button_press(short int buttonIndex) {
bool needs_redraw = false; bool needs_redraw = false;
switch(buttonIndex) { switch(buttonIndex) {
@ -94,6 +94,6 @@ void InputManager::draw_button() {
_tf->draw_box(mi.x, mi.y, mi.size_x, mi.size_y, mi.color); _tf->draw_box(mi.x, mi.y, mi.size_x, mi.size_y, mi.color);
} }
bool InputManager::are_buttons_pressed(int btn1, int btn2) { bool InputManager::are_buttons_pressed(short int btn1, short int btn2) {
return (buttonState[btn1] == LOW && buttonState[btn2] == LOW); return (buttonState[btn1] == LOW && buttonState[btn2] == LOW);
} }

View File

@ -7,19 +7,19 @@
class InputManager { class InputManager {
private: private:
int BUTTON_PINS[6] = {4, 5, 6, 7, 17, 16}; short int BUTTON_PINS[6] = {4, 5, 6, 7, 17, 16};
static constexpr int NUM_BUTTONS = 6; static constexpr short int NUM_BUTTONS = 6;
const unsigned long DEBOUNCE_DELAY = 25; // milliseconds const unsigned long DEBOUNCE_DELAY = 25; // milliseconds
unsigned long lastDebounceTime[NUM_BUTTONS] = {0}; unsigned long lastDebounceTime[NUM_BUTTONS] = {0};
int lastButtonState[NUM_BUTTONS] = {HIGH, HIGH, HIGH, HIGH, HIGH, HIGH}; short int lastButtonState[NUM_BUTTONS] = {HIGH, HIGH, HIGH, HIGH, HIGH, HIGH};
int buttonState[NUM_BUTTONS] = {HIGH, HIGH, HIGH, HIGH, HIGH, HIGH}; short int buttonState[NUM_BUTTONS] = {HIGH, HIGH, HIGH, HIGH, HIGH, HIGH};
DISPLAY_STATE* _display_state; DISPLAY_STATE* _display_state;
TFT_Handler* _tf; TFT_Handler* _tf;
Mouse_Icon mi; Mouse_Icon mi;
void handle_button_press(int buttonIndex); void handle_button_press(short int buttonIndex);
bool are_buttons_pressed(int btn1, int btn2); bool are_buttons_pressed(short int btn1, short int btn2);
public: public:
void init(DISPLAY_STATE* display_state, TFT_Handler* tf); void init(DISPLAY_STATE* display_state, TFT_Handler* tf);

View File

@ -12,7 +12,7 @@ Program::~Program() {
close(); close();
} }
void Program::init(int id, std::string name, Window* window, Shell* shell, TFT_Handler* tft, DISPLAY_STATE* display_state, CALIBRATION_IDLE calibration_idle) { void Program::init(short int id, const std::string& name, Window* window, Shell* shell, TFT_Handler* tft, DISPLAY_STATE* display_state, CALIBRATION_IDLE calibration_idle) {
_id = id; _id = id;
_name = name; _name = name;
_window = window; _window = window;

View File

@ -5,28 +5,29 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <LovyanGFX.hpp> #include <LovyanGFX.hpp>
#include "tft_handler.h"
// Forward declarations // Forward declarations
class Shell; class Shell;
class TFT_Handler; class TFT_Handler;
struct TaskBarItem { struct TaskBarItem {
int id; short int id;
int place_x; short int place_x;
int place_y; short int place_y;
int width; short int width;
int height; short int height;
int offset_x; short int offset_x;
bool focused; bool focused;
std::string name; std::string name;
}; };
struct DesktopItem { struct DesktopItem {
int id; short int id;
int place_x; short int place_x;
int place_y; short int place_y;
int icon_size_x; short int icon_size_x;
int icon_size_y; short int icon_size_y;
std::string name; std::string name;
std::string program_class; // Which program class to instantiate std::string program_class; // Which program class to instantiate
}; };
@ -40,34 +41,48 @@ enum class WindowAction {
}; };
struct WindowDecoration { struct WindowDecoration {
int x_offset; short int x_offset;
int y_offset; short int y_offset;
int width; short int width;
int height; short int height;
WindowAction action; WindowAction action;
}; };
struct WindowContentText { struct WindowContentText {
int x; short int x;
int y; short int y;
int size; short int size;
std::string text; std::string text;
}; };
struct Window { struct Window {
int id; short int id;
int x; short int x;
int y; short int y;
int width; short int width;
int height; short int height;
int background_color; short int background_color;
int foreground_color; short int foreground_color;
bool focused; bool focused;
bool minimized; bool minimized;
std::string title; std::string title;
std::vector<WindowDecoration> window_decorations; std::vector<WindowDecoration> window_decorations;
std::vector<WindowContentText> window_content_text; std::vector<WindowContentText> window_content_text;
bool hasSprite = false;
LGFX_Sprite sprite; LGFX_Sprite sprite;
// Constructor that initializes sprite with display pointer
Window(LGFX* display) : sprite(display) {
id = 0;
x = 0;
y = 0;
width = 0;
height = 0;
background_color = 0;
foreground_color = 0;
focused = false;
minimized = false;
}
}; };
// Base Program class - all programs inherit from this // Base Program class - all programs inherit from this
@ -78,7 +93,7 @@ protected:
TFT_Handler* _tft; TFT_Handler* _tft;
DISPLAY_STATE* _display_state; DISPLAY_STATE* _display_state;
TaskHandle_t _task_handle; TaskHandle_t _task_handle;
int _id; short int _id;
std::string _name; std::string _name;
bool _running; bool _running;
CALIBRATION_IDLE _calibration_idle; CALIBRATION_IDLE _calibration_idle;
@ -90,7 +105,7 @@ public:
virtual ~Program(); virtual ~Program();
// Initialize the program with its window and shell reference // Initialize the program with its window and shell reference
void init(int id, std::string name, Window* window, Shell* shell, TFT_Handler* tft, DISPLAY_STATE* display_state, CALIBRATION_IDLE calibration_idle); void init(short int id, const std::string& name, Window* window, Shell* shell, TFT_Handler* tft, DISPLAY_STATE* display_state, CALIBRATION_IDLE calibration_idle);
// Override this in your specific programs // Override this in your specific programs
virtual void run() = 0; virtual void run() = 0;

View File

@ -189,7 +189,7 @@ void Shell::draw_all() {
tft->end_draw(); tft->end_draw();
} }
void Shell::draw_window(Window window) { void Shell::draw_window(const Window& window) {
if (window.minimized) return; if (window.minimized) return;
// Outer shadow // Outer shadow
@ -228,6 +228,8 @@ void Shell::draw_window(Window window) {
for (WindowContentText text : window.window_content_text) { for (WindowContentText text : window.window_content_text) {
tft->draw_text(text.x, text.y, text.text, COL_BLACK, text.size); tft->draw_text(text.x, text.y, text.text, COL_BLACK, text.size);
} }
if (window.hasSprite) tft->push_sprite(window.sprite);
} }
// ======= Desktop ======= // ======= Desktop =======
@ -235,7 +237,7 @@ void Shell::draw_background(int color) {
tft->fill_screen(color); tft->fill_screen(color);
} }
void Shell::draw_desktop_Item(DesktopItem desktop_item) { void Shell::draw_desktop_Item(const DesktopItem& desktop_item) {
tft->draw_box(desktop_item.place_x, desktop_item.place_y, desktop_item.icon_size_x, desktop_item.icon_size_y, 0x4648); tft->draw_box(desktop_item.place_x, desktop_item.place_y, desktop_item.icon_size_x, desktop_item.icon_size_y, 0x4648);
} }
@ -340,7 +342,7 @@ int Shell::handle_desktop_click(CLICK_EVENT event) {
} }
// Create window // Create window
Window* win = new Window(); Window* win = new Window(&tft->tft);
WindowDecoration close_btn = { WindowDecoration close_btn = {
.x_offset = 6, .x_offset = 6,
@ -371,7 +373,6 @@ int Shell::handle_desktop_click(CLICK_EVENT event) {
win->minimized = false; win->minimized = false;
win->title = item.name; win->title = item.name;
win->window_content_text = {}; win->window_content_text = {};
win->sprite = LGFX_Sprite(&tft->tft);
// Spawn program using the program_class // Spawn program using the program_class
bool result = _system_manager->spawn_program(win, item.program_class); bool result = _system_manager->spawn_program(win, item.program_class);

View File

@ -28,13 +28,13 @@ public:
void create_window(Window* window); void create_window(Window* window);
void close_window(int window_id); void close_window(int window_id);
void minimize_window(int window_id); void minimize_window(int window_id);
void draw_window(Window window); void draw_window(const Window& window);
// ======= Desktop ======= // ======= Desktop =======
void draw_background(int color); void draw_background(int color);
void draw_task_bar(int color); void draw_task_bar(int color);
void draw_start_menu(); void draw_start_menu();
void draw_desktop_Item(DesktopItem desktop_item); void draw_desktop_Item(const DesktopItem& desktop_item);
// ======= Shared ======= // ======= Shared =======
void draw_all(); void draw_all();

View File

@ -48,7 +48,7 @@ bool SystemManager::spawn_program(Window* window, const std::string& program_cla
return true; return true;
} }
void SystemManager::close_program(int id) { void SystemManager::close_program(short int id) {
for (size_t i = 0; i < _programs.size(); ++i) { for (size_t i = 0; i < _programs.size(); ++i) {
if (_programs[i]->get_id() == id) { if (_programs[i]->get_id() == id) {
Serial.printf("Closing program ID: %d\n", id); Serial.printf("Closing program ID: %d\n", id);

View File

@ -15,7 +15,7 @@ private:
DISPLAY_STATE* _display_state; DISPLAY_STATE* _display_state;
Shell* _shell; Shell* _shell;
TFT_Handler* _tft; TFT_Handler* _tft;
int _next_program_id = 1; short int _next_program_id = 1;
CALIBRATION_IDLE _calibration_idle; CALIBRATION_IDLE _calibration_idle;
// Factory function type: creates a new instance of a Program // Factory function type: creates a new instance of a Program
@ -41,5 +41,5 @@ public:
bool spawn_program(Window* window, const std::string& program_class); bool spawn_program(Window* window, const std::string& program_class);
// Close a running program // Close a running program
void close_program(int id); void close_program(short int id);
}; };

View File

@ -17,21 +17,21 @@ void TFT_Handler::end_draw() {
tft.endWrite(); tft.endWrite();
} }
void TFT_Handler::draw_box(int x, int y, int size_x, int size_y, int color) { void TFT_Handler::draw_box(short int x, short int y, short int size_x, short int size_y, int color) {
tft.setRotation(3); tft.setRotation(3);
tft.fillRect(x, y, size_x, size_y, color); tft.fillRect(x, y, size_x, size_y, color);
} }
void TFT_Handler::draw_rect(int x, int y, int size_x, int size_y, int thickness, int color) { void TFT_Handler::draw_rect(short int x, short int y, short int size_x, short int size_y, short int thickness, int color) {
tft.setRotation(3); tft.setRotation(3);
tft.drawRect(x, y, size_x, size_y, color); tft.drawRect(x, y, size_x, size_y, color);
} }
void TFT_Handler::draw_line(int x1, int y1, int x2, int y2, int color) { void TFT_Handler::draw_line(short int x1, short int y1, short int x2, short int y2, int color) {
tft.drawLine(x1, y1, x2, y2, color); tft.drawLine(x1, y1, x2, y2, color);
} }
void TFT_Handler::draw_text(int x, int y, std::string str, int color, int size) { void TFT_Handler::draw_text(short int x, short int y, const std::string& str, int color, short int size) {
tft.setTextColor(color); tft.setTextColor(color);
tft.setTextSize(size); tft.setTextSize(size);
tft.drawString(str.c_str(), x, y); tft.drawString(str.c_str(), x, y);
@ -41,6 +41,6 @@ void TFT_Handler::fill_screen(int color) {
tft.fillScreen(color); tft.fillScreen(color);
} }
void TFT_Handler::draw_box_sprite(int x, int y, int size_x, int size_y, int color) { void TFT_Handler::push_sprite(LGFX_Sprite sprite) {
sprite.pushSprite(0, 0);
} }

View File

@ -59,11 +59,11 @@ public:
void start_draw(); void start_draw();
void end_draw(); void end_draw();
void draw_box(int x, int y, int size_x, int size_y, int color); void draw_box(short int x, short int y, short int size_x, short int size_y, int color);
void draw_rect(int x, int y, int size_x, int size_y, int thickness, int color); void draw_rect(short int x, short int y, short int size_x, short int size_y, short int thickness, int color);
void draw_line(int x1, int y1, int x2, int y2, int color); void draw_line(short int x1, short int y1, short int x2, short int y2, int color);
void draw_text(int x, int y, std::string str, int color, int size); void draw_text(short int x, short int y, const std::string& str, int color, short int size);
void fill_screen(int color); void fill_screen(int color);
void push_sprite(LGFX_Sprite sprite);
void draw_box_sprite(int x, int y, int size_x, int size_y, int color);
}; };