#ifndef GUI_H
#define GUI_H


#include "os.h"
#include "platform/platform.h"
#include "font.h"


struct WidgetS;

typedef void (*GuiCallbackT)(void *data, ...);
typedef void (*WidgetEventT)(struct WidgetS *widget, ...);

typedef struct PointS {
	int16_t x;
	int16_t y;
} PointT;

typedef struct RectS {
	int16_t      x;
	int16_t      y;
	union {
		int16_t  w;
		int16_t  x2;
	};
	union {
		int16_t  h;
		int16_t  y2;
	};
} RectT;

typedef struct RegisterS {
	char         *widgetName;
	WidgetEventT  paint;
	WidgetEventT  destroy;
	GuiCallbackT  unregister;
} RegisterT;

typedef struct WidgetS {
	uint8_t       magic;
	RectT         r;
	RegisterT    *reg;
} WidgetT;

typedef RegisterT *(*WidgetRegisterT)(uint8_t);


extern SurfaceT *__guiBackBuffer;
extern SurfaceT *__guiScreenBuffer;
extern ColorT   *__guiBaseColors;
extern FontT    *__guiFontVGA8x14;


#define GUI_BLACK        __guiBaseColors[0]
#define GUI_BLUE         __guiBaseColors[1]
#define GUI_GREEN        __guiBaseColors[2]
#define GUI_CYAN         __guiBaseColors[3]
#define GUI_RED          __guiBaseColors[4]
#define GUI_MAGENTA      __guiBaseColors[5]
#define GUI_BROWN        __guiBaseColors[6]
#define GUI_LIGHTGRAY    __guiBaseColors[7]
#define GUI_DARKGRAY     __guiBaseColors[8]
#define GUI_LIGHTBLUE    __guiBaseColors[9]
#define GUI_LIGHTGREEN   __guiBaseColors[10]
#define GUI_LIGHTCYAN    __guiBaseColors[11]
#define GUI_LIGHTRED     __guiBaseColors[12]
#define GUI_LIGHTMAGENTA __guiBaseColors[13]
#define GUI_YELLOW       __guiBaseColors[14]
#define GUI_WHITE        __guiBaseColors[15]


void guiModesShow(void);
void guiRegister(WidgetRegisterT widgetRegister);
void guiRun(void);
void guiShutdown(void);
void guiStartup(int16_t width, int16_t height, int16_t depth);
void guiStop(void);
void guiWidgetBaseSet(WidgetT *widget, uint8_t magic, uint16_t x, uint16_t y, uint16_t w, uint16_t h);


#endif // GUI_H
