Begin refactor.

This commit is contained in:
2021-09-18 23:13:05 -07:00
parent df53c646a2
commit 2b7446b818
143 changed files with 1706 additions and 2345 deletions

View File

@ -6,7 +6,20 @@
*/
#pragma once
#include <dawn/dawn.h>
#include "../libs.h"
#define ALIGN_POS_CENTER flagDefine(0)
#define ALIGN_POS_START flagDefine(1)
#define ALIGN_POS_END flagDefine(2)
#define ALIGN_SIZE_FILL flagDefine(3)
#define ALIGN_SIZE_ORIGINAL flagDefine(4)
#define ALIGN_SIZE_RATIO flagDefine(5)
typedef struct {
float x, y;
float width, height;
} align_t;
/**
* Return the alignment for a specific access, really this doesn't need to be

View File

@ -4,7 +4,28 @@
// https://opensource.org/licenses/MIT
#pragma once
#include <dawn/dawn.h>
#include "../libs.h"
/** Maximum breakpoints that the list can support. */
#define BREAKPOINT_COUNT_MAX 0x04
/** Callback for when a new breakpint is reached. */
typedef void breakpointcallback_t(void *user, uint8_t i, float breakpoint);
typedef struct {
/** List of breakpoints */
float breakpoints[BREAKPOINT_COUNT_MAX];
uint8_t breakpointCount;
/** Which breakpoint is current */
uint8_t breakpointCurrent;
/** Pointer to any custom user data. */
void *user;
/** Callback for when a breakpoint is reached */
breakpointcallback_t *onBreakpoint;
} breakpointlist_t;
/**
* Initialize a breakpoint.

View File

@ -5,12 +5,25 @@
* https://opensource.org/licenses/MIT
*/
#include <dawn/dawn.h>
#pragma once
#include "../libs.h"
#include "../display/shader.h"
#include "../display/primitive.h"
#include "../display/primitives/quad.h"
#include "../display/font.h"
/** Size of the border (in pixels) on each edge */
#define FRAME_BORDER_SIZE 16
/** Total border size for a given frame on each axis */
#define FRAME_BORDER_SIZE_FULL FRAME_BORDER_SIZE * 2
/** How many quads are within the frame */
#define FRAME_PRIMITIVE_COUNT 9
typedef struct {
texture_t *texture;
primitive_t primitive;
} frame_t;
/**
* Initialize a GUI Frame.
*

View File

@ -6,12 +6,21 @@
*/
#pragma once
#include <dawn/dawn.h>
#include "../engine/engine.h"
#include "../libs.h"
#include "frame.h"
#include "textmenu.h"
#include "grid.h"
#include "menu.h"
/** The default gutter for the grid of a framed text menu */
#define FRAMED_TEXT_MENU_GUTTER_DEFAULT 8.0f
typedef struct {
frame_t frame;
textmenu_t menu;
} framedtextmenu_t;
/**
* Initialize a framed text ui element.
*

View File

@ -6,9 +6,40 @@
*/
#pragma once
#include <dawn/dawn.h>
#include "../libs.h"
#include "align.h"
/** Maximum number of columns a grid can have */
#define GRID_COLUMN_COUNT_MAX 16
/** Maximum number of rows a grid can have */
#define GRID_ROW_COUNT_MAX GRID_COLUMN_COUNT_MAX
/** Cell size for "auto", basically to fill the remaining space evenly */
#define GRID_CEL_SIZE_AUTO -1
/** Definitio of a grid */
typedef struct {
/** Count of columns/rows in the grid */
uint8_t columns, rows;
/** Cell Definitions, used to control how the cells will size themselves */
float columnDefinitions[GRID_COLUMN_COUNT_MAX];
float rowDefinitions[GRID_COLUMN_COUNT_MAX];
/** Settings to control gutters (space between cells) and border (of grid) */
float gutterX, gutterY;
float borderX, borderY;
/** Calculated sizes and positions for each cell */
float columnSizes[GRID_COLUMN_COUNT_MAX];
float columnPositions[GRID_COLUMN_COUNT_MAX];
float rowSizes[GRID_ROW_COUNT_MAX];
float rowPositions[GRID_COLUMN_COUNT_MAX];
/** Cached size of the grid */
float width, height;
} grid_t;
/**
* Initialize a grid system.
*

View File

@ -6,11 +6,17 @@
*/
#pragma once
#include <dawn/dawn.h>
#include "../libs.h"
#include "../display/primitive.h"
#include "../display/primitives/quad.h"
#include "../display/shader.h"
typedef struct {
texture_t *texture;
primitive_t quad;
float width, height;
} image_t;
/**
* Initialize an image.
*

View File

@ -4,11 +4,20 @@
// https://opensource.org/licenses/MIT
#pragma once
#include <dawn/dawn.h>
#include "../libs.h"
#include "../display/shader.h"
#include "../display/primitive.h"
#include "../display/font.h"
/** Representation of a Label UI Element */
typedef struct {
font_t *font;
float fontSize;
float maxWidth;
fonttextinfo_t info;
primitive_t primitive;
} label_t;
/**
* Initialize a Label UI Element.
* @param label Label to initialize.

View File

@ -6,10 +6,35 @@
*/
#pragma once
#include <dawn/dawn.h>
#include "../libs.h"
#include "../input/input.h"
#include "../epoch/epoch.h"
#include "../util/array.h"
#include "../engine/engine.h"
/** The maximum number of items a menu can hold */
#define MENU_ITEMS_MAX 32
/** Callback for when menu events are fired. */
typedef void menucallback_t(void *user, uint8_t i);
typedef struct {
uint8_t x;
uint8_t y;
uint8_t width;
uint8_t height;
} menuitem_t;
typedef struct {
menuitem_t items[MENU_ITEMS_MAX];
uint8_t itemCount;
uint8_t selected;
uint8_t cursorX;
uint8_t cursorY;
void *user;
menucallback_t *onSelect;
} menu_t;
/**
* Initialize a menu.

View File

@ -6,12 +6,18 @@
*/
#pragma once
#include <dawn/dawn.h>
#include "../libs.h"
#include "../display/texture.h"
#include "../display/shader.h"
#include "../display/primitive.h"
#include "../display/primitives/quad.h"
typedef struct {
float width, height;
texture_t texture;
primitive_t quad;
} rectangle_t;
void rectangleInit(rectangle_t *rectangle);
void rectangleSetColor(rectangle_t *rectangle, pixel_t color);

View File

@ -6,12 +6,31 @@
*/
#pragma once
#include <dawn/dawn.h>
#include "../libs.h"
#include "menu.h"
#include "grid.h"
#include "label.h"
#include "rectangle.h"
/** Colour of the selection box for the text menu */
#define TEXTMENU_SELECTION_COLOR ((pixel_t){.r=0xFF,.g=0xFF,.b=0xFF,.a=0x64})
/** Callback type for when an item is selected */
typedef void textmenucallback_t(void *user, uint8_t i, char *text);
typedef struct {
menu_t menu;
grid_t grid;
font_t *font;
rectangle_t rectangle;
char *texts[MENU_ITEMS_MAX];
label_t labels[MENU_ITEMS_MAX];
textmenucallback_t *onSelect;
void *user;
} textmenu_t;
/** Callback to be notified from the menu when the menu items are selected. */
void _textMenuOnSelect(void *user, uint8_t i);