PocketPutr/Desktop_Test/program.h

121 lines
2.4 KiB
C++

#pragma once
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "GLOBALS.h"
#include <string>
#include <vector>
#include <LovyanGFX.hpp>
#include "tft_handler.h"
#include "event_manager.h"
// Forward declarations
class Shell;
class TFT_Handler;
struct TaskBarItem {
std::string name;
short place_x;
short place_y;
short width;
short height;
char id;
char offset_x;
bool focused;
};
struct DesktopItem {
std::string program_class; // Which program class to instantiate
std::string name;
short place_x;
short place_y;
char id;
char icon_size_x;
char icon_size_y;
};
enum class WindowAction : uint8_t {
EXIT = 1,
FILE = 2,
HELP = 3,
MINIMIZE = 4,
CLOSE = 5,
};
struct WindowDecoration {
short x_offset;
short y_offset;
short width;
short height;
WindowAction action;
};
struct WindowContentText {
std::string text;
short x;
short y;
char size;
bool selectable = false;
bool selected = false;
};
struct ContentButton {
std::string action;
short x;
short y;
short width;
short height;
bool pressed;
};
struct Window {
std::string title;
std::vector<WindowContentText> window_content_text;
std::vector<WindowDecoration> window_decorations;
std::vector<ContentButton> content_buttons;
unsigned short x;
unsigned short y;
unsigned short width;
unsigned short height;
unsigned short background_color;
unsigned short foreground_color;
char id;
bool focused;
bool minimized;
};
// Base Program class - all programs inherit from this
class Program : public IEventListener {
protected:
std::string _name;
Window* _window;
CALIBRATION_IDLE _calibration_idle;
Shell* _shell;
TFT_Handler* _tft;
DISPLAY_STATE* _display_state;
TaskHandle_t _task_handle;
char _id;
bool _running;
static void task_wrapper(void* pvParameters);
public:
Program();
virtual ~Program();
// Initialize the program with its window and shell reference
void init(char id, const std::string& name, Window* window, Shell* shell, TFT_Handler* tft, DISPLAY_STATE* display_state, CALIBRATION_IDLE calibration_idle);
// Override this in your specific programs
virtual void run() = 0;
// listen to click events
void on_click_event(CLICK_EVENT event) override;
// Called when the program should stop
virtual void close();
// Getters
short get_id() const { return _id; }
std::string get_name() const { return _name; }
Window* get_window() const { return _window; }
};