Taskbar now has items
This commit is contained in:
parent
4f7aba8aa3
commit
2eaa9563d2
@ -1,14 +1,11 @@
|
||||
#include "window_manager.h"
|
||||
#include "desktop_hander.h"
|
||||
#include "input_manager.h"
|
||||
#include "tft_handler.h"
|
||||
#include "event_manager.h"
|
||||
#include "GLOBALS.h"
|
||||
#include "global_queue.h"
|
||||
#include <vector>
|
||||
|
||||
WindowManager* wm;
|
||||
Desktop_Hander* dh;
|
||||
InputManager* im;
|
||||
TFT_Handler* th;
|
||||
|
||||
@ -33,7 +30,6 @@ void setup() {
|
||||
|
||||
// Create managers
|
||||
wm = new WindowManager();
|
||||
dh = new Desktop_Hander();
|
||||
im = new InputManager();
|
||||
th = new TFT_Handler();
|
||||
|
||||
@ -43,11 +39,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);
|
||||
wm->init(th, _display_state);
|
||||
|
||||
// Create input task on Core 0
|
||||
@ -113,7 +106,6 @@ void setup() {
|
||||
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);
|
||||
|
||||
@ -4,6 +4,13 @@
|
||||
#define MAX_SCREEN_WIDTH 480
|
||||
#define MAX_SCREEN_HEIGHT 320
|
||||
|
||||
#define COL_WHITE 0xffff
|
||||
#define COL_BLACK 0x0000
|
||||
#define COL_GREY 0xbdf7
|
||||
#define COL_LIGHT_GREY 0x8410
|
||||
#define COL_DARK_BLUE 0x0014
|
||||
#define COL_RED 0xf800
|
||||
|
||||
enum CLICK_EVENTS {
|
||||
NONE = 0,
|
||||
LEFT_CLICK = 1,
|
||||
|
||||
@ -5,8 +5,9 @@ struct TaskBarItem {
|
||||
int id;
|
||||
int place_x;
|
||||
int place_y;
|
||||
int icon_size_x;
|
||||
int icon_size_y;
|
||||
int width;
|
||||
int height;
|
||||
int offset_x;
|
||||
bool focused;
|
||||
std::string name;
|
||||
};
|
||||
|
||||
@ -1,102 +0,0 @@
|
||||
#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 click events
|
||||
EventManager::getInstance().subscribe(this);
|
||||
|
||||
// Create desktop items
|
||||
for (int i = 0; i < 5; i++) {
|
||||
Desktop_Item di = {
|
||||
.id = i,
|
||||
.place_x = i * 50 + 1,
|
||||
.place_y = 10,
|
||||
.icon_size_x = 45,
|
||||
.icon_size_y = 50,
|
||||
};
|
||||
items.push_back(di);
|
||||
}
|
||||
|
||||
re_draw_desktop();
|
||||
}
|
||||
|
||||
void Desktop_Hander::re_draw_desktop() {
|
||||
draw_background(0x0410);
|
||||
draw_task_bar(0xbdf7);
|
||||
|
||||
for (const auto& item : items) {
|
||||
draw_desktop_Item(item);
|
||||
}
|
||||
}
|
||||
|
||||
void Desktop_Hander::draw_background(int color) {
|
||||
tft->fill_screen(color);
|
||||
}
|
||||
|
||||
void Desktop_Hander::draw_task_bar(int color) {
|
||||
// bar
|
||||
tft->draw_box(0, 293, 480, 40, color);
|
||||
tft->draw_line(0, 294, 480, 294, 0xffff);
|
||||
|
||||
// Outer shadow
|
||||
tft->draw_box(5, 297, 53, 21, 0x0000);
|
||||
|
||||
// Inner shadow
|
||||
tft->draw_box(6, 298, 51, 19, 0x8410);
|
||||
|
||||
// Highlight
|
||||
tft->draw_box(5, 297, 51, 19, 0xffff);
|
||||
|
||||
// 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) {
|
||||
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(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(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) {
|
||||
if (event.x >= item.place_x &&
|
||||
event.x <= (item.place_x + item.icon_size_x) &&
|
||||
event.y >= item.place_y &&
|
||||
event.y <= (item.place_y + item.icon_size_y)) {
|
||||
|
||||
Serial.print("Desktop item clicked: ");
|
||||
Serial.println(item.id);
|
||||
|
||||
// TODO: Handle icon click (open window, etc.)
|
||||
return item.id;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
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");
|
||||
|
||||
// TODO: Handle icon click (open window, etc.)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
#pragma once
|
||||
#include "desktop.h"
|
||||
#include "tft_handler.h"
|
||||
#include "event_manager.h"
|
||||
#include <vector>
|
||||
#include "GLOBALS.h"
|
||||
|
||||
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);
|
||||
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(Desktop_Item desktop_item);
|
||||
|
||||
// IEventListener interface
|
||||
void on_click_event(CLICK_EVENT event) override;
|
||||
};
|
||||
@ -1,7 +1,6 @@
|
||||
#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) {
|
||||
@ -10,8 +9,32 @@ void WindowManager::init(TFT_Handler* th, DISPLAY_STATE* ds) {
|
||||
|
||||
// Subscribe to click events
|
||||
EventManager::getInstance().subscribe(this);
|
||||
|
||||
// Create desktop items
|
||||
for (int i = 0; i < 5; i++) {
|
||||
Desktop_Item di = {
|
||||
.id = i,
|
||||
.place_x = i * 50 + 1,
|
||||
.place_y = 10,
|
||||
.icon_size_x = 45,
|
||||
.icon_size_y = 50,
|
||||
};
|
||||
items.push_back(di);
|
||||
}
|
||||
}
|
||||
|
||||
void WindowManager::on_click_event(CLICK_EVENT event) {
|
||||
if (event.event != CLICK_EVENTS::LEFT_CLICK) return;
|
||||
|
||||
int icon_id = handle_desktop_click(event);
|
||||
int window_id = handle_window_click(event);
|
||||
int tast_icon_id = handle_taskbar_click(event);
|
||||
bool ckicked_start_button = handle_start_button_click(event);
|
||||
|
||||
if (window_id >= 0) display_state->update_display.store(true);
|
||||
}
|
||||
|
||||
// ======= Window =======
|
||||
void WindowManager::create_window(Window window) {
|
||||
int total_pos_x = window.x + window.width;
|
||||
int total_pos_y = window.y + window.height;
|
||||
@ -21,6 +44,27 @@ void WindowManager::create_window(Window window) {
|
||||
if (total_pos_y > MAX_SCREEN_HEIGHT) window.y = MAX_SCREEN_HEIGHT - window.height - 29;
|
||||
|
||||
windows.push_back(window);
|
||||
|
||||
TaskBarItem item;
|
||||
item.id = window.id;
|
||||
item.focused = window.focused;
|
||||
item.name = window.title;
|
||||
item.width = 60;
|
||||
item.height = 18;
|
||||
item.offset_x = 65;
|
||||
item.place_y = 298;
|
||||
|
||||
// Set place_x and place_y for ALL items
|
||||
if (task_bar_items.size() == 0) {
|
||||
item.place_x = 60;
|
||||
} else {
|
||||
// For subsequent items, use the previous item's position + offset
|
||||
const TaskBarItem& prev = task_bar_items.back();
|
||||
item.place_x = prev.place_x + prev.offset_x;
|
||||
}
|
||||
|
||||
task_bar_items.push_back(item);
|
||||
|
||||
display_state->update_display.store(true);
|
||||
}
|
||||
|
||||
@ -32,6 +76,14 @@ void WindowManager::close_window(int window_id) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto it = task_bar_items.begin(); it != task_bar_items.end(); ++it) {
|
||||
if (it->id == window_id) {
|
||||
task_bar_items.erase(it);
|
||||
display_state->update_display.store(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WindowManager::minimize_window(int window_id) {
|
||||
@ -46,6 +98,14 @@ void WindowManager::minimize_window(int window_id) {
|
||||
|
||||
void WindowManager::draw_all() {
|
||||
tft->start_draw();
|
||||
|
||||
draw_background(0x0410);
|
||||
draw_task_bar(0xbdf7);
|
||||
|
||||
for (const auto& item : items) {
|
||||
draw_desktop_Item(item);
|
||||
}
|
||||
|
||||
for (const auto& win : windows) {
|
||||
draw_window(win);
|
||||
}
|
||||
@ -70,7 +130,6 @@ void WindowManager::draw_window(Window window) {
|
||||
// Decorations
|
||||
tft->draw_box(window.x + 3, window.y + 3, window.width - 6, 30, window.foreground_color);
|
||||
|
||||
|
||||
for (auto it = window.window_decorations.begin(); it != window.window_decorations.end(); ++it) {
|
||||
if (it->action == WindowAction::CLOSE) {
|
||||
// Close button
|
||||
@ -90,12 +149,45 @@ void WindowManager::draw_window(Window window) {
|
||||
tft->draw_box(window.x + 3, window.y + 35, window.width - 6, window.height - 38, COL_WHITE);
|
||||
}
|
||||
|
||||
void WindowManager::on_click_event(CLICK_EVENT event) {
|
||||
if (event.event != CLICK_EVENTS::LEFT_CLICK) return;
|
||||
// ======= Desktop =======
|
||||
void WindowManager::draw_background(int color) {
|
||||
tft->fill_screen(color);
|
||||
}
|
||||
|
||||
int clicked_id = handle_window_click(event);
|
||||
void WindowManager::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);
|
||||
}
|
||||
|
||||
if (clicked_id >= 0) display_state->update_display.store(true);
|
||||
void WindowManager::draw_task_bar(int color) {
|
||||
// bar
|
||||
tft->draw_box(0, 293, 480, 40, color);
|
||||
tft->draw_line(0, 294, 480, 294, 0xffff);
|
||||
|
||||
// Outer shadow
|
||||
tft->draw_box(5, 297, 53, 21, 0x0000);
|
||||
|
||||
// Inner shadow
|
||||
tft->draw_box(6, 298, 51, 19, 0x8410);
|
||||
|
||||
// Highlight
|
||||
tft->draw_box(5, 297, 51, 19, 0xffff);
|
||||
|
||||
// Button
|
||||
tft->draw_box(6, 298, 50, 18, color);
|
||||
|
||||
Serial.println(task_bar_items.size());
|
||||
|
||||
//int temp_x = 0;
|
||||
|
||||
for (TaskBarItem item : task_bar_items) {
|
||||
//temp_x += item.offset_x;
|
||||
if (item.focused) {
|
||||
tft->draw_box(item.place_x, item.place_y, item.width, item.height, COL_BLACK);
|
||||
}
|
||||
else {
|
||||
tft->draw_box(item.place_x, item.place_y, item.width, item.height, COL_DARK_BLUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int WindowManager::handle_window_click(CLICK_EVENT event) {
|
||||
@ -142,3 +234,38 @@ int WindowManager::handle_window_click(CLICK_EVENT event) {
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int WindowManager::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) {
|
||||
if (event.x >= item.place_x &&
|
||||
event.x <= (item.place_x + item.icon_size_x) &&
|
||||
event.y >= item.place_y &&
|
||||
event.y <= (item.place_y + item.icon_size_y)) {
|
||||
|
||||
Serial.print("Desktop item clicked: ");
|
||||
Serial.println(item.id);
|
||||
|
||||
// TODO: Handle icon click (open window, etc.)
|
||||
return item.id;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int WindowManager::handle_taskbar_click(CLICK_EVENT event) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool WindowManager::handle_start_button_click(CLICK_EVENT event) {
|
||||
if (event.x >= 6 && event.x <= (6 + 50) && event.y >= 298 && event.y <= (298 + 18)) {
|
||||
Serial.println("Taskbar button clicked");
|
||||
|
||||
// TODO: Handle icon click (open window, etc.)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -1,34 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#include "window.h"
|
||||
#include "desktop.h"
|
||||
#include "tft_handler.h"
|
||||
#include "event_manager.h"
|
||||
#include <vector>
|
||||
#include "GLOBALS.h"
|
||||
|
||||
#define COL_WHITE 0xffff
|
||||
#define COL_BLACK 0x0000
|
||||
#define COL_GREY 0xbdf7
|
||||
#define COL_LIGHT_GREY 0x8410
|
||||
#define COL_DARK_BLUE 0x0014
|
||||
#define COL_RED 0xf800
|
||||
|
||||
class WindowManager : public IEventListener {
|
||||
private:
|
||||
TFT_Handler* tft;
|
||||
DISPLAY_STATE* display_state;
|
||||
std::vector<Window> windows;
|
||||
std::vector<TaskBarItem> task_bar_items;
|
||||
std::vector<Desktop_Item> items;
|
||||
|
||||
int handle_window_click(CLICK_EVENT event);
|
||||
int handle_desktop_click(CLICK_EVENT event);
|
||||
int handle_taskbar_click(CLICK_EVENT event);
|
||||
bool handle_start_button_click(CLICK_EVENT event);
|
||||
|
||||
public:
|
||||
void init(TFT_Handler* th, DISPLAY_STATE* ds);
|
||||
|
||||
// ======= Window =======
|
||||
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);
|
||||
|
||||
// ======= Desktop =======
|
||||
void draw_background(int color);
|
||||
void draw_task_bar(int color);
|
||||
void draw_desktop_Item(Desktop_Item desktop_item);
|
||||
|
||||
// ======= Shared =======
|
||||
void draw_all();
|
||||
// IEventListener interface
|
||||
void on_click_event(CLICK_EVENT event) override;
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user