#include "desktop_hander.h" #include "tft_handler.h" void Desktop_Hander::init(TFT_Handler* th, DISPLAY_STATE* ds) { tft = th; display_state = ds; // Subscribe to events EventManager::getInstance().subscribe(this); // Create desktop items for (int i = 0; i < 5; i++) { Desktop_Item di = { .id = i, .place_x = i * 50 + 1, .place_y = 10, .icon_size_x = 45, .icon_size_y = 50, }; items.push_back(di); } re_draw_desktop(); } void Desktop_Hander::re_draw_desktop() { draw_background(0x0410); draw_task_bar(0xbdf7); for (const auto& item : items) { draw_desktop_Item(item); } } void Desktop_Hander::draw_background(int color) { tft->fill_screen(color); } void Desktop_Hander::draw_task_bar(int color) { // bar tft->draw_box(0, 293, 480, 40, color); tft->draw_line(0, 294, 480, 294, 0xffff); // Outer shadow tft->draw_box(5, 297, 53, 21, 0x0000); // Inner shadow tft->draw_box(6, 298, 51, 19, 0x8410); // Highlight tft->draw_box(5, 297, 51, 19, 0xffff); // Button tft->draw_box(6, 298, 50, 18, color); } void Desktop_Hander::draw_desktop_Item(const Desktop_Item& desktop_item) { tft->draw_box(desktop_item.place_x, desktop_item.place_y, desktop_item.icon_size_x, desktop_item.icon_size_y, 0x4648); } void Desktop_Hander::on_click_event(const CLICK_EVENT& event) { if (event.event != CLICK_EVENTS::LEFT_CLICK) { return; } handle_desktop_click(event); } void Desktop_Hander::handle_desktop_click(const CLICK_EVENT& event) { // Check if click is on desktop (not on taskbar or windows) // This is where you'd check if an icon was clicked for (const auto& item : items) { 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)) { Serial.print("Desktop item clicked: "); Serial.println(item.id); // TODO: Handle icon click (open window, etc.) break; } } }