This commit is contained in:
Rasmus Rasmussen 2025-12-16 20:48:21 +01:00
parent 526ba71d57
commit f71b54e5f2
6 changed files with 21 additions and 24 deletions

View File

@ -76,8 +76,8 @@ void setup() {
Window win1 = {
.id = 0,
.x = 170,
.y = 30,
.x = 10,
.y = 10,
.width = 350,
.height = 250,
.background_color = 0xbdf7,
@ -90,10 +90,10 @@ void setup() {
Window win2 = {
.id = 1,
.x = 30,
.y = 150,
.x = 70,
.y = 40,
.width = 350,
.height = 270,
.height = 200,
.background_color = 0xbdf7,
.foreground_color = COL_DARK_BLUE,
.focused = true,
@ -114,5 +114,5 @@ void loop() {
_display_state->update_display.store(false);
}
delay(50);
delay(5);
}

View File

@ -54,18 +54,18 @@ void Desktop_Hander::draw_task_bar(int color) {
tft->draw_box(6, 298, 50, 18, color);
}
void Desktop_Hander::draw_desktop_Item(const Desktop_Item& desktop_item) {
void Desktop_Hander::draw_desktop_Item(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) {
void Desktop_Hander::on_click_event(CLICK_EVENT event) {
if (event.event != CLICK_EVENTS::LEFT_CLICK) return;
int id = handle_desktop_click(event);
bool task_bar_clicked = handle_taskbar_click(event);
}
int Desktop_Hander::handle_desktop_click(const CLICK_EVENT& event) {
int Desktop_Hander::handle_desktop_click(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) {
@ -85,7 +85,7 @@ int Desktop_Hander::handle_desktop_click(const CLICK_EVENT& event) {
return -1;
}
bool Desktop_Hander::handle_taskbar_click(const CLICK_EVENT& event) {
bool Desktop_Hander::handle_taskbar_click(CLICK_EVENT event) {
if (event.x >= 6 && event.x <= (6 + 50) && event.y >= 298 && event.y <= (298 + 18)) {
Serial.println("Taskbar button clicked");

View File

@ -11,16 +11,16 @@ private:
DISPLAY_STATE* display_state;
std::vector<Desktop_Item> items;
int handle_desktop_click(const CLICK_EVENT& event);
bool handle_taskbar_click(const CLICK_EVENT& event);
int handle_desktop_click(CLICK_EVENT event);
bool handle_taskbar_click(CLICK_EVENT event);
public:
void init(TFT_Handler* th, DISPLAY_STATE* ds);
void re_draw_desktop();
void draw_background(int color);
void draw_task_bar(int color);
void draw_desktop_Item(const Desktop_Item& desktop_item);
void draw_desktop_Item(Desktop_Item desktop_item);
// IEventListener interface
void on_click_event(const CLICK_EVENT& event) override;
void on_click_event(CLICK_EVENT event) override;
};

View File

@ -11,7 +11,7 @@
// Forward declare to avoid circular dependency
class IEventListener {
public:
virtual void on_click_event(const CLICK_EVENT& event) = 0;
virtual void on_click_event(CLICK_EVENT event) = 0;
virtual ~IEventListener() = default;
};

View File

@ -41,7 +41,7 @@ void WindowManager::draw_all() {
tft->end_draw();
}
void WindowManager::draw_window(const Window& window) {
void WindowManager::draw_window(Window window) {
// Outer shadow
tft->draw_rect(window.x, window.y, window.width + 2, window.height + 2, 1, 0x0000);
@ -77,7 +77,7 @@ void WindowManager::draw_window(const Window& window) {
tft->draw_box(window.x + 3, window.y + 35, window.width - 6, window.height - 38, COL_WHITE);
}
void WindowManager::on_click_event(const CLICK_EVENT& event) {
void WindowManager::on_click_event(CLICK_EVENT event) {
if (event.event != CLICK_EVENTS::LEFT_CLICK) return;
int clicked_id = handle_window_click(event);
@ -85,7 +85,7 @@ void WindowManager::on_click_event(const CLICK_EVENT& event) {
if (clicked_id >= 0) display_state->update_display.store(true);
}
int WindowManager::handle_window_click(const CLICK_EVENT& event) {
int WindowManager::handle_window_click(CLICK_EVENT event) {
// Iterate BACKWARDS - last window is on top
for (int i = windows.size() - 1; i >= 0; i--) {
Window& window = windows[i];
@ -94,14 +94,11 @@ int WindowManager::handle_window_click(const CLICK_EVENT& event) {
if (event.x >= window.x && event.x <= (window.x + window.width) &&
event.y >= window.y && event.y <= (window.y + window.height)) {
Serial.println("lol");
for (auto it = window.window_decorations.begin(); it != window.window_decorations.end(); ++it) {
int x = window.x + it->x_offset;
int y = window.y + it->y_offset;
Serial.printf("x: %i y: %i\n", x, y);
if (event.x >= x && event.x <= (x + it->width) && event.y >= y && event.y <= (y + it->height) && it->action == WindowAction::CLOSE) {
Serial.println("lollllll");
close_window(window.id);
return window.id;
}

View File

@ -19,15 +19,15 @@ private:
DISPLAY_STATE* display_state;
std::vector<Window> windows;
int handle_window_click(const CLICK_EVENT& event);
int handle_window_click(CLICK_EVENT event);
public:
void init(TFT_Handler* th, DISPLAY_STATE* ds);
void create_window(Window window);
void close_window(int window_id);
void draw_all();
void draw_window(const Window& window);
void draw_window(Window window);
// IEventListener interface
void on_click_event(const CLICK_EVENT& event) override;
void on_click_event(CLICK_EVENT event) override;
};