Prepare for render re-write
This commit is contained in:
parent
9b118b2d80
commit
740c8e01c1
@ -20,8 +20,8 @@ enum CLICK_EVENTS {
|
||||
};
|
||||
|
||||
struct CLICK_EVENT {
|
||||
int x;
|
||||
int y;
|
||||
short int x;
|
||||
short int y;
|
||||
CLICK_EVENTS event;
|
||||
};
|
||||
|
||||
@ -32,7 +32,7 @@ enum class ApplicationEventState {
|
||||
};
|
||||
|
||||
struct APPLICATION_EVENT {
|
||||
int id;
|
||||
short int id;
|
||||
ApplicationEventState state;
|
||||
char title[64];
|
||||
};
|
||||
|
||||
@ -92,9 +92,13 @@ public:
|
||||
void run() override {
|
||||
_window->x += 150;
|
||||
_window->width -= 50;
|
||||
//_window->sprite.setPsram(true);
|
||||
//_window->sprite.createSprite(10, 10);
|
||||
//_window->sprite.setColorDepth(16);
|
||||
_window->sprite.setPsram(false);
|
||||
_window->sprite.createSprite(10, 10);
|
||||
_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!");
|
||||
WindowContentText ram_usage;
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
struct Mouse_Icon {
|
||||
int x;
|
||||
int y;
|
||||
int size_x;
|
||||
int size_y;
|
||||
int color;
|
||||
short int x;
|
||||
short int y;
|
||||
short int size_x;
|
||||
short int size_y;
|
||||
short int color;
|
||||
};
|
||||
@ -23,7 +23,7 @@ void InputManager::init(DISPLAY_STATE* display_state, TFT_Handler* tf) {
|
||||
|
||||
void InputManager::update() {
|
||||
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]) {
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
@ -7,19 +7,19 @@
|
||||
|
||||
class InputManager {
|
||||
private:
|
||||
int BUTTON_PINS[6] = {4, 5, 6, 7, 17, 16};
|
||||
static constexpr int NUM_BUTTONS = 6;
|
||||
short int BUTTON_PINS[6] = {4, 5, 6, 7, 17, 16};
|
||||
static constexpr short int NUM_BUTTONS = 6;
|
||||
const unsigned long DEBOUNCE_DELAY = 25; // milliseconds
|
||||
unsigned long lastDebounceTime[NUM_BUTTONS] = {0};
|
||||
int lastButtonState[NUM_BUTTONS] = {HIGH, HIGH, HIGH, HIGH, HIGH, HIGH};
|
||||
int buttonState[NUM_BUTTONS] = {HIGH, HIGH, HIGH, HIGH, HIGH, HIGH};
|
||||
short int lastButtonState[NUM_BUTTONS] = {HIGH, HIGH, HIGH, HIGH, HIGH, HIGH};
|
||||
short int buttonState[NUM_BUTTONS] = {HIGH, HIGH, HIGH, HIGH, HIGH, HIGH};
|
||||
|
||||
DISPLAY_STATE* _display_state;
|
||||
TFT_Handler* _tf;
|
||||
Mouse_Icon mi;
|
||||
|
||||
void handle_button_press(int buttonIndex);
|
||||
bool are_buttons_pressed(int btn1, int btn2);
|
||||
void handle_button_press(short int buttonIndex);
|
||||
bool are_buttons_pressed(short int btn1, short int btn2);
|
||||
|
||||
public:
|
||||
void init(DISPLAY_STATE* display_state, TFT_Handler* tf);
|
||||
|
||||
@ -12,7 +12,7 @@ Program::~Program() {
|
||||
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;
|
||||
_name = name;
|
||||
_window = window;
|
||||
|
||||
@ -5,28 +5,29 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <LovyanGFX.hpp>
|
||||
#include "tft_handler.h"
|
||||
|
||||
// Forward declarations
|
||||
class Shell;
|
||||
class TFT_Handler;
|
||||
|
||||
struct TaskBarItem {
|
||||
int id;
|
||||
int place_x;
|
||||
int place_y;
|
||||
int width;
|
||||
int height;
|
||||
int offset_x;
|
||||
short int id;
|
||||
short int place_x;
|
||||
short int place_y;
|
||||
short int width;
|
||||
short int height;
|
||||
short int offset_x;
|
||||
bool focused;
|
||||
std::string name;
|
||||
};
|
||||
|
||||
struct DesktopItem {
|
||||
int id;
|
||||
int place_x;
|
||||
int place_y;
|
||||
int icon_size_x;
|
||||
int icon_size_y;
|
||||
short int id;
|
||||
short int place_x;
|
||||
short int place_y;
|
||||
short int icon_size_x;
|
||||
short int icon_size_y;
|
||||
std::string name;
|
||||
std::string program_class; // Which program class to instantiate
|
||||
};
|
||||
@ -40,34 +41,48 @@ enum class WindowAction {
|
||||
};
|
||||
|
||||
struct WindowDecoration {
|
||||
int x_offset;
|
||||
int y_offset;
|
||||
int width;
|
||||
int height;
|
||||
short int x_offset;
|
||||
short int y_offset;
|
||||
short int width;
|
||||
short int height;
|
||||
WindowAction action;
|
||||
};
|
||||
|
||||
struct WindowContentText {
|
||||
int x;
|
||||
int y;
|
||||
int size;
|
||||
short int x;
|
||||
short int y;
|
||||
short int size;
|
||||
std::string text;
|
||||
};
|
||||
|
||||
struct Window {
|
||||
int id;
|
||||
int x;
|
||||
int y;
|
||||
int width;
|
||||
int height;
|
||||
int background_color;
|
||||
int foreground_color;
|
||||
short int id;
|
||||
short int x;
|
||||
short int y;
|
||||
short int width;
|
||||
short int height;
|
||||
short int background_color;
|
||||
short int foreground_color;
|
||||
bool focused;
|
||||
bool minimized;
|
||||
std::string title;
|
||||
std::vector<WindowDecoration> window_decorations;
|
||||
std::vector<WindowContentText> window_content_text;
|
||||
bool hasSprite = false;
|
||||
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
|
||||
@ -78,7 +93,7 @@ protected:
|
||||
TFT_Handler* _tft;
|
||||
DISPLAY_STATE* _display_state;
|
||||
TaskHandle_t _task_handle;
|
||||
int _id;
|
||||
short int _id;
|
||||
std::string _name;
|
||||
bool _running;
|
||||
CALIBRATION_IDLE _calibration_idle;
|
||||
@ -90,7 +105,7 @@ public:
|
||||
virtual ~Program();
|
||||
|
||||
// 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
|
||||
virtual void run() = 0;
|
||||
|
||||
@ -189,7 +189,7 @@ void Shell::draw_all() {
|
||||
tft->end_draw();
|
||||
}
|
||||
|
||||
void Shell::draw_window(Window window) {
|
||||
void Shell::draw_window(const Window& window) {
|
||||
if (window.minimized) return;
|
||||
|
||||
// Outer shadow
|
||||
@ -228,6 +228,8 @@ void Shell::draw_window(Window window) {
|
||||
for (WindowContentText text : window.window_content_text) {
|
||||
tft->draw_text(text.x, text.y, text.text, COL_BLACK, text.size);
|
||||
}
|
||||
|
||||
if (window.hasSprite) tft->push_sprite(window.sprite);
|
||||
}
|
||||
|
||||
// ======= Desktop =======
|
||||
@ -235,7 +237,7 @@ void Shell::draw_background(int 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);
|
||||
}
|
||||
|
||||
@ -340,7 +342,7 @@ int Shell::handle_desktop_click(CLICK_EVENT event) {
|
||||
}
|
||||
|
||||
// Create window
|
||||
Window* win = new Window();
|
||||
Window* win = new Window(&tft->tft);
|
||||
|
||||
WindowDecoration close_btn = {
|
||||
.x_offset = 6,
|
||||
@ -371,7 +373,6 @@ int Shell::handle_desktop_click(CLICK_EVENT event) {
|
||||
win->minimized = false;
|
||||
win->title = item.name;
|
||||
win->window_content_text = {};
|
||||
win->sprite = LGFX_Sprite(&tft->tft);
|
||||
|
||||
// Spawn program using the program_class
|
||||
bool result = _system_manager->spawn_program(win, item.program_class);
|
||||
|
||||
@ -28,13 +28,13 @@ public:
|
||||
void create_window(Window* window);
|
||||
void close_window(int window_id);
|
||||
void minimize_window(int window_id);
|
||||
void draw_window(Window window);
|
||||
void draw_window(const Window& window);
|
||||
|
||||
// ======= Desktop =======
|
||||
void draw_background(int color);
|
||||
void draw_task_bar(int color);
|
||||
void draw_start_menu();
|
||||
void draw_desktop_Item(DesktopItem desktop_item);
|
||||
void draw_desktop_Item(const DesktopItem& desktop_item);
|
||||
|
||||
// ======= Shared =======
|
||||
void draw_all();
|
||||
|
||||
@ -48,7 +48,7 @@ bool SystemManager::spawn_program(Window* window, const std::string& program_cla
|
||||
return true;
|
||||
}
|
||||
|
||||
void SystemManager::close_program(int id) {
|
||||
void SystemManager::close_program(short int id) {
|
||||
for (size_t i = 0; i < _programs.size(); ++i) {
|
||||
if (_programs[i]->get_id() == id) {
|
||||
Serial.printf("Closing program ID: %d\n", id);
|
||||
|
||||
@ -15,7 +15,7 @@ private:
|
||||
DISPLAY_STATE* _display_state;
|
||||
Shell* _shell;
|
||||
TFT_Handler* _tft;
|
||||
int _next_program_id = 1;
|
||||
short int _next_program_id = 1;
|
||||
CALIBRATION_IDLE _calibration_idle;
|
||||
|
||||
// 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);
|
||||
|
||||
// Close a running program
|
||||
void close_program(int id);
|
||||
void close_program(short int id);
|
||||
};
|
||||
@ -17,21 +17,21 @@ void TFT_Handler::end_draw() {
|
||||
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.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.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);
|
||||
}
|
||||
|
||||
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.setTextSize(size);
|
||||
tft.drawString(str.c_str(), x, y);
|
||||
@ -41,6 +41,6 @@ void TFT_Handler::fill_screen(int 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);
|
||||
}
|
||||
@ -59,11 +59,11 @@ public:
|
||||
void start_draw();
|
||||
void end_draw();
|
||||
|
||||
void draw_box(int x, int y, int size_x, int size_y, int color);
|
||||
void draw_rect(int x, int y, int size_x, int size_y, int thickness, int color);
|
||||
void draw_line(int x1, int y1, int x2, int y2, int color);
|
||||
void draw_text(int x, int y, std::string str, int color, int size);
|
||||
void draw_box(short int x, short int y, short int size_x, short int size_y, 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(short int x1, short int y1, short int x2, short int y2, int color);
|
||||
void draw_text(short int x, short int y, const std::string& str, int color, short int size);
|
||||
void fill_screen(int color);
|
||||
|
||||
void draw_box_sprite(int x, int y, int size_x, int size_y, int color);
|
||||
void push_sprite(LGFX_Sprite sprite);
|
||||
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user