Testing
This commit is contained in:
parent
526ba71d57
commit
f71b54e5f2
@ -76,8 +76,8 @@ void setup() {
|
|||||||
|
|
||||||
Window win1 = {
|
Window win1 = {
|
||||||
.id = 0,
|
.id = 0,
|
||||||
.x = 170,
|
.x = 10,
|
||||||
.y = 30,
|
.y = 10,
|
||||||
.width = 350,
|
.width = 350,
|
||||||
.height = 250,
|
.height = 250,
|
||||||
.background_color = 0xbdf7,
|
.background_color = 0xbdf7,
|
||||||
@ -90,10 +90,10 @@ void setup() {
|
|||||||
|
|
||||||
Window win2 = {
|
Window win2 = {
|
||||||
.id = 1,
|
.id = 1,
|
||||||
.x = 30,
|
.x = 70,
|
||||||
.y = 150,
|
.y = 40,
|
||||||
.width = 350,
|
.width = 350,
|
||||||
.height = 270,
|
.height = 200,
|
||||||
.background_color = 0xbdf7,
|
.background_color = 0xbdf7,
|
||||||
.foreground_color = COL_DARK_BLUE,
|
.foreground_color = COL_DARK_BLUE,
|
||||||
.focused = true,
|
.focused = true,
|
||||||
@ -114,5 +114,5 @@ void loop() {
|
|||||||
_display_state->update_display.store(false);
|
_display_state->update_display.store(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
delay(50);
|
delay(5);
|
||||||
}
|
}
|
||||||
@ -54,18 +54,18 @@ void Desktop_Hander::draw_task_bar(int color) {
|
|||||||
tft->draw_box(6, 298, 50, 18, 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);
|
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;
|
if (event.event != CLICK_EVENTS::LEFT_CLICK) return;
|
||||||
|
|
||||||
int id = handle_desktop_click(event);
|
int id = handle_desktop_click(event);
|
||||||
bool task_bar_clicked = handle_taskbar_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)
|
// Check if click is on desktop (not on taskbar or windows)
|
||||||
// This is where you'd check if an icon was clicked
|
// This is where you'd check if an icon was clicked
|
||||||
for (const auto& item : items) {
|
for (const auto& item : items) {
|
||||||
@ -85,7 +85,7 @@ int Desktop_Hander::handle_desktop_click(const CLICK_EVENT& event) {
|
|||||||
return -1;
|
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)) {
|
if (event.x >= 6 && event.x <= (6 + 50) && event.y >= 298 && event.y <= (298 + 18)) {
|
||||||
Serial.println("Taskbar button clicked");
|
Serial.println("Taskbar button clicked");
|
||||||
|
|
||||||
|
|||||||
@ -11,16 +11,16 @@ private:
|
|||||||
DISPLAY_STATE* display_state;
|
DISPLAY_STATE* display_state;
|
||||||
std::vector<Desktop_Item> items;
|
std::vector<Desktop_Item> items;
|
||||||
|
|
||||||
int handle_desktop_click(const CLICK_EVENT& event);
|
int handle_desktop_click(CLICK_EVENT event);
|
||||||
bool handle_taskbar_click(const CLICK_EVENT& event);
|
bool handle_taskbar_click(CLICK_EVENT event);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void init(TFT_Handler* th, DISPLAY_STATE* ds);
|
void init(TFT_Handler* th, DISPLAY_STATE* ds);
|
||||||
void re_draw_desktop();
|
void re_draw_desktop();
|
||||||
void draw_background(int color);
|
void draw_background(int color);
|
||||||
void draw_task_bar(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
|
// IEventListener interface
|
||||||
void on_click_event(const CLICK_EVENT& event) override;
|
void on_click_event(CLICK_EVENT event) override;
|
||||||
};
|
};
|
||||||
@ -11,7 +11,7 @@
|
|||||||
// Forward declare to avoid circular dependency
|
// Forward declare to avoid circular dependency
|
||||||
class IEventListener {
|
class IEventListener {
|
||||||
public:
|
public:
|
||||||
virtual void on_click_event(const CLICK_EVENT& event) = 0;
|
virtual void on_click_event(CLICK_EVENT event) = 0;
|
||||||
virtual ~IEventListener() = default;
|
virtual ~IEventListener() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -41,7 +41,7 @@ void WindowManager::draw_all() {
|
|||||||
tft->end_draw();
|
tft->end_draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowManager::draw_window(const Window& window) {
|
void WindowManager::draw_window(Window window) {
|
||||||
// Outer shadow
|
// Outer shadow
|
||||||
tft->draw_rect(window.x, window.y, window.width + 2, window.height + 2, 1, 0x0000);
|
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);
|
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;
|
if (event.event != CLICK_EVENTS::LEFT_CLICK) return;
|
||||||
|
|
||||||
int clicked_id = handle_window_click(event);
|
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);
|
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
|
// 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];
|
||||||
@ -94,14 +94,11 @@ int WindowManager::handle_window_click(const CLICK_EVENT& event) {
|
|||||||
if (event.x >= window.x && event.x <= (window.x + window.width) &&
|
if (event.x >= window.x && event.x <= (window.x + window.width) &&
|
||||||
event.y >= window.y && event.y <= (window.y + window.height)) {
|
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) {
|
for (auto it = window.window_decorations.begin(); it != window.window_decorations.end(); ++it) {
|
||||||
int x = window.x + it->x_offset;
|
int x = window.x + it->x_offset;
|
||||||
int y = window.y + it->y_offset;
|
int y = window.y + it->y_offset;
|
||||||
Serial.printf("x: %i y: %i\n", x, y);
|
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) {
|
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);
|
close_window(window.id);
|
||||||
return window.id;
|
return window.id;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,15 +19,15 @@ private:
|
|||||||
DISPLAY_STATE* display_state;
|
DISPLAY_STATE* display_state;
|
||||||
std::vector<Window> windows;
|
std::vector<Window> windows;
|
||||||
|
|
||||||
int handle_window_click(const CLICK_EVENT& event);
|
int handle_window_click(CLICK_EVENT event);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void init(TFT_Handler* th, DISPLAY_STATE* ds);
|
void init(TFT_Handler* th, DISPLAY_STATE* ds);
|
||||||
void create_window(Window window);
|
void create_window(Window window);
|
||||||
void close_window(int window_id);
|
void close_window(int window_id);
|
||||||
void draw_all();
|
void draw_all();
|
||||||
void draw_window(const Window& window);
|
void draw_window(Window window);
|
||||||
|
|
||||||
// IEventListener interface
|
// IEventListener interface
|
||||||
void on_click_event(const CLICK_EVENT& event) override;
|
void on_click_event(CLICK_EVENT event) override;
|
||||||
};
|
};
|
||||||
Loading…
Reference in New Issue
Block a user