PocketPutr/Desktop_Test/program.h

105 lines
2.2 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"
// Forward declarations
class Shell;
class TFT_Handler;
struct TaskBarItem {
short int id;
short int place_x;
short int place_y;
short int width;
short int height;
short int offset_x;
bool focused;
std::string name;
};
struct DesktopItem {
short int id;
short int place_x;
short int place_y;
short int icon_size_x;
short int icon_size_y;
std::string name;
std::string program_class; // Which program class to instantiate
};
enum class WindowAction {
EXIT = 1,
FILE = 2,
HELP = 3,
MINIMIZE = 4,
CLOSE = 5,
};
struct WindowDecoration {
short int x_offset;
short int y_offset;
short int width;
short int height;
WindowAction action;
};
struct WindowContentText {
short int x;
short int y;
short int size;
std::string text;
};
struct Window {
short int id;
short int x;
short int y;
short int width;
short int height;
short int background_color;
short int foreground_color;
bool focused;
bool minimized;
std::string title;
std::vector<WindowDecoration> window_decorations;
std::vector<WindowContentText> window_content_text;
};
// Base Program class - all programs inherit from this
class Program {
protected:
Window* _window;
Shell* _shell;
TFT_Handler* _tft;
DISPLAY_STATE* _display_state;
TaskHandle_t _task_handle;
short int _id;
std::string _name;
bool _running;
CALIBRATION_IDLE _calibration_idle;
static void task_wrapper(void* pvParameters);
public:
Program();
virtual ~Program();
// Initialize the program with its window and shell reference
void init(short int 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;
// Called when the program should stop
virtual void close();
// Getters
int get_id() const { return _id; }
std::string get_name() const { return _name; }
Window* get_window() const { return _window; }
};