diff --git a/Desktop_Test/Desktop_Test.ino b/Desktop_Test/Desktop_Test.ino index f6f3fba..4036063 100644 --- a/Desktop_Test/Desktop_Test.ino +++ b/Desktop_Test/Desktop_Test.ino @@ -4,6 +4,7 @@ #include "tft_handler.h" #include "event_manager.h" #include "GLOBALS.h" +#include WindowManager* wm; Desktop_Hander* dh; @@ -52,6 +53,27 @@ void setup() { delay(100); // Create test windows + + WindowDecoration dec1 = { + .x_offset = 6, + .y_offset = 5, + .width = 25, + .height = 25, + .action = WindowAction::CLOSE, + }; + + WindowDecoration dec2 = { + .x_offset = 36, + .y_offset = 5, + .width = 25, + .height = 25, + .action = WindowAction::CLOSE, + }; + + std::vector wdec; + wdec.push_back(dec1); + wdec.push_back(dec2); + Window win1 = { .id = 0, .x = 170, @@ -62,7 +84,7 @@ void setup() { .foreground_color = COL_DARK_BLUE, .focused = false, .title = "Hello World!", - .window_actions = {}, + .window_decorations = wdec, }; wm->create_window(win1); @@ -76,7 +98,7 @@ void setup() { .foreground_color = COL_DARK_BLUE, .focused = true, .title = "Second Window", - .window_actions = {}, + .window_decorations = wdec, }; wm->create_window(win2); diff --git a/Desktop_Test/GLOBALS.h b/Desktop_Test/GLOBALS.h index 229427f..2d71628 100644 --- a/Desktop_Test/GLOBALS.h +++ b/Desktop_Test/GLOBALS.h @@ -1,6 +1,9 @@ #pragma once #include +#define MAX_SCREEN_WIDTH 480 +#define MAX_SCREEN_HEIGHT 320 + enum CLICK_EVENTS { NONE = 0, LEFT_CLICK = 1, diff --git a/Desktop_Test/desktop_hander.cpp b/Desktop_Test/desktop_hander.cpp index 917a552..c90f8bb 100644 --- a/Desktop_Test/desktop_hander.cpp +++ b/Desktop_Test/desktop_hander.cpp @@ -59,9 +59,7 @@ void Desktop_Hander::draw_desktop_Item(const Desktop_Item& desktop_item) { } void Desktop_Hander::on_click_event(const CLICK_EVENT& event) { - if (event.event != CLICK_EVENTS::LEFT_CLICK) { - return; - } + if (event.event != CLICK_EVENTS::LEFT_CLICK) return; int id = handle_desktop_click(event); bool task_bar_clicked = handle_taskbar_click(event); diff --git a/Desktop_Test/window.h b/Desktop_Test/window.h index e0c6fa5..c23d82a 100644 --- a/Desktop_Test/window.h +++ b/Desktop_Test/window.h @@ -6,6 +6,16 @@ enum class WindowAction { EXIT = 1, FILE = 2, HELP = 3, + MINIMIZE = 4, + CLOSE = 5, +}; + +struct WindowDecoration { + int x_offset; + int y_offset; + int width; + int height; + WindowAction action; }; struct Window { @@ -18,5 +28,5 @@ struct Window { int foreground_color; bool focused; std::string title; - std::vector window_actions; + std::vector window_decorations; }; \ No newline at end of file diff --git a/Desktop_Test/window_manager.cpp b/Desktop_Test/window_manager.cpp index 41d59ce..ee86b3d 100644 --- a/Desktop_Test/window_manager.cpp +++ b/Desktop_Test/window_manager.cpp @@ -1,3 +1,4 @@ +#include "GLOBALS.h" #include "window_manager.h" #include @@ -13,8 +14,9 @@ void WindowManager::create_window(Window window) { int total_pos_x = window.x + window.width; int total_pos_y = window.y + window.height; - if (total_pos_x > 480) window.x = total_pos_x - 480; - if (total_pos_y > 320) window.y = total_pos_y - 320; + // Clamp window within the screen size AND taskbar + if (total_pos_x > MAX_SCREEN_WIDTH) window.x = MAX_SCREEN_WIDTH - window.width; + if (total_pos_y > MAX_SCREEN_HEIGHT) window.y = MAX_SCREEN_HEIGHT - window.height - 29; windows.push_back(window); display_state->update_display.store(true); @@ -68,15 +70,11 @@ void WindowManager::draw_window(const Window& window) { } void WindowManager::on_click_event(const CLICK_EVENT& event) { - if (event.event != CLICK_EVENTS::LEFT_CLICK) { - return; - } + if (event.event != CLICK_EVENTS::LEFT_CLICK) return; int clicked_id = handle_window_click(event); - if (clicked_id >= 0) { - display_state->update_display.store(true); - } + if (clicked_id >= 0) display_state->update_display.store(true); } int WindowManager::handle_window_click(const CLICK_EVENT& event) { @@ -88,9 +86,9 @@ 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)) { - if (window.focused) { - return -1; - } + if (window.focused) return -1; + + // Unfocus all windows for (auto& win : windows) {