Temp commit before rewriting the window- and desktop manager
This commit is contained in:
parent
f71b54e5f2
commit
4f7aba8aa3
@ -4,6 +4,7 @@
|
||||
#include "tft_handler.h"
|
||||
#include "event_manager.h"
|
||||
#include "GLOBALS.h"
|
||||
#include "global_queue.h"
|
||||
#include <vector>
|
||||
|
||||
WindowManager* wm;
|
||||
@ -42,6 +43,8 @@ void setup() {
|
||||
// Initialize event manager (creates dispatcher task)
|
||||
EventManager::getInstance().init();
|
||||
|
||||
initGlobalQueue();
|
||||
|
||||
// Initialize components (they subscribe to events)
|
||||
im->init(_display_state, th);
|
||||
dh->init(th, _display_state);
|
||||
@ -83,6 +86,7 @@ void setup() {
|
||||
.background_color = 0xbdf7,
|
||||
.foreground_color = COL_DARK_BLUE,
|
||||
.focused = false,
|
||||
.minimized = false,
|
||||
.title = "Hello World!",
|
||||
.window_decorations = wdec,
|
||||
};
|
||||
@ -97,6 +101,7 @@ void setup() {
|
||||
.background_color = 0xbdf7,
|
||||
.foreground_color = COL_DARK_BLUE,
|
||||
.focused = true,
|
||||
.minimized = false,
|
||||
.title = "Second Window",
|
||||
.window_decorations = wdec,
|
||||
};
|
||||
@ -114,5 +119,5 @@ void loop() {
|
||||
_display_state->update_display.store(false);
|
||||
}
|
||||
|
||||
delay(5);
|
||||
delay(0);
|
||||
}
|
||||
@ -16,6 +16,18 @@ struct CLICK_EVENT {
|
||||
CLICK_EVENTS event;
|
||||
};
|
||||
|
||||
enum class ApplicationEventState {
|
||||
NONE = 0,
|
||||
CREATED = 1,
|
||||
CLOSED = 2,
|
||||
};
|
||||
|
||||
struct APPLICATION_EVENT {
|
||||
int id;
|
||||
ApplicationEventState state;
|
||||
char title[64];
|
||||
};
|
||||
|
||||
struct DISPLAY_STATE {
|
||||
std::atomic<bool> update_display;
|
||||
};
|
||||
@ -1,5 +1,15 @@
|
||||
#pragma once
|
||||
#include "WString.h"
|
||||
#include <string>
|
||||
|
||||
struct TaskBarItem {
|
||||
int id;
|
||||
int place_x;
|
||||
int place_y;
|
||||
int icon_size_x;
|
||||
int icon_size_y;
|
||||
bool focused;
|
||||
std::string name;
|
||||
};
|
||||
|
||||
struct Desktop_Item {
|
||||
int id;
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
#include "desktop_hander.h"
|
||||
#include "global_queue.h"
|
||||
#include "tft_handler.h"
|
||||
|
||||
void Desktop_Hander::init(TFT_Handler* th, DISPLAY_STATE* ds) {
|
||||
tft = th;
|
||||
display_state = ds;
|
||||
|
||||
// Subscribe to events
|
||||
// Subscribe to click events
|
||||
EventManager::getInstance().subscribe(this);
|
||||
|
||||
// Create desktop items
|
||||
@ -52,6 +53,10 @@ void Desktop_Hander::draw_task_bar(int color) {
|
||||
|
||||
// Button
|
||||
tft->draw_box(6, 298, 50, 18, color);
|
||||
|
||||
for (TaskBarItem item : task_bar_items) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void Desktop_Hander::draw_desktop_Item(Desktop_Item desktop_item) {
|
||||
|
||||
@ -9,6 +9,7 @@ class Desktop_Hander : public IEventListener {
|
||||
private:
|
||||
TFT_Handler* tft;
|
||||
DISPLAY_STATE* display_state;
|
||||
std::vector<TaskBarItem> task_bar_items;
|
||||
std::vector<Desktop_Item> items;
|
||||
|
||||
int handle_desktop_click(CLICK_EVENT event);
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
#include "GLOBALS.h"
|
||||
#include "event_manager.h"
|
||||
|
||||
void EventManager::init() {
|
||||
@ -5,7 +6,7 @@ void EventManager::init() {
|
||||
}
|
||||
|
||||
void EventManager::publish(const CLICK_EVENT& event) {
|
||||
xQueueSend(_event_queue, &event, 0);
|
||||
xQueueSend(_click_event_queue, &event, 0);
|
||||
}
|
||||
|
||||
void EventManager::subscribe(IEventListener* listener) {
|
||||
@ -24,7 +25,7 @@ void EventManager::dispatch_task(void* pvParameters) {
|
||||
CLICK_EVENT event;
|
||||
|
||||
for (;;) {
|
||||
if (xQueueReceive(self->_event_queue, &event, portMAX_DELAY)) {
|
||||
if (xQueueReceive(self->_click_event_queue, &event, portMAX_DELAY)) {
|
||||
// Dispatch to all listeners
|
||||
for (auto* listener : self->_listeners) {
|
||||
listener->on_click_event(event);
|
||||
|
||||
@ -17,12 +17,12 @@ public:
|
||||
|
||||
class EventManager {
|
||||
private:
|
||||
QueueHandle_t _event_queue;
|
||||
QueueHandle_t _click_event_queue;
|
||||
std::vector<IEventListener*> _listeners;
|
||||
TaskHandle_t _dispatcher_task;
|
||||
|
||||
EventManager() {
|
||||
_event_queue = xQueueCreate(10, sizeof(CLICK_EVENT));
|
||||
_click_event_queue = xQueueCreate(10, sizeof(CLICK_EVENT));
|
||||
}
|
||||
|
||||
EventManager(const EventManager&) = delete;
|
||||
|
||||
@ -51,22 +51,18 @@ void InputManager::handle_button_press(int buttonIndex) {
|
||||
mi.x = (mi.x + 5 > 476) ? 476 : mi.x + 5;
|
||||
needs_redraw = true;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
mi.y = (mi.y + 5 > 316) ? 316 : mi.y + 5;
|
||||
needs_redraw = true;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
mi.y = (mi.y - 5 < 0) ? 0 : mi.y - 5;
|
||||
needs_redraw = true;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
mi.x = (mi.x - 5 < 0) ? 0 : mi.x - 5;
|
||||
needs_redraw = true;
|
||||
break;
|
||||
|
||||
case 4: // Click
|
||||
{
|
||||
CLICK_EVENT event = {
|
||||
@ -77,7 +73,6 @@ void InputManager::handle_button_press(int buttonIndex) {
|
||||
EventManager::getInstance().publish(event);
|
||||
}
|
||||
break;
|
||||
|
||||
case 5: // Right click
|
||||
{
|
||||
CLICK_EVENT event = {
|
||||
|
||||
@ -27,6 +27,7 @@ struct Window {
|
||||
int background_color;
|
||||
int foreground_color;
|
||||
bool focused;
|
||||
bool minimized;
|
||||
std::string title;
|
||||
std::vector<WindowDecoration> window_decorations;
|
||||
};
|
||||
@ -1,13 +1,14 @@
|
||||
#include "window.h"
|
||||
#include "GLOBALS.h"
|
||||
#include "window_manager.h"
|
||||
#include "global_queue.h"
|
||||
#include <algorithm>
|
||||
|
||||
void WindowManager::init(TFT_Handler* th, DISPLAY_STATE* ds) {
|
||||
tft = th;
|
||||
display_state = ds;
|
||||
|
||||
// Subscribe to events
|
||||
// Subscribe to click events
|
||||
EventManager::getInstance().subscribe(this);
|
||||
}
|
||||
|
||||
@ -33,6 +34,16 @@ void WindowManager::close_window(int window_id) {
|
||||
}
|
||||
}
|
||||
|
||||
void WindowManager::minimize_window(int window_id) {
|
||||
for (auto it = windows.begin(); it != windows.end(); ++it) {
|
||||
if (it->id == window_id) {
|
||||
it->minimized = true;
|
||||
display_state->update_display.store(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WindowManager::draw_all() {
|
||||
tft->start_draw();
|
||||
for (const auto& win : windows) {
|
||||
@ -42,6 +53,8 @@ void WindowManager::draw_all() {
|
||||
}
|
||||
|
||||
void WindowManager::draw_window(Window window) {
|
||||
if (window.minimized) return;
|
||||
|
||||
// Outer shadow
|
||||
tft->draw_rect(window.x, window.y, window.width + 2, window.height + 2, 1, 0x0000);
|
||||
|
||||
@ -97,11 +110,16 @@ int WindowManager::handle_window_click(CLICK_EVENT event) {
|
||||
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) {
|
||||
close_window(window.id);
|
||||
return window.id;
|
||||
}
|
||||
|
||||
if (event.x >= x && event.x <= (x + it->width) && event.y >= y && event.y <= (y + it->height) && it->action == WindowAction::MINIMIZE) {
|
||||
minimize_window(window.id);
|
||||
return window.id;
|
||||
}
|
||||
}
|
||||
|
||||
if (window.focused) return -1;
|
||||
|
||||
@ -25,6 +25,7 @@ public:
|
||||
void init(TFT_Handler* th, DISPLAY_STATE* ds);
|
||||
void create_window(Window window);
|
||||
void close_window(int window_id);
|
||||
void minimize_window(int window_id);
|
||||
void draw_all();
|
||||
void draw_window(Window window);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user