roo_e/roo-e/src/gui/gui.h

165 lines
5 KiB
C

/*
* Roo/E, the Kangaroo Punch Portable GUI Toolkit
* Copyright (C) 2022 Scott Duensing
*
* http://kangaroopunch.com
*
*
* This file is part of Roo/E.
*
* Roo/E is free software: you can redistribute it and/or modify it under the
* terms of the GNU Affero General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* Roo/E is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Roo/E. If not, see <https://www.gnu.org/licenses/>.
*
*/
#ifndef GUI_H
#define GUI_H
#include "os.h"
#include "platform/platform.h"
#include "font.h"
#define WIDGET_DIRTY 1
#define WIDGET_HIDDEN 2
#define WIDGET_DISABLED 4
#define WIDGET_RAW_INPUT 8
#define WIDGET_IS_WINDOW 16 // This lets us know if this widget is being used as one of the components of a window.
#define CLICK_RAW_INPUT 1
#define CLICK_LEFT_CANCEL 2
#define CLICK_LEFT_DOWN 3
#define CLICK_LEFT_UP 4
struct WidgetS;
struct WindowS;
typedef void (*GuiCallbackT)(void *data, ...);
typedef void (*WidgetEventT)(struct WidgetS *widget, ...);
typedef void (*ClickHandlerT)(struct WidgetS *widget, uint16_t x, uint16_t y, uint8_t event, void *data);
typedef struct WidgetS *(*WidgetFindT)(struct WidgetS *widget, uint16_t x, uint16_t y, int16_t *localX, int16_t *localY);
typedef struct PointS {
int16_t x;
int16_t y;
} PointT;
typedef struct RectS {
int16_t x;
int16_t y;
int16_t x2;
int16_t y2;
} RectT;
typedef struct RectWS {
int16_t x;
int16_t y;
int16_t w;
int16_t h;
} RectWT;
typedef struct RegisterS {
char *widgetName; // Text name of widget.
ClickHandlerT click; // Click handler.
WidgetEventT destroy; // Destroy routine.
WidgetEventT paint; // Paint routine.
GuiCallbackT unregister; // Unregister routine.
WidgetFindT findWidget; // Returns widget located under cursor.
} RegisterT;
typedef struct WidgetS {
uint8_t magic; // Magic ID of widget. Must be first!
RectWT r; // Outer bounds of widget. NOTE: USES WIDTH/HEIGHT, NOT X2/Y2!
RegisterT *reg; // Registration information.
void *data; // Pointer to arbitrary data for user.
uint16_t flags; // Widget flags (see defines above).
struct WidgetS *parent; // Who owns this widget?
struct WidgetS **children; // Widgets contained in this widget.
} WidgetT;
typedef struct ClickRawInputS {
void *data;
EventT *event;
} ClickRawInputT;
typedef RegisterT *(*WidgetRegisterT)(uint8_t);
extern SurfaceT *__guiBackBuffer;
extern SurfaceT *__guiScreenBuffer;
extern ColorT *__guiBaseColors;
extern FontT *__guiFontVGA8x8;
extern FontT *__guiFontVGA8x14;
extern FontT *__guiFontVGA8x16;
#define MOUSE_POINTER 0
#define MOUSE_RESIZE 1
#define MOUSE_COUNT 2
#define SCROLL_SPEED_SLOW 5
#define SCROLL_SPEED_FAST 25
#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]
#define W (WidgetT *) // Cast any widget to base WidgetT type.
#define C(n) ((n) << 3) // Multiply by 8 to get "cells".
void guiEventsDo(void);
uint8_t guiMousePointerGet(void);
void guiMousePointerSet(uint8_t pointer);
void guiRegister(WidgetRegisterT widgetRegister);
void guiRun(void);
void guiShutdown(void);
uint8_t guiStartup(int16_t width, int16_t height, int16_t depth);
void guiStop(void);
void widgetAdd(WidgetT *target, int16_t x, int16_t y, WidgetT *widget);
void widgetBaseSet(WidgetT *widget, uint8_t magic, uint16_t w, uint16_t h);
uint8_t widgetChildrenDirty(WidgetT *widget);
uint8_t widgetChildrenPaint(WidgetT *widget);
void widgetDestroy(WidgetT *widget);
uint8_t widgetDirtyGet(WidgetT *widget);
void widgetDirtySet(WidgetT *widget, uint8_t dirty);
WidgetT *widgetFinder(WidgetT *widget, uint16_t x, uint16_t y, int16_t *localX, int16_t *localY);
void widgetInputSetRaw(WidgetT *widget, uint8_t raw);
uint8_t widgetIsInWidget(WidgetT *widget, WidgetT *parent);
void widgetMove(WidgetT *widget, int16_t x, int16_t y);
void widgetPaintManually(WidgetT *widget, int16_t x, int16_t y);
void widgetRemove(WidgetT *target, WidgetT *widget);
#endif // GUI_H