Pre-commit before it all goes down the drain
This commit is contained in:
parent
6a77bacb7e
commit
f56a7fa9f2
@ -4,6 +4,7 @@
|
||||
#include "tft_handler.h"
|
||||
#include "event_manager.h"
|
||||
#include "GLOBALS.h"
|
||||
#include <vector>
|
||||
|
||||
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<WindowDecoration> 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);
|
||||
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
#pragma once
|
||||
#include <atomic>
|
||||
|
||||
#define MAX_SCREEN_WIDTH 480
|
||||
#define MAX_SCREEN_HEIGHT 320
|
||||
|
||||
enum CLICK_EVENTS {
|
||||
NONE = 0,
|
||||
LEFT_CLICK = 1,
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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<WindowAction> window_actions;
|
||||
std::vector<WindowDecoration> window_decorations;
|
||||
};
|
||||
@ -1,3 +1,4 @@
|
||||
#include "GLOBALS.h"
|
||||
#include "window_manager.h"
|
||||
#include <algorithm>
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user