Temp before making everything either shitty or fucking awesome

This commit is contained in:
Rasmus Rasmussen 2026-01-09 20:30:54 +01:00
parent 740c8e01c1
commit 9206972133
6 changed files with 29 additions and 43 deletions

View File

@ -92,13 +92,6 @@ public:
void run() override { void run() override {
_window->x += 150; _window->x += 150;
_window->width -= 50; _window->width -= 50;
_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!"); Serial.println("Settings started!");
WindowContentText ram_usage; WindowContentText ram_usage;

View File

@ -68,21 +68,6 @@ struct Window {
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;
// 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

View File

@ -139,7 +139,7 @@ void Shell::create_window(Window* window) {
display_state->update_display.store(true); display_state->update_display.store(true);
} }
void Shell::close_window(int window_id) { void Shell::close_window(short int window_id) {
for (auto it = windows.begin(); it != windows.end(); ++it) { for (auto it = windows.begin(); it != windows.end(); ++it) {
if ((*it)->id == window_id) { if ((*it)->id == window_id) {
windows.erase(it); windows.erase(it);
@ -160,7 +160,7 @@ void Shell::close_window(int window_id) {
Helpers::recalculate_taskbar(task_bar_items); Helpers::recalculate_taskbar(task_bar_items);
} }
void Shell::minimize_window(int window_id) { void Shell::minimize_window(short int window_id) {
for (auto it = windows.begin(); it != windows.end(); ++it) { for (auto it = windows.begin(); it != windows.end(); ++it) {
for (int i = 0; i < task_bar_items.size(); ++i) { for (int i = 0; i < task_bar_items.size(); ++i) {
if ((*it)->id == window_id && (*it)->id == task_bar_items[i].id) { if ((*it)->id == window_id && (*it)->id == task_bar_items[i].id) {
@ -229,11 +229,11 @@ void Shell::draw_window(const Window& window) {
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); tft->push_sprite();
} }
// ======= Desktop ======= // ======= Desktop =======
void Shell::draw_background(int color) { void Shell::draw_background(short int color) {
tft->fill_screen(color); tft->fill_screen(color);
} }
@ -241,7 +241,7 @@ 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);
} }
void Shell::draw_task_bar(int color) { void Shell::draw_task_bar(short int color) {
// bar // bar
tft->draw_box(0, 293, 480, 40, color); tft->draw_box(0, 293, 480, 40, color);
tft->draw_line(0, 294, 480, 294, 0xffff); tft->draw_line(0, 294, 480, 294, 0xffff);
@ -281,7 +281,7 @@ void Shell::draw_start_menu() {
} }
int Shell::handle_window_click(CLICK_EVENT event) { short int Shell::handle_window_click(CLICK_EVENT event) {
// Iterate BACKWARDS - last window is on top // Iterate BACKWARDS - last window is on top
for (int i = windows.size() - 1; i >= 0; i--) { for (int i = windows.size() - 1; i >= 0; i--) {
Window* window = windows[i]; Window* window = windows[i];
@ -329,7 +329,7 @@ int Shell::handle_window_click(CLICK_EVENT event) {
return -1; return -1;
} }
int Shell::handle_desktop_click(CLICK_EVENT event) { short int Shell::handle_desktop_click(CLICK_EVENT event) {
for (const auto& item : items) { for (const auto& item : items) {
if (event.x >= item.place_x && event.x <= (item.place_x + item.icon_size_x) if (event.x >= item.place_x && event.x <= (item.place_x + item.icon_size_x)
&& event.y >= item.place_y && event.y <= (item.place_y + item.icon_size_y)) { && event.y >= item.place_y && event.y <= (item.place_y + item.icon_size_y)) {
@ -342,7 +342,7 @@ int Shell::handle_desktop_click(CLICK_EVENT event) {
} }
// Create window // Create window
Window* win = new Window(&tft->tft); Window* win = new Window();
WindowDecoration close_btn = { WindowDecoration close_btn = {
.x_offset = 6, .x_offset = 6,
@ -390,7 +390,7 @@ int Shell::handle_desktop_click(CLICK_EVENT event) {
return -1; return -1;
} }
int Shell::handle_taskbar_click(CLICK_EVENT event) { short int Shell::handle_taskbar_click(CLICK_EVENT event) {
for (int i = 0; i < task_bar_items.size(); ++i) { for (int i = 0; i < task_bar_items.size(); ++i) {
if (event.x >= task_bar_items[i].place_x && event.x <= (task_bar_items[i].place_x + task_bar_items[i].width) && event.y >= task_bar_items[i].place_y && event.y <= (task_bar_items[i].place_y + task_bar_items[i].height)) { if (event.x >= task_bar_items[i].place_x && event.x <= (task_bar_items[i].place_x + task_bar_items[i].width) && event.y >= task_bar_items[i].place_y && event.y <= (task_bar_items[i].place_y + task_bar_items[i].height)) {
for (int j = 0; j < windows.size(); ++j) { for (int j = 0; j < windows.size(); ++j) {

View File

@ -16,9 +16,9 @@ private:
SystemManager* _system_manager; SystemManager* _system_manager;
int handle_window_click(CLICK_EVENT event); short int handle_window_click(CLICK_EVENT event);
int handle_desktop_click(CLICK_EVENT event); short int handle_desktop_click(CLICK_EVENT event);
int handle_taskbar_click(CLICK_EVENT event); short int handle_taskbar_click(CLICK_EVENT event);
bool handle_start_button_click(CLICK_EVENT event); bool handle_start_button_click(CLICK_EVENT event);
public: public:
@ -26,13 +26,13 @@ public:
// ======= Window ======= // ======= Window =======
void create_window(Window* window); void create_window(Window* window);
void close_window(int window_id); void close_window(short int window_id);
void minimize_window(int window_id); void minimize_window(short int window_id);
void draw_window(const Window& window); void draw_window(const Window& window);
// ======= Desktop ======= // ======= Desktop =======
void draw_background(int color); void draw_background(short int color);
void draw_task_bar(int color); void draw_task_bar(short int color);
void draw_start_menu(); void draw_start_menu();
void draw_desktop_Item(const DesktopItem& desktop_item); void draw_desktop_Item(const DesktopItem& desktop_item);

View File

@ -6,7 +6,12 @@ void TFT_Handler::init(DISPLAY_STATE* display_state) {
tft.setColorDepth(16); tft.setColorDepth(16);
tft.init(); tft.init();
tft.setRotation(3);
tft.fillScreen(0x0000); tft.fillScreen(0x0000);
sprite.setColorDepth(16);
sprite.setPsram(true);
sprite.createSprite(480, 320);
} }
void TFT_Handler::start_draw() { void TFT_Handler::start_draw() {
@ -18,12 +23,10 @@ void TFT_Handler::end_draw() {
} }
void TFT_Handler::draw_box(short int x, short int y, short int size_x, short 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); tft.fillRect(x, y, size_x, size_y, 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) { 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); tft.drawRect(x, y, size_x, size_y, color);
} }
@ -41,6 +44,6 @@ void TFT_Handler::fill_screen(int color) {
tft.fillScreen(color); tft.fillScreen(color);
} }
void TFT_Handler::push_sprite(LGFX_Sprite sprite) { void TFT_Handler::push_sprite() {
sprite.pushSprite(0, 0); sprite.pushSprite(0, 0);
} }

View File

@ -23,8 +23,10 @@ public:
cfg.pin_mosi = 11; cfg.pin_mosi = 11;
cfg.pin_dc = 21; cfg.pin_dc = 21;
cfg.pin_miso = -1; cfg.pin_miso = -1;
cfg.freq_write = 40000000; cfg.freq_write = 60000000;
cfg.freq_read = 16000000; cfg.freq_read = 16000000;
cfg.use_lock = true;
cfg.dma_channel = 1;
spi.config(cfg); // *** APPLY CONFIG *** spi.config(cfg); // *** APPLY CONFIG ***
} }
@ -53,6 +55,9 @@ class TFT_Handler {
public: public:
LGFX tft; LGFX tft;
DISPLAY_STATE* _display_state; DISPLAY_STATE* _display_state;
LGFX_Sprite sprite;
TFT_Handler() : sprite(&tft) {}
void init(DISPLAY_STATE* display_state); void init(DISPLAY_STATE* display_state);
@ -64,6 +69,6 @@ public:
void draw_line(short int x1, short int y1, short int x2, short int y2, 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 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 push_sprite();
}; };