118 lines
2.4 KiB
C++
118 lines
2.4 KiB
C++
#include "window_manager.h"
|
|
#include "desktop_hander.h"
|
|
#include "input_manager.h"
|
|
#include "tft_handler.h"
|
|
#include "event_manager.h"
|
|
#include "GLOBALS.h"
|
|
#include <vector>
|
|
|
|
WindowManager* wm;
|
|
Desktop_Hander* dh;
|
|
InputManager* im;
|
|
TFT_Handler* th;
|
|
|
|
DISPLAY_STATE* _display_state;
|
|
|
|
TaskHandle_t InputTask;
|
|
|
|
void input_task(void* pvParameters) {
|
|
for(;;) {
|
|
im->update();
|
|
vTaskDelay(1);
|
|
}
|
|
}
|
|
|
|
void setup() {
|
|
Serial.begin(115200);
|
|
Serial.println("Initializing...");
|
|
|
|
// Create shared state
|
|
_display_state = new DISPLAY_STATE();
|
|
_display_state->update_display.store(false);
|
|
|
|
// Create managers
|
|
wm = new WindowManager();
|
|
dh = new Desktop_Hander();
|
|
im = new InputManager();
|
|
th = new TFT_Handler();
|
|
|
|
// Initialize in order
|
|
th->init(_display_state);
|
|
|
|
// Initialize event manager (creates dispatcher task)
|
|
EventManager::getInstance().init();
|
|
|
|
// Initialize components (they subscribe to events)
|
|
im->init(_display_state, th);
|
|
dh->init(th, _display_state);
|
|
wm->init(th, _display_state);
|
|
|
|
// Create input task on Core 0
|
|
xTaskCreatePinnedToCore(input_task, "input_task", 4096, NULL, 1, &InputTask, 0);
|
|
|
|
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::MINIMIZE,
|
|
};
|
|
|
|
std::vector<WindowDecoration> wdec;
|
|
wdec.push_back(dec1);
|
|
wdec.push_back(dec2);
|
|
|
|
Window win1 = {
|
|
.id = 0,
|
|
.x = 10,
|
|
.y = 10,
|
|
.width = 350,
|
|
.height = 250,
|
|
.background_color = 0xbdf7,
|
|
.foreground_color = COL_DARK_BLUE,
|
|
.focused = false,
|
|
.title = "Hello World!",
|
|
.window_decorations = wdec,
|
|
};
|
|
wm->create_window(win1);
|
|
|
|
Window win2 = {
|
|
.id = 1,
|
|
.x = 70,
|
|
.y = 40,
|
|
.width = 350,
|
|
.height = 200,
|
|
.background_color = 0xbdf7,
|
|
.foreground_color = COL_DARK_BLUE,
|
|
.focused = true,
|
|
.title = "Second Window",
|
|
.window_decorations = wdec,
|
|
};
|
|
wm->create_window(win2);
|
|
|
|
Serial.println("Initialization complete");
|
|
}
|
|
|
|
void loop() {
|
|
// Only handle rendering in main loop
|
|
if (_display_state->update_display.load()) {
|
|
dh->re_draw_desktop();
|
|
wm->draw_all();
|
|
im->draw_button();
|
|
_display_state->update_display.store(false);
|
|
}
|
|
|
|
delay(5);
|
|
} |