Added GUI Frame
This commit is contained in:
@ -60,6 +60,7 @@
|
||||
#include "poker/winner.h"
|
||||
|
||||
// User Interface Objects
|
||||
#include "ui/frame.h"
|
||||
#include "ui/label.h"
|
||||
|
||||
// Utility Objects
|
||||
|
@ -14,4 +14,5 @@ typedef struct {
|
||||
font_t font;
|
||||
shader_t shader;
|
||||
language_t language;
|
||||
texture_t testTexture;
|
||||
} pokergameassets_t;
|
20
include/dawn/ui/frame.h
Normal file
20
include/dawn/ui/frame.h
Normal file
@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../libs.h"
|
||||
#include "../display/primitive.h"
|
||||
#include "../display/gui/font.h"
|
||||
|
||||
#define FRAME_BORDER_SIZE 16
|
||||
#define FRAME_PRIMITIVE_COUNT 9
|
||||
|
||||
typedef struct {
|
||||
float x, y, z;
|
||||
texture_t *texture;
|
||||
primitive_t primitive;
|
||||
} frame_t;
|
@ -9,8 +9,10 @@
|
||||
#include "../libs.h"
|
||||
|
||||
#define STRING_HANDLEBAR_KEY_MAXLENGTH 32
|
||||
#define STRING_HANDLEBAR_LIST_VARIABLE_SIZE 512
|
||||
#define STRING_HANDLEBAR_LIST_VARIABLE_COUNT 64
|
||||
|
||||
#define STRING_STACK_STRING_SIZE 256
|
||||
#define STRING_STACK_STRING_COUNT 128
|
||||
#define STRING_STACK_BUFFER STRING_STACK_STRING_SIZE * STRING_STACK_STRING_COUNT
|
||||
|
||||
/** Representation of a String Handlebar Variable */
|
||||
typedef struct {
|
||||
@ -20,9 +22,12 @@ typedef struct {
|
||||
char *value;
|
||||
} stringhandlebarvariable_t;
|
||||
|
||||
/** Definition of a string stack to push and pop strings from. */
|
||||
typedef struct {
|
||||
char buffer[
|
||||
STRING_HANDLEBAR_LIST_VARIABLE_SIZE * STRING_HANDLEBAR_LIST_VARIABLE_COUNT
|
||||
];
|
||||
stringhandlebarvariable_t variables[STRING_HANDLEBAR_LIST_VARIABLE_COUNT];
|
||||
} stringhandlebarvariablelist_t;
|
||||
/** Raw char buffer, for holding strings */
|
||||
char buffer[STRING_STACK_BUFFER];
|
||||
/** Strings themselves */
|
||||
char *strings[STRING_STACK_STRING_COUNT];
|
||||
/** How many strings are on the stack */
|
||||
int32_t size;
|
||||
} stringstack_t;
|
@ -7,8 +7,6 @@
|
||||
|
||||
#include "game.h"
|
||||
|
||||
language_t language;
|
||||
|
||||
bool gameInit(game_t *game) {
|
||||
// Init the engine and the rendering pipeline
|
||||
engineInit(&game->engine, game);
|
||||
|
@ -7,6 +7,8 @@
|
||||
|
||||
#include "pokergame.h"
|
||||
|
||||
frame_t frame;
|
||||
|
||||
bool pokerGameInit(game_t *game) {
|
||||
pokergame_t *pokerGame = &game->pokerGame;
|
||||
|
||||
@ -19,10 +21,15 @@ bool pokerGameInit(game_t *game) {
|
||||
// Initialize the UI.
|
||||
pokerUiInit(pokerGame);
|
||||
|
||||
frameInit(&frame);
|
||||
frame.texture = &pokerGame->assets.testTexture;
|
||||
|
||||
// Prep the VN Conversation Engine.
|
||||
vnSceneInit(&pokerGame->scene, &pokerGame->assets.font);
|
||||
pokerGameActionStartAdd(pokerGame);
|
||||
queueNext(&pokerGame->scene.conversation.actionQueue);
|
||||
// pokerGameActionStartAdd(pokerGame);
|
||||
// queueNext(&pokerGame->scene.conversation.actionQueue);
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -37,11 +44,12 @@ void pokerGameUpdate(game_t *game) {
|
||||
// Bind the shader.
|
||||
shaderUse(&pokerGame->assets.shader);
|
||||
|
||||
// Render the visual novel scene
|
||||
vnSceneRenderWorld(&pokerGame->scene, &game->engine, &pokerGame->assets.shader);
|
||||
|
||||
// Render the visual novel scene
|
||||
// vnSceneRenderWorld(&pokerGame->scene, &game->engine, &pokerGame->assets.shader);
|
||||
vnSceneRenderGui(&pokerGame->scene, &game->engine, &pokerGame->assets.shader);
|
||||
pokerUiRender(pokerGame);
|
||||
frameRender(&frame, &pokerGame->assets.shader);
|
||||
// pokerUiRender(pokerGame);
|
||||
}
|
||||
|
||||
void pokerGameDispose(game_t *game) {
|
||||
|
@ -14,6 +14,8 @@
|
||||
#include "actions/start.h"
|
||||
#include "pokerui.h"
|
||||
|
||||
#include "../../ui/frame.h"
|
||||
|
||||
/**
|
||||
* Initializes the game state for the poker game.
|
||||
*
|
||||
|
@ -11,7 +11,8 @@ bool pokerGameAssetsInit(pokergameassets_t *assets) {
|
||||
assetShaderLoad(&assets->shader,
|
||||
"shaders/textured.vert", "shaders/textured.frag"
|
||||
);
|
||||
languageInit(&assets->language, "locales/language/en-US.csv");
|
||||
languageInit(&assets->language, "locale/language/en-US.csv");
|
||||
assetTextureLoad(&assets->testTexture, "test_texture.png");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
115
src/ui/frame.c
Normal file
115
src/ui/frame.c
Normal file
@ -0,0 +1,115 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "frame.h"
|
||||
|
||||
void frameInit(frame_t *frame) {
|
||||
frame->x = 0;
|
||||
frame->y = 0;
|
||||
frame->z = 0;
|
||||
|
||||
primitiveInit(
|
||||
&frame->primitive,
|
||||
QUAD_VERTICE_COUNT * FRAME_PRIMITIVE_COUNT,
|
||||
QUAD_INDICE_COUNT * FRAME_PRIMITIVE_COUNT
|
||||
);
|
||||
|
||||
frameSetInnerSize(frame, FRAME_BORDER_SIZE*3, FRAME_BORDER_SIZE*3);
|
||||
}
|
||||
|
||||
void frameSetSize(frame_t *frame, float width, float height) {
|
||||
frameSetInnerSize(frame,
|
||||
width - (FRAME_BORDER_SIZE * 2),
|
||||
height - (FRAME_BORDER_SIZE * 2)
|
||||
);
|
||||
}
|
||||
|
||||
void frameSetInnerSize(frame_t *frame, float width, float height) {
|
||||
float rightStart = FRAME_BORDER_SIZE + width;
|
||||
float rightEnd = rightStart + FRAME_BORDER_SIZE;
|
||||
|
||||
float bottomStart = FRAME_BORDER_SIZE + height;
|
||||
float bottomEnd = bottomStart + FRAME_BORDER_SIZE;
|
||||
|
||||
float tw = 0.33333;
|
||||
float th = tw;
|
||||
|
||||
// Buffer the top left edge
|
||||
quadBuffer(&frame->primitive, 0,
|
||||
0, 0, 0, 0,
|
||||
FRAME_BORDER_SIZE, FRAME_BORDER_SIZE, tw, th,
|
||||
0, 0
|
||||
);
|
||||
|
||||
// Buffer the top edge.
|
||||
quadBuffer(&frame->primitive, 0,
|
||||
FRAME_BORDER_SIZE, 0, tw, 0,
|
||||
rightStart, FRAME_BORDER_SIZE, tw*2, th,
|
||||
QUAD_VERTICE_COUNT, QUAD_INDICE_COUNT
|
||||
);
|
||||
|
||||
// Buffer the top right edge.
|
||||
quadBuffer(&frame->primitive, 0,
|
||||
rightStart, 0, tw*2, 0,
|
||||
rightEnd, FRAME_BORDER_SIZE, tw*3, th,
|
||||
QUAD_VERTICE_COUNT*2, QUAD_INDICE_COUNT*2
|
||||
);
|
||||
|
||||
|
||||
// Buffer the left edge
|
||||
quadBuffer(&frame->primitive, 0,
|
||||
0, FRAME_BORDER_SIZE, 0, th,
|
||||
FRAME_BORDER_SIZE, bottomStart, tw, th*2,
|
||||
QUAD_VERTICE_COUNT*3, QUAD_INDICE_COUNT*3
|
||||
);
|
||||
|
||||
// Buffer the center
|
||||
quadBuffer(&frame->primitive, 0,
|
||||
FRAME_BORDER_SIZE, FRAME_BORDER_SIZE, tw, th,
|
||||
rightStart, bottomStart, tw*2, th*2,
|
||||
QUAD_VERTICE_COUNT*4, QUAD_INDICE_COUNT*4
|
||||
);
|
||||
|
||||
// Buffer the right edge.
|
||||
quadBuffer(&frame->primitive, 0,
|
||||
rightStart, FRAME_BORDER_SIZE, tw*2, th,
|
||||
rightEnd, bottomStart, tw*3, th*2,
|
||||
QUAD_VERTICE_COUNT*5, QUAD_INDICE_COUNT*5
|
||||
);
|
||||
|
||||
|
||||
// Buffer the bottom left edge.
|
||||
quadBuffer(&frame->primitive, 0,
|
||||
0, bottomStart, 0, th*2,
|
||||
FRAME_BORDER_SIZE, bottomEnd, tw, th*3,
|
||||
QUAD_VERTICE_COUNT*6, QUAD_INDICE_COUNT*6
|
||||
);
|
||||
|
||||
// Buffer the bottom edge.
|
||||
quadBuffer(&frame->primitive, 0,
|
||||
FRAME_BORDER_SIZE, bottomStart, tw, th*2,
|
||||
rightStart, bottomEnd, tw*2, th*3,
|
||||
QUAD_VERTICE_COUNT*7, QUAD_INDICE_COUNT*7
|
||||
);
|
||||
|
||||
// Buffer the bottom right edge.
|
||||
quadBuffer(&frame->primitive, 0,
|
||||
rightStart, bottomStart, tw*2, th*2,
|
||||
rightEnd, bottomEnd, tw*3, th*3,
|
||||
QUAD_VERTICE_COUNT*8, QUAD_INDICE_COUNT*8
|
||||
);
|
||||
}
|
||||
|
||||
void frameRender(frame_t *frame, shader_t *shader) {
|
||||
shaderUsePosition(shader, frame->x, frame->y, frame->z, 0, 0, 0);
|
||||
shaderUseTexture(shader, frame->texture);
|
||||
primitiveDraw(&frame->primitive, 0, -1);
|
||||
}
|
||||
|
||||
void frameDispose(frame_t *frame) {
|
||||
primitiveDispose(&frame->primitive);
|
||||
}
|
22
src/ui/frame.h
Normal file
22
src/ui/frame.h
Normal file
@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include <dawn/dawn.h>
|
||||
#include "../display/shader.h"
|
||||
#include "../display/primitive.h"
|
||||
#include "../display/primitives/quad.h"
|
||||
#include "../display/gui/font.h"
|
||||
|
||||
void frameInit(frame_t *frame);
|
||||
|
||||
void frameSetSize(frame_t *frame, float width, float height);
|
||||
|
||||
void frameSetInnerSize(frame_t *frame, float width, float height);
|
||||
|
||||
void frameRender(frame_t *frame, shader_t *shader);
|
||||
|
||||
void frameDispose(frame_t *frame);
|
@ -9,10 +9,32 @@
|
||||
#include "../display/primitive.h"
|
||||
#include "../display/gui/font.h"
|
||||
|
||||
/**
|
||||
* Initialize a Label UI Element.
|
||||
* @param label Label to initialize.
|
||||
*/
|
||||
void labelInit(label_t *label);
|
||||
|
||||
/**
|
||||
* Sets the text for a given label.
|
||||
*
|
||||
* @param label Label to update.
|
||||
* @param font Font to use.
|
||||
* @param text Text to set.
|
||||
*/
|
||||
void labelSetText(label_t *label, font_t *font, char *text);
|
||||
|
||||
/**
|
||||
* Render a label UI element.
|
||||
*
|
||||
* @param label Label to render.
|
||||
* @param shader Shader to use while rendering.
|
||||
*/
|
||||
void labelRender(label_t *label, shader_t *shader);
|
||||
|
||||
/**
|
||||
* Dispose a previously created label.
|
||||
*
|
||||
* @param label Label to dispose.
|
||||
*/
|
||||
void labelDispose(label_t *label);
|
@ -98,3 +98,18 @@ int32_t stringHandlebarsBuffer(char *source,
|
||||
// Return the count of chars we wrote to the buffer. -1 due to null term.
|
||||
return l - 1;
|
||||
}
|
||||
|
||||
void stringStackInit(stringstack_t *stack) {
|
||||
stack->size = 0;
|
||||
}
|
||||
|
||||
void stringStackPush(stringstack_t *stack, char *string) {
|
||||
size_t offset = stack->size * STRING_STACK_STRING_SIZE;
|
||||
arrayCopy(sizeof(char), string, strlen(string) + 1, stack->strings + offset);
|
||||
stack->strings[stack->size] = stack->buffer + offset;
|
||||
stack->size++;
|
||||
}
|
||||
|
||||
void stringStackPop(stringstack_t *stack) {
|
||||
stack->size -= 1;
|
||||
}
|
@ -5,6 +5,7 @@
|
||||
|
||||
#pragma once
|
||||
#include <dawn/dawn.h>
|
||||
#include "array.h"
|
||||
|
||||
/**
|
||||
* Replaces handlebars within the string with items from the list of variables.
|
||||
@ -22,3 +23,23 @@
|
||||
int32_t stringHandlebarsBuffer(char *source,
|
||||
stringhandlebarvariable_t *variables, int32_t variableCount, char *buffer
|
||||
);
|
||||
|
||||
/**
|
||||
* Initializes a string stack for pushing strings on to.
|
||||
* @param stack Stack to initialize.
|
||||
*/
|
||||
void stringStackInit(stringstack_t *stack);
|
||||
|
||||
/**
|
||||
* Push a string onto the stack. The source string will be copied so you can
|
||||
* change the original pointer after this push operation.
|
||||
* @param stack Stack to push onto.
|
||||
* @param string String to copy and push.
|
||||
*/
|
||||
void stringStackPush(stringstack_t *stack, char *string);
|
||||
|
||||
/**
|
||||
* Pop an element off the end of a string stack.
|
||||
* @param stack Stack to pop from.
|
||||
*/
|
||||
void stringStackPop(stringstack_t *stack);
|
Reference in New Issue
Block a user