VN Textbox can now be any size

This commit is contained in:
2022-11-06 11:45:10 -08:00
parent db90bd1476
commit 6f4ab49caa
23 changed files with 1493 additions and 1317 deletions

View File

@ -1,195 +1,195 @@
// Copyright (c) 2022 Dominic Masters // Copyright (c) 2022 Dominic Masters
// //
// This software is released under the MIT License. // This software is released under the MIT License.
// https://opensource.org/licenses/MIT // https://opensource.org/licenses/MIT
#include "TrueTypeFont.hpp" #include "TrueTypeFont.hpp"
#ifndef STB_TRUETYPE_IMPLEMENTATION #ifndef STB_TRUETYPE_IMPLEMENTATION
#define STB_TRUETYPE_IMPLEMENTATION #define STB_TRUETYPE_IMPLEMENTATION
#include <stb_truetype.h> #include <stb_truetype.h>
#endif #endif
using namespace Dawn; using namespace Dawn;
void TrueTypeFont::bakeQuad(truetypequad_t *quad,float_t *x,float_t *y,char c){ void TrueTypeFont::bakeQuad(truetypequad_t *quad,float_t *x,float_t *y,char c){
stbtt_GetBakedQuad( stbtt_GetBakedQuad(
this->characterData, this->characterData,
this->texture.getWidth(), this->texture.getHeight(), this->texture.getWidth(), this->texture.getHeight(),
((int32_t)c) - TRUETYPE_FIRST_CHAR, ((int32_t)c) - TRUETYPE_FIRST_CHAR,
x, y, quad, x, y, quad,
TRUETYPE_FILL_MODE TRUETYPE_FILL_MODE
); );
} }
float_t TrueTypeFont::getScale(float_t scale) { float_t TrueTypeFont::getScale(float_t scale) {
return scale / this->fontSize; return scale / this->fontSize;
} }
float_t TrueTypeFont::getSpaceSize(float_t fontSize) { float_t TrueTypeFont::getSpaceSize(float_t fontSize) {
return mathRoundFloat(this->fontSize * 0.3f); return mathRoundFloat(this->fontSize * 0.3f);
} }
float_t TrueTypeFont::getInitialLineHeight(float_t fontSize) { float_t TrueTypeFont::getInitialLineHeight(float_t fontSize) {
return 8.0f; return 8.0f;
} }
void TrueTypeFont::buffer( void TrueTypeFont::buffer(
std::string text, std::string text,
float_t fontSize, float_t fontSize,
float_t maxWidth, float_t maxWidth,
Mesh &mesh, Mesh &mesh,
struct FontMeasure *info struct FontMeasure *info
) { ) {
auto stringLength = text.length(); auto stringLength = text.length();
if(stringLength == 0) { if(stringLength == 0) {
info->length = 0; info->length = 0;
info->realLength = 0; info->realLength = 0;
info->lines.clear(); info->lines.clear();
info->height = 0; info->height = 0;
info->width = 0; info->width = 0;
info->height = 0.0f; info->height = 0.0f;
info->lineHeight = 0.0f; info->lineHeight = 0.0f;
mesh.createBuffers(0, 0); mesh.createBuffers(0, 0);
return; return;
} }
auto quads = new truetypequad_t[stringLength]; auto quads = new truetypequad_t[stringLength];
// Get the font scale // Get the font scale
auto scale = this->getScale(fontSize); auto scale = this->getScale(fontSize);
// Adjust the max width to match the scale, and allow "no max width". // Adjust the max width to match the scale, and allow "no max width".
maxWidth = maxWidth == -1 ? 9999999 : maxWidth * (1 / scale); maxWidth = maxWidth == -1 ? 9999999 : maxWidth * (1 / scale);
// Which index in the original text var is the current word from // Which index in the original text var is the current word from
int32_t wordStart = 0; int32_t wordStart = 0;
// Setup Scales // Setup Scales
info->length = 0; info->length = 0;
info->realLength = 0; info->realLength = 0;
info->lines.clear(); info->lines.clear();
info->lineHeight = this->getLineHeight(fontSize) * scale; info->lineHeight = this->getLineHeight(fontSize) * scale;
// Prepare the line counters // Prepare the line counters
info->addLine(0, 0); info->addLine(0, 0);
// Reset Dimensions // Reset Dimensions
info->width = info->height = 0; info->width = info->height = 0;
// Setup the initial loop state, and X/Y coords for the quad. // Setup the initial loop state, and X/Y coords for the quad.
int32_t i = 0; int32_t i = 0;
float_t x = 0; float_t x = 0;
float_t y = this->getInitialLineHeight(fontSize); float_t y = this->getInitialLineHeight(fontSize);
float_t wordX = 0; float_t wordX = 0;
char c; char c;
while(c = text[i++]) { while(c = text[i++]) {
info->length++; info->length++;
// When space, start of new word about to begin // When space, start of new word about to begin
if(c == FONT_SPACE) { if(c == FONT_SPACE) {
x += this->getSpaceSize(fontSize); x += this->getSpaceSize(fontSize);
// Did this space cause a newline? // Did this space cause a newline?
if(x > maxWidth) { if(x > maxWidth) {
info->addLine(info->realLength, 0); info->addLine(info->realLength, 0);
y += this->getLineHeight(fontSize); y += this->getLineHeight(fontSize);
x = 0; x = 0;
} }
wordX = x; wordX = x;
wordStart = info->realLength; wordStart = info->realLength;
continue; continue;
} }
// New line. // New line.
if(c == FONT_NEWLINE) { if(c == FONT_NEWLINE) {
info->addLine(info->realLength, 0); info->addLine(info->realLength, 0);
wordStart = info->realLength; wordStart = info->realLength;
y += this->getLineHeight(fontSize); y += this->getLineHeight(fontSize);
x = 0; x = 0;
continue; continue;
} }
// Generate the quad. // Generate the quad.
auto quad = quads + info->realLength; auto quad = quads + info->realLength;
this->bakeQuad(quad, &x, &y, c); this->bakeQuad(quad, &x, &y, c);
// Now measure the width of the line (take the right side of that quad) // Now measure the width of the line (take the right side of that quad)
if(quad->x1 > maxWidth) { if(quad->x1 > maxWidth) {
// We've exceeded the edge, go back to the start of the word and newline. // We've exceeded the edge, go back to the start of the word and newline.
x = quad->x1 - wordX; x = quad->x1 - wordX;
for(auto j = wordStart; j <= info->realLength; j++) { for(auto j = wordStart; j <= info->realLength; j++) {
quad = quads + j; quad = quads + j;
quad->x0 -= wordX; quad->x0 -= wordX;
quad->x1 -= wordX; quad->x1 -= wordX;
quad->y0 += this->getLineHeight(fontSize); quad->y0 += this->getLineHeight(fontSize);
quad->y1 += this->getLineHeight(fontSize); quad->y1 += this->getLineHeight(fontSize);
} }
// Go back to the previous (still current) line and remove the chars // Go back to the previous (still current) line and remove the chars
info->lines[info->lines.size() - 1].length -= info->realLength - wordStart; info->lines[info->lines.size() - 1].length -= info->realLength - wordStart;
// Next line begins with this word // Next line begins with this word
y += this->getLineHeight(fontSize); y += this->getLineHeight(fontSize);
info->addLine(wordStart, info->realLength-wordStart); info->addLine(wordStart, info->realLength-wordStart);
wordX = 0; wordX = 0;
} }
info->lines[info->lines.size() - 1].length++; info->lines[info->lines.size() - 1].length++;
info->realLength++; info->realLength++;
} }
// Initialize primitive // Initialize primitive
mesh.createBuffers( mesh.createBuffers(
QUAD_VERTICE_COUNT * info->realLength, QUAD_VERTICE_COUNT * info->realLength,
QUAD_INDICE_COUNT * info->realLength QUAD_INDICE_COUNT * info->realLength
); );
for(auto j = 0; j < info->realLength; j++) { for(auto j = 0; j < info->realLength; j++) {
auto quad = quads + j; auto quad = quads + j;
// Scale the Quad // Scale the Quad
if(scale != 1.0) { if(scale != 1.0) {
quad->x0 *= scale; quad->x0 *= scale;
quad->x1 *= scale; quad->x1 *= scale;
quad->y0 *= scale; quad->y0 *= scale;
quad->y1 *= scale; quad->y1 *= scale;
} }
// Update the dimensions. // Update the dimensions.
info->width = mathMax<float_t>(info->width, quad->x1); info->width = mathMax<float_t>(info->width, quad->x1);
info->height = mathMax<float_t>(info->height, quad->y1); info->height = mathMax<float_t>(info->height, quad->y1);
// Buffer the quad. // Buffer the quad.
QuadMesh::bufferQuadMesh(&mesh, QuadMesh::bufferQuadMesh(&mesh,
glm::vec2(quad->x0, quad->y0), glm::vec2(quad->s0, quad->t0), glm::vec2(quad->x0, quad->y0), glm::vec2(quad->s0, quad->t0),
glm::vec2(quad->x1, quad->y1), glm::vec2(quad->s1, quad->t1), glm::vec2(quad->x1, quad->y1), glm::vec2(quad->s1, quad->t1),
j * QUAD_VERTICE_COUNT, j * QUAD_INDICE_COUNT j * QUAD_VERTICE_COUNT, j * QUAD_INDICE_COUNT
); );
} }
delete quads; delete quads;
} }
Texture & TrueTypeFont::getTexture() { Texture & TrueTypeFont::getTexture() {
return this->texture; return this->texture;
} }
void TrueTypeFont::draw(Mesh &mesh, int32_t startchar, int32_t length) { void TrueTypeFont::draw(Mesh &mesh, int32_t startchar, int32_t length) {
mesh.draw( mesh.draw(
MESH_DRAW_MODE_TRIANGLES, MESH_DRAW_MODE_TRIANGLES,
startchar * QUAD_INDICE_COUNT, startchar * QUAD_INDICE_COUNT,
length == -1 ? length : length * QUAD_INDICE_COUNT length == -1 ? length : length * QUAD_INDICE_COUNT
); );
} }
float_t TrueTypeFont::getLineHeight(float_t fontSize) { float_t TrueTypeFont::getLineHeight(float_t fontSize) {
return 13.0f; return 13.0f;
} }
float_t TrueTypeFont::getDefaultFontSize() { float_t TrueTypeFont::getDefaultFontSize() {
return (float_t)this->fontSize; return (float_t)this->fontSize;
} }

View File

@ -1,83 +1,83 @@
// Copyright (c) 2022 Dominic Masters // Copyright (c) 2022 Dominic Masters
// //
// This software is released under the MIT License. // This software is released under the MIT License.
// https://opensource.org/licenses/MIT // https://opensource.org/licenses/MIT
#pragma once #pragma once
#include "Font.hpp" #include "Font.hpp"
namespace Dawn { namespace Dawn {
/** Which character (ASCII) to start the font from */ /** Which character (ASCII) to start the font from */
#define TRUETYPE_FIRST_CHAR 32 #define TRUETYPE_FIRST_CHAR 32
/** How many characters (after the first char) to generate */ /** How many characters (after the first char) to generate */
#define TRUETYPE_NUM_CHARS 96 #define TRUETYPE_NUM_CHARS 96
/** Refer to STBTT docs for OpenGL Fill Mode v d3d Fill Modes */ /** Refer to STBTT docs for OpenGL Fill Mode v d3d Fill Modes */
#define TRUETYPE_FILL_MODE 0 #define TRUETYPE_FILL_MODE 0
typedef stbtt_bakedchar truetypechar_t; typedef stbtt_bakedchar truetypechar_t;
typedef stbtt_aligned_quad truetypequad_t; typedef stbtt_aligned_quad truetypequad_t;
class TrueTypeFont : public Font { class TrueTypeFont : public Font {
protected: protected:
/** /**
* Calculate the quad information for a given character. * Calculate the quad information for a given character.
* *
* @param font Font to get the character from. * @param font Font to get the character from.
* @param quad Pointer to the quad to store the quad information in. * @param quad Pointer to the quad to store the quad information in.
* @param x Pointer to the X position for the quad. * @param x Pointer to the X position for the quad.
* @param y Pointer to the Y position for the quad. * @param y Pointer to the Y position for the quad.
* @param c Character to get the quad and position information for. * @param c Character to get the quad and position information for.
*/ */
void bakeQuad(truetypequad_t *quad, float_t *x, float_t *y, char c); void bakeQuad(truetypequad_t *quad, float_t *x, float_t *y, char c);
/** /**
* Returns the font scale to use for rendering your desired font size at a * Returns the font scale to use for rendering your desired font size at a
* font size that is different than the precompiled font size for this * font size that is different than the precompiled font size for this
* true type font. For example, let's say you render your font size at 36 * true type font. For example, let's say you render your font size at 36
* when you are precompiling it, but rather than creating a new font just * when you are precompiling it, but rather than creating a new font just
* to add a size 24, you can instead use this method to get the scale to * to add a size 24, you can instead use this method to get the scale to
* use to downscale your font to match. * use to downscale your font to match.
* *
* @param font TrueType font to get the scale of. * @param font TrueType font to get the scale of.
* @param fontSize Font size you desire. * @param fontSize Font size you desire.
* @return The scale used to get the font size that will match. * @return The scale used to get the font size that will match.
*/ */
float_t getScale(float_t fontSize); float_t getScale(float_t fontSize);
/** /**
* Returns the size of a space character for a given font. * Returns the size of a space character for a given font.
* *
* @param fontSize Font size of the font to get the space size for. * @param fontSize Font size of the font to get the space size for.
* @return The size of the space character. * @return The size of the space character.
*/ */
float_t getSpaceSize(float_t fontSize); float_t getSpaceSize(float_t fontSize);
/** /**
* Returns the initial line height of a font. * Returns the initial line height of a font.
* *
* @param fontSize Font size for the font to get the line height of. * @param fontSize Font size for the font to get the line height of.
* @return The line height initial value. * @return The line height initial value.
*/ */
float_t getInitialLineHeight(float_t fontSize); float_t getInitialLineHeight(float_t fontSize);
public: public:
Texture texture; Texture texture;
int32_t fontSize; int32_t fontSize;
truetypechar_t characterData[TRUETYPE_NUM_CHARS]; truetypechar_t characterData[TRUETYPE_NUM_CHARS];
void buffer( void buffer(
std::string text, std::string text,
float_t fontSize, float_t fontSize,
float_t maxWidth, float_t maxWidth,
Mesh &mesh, Mesh &mesh,
struct FontMeasure *info struct FontMeasure *info
) override; ) override;
Texture & getTexture() override; Texture & getTexture() override;
void draw(Mesh &mesh, int32_t startCharacter, int32_t length) override; void draw(Mesh &mesh, int32_t startCharacter, int32_t length) override;
float_t getLineHeight(float_t fontSize) override; float_t getLineHeight(float_t fontSize) override;
float_t getDefaultFontSize() override; float_t getDefaultFontSize() override;
}; };
} }

View File

@ -1,115 +1,115 @@
// Copyright (c) 2022 Dominic Masters // Copyright (c) 2022 Dominic Masters
// //
// This software is released under the MIT License. // This software is released under the MIT License.
// https://opensource.org/licenses/MIT // https://opensource.org/licenses/MIT
#pragma once #pragma once
#include "display/Texture.hpp" #include "display/Texture.hpp"
namespace Dawn { namespace Dawn {
class Material; class Material;
enum ShaderParameterType { enum ShaderParameterType {
SHADER_PARAMETER_TYPE_MATRIX, SHADER_PARAMETER_TYPE_MATRIX,
SHADER_PARAMETER_TYPE_BOOLEAN, SHADER_PARAMETER_TYPE_BOOLEAN,
SHADER_PARAMETER_TYPE_COLOR, SHADER_PARAMETER_TYPE_COLOR,
SHADER_PARAMETER_TYPE_VECTOR3, SHADER_PARAMETER_TYPE_VECTOR3,
SHADER_PARAMETER_TYPE_TEXTURE, SHADER_PARAMETER_TYPE_TEXTURE,
SHADER_PARAMETER_TYPE_FLOAT SHADER_PARAMETER_TYPE_FLOAT
}; };
template<typename T> template<typename T>
class IShader { class IShader {
public: public:
/** /**
* Attaches the supplied shader as the current shader. * Attaches the supplied shader as the current shader.
*/ */
virtual void bind() = 0; virtual void bind() = 0;
/** /**
* Requested by the Material to set the default parameters of the shader. * Requested by the Material to set the default parameters of the shader.
* Each parameter really should have a default value set so that there is * Each parameter really should have a default value set so that there is
* no nullptr's or other issues. * no nullptr's or other issues.
* *
* @param material Material to set the default parameters on to. * @param material Material to set the default parameters on to.
*/ */
virtual void setDefaultParameters(Material &material) = 0; virtual void setDefaultParameters(Material &material) = 0;
/** /**
* Requested by the render pipeline (typically) to set global level (once * Requested by the render pipeline (typically) to set global level (once
* per frame) parameters. * per frame) parameters.
* *
* @param projection Projection matrix of the current viewport. * @param projection Projection matrix of the current viewport.
* @param view View matrix of the current viewport. * @param view View matrix of the current viewport.
*/ */
virtual void setGlobalParameters( virtual void setGlobalParameters(
glm::mat4 projection, glm::mat4 projection,
glm::mat4 view glm::mat4 view
) = 0; ) = 0;
/** /**
* Requested by the render pipeline (typically) to set mesh-level params. * Requested by the render pipeline (typically) to set mesh-level params.
* This may be performed multiple times per frame. * This may be performed multiple times per frame.
* *
* @param position Matrix of the position of the mesh. * @param position Matrix of the position of the mesh.
*/ */
virtual void setMeshParameters(glm::mat4 position) = 0; virtual void setMeshParameters(glm::mat4 position) = 0;
/** /**
* Retreives the list of all parameters that the shader supports. This * Retreives the list of all parameters that the shader supports. This
* should not include the GLOBAL shader parameters (listed above) since * should not include the GLOBAL shader parameters (listed above) since
* those will be modified by the engine directly. * those will be modified by the engine directly.
* *
* @return Key-Value-Pair of Shader parameters and their type. * @return Key-Value-Pair of Shader parameters and their type.
*/ */
virtual std::map<T, enum ShaderParameterType> getParameters() = 0; virtual std::map<T, enum ShaderParameterType> getParameters() = 0;
/** /**
* Set's a specific shader parameter to a matrix. * Set's a specific shader parameter to a matrix.
* *
* @param parameter parameter on the shader to set. * @param parameter parameter on the shader to set.
* @param matrix Matrix to apply. * @param matrix Matrix to apply.
*/ */
virtual void setMatrix(T parameter, glm::mat4 matrix) = 0; virtual void setMatrix(T parameter, glm::mat4 matrix) = 0;
/** /**
* Attaches a boolean to a shader. * Attaches a boolean to a shader.
* *
* @param parameter parameter to set. * @param parameter parameter to set.
* @param value Value to set. * @param value Value to set.
*/ */
virtual void setBoolean(T parameter, bool_t value) = 0; virtual void setBoolean(T parameter, bool_t value) = 0;
/** /**
* Set a color on to the shader. * Set a color on to the shader.
* *
* @param parameter parameter to set the color to. * @param parameter parameter to set the color to.
* @param color Color to set. * @param color Color to set.
*/ */
virtual void setColor(T parameter, struct Color color) = 0; virtual void setColor(T parameter, struct Color color) = 0;
/** /**
* Set a 3D vector on to the shader. * Set a 3D vector on to the shader.
* *
* @param parameter parameter to set the vector to. * @param parameter parameter to set the vector to.
* @param vector Vector to set. * @param vector Vector to set.
*/ */
virtual void setVector3(T parameter, glm::vec3 vector) = 0; virtual void setVector3(T parameter, glm::vec3 vector) = 0;
/** /**
* Attaches a texture to the currently bound shader. * Attaches a texture to the currently bound shader.
* *
* @param parameter parameter to set the texture on to. * @param parameter parameter to set the texture on to.
* @param texture Texture to bind to the parameter. * @param texture Texture to bind to the parameter.
*/ */
virtual void setTexture(T parameter, Texture *texture) = 0; virtual void setTexture(T parameter, Texture *texture) = 0;
/** /**
* Sets a floating point value to the shader. * Sets a floating point value to the shader.
* *
* @param parameter Paramater to set the float ont o. * @param parameter Paramater to set the float ont o.
* @param float Float to bind. * @param Float to bind.
*/ */
virtual void setFloat(T parameter, float_t value) = 0; virtual void setFloat(T parameter, float_t value) = 0;
}; };
} }

View File

@ -1,67 +1,58 @@
// Copyright (c) 2022 Dominic Masters // Copyright (c) 2022 Dominic Masters
// //
// This software is released under the MIT License. // This software is released under the MIT License.
// https://opensource.org/licenses/MIT // https://opensource.org/licenses/MIT
#pragma once #pragma once
#include "dawnlibs.hpp" #include "dawnlibs.hpp"
#include "scene/Scene.hpp" #include "scene/Scene.hpp"
#include "display/RenderManager.hpp" #include "display/RenderManager.hpp"
#include "asset/AssetManager.hpp" #include "asset/AssetManager.hpp"
#include "input/InputManager.hpp" #include "input/InputManager.hpp"
#include "time/TimeManager.hpp" #include "time/TimeManager.hpp"
#include "input/InputBinds.hpp" #include "input/InputBinds.hpp"
#define DAWN_GAME_INIT_RESULT_SUCCESS 0 #define DAWN_GAME_INIT_RESULT_SUCCESS 0
#define DAWN_GAME_UPDATE_RESULT_SUCCESS 0 #define DAWN_GAME_UPDATE_RESULT_SUCCESS 0
#define DAWN_GAME_UPDATE_RESULT_EXIT 1 #define DAWN_GAME_UPDATE_RESULT_EXIT 1
namespace Dawn { namespace Dawn {
class DawnHost; class DawnHost;
class DawnGame { class IDawnGame {
public: public:
std::shared_ptr<Scene> scene; std::shared_ptr<Scene> scene;
DawnHost &host;
RenderManager renderManager; /**
AssetManager assetManager; * Initialize the game. This is performed by the host at a time that is
InputManager inputManager; * deemed to have the host ready for the game's initialization. This will
TimeManager timeManager; * return an initialize result, where DAWN_GAME_INIT_RESULT_SUCCESS is
* the only "successful" result, anything else is deemed a failure state.
/** *
* Construct a new instance of the DawnGame. * @param host Pointer to the host that is running this game.
* * @return The game initialize result.
*/ */
DawnGame(DawnHost &host); virtual int32_t init() = 0;
/** /**
* Initialize the game. This is performed by the host at a time that is * Performs a game update operation. This operation should occur exactly
* deemed to have the host ready for the game's initialization. This will * once per frame, synchronously on the main thread. Updates can only
* return an initialize result, where DAWN_GAME_INIT_RESULT_SUCCESS is * have two valid exit results, either DAWN_GAME_UPDATE_RESULT_SUCCESS for
* the only "successful" result, anything else is deemed a failure state. * a successful update, and request that we continue to update, or
* * DAWN_GAME_UPDATE_RESULT_EXIT for a successful update but to request
* @param host Pointer to the host that is running this game. * that no more update operations occur. Any other result is considered a
* @return The game initialize result. * failure state.
*/ *
int32_t init(); * @param delta Time delta to tick the game by.
* @return The game update result.
/** */
* Performs a game update operation. This operation should occur exactly virtual int32_t update(float_t delta) = 0;
* once per frame, synchronously on the main thread. Updates can only
* have two valid exit results, either DAWN_GAME_UPDATE_RESULT_SUCCESS for /**
* a successful update, and request that we continue to update, or * Cleanup the memory of the DawnGame instance.
* DAWN_GAME_UPDATE_RESULT_EXIT for a successful update but to request */
* that no more update operations occur. Any other result is considered a virtual ~IDawnGame() {
* failure state.
* }
* @param delta Time delta to tick the game by. };
* @return The game update result.
*/
int32_t update(float_t delta);
/**
* Cleanup the memory of the DawnGame instance.
*/
~DawnGame();
};
} }

View File

@ -1,130 +1,134 @@
// Copyright (c) 2022 Dominic Masters // Copyright (c) 2022 Dominic Masters
// //
// This software is released under the MIT License. // This software is released under the MIT License.
// https://opensource.org/licenses/MIT // https://opensource.org/licenses/MIT
#include "UIBorder.hpp" #include "UIBorder.hpp"
using namespace Dawn; using namespace Dawn;
UIBorder::UIBorder(UICanvas &canvas) : UIComponent(canvas) { UIBorder::UIBorder(UICanvas &canvas) : UIComponent(canvas) {
this->mesh.createBuffers(QUAD_VERTICE_COUNT * 9, QUAD_INDICE_COUNT * 9); this->mesh.createBuffers(QUAD_VERTICE_COUNT * 9, QUAD_INDICE_COUNT * 9);
this->texture = new Texture(); this->texture = new Texture();
this->texture->setSize(3, 3); this->texture->setSize(3, 3);
struct Color pixels[9] = { struct Color pixels[9] = {
COLOR_WHITE, COLOR_RED, COLOR_BLUE, COLOR_WHITE, COLOR_RED, COLOR_BLUE,
COLOR_GREEN, COLOR_MAGENTA, COLOR_BLACK, COLOR_GREEN, COLOR_MAGENTA, COLOR_BLACK,
COLOR_CORNFLOWER_BLUE, COLOR_WHITE, COLOR_MAGENTA COLOR_CORNFLOWER_BLUE, COLOR_WHITE, COLOR_MAGENTA
}; };
this->texture->buffer(pixels); this->texture->buffer(pixels);
this->updatePositions(); this->updatePositions();
} }
void UIBorder::updatePositions() { void UIBorder::updatePositions() {
UIComponent::updatePositions(); UIComponent::updatePositions();
glm::vec2 oneThird = this->uv1 / 3.0f; glm::vec2 oneThird = this->uv1 / 3.0f;
glm::vec2 overallDimensions = glm::vec2(this->getWidth(), this->getHeight()); glm::vec2 overallDimensions = glm::vec2(this->getWidth(), this->getHeight());
glm::vec2 innerDimensions = overallDimensions - (this->edgeDimensions * 2.0f); glm::vec2 innerDimensions = overallDimensions - (this->edgeDimensions * 2.0f);
// Top Left. // Top Left.
QuadMesh::bufferQuadMesh(&this->mesh, QuadMesh::bufferQuadMesh(&this->mesh,
glm::vec2(0, 0), glm::vec2(0, 0),
this->uv0, this->uv0,
edgeDimensions, edgeDimensions,
this->uv0 + oneThird, this->uv0 + oneThird,
0, 0 0, 0
); );
// Top Center // Top Center
QuadMesh::bufferQuadMesh(&this->mesh, QuadMesh::bufferQuadMesh(&this->mesh,
glm::vec2(edgeDimensions.x, 0), glm::vec2(edgeDimensions.x, 0),
this->uv0 + glm::vec2(oneThird.x, 0), this->uv0 + glm::vec2(oneThird.x, 0),
glm::vec2(edgeDimensions.x + innerDimensions.x, edgeDimensions.y), glm::vec2(edgeDimensions.x + innerDimensions.x, edgeDimensions.y),
this->uv0 + glm::vec2(oneThird.x * 2.0f, oneThird.y), this->uv0 + glm::vec2(oneThird.x * 2.0f, oneThird.y),
QUAD_VERTICE_COUNT, QUAD_INDICE_COUNT QUAD_VERTICE_COUNT, QUAD_INDICE_COUNT
); );
// Top Right // Top Right
QuadMesh::bufferQuadMesh(&this->mesh, QuadMesh::bufferQuadMesh(&this->mesh,
glm::vec2(edgeDimensions.x + innerDimensions.x, 0), glm::vec2(edgeDimensions.x + innerDimensions.x, 0),
this->uv0 + glm::vec2(oneThird.x * 2.0f, 0), this->uv0 + glm::vec2(oneThird.x * 2.0f, 0),
glm::vec2(overallDimensions.x, edgeDimensions.y), glm::vec2(overallDimensions.x, edgeDimensions.y),
glm::vec2(this->uv1.x, this->uv0.y + oneThird.y), glm::vec2(this->uv1.x, this->uv0.y + oneThird.y),
QUAD_VERTICE_COUNT * 2, QUAD_INDICE_COUNT * 2 QUAD_VERTICE_COUNT * 2, QUAD_INDICE_COUNT * 2
); );
// Middle Left // Middle Left
QuadMesh::bufferQuadMesh(&this->mesh, QuadMesh::bufferQuadMesh(&this->mesh,
glm::vec2(0, edgeDimensions.y), glm::vec2(0, edgeDimensions.y),
this->uv0 + glm::vec2(0, oneThird.y), this->uv0 + glm::vec2(0, oneThird.y),
glm::vec2(edgeDimensions.x, edgeDimensions.y + innerDimensions.y), glm::vec2(edgeDimensions.x, edgeDimensions.y + innerDimensions.y),
this->uv0 + glm::vec2(oneThird.x, oneThird.y * 2.0f), this->uv0 + glm::vec2(oneThird.x, oneThird.y * 2.0f),
QUAD_VERTICE_COUNT * 3, QUAD_INDICE_COUNT * 3 QUAD_VERTICE_COUNT * 3, QUAD_INDICE_COUNT * 3
); );
// Center // Center
QuadMesh::bufferQuadMesh(&this->mesh, QuadMesh::bufferQuadMesh(&this->mesh,
edgeDimensions, edgeDimensions,
this->uv0 + oneThird, this->uv0 + oneThird,
edgeDimensions + innerDimensions, edgeDimensions + innerDimensions,
this->uv0 + (oneThird * 2.0f), this->uv0 + (oneThird * 2.0f),
QUAD_VERTICE_COUNT * 4, QUAD_INDICE_COUNT * 4 QUAD_VERTICE_COUNT * 4, QUAD_INDICE_COUNT * 4
); );
// Middle Right // Middle Right
QuadMesh::bufferQuadMesh(&this->mesh, QuadMesh::bufferQuadMesh(&this->mesh,
edgeDimensions + glm::vec2(innerDimensions.x, 0), edgeDimensions + glm::vec2(innerDimensions.x, 0),
this->uv0 + glm::vec2(oneThird.x * 2.0f, oneThird.y), this->uv0 + glm::vec2(oneThird.x * 2.0f, oneThird.y),
edgeDimensions + innerDimensions + glm::vec2(edgeDimensions.x, 0), edgeDimensions + innerDimensions + glm::vec2(edgeDimensions.x, 0),
this->uv1 - glm::vec2(0.0f, oneThird.y), this->uv1 - glm::vec2(0.0f, oneThird.y),
QUAD_VERTICE_COUNT * 5, QUAD_INDICE_COUNT * 5 QUAD_VERTICE_COUNT * 5, QUAD_INDICE_COUNT * 5
); );
// Bottom Left // Bottom Left
QuadMesh::bufferQuadMesh(&this->mesh, QuadMesh::bufferQuadMesh(&this->mesh,
glm::vec2(0.0f, edgeDimensions.y + innerDimensions.y), glm::vec2(0.0f, edgeDimensions.y + innerDimensions.y),
this->uv0 + glm::vec2(0.0f, uv1.y - oneThird.y), this->uv0 + glm::vec2(0.0f, uv1.y - oneThird.y),
glm::vec2(edgeDimensions.x, overallDimensions.y), glm::vec2(edgeDimensions.x, overallDimensions.y),
this->uv1 - glm::vec2(oneThird.x * 2.0f, 0.0f), this->uv1 - glm::vec2(oneThird.x * 2.0f, 0.0f),
QUAD_VERTICE_COUNT * 6, QUAD_INDICE_COUNT * 6 QUAD_VERTICE_COUNT * 6, QUAD_INDICE_COUNT * 6
); );
// Bottom Center // Bottom Center
QuadMesh::bufferQuadMesh(&this->mesh, QuadMesh::bufferQuadMesh(&this->mesh,
edgeDimensions + glm::vec2(0.0f, innerDimensions.y), edgeDimensions + glm::vec2(0.0f, innerDimensions.y),
this->uv1 - oneThird, this->uv1 - oneThird,
overallDimensions - glm::vec2(edgeDimensions.x, 0.0f), overallDimensions - glm::vec2(edgeDimensions.x, 0.0f),
this->uv1 - glm::vec2(oneThird.x, 0.0f), this->uv1 - glm::vec2(oneThird.x, 0.0f),
QUAD_VERTICE_COUNT * 7, QUAD_INDICE_COUNT * 7 QUAD_VERTICE_COUNT * 7, QUAD_INDICE_COUNT * 7
); );
// Bottom Right // Bottom Right
QuadMesh::bufferQuadMesh(&this->mesh, QuadMesh::bufferQuadMesh(&this->mesh,
overallDimensions - edgeDimensions, overallDimensions - edgeDimensions,
this->uv1 - oneThird, this->uv1 - oneThird,
overallDimensions, overallDimensions,
this->uv1, this->uv1,
QUAD_VERTICE_COUNT * 8, QUAD_INDICE_COUNT * 8 QUAD_VERTICE_COUNT * 8, QUAD_INDICE_COUNT * 8
); );
} }
void UIBorder::drawSelf(UIShader &shader, glm::mat4 transform) { void UIBorder::drawSelf(UIShader &shader, glm::mat4 transform) {
if(this->texture == nullptr) return; if(this->texture == nullptr) return;
shader.setUIColor(COLOR_WHITE); shader.setUIColor(COLOR_WHITE);
shader.setUIModel(transform); shader.setUIModel(transform);
shader.setUITexture(this->texture); shader.setUITexture(this->texture);
this->mesh.draw(MESH_DRAW_MODE_TRIANGLES, 0, -1); this->mesh.draw(MESH_DRAW_MODE_TRIANGLES, 0, -1);
} }
void UIBorder::setBorderSize(glm::vec2 borderSize) { void UIBorder::setBorderSize(glm::vec2 borderSize) {
this->edgeDimensions = borderSize; this->edgeDimensions = borderSize;
this->updatePositions(); this->updatePositions();
} }
glm::vec2 UIBorder::getBorderSize() { glm::vec2 UIBorder::getInnerSize() {
return this->edgeDimensions; return glm::vec2(this->getWidth(), this->getHeight()) - this->edgeDimensions;
}
glm::vec2 UIBorder::getBorderSize() {
return this->edgeDimensions;
} }

View File

@ -1,30 +1,48 @@
// Copyright (c) 2022 Dominic Masters // Copyright (c) 2022 Dominic Masters
// //
// This software is released under the MIT License. // This software is released under the MIT License.
// https://opensource.org/licenses/MIT // https://opensource.org/licenses/MIT
#pragma once #pragma once
#include "UIComponent.hpp" #include "UIComponent.hpp"
#include "display/mesh/QuadMesh.hpp" #include "display/mesh/QuadMesh.hpp"
#include "display/Texture.hpp" #include "display/Texture.hpp"
namespace Dawn { namespace Dawn {
class UIBorder : public UIComponent { class UIBorder : public UIComponent {
private: private:
Mesh mesh; Mesh mesh;
glm::vec2 edgeDimensions = glm::vec2(8.0f, 8.0f); glm::vec2 edgeDimensions = glm::vec2(8.0f, 8.0f);
glm::vec2 uv0 = glm::vec2(0.0f, 0.0f); glm::vec2 uv0 = glm::vec2(0.0f, 0.0f);
glm::vec2 uv1 = glm::vec2(1.0f, 1.0f); glm::vec2 uv1 = glm::vec2(1.0f, 1.0f);
void updatePositions() override; void updatePositions() override;
void drawSelf(UIShader &shader, glm::mat4 selfTransform) override;
public:
Texture *texture; public:
Texture *texture;
UIBorder(UICanvas &canvas);
void drawSelf(UIShader &shader, glm::mat4 selfTransform) override; UIBorder(UICanvas &canvas);
void setBorderSize(glm::vec2 borderSize); /**
glm::vec2 getBorderSize(); * Changes the dimensions of the border.
}; *
* @param borderSize Size of the border.
*/
void setBorderSize(glm::vec2 borderSize);
/**
* Returns the size of the border.
*
* @return Border size of this UI border.
*/
glm::vec2 getBorderSize();
/**
* Returns the size of the area within the border.
*
* @return The inner content area size.
*/
glm::vec2 getInnerSize();
};
} }

View File

@ -1,153 +1,158 @@
// Copyright (c) 2022 Dominic Masters // Copyright (c) 2022 Dominic Masters
// //
// This software is released under the MIT License. // This software is released under the MIT License.
// https://opensource.org/licenses/MIT // https://opensource.org/licenses/MIT
#include "UIComponent.hpp" #include "UIComponent.hpp"
using namespace Dawn; using namespace Dawn;
UIComponent::UIComponent(UICanvas &canvas) : UIComponent::UIComponent(UICanvas &canvas) :
canvas(canvas) canvas(canvas)
{ {
} }
void UIComponent::updatePositions() { void UIComponent::updatePositions() {
// X Alignment // X Alignment
if(this->alignX == UI_COMPONENT_ALIGN_STRETCH) { if(this->alignX == UI_COMPONENT_ALIGN_STRETCH) {
if(this->parent == nullptr) { if(this->parent == nullptr) {
this->width = this->canvas.getWidth(); this->width = this->canvas.getWidth();
} else { } else {
this->width = this->parent->getWidth(); this->width = this->parent->getWidth();
} }
this->relativeX = this->alignment[0]; this->relativeX = this->alignment[0];
this->width -= (this->alignment[0] + this->alignment[2]); this->width -= (this->alignment[0] + this->alignment[2]);
} else if(this->alignX == UI_COMPONENT_ALIGN_START) { } else if(this->alignX == UI_COMPONENT_ALIGN_START) {
this->relativeX = this->alignment[0]; this->relativeX = this->alignment[0];
this->width = this->alignment[2]; this->width = this->alignment[2];
} else if(this->alignX == UI_COMPONENT_ALIGN_END) { } else if(this->alignX == UI_COMPONENT_ALIGN_END) {
this->width = this->alignment[0]; this->width = this->alignment[0];
if(this->parent == nullptr) { if(this->parent == nullptr) {
this->relativeX = this->canvas.getWidth(); this->relativeX = this->canvas.getWidth();
} else { } else {
this->relativeX = this->parent->getWidth(); this->relativeX = this->parent->getWidth();
} }
this->relativeX -= this->width; this->relativeX -= this->width;
this->relativeX -= this->alignment[2]; this->relativeX -= this->alignment[2];
} else if(this->alignX == UI_COMPONENT_ALIGN_MIDDLE) { } else if(this->alignX == UI_COMPONENT_ALIGN_MIDDLE) {
this->width = this->alignment[2]; this->width = this->alignment[2];
if(this->parent == nullptr) { if(this->parent == nullptr) {
this->relativeX = this->canvas.getWidth(); this->relativeX = this->canvas.getWidth();
} else { } else {
this->relativeX = this->parent->getWidth(); this->relativeX = this->parent->getWidth();
} }
this->relativeX = (this->relativeX / 2.0f) - (this->width / 2.0f) + this->alignment[0]; this->relativeX = (this->relativeX / 2.0f) - (this->width / 2.0f) + this->alignment[0];
} }
// Y Alignment // Y Alignment
if(this->alignY == UI_COMPONENT_ALIGN_STRETCH) { if(this->alignY == UI_COMPONENT_ALIGN_STRETCH) {
if(this->parent == nullptr) { if(this->parent == nullptr) {
this->height = this->canvas.getHeight(); this->height = this->canvas.getHeight();
} else { } else {
this->height = this->parent->getHeight(); this->height = this->parent->getHeight();
} }
this->relativeY = this->alignment[1]; this->relativeY = this->alignment[1];
this->height -= (this->alignment[1] + this->alignment[3]); this->height -= (this->alignment[1] + this->alignment[3]);
} else if(this->alignY == UI_COMPONENT_ALIGN_START) { } else if(this->alignY == UI_COMPONENT_ALIGN_START) {
this->relativeY = this->alignment[1]; this->relativeY = this->alignment[1];
this->height = this->alignment[3]; this->height = this->alignment[3];
} else if(this->alignY == UI_COMPONENT_ALIGN_END) { } else if(this->alignY == UI_COMPONENT_ALIGN_END) {
this->height = this->alignment[1]; this->height = this->alignment[1];
if(this->parent == nullptr) { if(this->parent == nullptr) {
this->relativeY = this->canvas.getHeight(); this->relativeY = this->canvas.getHeight();
} else { } else {
this->relativeY = this->parent->getHeight(); this->relativeY = this->parent->getHeight();
} }
this->relativeY -= this->height; this->relativeY -= this->height;
this->relativeY -= this->alignment[3]; this->relativeY -= this->alignment[3];
} else if(this->alignY == UI_COMPONENT_ALIGN_MIDDLE) { } else if(this->alignY == UI_COMPONENT_ALIGN_MIDDLE) {
this->height = this->alignment[3]; this->height = this->alignment[3];
if(this->parent == nullptr) { if(this->parent == nullptr) {
this->relativeY = this->canvas.getHeight(); this->relativeY = this->canvas.getHeight();
} else { } else {
this->relativeY = this->parent->getHeight(); this->relativeY = this->parent->getHeight();
} }
this->relativeY = (this->relativeY / 2.0f) - (this->height / 2.0f) + this->alignment[1]; this->relativeY = (this->relativeY / 2.0f) - (this->height / 2.0f) + this->alignment[1];
} }
// Update children // Update children
auto it = this->children.begin(); auto it = this->children.begin();
while(it != this->children.end()) { while(it != this->children.end()) {
(*it)->updatePositions(); (*it)->updatePositions();
++it; ++it;
} }
}
// Fire event
float_t UIComponent::getWidth() { eventAlignmentUpdated.invoke(
return this->width; this->width, this->height, this->relativeX, this->relativeY
} );
}
float_t UIComponent::getHeight() {
return this->height; float_t UIComponent::getWidth() {
} return this->width;
}
float_t UIComponent::getRelativeX() {
return this->relativeX; float_t UIComponent::getHeight() {
} return this->height;
}
float_t UIComponent::getRelativeY() {
return this->relativeY; float_t UIComponent::getRelativeX() {
} return this->relativeX;
}
void UIComponent::setTransform(
UIComponentAlign xAlign, float_t UIComponent::getRelativeY() {
UIComponentAlign yAlign, return this->relativeY;
glm::vec4 alignment, }
float_t z
) { void UIComponent::setTransform(
this->alignX = xAlign; UIComponentAlign xAlign,
this->alignY = yAlign; UIComponentAlign yAlign,
this->alignment = alignment; glm::vec4 alignment,
this->z = z; float_t z
this->updatePositions(); ) {
} this->alignX = xAlign;
this->alignY = yAlign;
void UIComponent::draw(UIShader &uiShader, glm::mat4 parentTransform) { this->alignment = alignment;
// Calculate self transform matrix this->z = z;
glm::mat4 selfTransform = parentTransform * glm::translate( this->updatePositions();
glm::mat4(1.0f), glm::vec3(this->relativeX, this->relativeY, this->z) }
);
void UIComponent::draw(UIShader &uiShader, glm::mat4 parentTransform) {
// Draw Self // Calculate self transform matrix
this->drawSelf(uiShader, selfTransform); glm::mat4 selfTransform = parentTransform * glm::translate(
glm::mat4(1.0f), glm::vec3(this->relativeX, this->relativeY, this->z)
// Render children );
auto it = this->children.begin();
while(it != this->children.end()) { // Draw Self
(*it)->draw(uiShader, selfTransform); this->drawSelf(uiShader, selfTransform);
++it;
} // Render children
} auto it = this->children.begin();
while(it != this->children.end()) {
void UIComponent::addChild(UIComponent *child) { (*it)->draw(uiShader, selfTransform);
if(child->parent == this) return; ++it;
if(child->parent != nullptr) child->parent->removeChild(child); }
this->children.push_back(child); }
child->parent = this;
} void UIComponent::addChild(UIComponent *child) {
if(child->parent == this) return;
void UIComponent::removeChild(UIComponent *child) { if(child->parent != nullptr) child->parent->removeChild(child);
if(child->parent != this) throw "Invalid child"; this->children.push_back(child);
auto it = this->children.begin(); child->parent = this;
while(it != this->children.end()) { }
if(*it == child) {
this->children.erase(it); void UIComponent::removeChild(UIComponent *child) {
break; if(child->parent != this) throw "Invalid child";
} auto it = this->children.begin();
++it; while(it != this->children.end()) {
} if(*it == child) {
} this->children.erase(it);
break;
UIComponent::~UIComponent() { }
++it;
}
}
UIComponent::~UIComponent() {
} }

View File

@ -1,82 +1,128 @@
// Copyright (c) 2022 Dominic Masters // Copyright (c) 2022 Dominic Masters
// //
// This software is released under the MIT License. // This software is released under the MIT License.
// https://opensource.org/licenses/MIT // https://opensource.org/licenses/MIT
#pragma once #pragma once
#include "scene/components/ui/UICanvas.hpp" #include "scene/components/ui/UICanvas.hpp"
#include "scene/Scene.hpp" #include "scene/Scene.hpp"
#include "display/Color.hpp" #include "display/Color.hpp"
#include "display/shader/UIShader.hpp" #include "display/shader/UIShader.hpp"
namespace Dawn { namespace Dawn {
enum UIComponentAlign { enum UIComponentAlign {
UI_COMPONENT_ALIGN_START, UI_COMPONENT_ALIGN_START,
UI_COMPONENT_ALIGN_MIDDLE, UI_COMPONENT_ALIGN_MIDDLE,
UI_COMPONENT_ALIGN_END, UI_COMPONENT_ALIGN_END,
UI_COMPONENT_ALIGN_STRETCH UI_COMPONENT_ALIGN_STRETCH
}; };
class UIComponent { class UIComponent {
protected: protected:
// Calculated (and cached) values // Calculated (and cached) values
float_t width = 1; float_t width = 1;
float_t height = 1; float_t height = 1;
float_t relativeX = 0; float_t relativeX = 0;
float_t relativeY = 0; float_t relativeY = 0;
// Setting values // Setting values
UIComponentAlign alignX = UI_COMPONENT_ALIGN_START; UIComponentAlign alignX = UI_COMPONENT_ALIGN_START;
UIComponentAlign alignY = UI_COMPONENT_ALIGN_START; UIComponentAlign alignY = UI_COMPONENT_ALIGN_START;
glm::vec4 alignment = glm::vec4(0, 0, 32, 32); glm::vec4 alignment = glm::vec4(0, 0, 32, 32);
float_t z = 0; float_t z = 0;
std::vector<UIComponent*> children; std::vector<UIComponent*> children;
UIComponent *parent = nullptr; UIComponent *parent = nullptr;
// I currently don't support rotation or scale. Not because I can't but // Events
// because it's basically un-necessary. Unity does support rotation but Event<float_t, float_t, float_t, float_t> eventAlignmentUpdated;
// it doesn't affect how the alignment side of things work (similar to how
// CSS would handle things) When I need to support these I will add the // I currently don't support rotation or scale. Not because I can't but
// code but right now it's not necessary // because it's basically un-necessary. Unity does support rotation but
// it doesn't affect how the alignment side of things work (similar to how
/** // CSS would handle things) When I need to support these I will add the
* Updates the cached/stored values based on the setting internal values. // code but right now it's not necessary
* You should watchdog this if you intend to do something when values are
* updated, e.g. if you need to resize a quad, or something. /**
*/ * Updates the cached/stored values based on the setting internal values.
virtual void updatePositions(); * You should watchdog this if you intend to do something when values are
* updated, e.g. if you need to resize a quad, or something.
public: */
UICanvas &canvas; virtual void updatePositions();
UIComponent(UICanvas &canvas); /**
* Intended to be overwritten by subclass. Called by the draw method to
/** * ask this child to draw.
* Returns the calculated width, based on the internal alignment values. *
* * @param uiShader UI Shader for the child to use.
* @return Width of the component. * @param selfTransform Self alignment transform.
*/ */
float_t getWidth(); virtual void drawSelf(UIShader &uiShader, glm::mat4 selfTransform) = 0;
float_t getHeight();
float_t getRelativeX(); public:
float_t getRelativeY(); UICanvas &canvas;
void setTransform( UIComponent(UICanvas &canvas);
UIComponentAlign xAlign,
UIComponentAlign yAlign, /**
glm::vec4 alignment, * Returns the calculated width, based on the internal alignment values.
float_t z *
); * @return Width of the component.
*/
// virtual void update() = 0; float_t getWidth();
void draw(UIShader &uiShader, glm::mat4 parentTransform);
virtual void drawSelf(UIShader &uiShader, glm::mat4 selfTransform) = 0; /**
* Returns the calculated height, based on the internal alignment values.
void addChild(UIComponent *child); *
void removeChild(UIComponent *child); * @return Height of the component.
*/
virtual ~UIComponent(); float_t getHeight();
friend class UICanvas; /**
}; * Returns the X position, relative to this components' parent.
*
* @return Relative X position.
*/
float_t getRelativeX();
/**
* Returns the Y position, relative to this components' parent.
*
* @return Relative Y position.
*/
float_t getRelativeY();
/**
* Updates the transformation for this component.
*
* @param xAlign X axis alignment method.
* @param yAlign Y axis alignment method.
* @param alignment Alignment parameters, changes depending on the align.
* @param z Z position (relative to screen).
*/
virtual void setTransform(
UIComponentAlign xAlign,
UIComponentAlign yAlign,
glm::vec4 alignment,
float_t z
);
void draw(UIShader &uiShader, glm::mat4 parentTransform);
/**
* Adds a child to this UI Component.
*
* @param child Child UI Component to add.
*/
void addChild(UIComponent *child);
/**
* Removes a child from this UI Component.
*
* @param child Child to remove.
*/
void removeChild(UIComponent *child);
virtual ~UIComponent();
friend class UICanvas;
};
} }

View File

@ -1,63 +1,73 @@
// Copyright (c) 2022 Dominic Masters // Copyright (c) 2022 Dominic Masters
// //
// This software is released under the MIT License. // This software is released under the MIT License.
// https://opensource.org/licenses/MIT // https://opensource.org/licenses/MIT
#include "UILabel.hpp" #include "UILabel.hpp"
using namespace Dawn; using namespace Dawn;
UILabel::UILabel(UICanvas &canvas) : UIComponent(canvas) { UILabel::UILabel(UICanvas &canvas) : UIComponent(canvas) {
} }
void UILabel::updatePositions() { void UILabel::updatePositions() {
UIComponent::updatePositions(); UIComponent::updatePositions();
this->updateMesh(); this->updateMesh();
} }
void UILabel::updateMesh() { void UILabel::updateMesh() {
if(!this->needsRebuffering) return; if(!this->needsRebuffering) return;
if(this->font == nullptr) return; if(this->font == nullptr) return;
if(this->text.size() == 0) return; if(this->text.size() == 0) return;
this->font->buffer( this->font->buffer(
this->text, this->text,
this->fontSize, this->fontSize,
this->getWidth(), this->getWidth(),
this->mesh, this->mesh,
&this->measure &this->measure
); );
this->needsRebuffering = false; this->needsRebuffering = false;
} }
std::string UILabel::getText() { std::string UILabel::getText() {
return this->text; return this->text;
} }
void UILabel::setFont(Font *font) { void UILabel::setFont(Font *font) {
this->font = font; this->font = font;
this->needsRebuffering = true; this->needsRebuffering = true;
} }
void UILabel::setText(std::string text) { void UILabel::setText(std::string text) {
this->text = text; this->text = text;
this->needsRebuffering = true; this->needsRebuffering = true;
} }
void UILabel::setFontSize(float_t fontSize) { void UILabel::setFontSize(float_t fontSize) {
this->fontSize = fontSize; this->fontSize = fontSize;
this->needsRebuffering = true; this->needsRebuffering = true;
} }
void UILabel::drawSelf(UIShader &shader, glm::mat4 selfTransform) { void UILabel::drawSelf(UIShader &shader, glm::mat4 selfTransform) {
if(this->font == nullptr || this->text.size() == 0) return; if(this->font == nullptr || this->text.size() == 0) return;
this->updateMesh(); this->updateMesh();
shader.setUIColor(this->textColor); shader.setUIColor(this->textColor);
shader.setUIModel(selfTransform); shader.setUIModel(selfTransform);
shader.setUITexture(&this->font->getTexture()); shader.setUITexture(&this->font->getTexture());
this->font->draw(this->mesh, this->startQuad, this->quadCount); this->font->draw(this->mesh, this->startQuad, this->quadCount);
}
void UILabel::setTransform(
UIComponentAlign xAlign,
UIComponentAlign yAlign,
glm::vec4 alignment,
float_t z
) {
this->needsRebuffering = true;
UIComponent::setTransform(xAlign, yAlign, alignment, z);
} }

View File

@ -1,67 +1,73 @@
// Copyright (c) 2022 Dominic Masters // Copyright (c) 2022 Dominic Masters
// //
// This software is released under the MIT License. // This software is released under the MIT License.
// https://opensource.org/licenses/MIT // https://opensource.org/licenses/MIT
#pragma once #pragma once
#include "UIComponent.hpp" #include "UIComponent.hpp"
#include "display/mesh/QuadMesh.hpp" #include "display/mesh/QuadMesh.hpp"
#include "display/font/Font.hpp" #include "display/font/Font.hpp"
namespace Dawn { namespace Dawn {
class UILabel : public UIComponent { class UILabel : public UIComponent {
private: private:
Mesh mesh; Mesh mesh;
bool_t needsRebuffering = true; bool_t needsRebuffering = true;
Font *font = nullptr; Font *font = nullptr;
std::string text = ""; std::string text = "";
float_t fontSize = 10.0f; float_t fontSize = 10.0f;
void updatePositions() override; void updatePositions() override;
public: public:
struct FontMeasure measure; struct FontMeasure measure;
int32_t startQuad = 0; int32_t startQuad = 0;
int32_t quadCount = -1; int32_t quadCount = -1;
/** The colour of this label */ /** The colour of this label */
struct Color textColor = COLOR_MAGENTA; struct Color textColor = COLOR_MAGENTA;
UILabel(UICanvas &canvas); UILabel(UICanvas &canvas);
void drawSelf(UIShader &shader, glm::mat4 selfTransform) override; void drawSelf(UIShader &shader, glm::mat4 selfTransform) override;
void setTransform(
/** UIComponentAlign xAlign,
* Internal method to force the font mesh to be recreated. UIComponentAlign yAlign,
*/ glm::vec4 alignment,
void updateMesh(); float_t z
) override;
/**
* Returns the current text that the label has. /**
* * Internal method to force the font mesh to be recreated.
* @return The current label string. */
*/ void updateMesh();
std::string getText();
/**
/** * Returns the current text that the label has.
* Set the font to use for the label. *
* * @return The current label string.
* @param font Font to use. */
*/ std::string getText();
void setFont(Font *font);
/**
/** * Set the font to use for the label.
* Sets the text for the label to use. *
* * @param font Font to use.
* @param text Text for the label to use. */
*/ void setFont(Font *font);
void setText(std::string text);
/**
/** * Sets the text for the label to use.
* Sets / Updates the font size for the label. *
* * @param text Text for the label to use.
* @param fontSize Font size to use. */
*/ void setText(std::string text);
void setFontSize(float_t fontSize);
/**
}; * Sets / Updates the font size for the label.
*
* @param fontSize Font size to use.
*/
void setFontSize(float_t fontSize);
};
} }

View File

@ -1,28 +1,28 @@
// Copyright (c) 2022 Dominic Masters // Copyright (c) 2022 Dominic Masters
// //
// This software is released under the MIT License. // This software is released under the MIT License.
// https://opensource.org/licenses/MIT // https://opensource.org/licenses/MIT
#pragma once #pragma once
#include "UIComponent.hpp" #include "UIComponent.hpp"
#include "display/mesh/QuadMesh.hpp" #include "display/mesh/QuadMesh.hpp"
#include "display/Texture.hpp" #include "display/Texture.hpp"
namespace Dawn { namespace Dawn {
class UISprite : public UIComponent { class UISprite : public UIComponent {
protected: protected:
void updatePositions() override; void updatePositions() override;
void drawSelf(UIShader &uiShader, glm::mat4 selfTransform) override;
public:
Mesh mesh; public:
Texture *texture; Mesh mesh;
Texture *texture;
/**
* UI Sprite Constructor, use the UIElement / UIComponent create instead. /**
* * UI Sprite Constructor, use the UIElement / UIComponent create instead.
* @param canvas Canvas that this sprite belongs to. *
*/ * @param canvas Canvas that this sprite belongs to.
UISprite(UICanvas &canvas); */
void drawSelf(UIShader &uiShader, glm::mat4 selfTransform) override; UISprite(UICanvas &canvas);
}; };
} }

View File

@ -1,8 +1,13 @@
# Copyright (c) 2022 Dominic Masters # Copyright (c) 2022 Dominic Masters
# #
# This software is released under the MIT License. # This software is released under the MIT License.
# https://opensource.org/licenses/MIT # https://opensource.org/licenses/MIT
# Sources
# Subdirs target_sources(${DAWN_TARGET_NAME}
PRIVATE
VisualNovelManager.cpp
)
# Subdirs
add_subdirectory(ui) add_subdirectory(ui)

View File

@ -3,6 +3,10 @@
// This software is released under the MIT License. // This software is released under the MIT License.
// https://opensource.org/licenses/MIT // https://opensource.org/licenses/MIT
#pragma once #include "VisualNovelManager.hpp"
#include "game/DawnGame.hpp"
#include "scene/components/Components.hpp" using namespace Dawn;
VisualNovelManager::VisualNovelManager() {
}

View File

@ -0,0 +1,16 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "dawnlibs.hpp"
namespace Dawn {
class VisualNovelManager {
protected:
public:
VisualNovelManager();
};
}

View File

@ -1,160 +1,162 @@
// Copyright (c) 2022 Dominic Masters // Copyright (c) 2022 Dominic Masters
// //
// This software is released under the MIT License. // This software is released under the MIT License.
// https://opensource.org/licenses/MIT // https://opensource.org/licenses/MIT
#include "VisualNovelTextbox.hpp" #include "VisualNovelTextbox.hpp"
#include "game/DawnGame.hpp" #include "game/DawnGame.hpp"
using namespace Dawn; using namespace Dawn;
VisualNovelTextbox::VisualNovelTextbox(UICanvas &canvas) : VisualNovelTextbox::VisualNovelTextbox(UICanvas &canvas) :
UIComponent(canvas), UIComponent(canvas),
border(canvas), border(canvas),
label(canvas) label(canvas)
{ {
// Border // Border
this->addChild(&this->border); this->addChild(&this->border);
// Label // Label
this->addChild(&this->label); this->addChild(&this->label);
this->label.startQuad = 0; this->label.startQuad = 0;
this->label.quadCount = 0; this->label.quadCount = 0;
this->updateSelfTransform(); this->canvas.getScene().eventSceneUnpausedUpdate.addListener(
this, &VisualNovelTextbox::textboxOnSceneUpdate
this->canvas.getScene().eventSceneUnpausedUpdate.addListener( );
this, &VisualNovelTextbox::textboxOnSceneUpdate }
);
} void VisualNovelTextbox::updatePositions() {
UIComponent::updatePositions();
void VisualNovelTextbox::updatePositions() {
UIComponent::updatePositions(); this->lineCurrent = 0;
this->timeCharacter = 0;
this->lineCurrent = 0;
this->timeCharacter = 0; this->border.setTransform(
UI_COMPONENT_ALIGN_STRETCH, UI_COMPONENT_ALIGN_STRETCH,
this->border.setTransform( glm::vec4(0, 0, 0, 0),
UI_COMPONENT_ALIGN_STRETCH, UI_COMPONENT_ALIGN_STRETCH, 0.0f
glm::vec4(0, 0, 0, 0), );
0.0f
); this->label.setTransform(
UI_COMPONENT_ALIGN_STRETCH,
this->label.setTransform( UI_COMPONENT_ALIGN_STRETCH,
UI_COMPONENT_ALIGN_STRETCH, glm::vec4(
UI_COMPONENT_ALIGN_STRETCH, this->border.getBorderSize() + this->labelPadding,
glm::vec4( this->border.getBorderSize() + this->labelPadding
this->border.getBorderSize() + this->labelPadding, ),
this->border.getBorderSize() + this->labelPadding 1.0f
), );
1.0f
); this->label.startQuad = 0;
this->label.quadCount = 0;
this->label.startQuad = 0; }
this->label.quadCount = 0;
} void VisualNovelTextbox::textboxOnSceneUpdate() {
DawnGame &game = this->canvas.getGame();
void VisualNovelTextbox::textboxOnSceneUpdate() {
DawnGame &game = this->canvas.getGame(); if(this->hasRevealedAllCurrentCharacters()) {
if(this->hasRevealedAllCharacters()) {
if(this->hasRevealedAllCurrentCharacters()) { if(game.inputManager.isPressed(INPUT_BIND_ACCEPT)) {
if(this->hasRevealedAllCharacters()) { this->eventClose.invoke();
if(game.inputManager.isPressed(INPUT_BIND_ACCEPT)) { }
std::cout << "Bruh" << std::endl; } else {
} if(game.inputManager.isPressed(INPUT_BIND_ACCEPT)) {
} else { this->lineCurrent += this->getCountOfVisibleLines();
if(game.inputManager.isPressed(INPUT_BIND_ACCEPT)) { this->label.startQuad = 0;
this->lineCurrent += VISUAL_NOVEL_TEXTBOX_LINES_MAX; for(int32_t i = 0; i < this->lineCurrent; i++) {
this->label.startQuad = 0; this->label.startQuad += this->label.measure.getQuadsOnLine(i);
for(int32_t i = 0; i < this->lineCurrent; i++) { }
this->label.startQuad += this->label.measure.getQuadsOnLine(i); this->label.quadCount = 0;
} this->timeCharacter = 0.0f;
this->label.quadCount = 0;
this->timeCharacter = 0.0f; this->label.setTransform(
UI_COMPONENT_ALIGN_STRETCH,
this->label.setTransform( UI_COMPONENT_ALIGN_STRETCH,
UI_COMPONENT_ALIGN_STRETCH, glm::vec4(
UI_COMPONENT_ALIGN_STRETCH, glm::vec2(
glm::vec4( this->border.getBorderSize().x + this->labelPadding.x,
glm::vec2( this->border.getBorderSize().y + this->labelPadding.y -
this->border.getBorderSize().x + this->labelPadding.x, this->label.measure.getHeightOfLineCount(this->lineCurrent)
this->border.getBorderSize().y + this->labelPadding.y - ),
this->label.measure.getHeightOfLineCount(this->lineCurrent) this->border.getBorderSize() + this->labelPadding
), ),
this->border.getBorderSize() + this->labelPadding 1.0f
), );
1.0f this->eventNewPage.invoke();
); }
} }
} return;
return; }
}
auto lastTimeCharacter = (int32_t)mathFloorFloat(this->timeCharacter);
if(game.inputManager.isDown(INPUT_BIND_ACCEPT)) { if(game.inputManager.isDown(INPUT_BIND_ACCEPT)) {
this->timeCharacter += game.timeManager.delta * VISUAL_NOVEL_TEXTBOX_SPEED_FASTER; this->timeCharacter += game.timeManager.delta * VISUAL_NOVEL_TEXTBOX_SPEED_FASTER;
} else { } else {
this->timeCharacter += game.timeManager.delta * VISUAL_NOVEL_TEXTBOX_SPEED; this->timeCharacter += game.timeManager.delta * VISUAL_NOVEL_TEXTBOX_SPEED;
} }
this->label.quadCount = (int32_t)mathFloorFloat(this->timeCharacter); auto newTimeCharacter = (int32_t)mathFloorFloat(this->timeCharacter);
} if(newTimeCharacter == lastTimeCharacter) return;
void VisualNovelTextbox::updateSelfTransform() { this->label.quadCount = newTimeCharacter;
float_t height; this->eventCharacterRevealed.invoke();
}
height = this->label.measure.getHeightOfLineCount(VISUAL_NOVEL_TEXTBOX_LINES_MAX);
int32_t VisualNovelTextbox::getCountOfVisibleLines() {
this->setTransform( int32_t i = 1;
UI_COMPONENT_ALIGN_STRETCH, UI_COMPONENT_ALIGN_START, glm::vec2 innerSize = this->border.getInnerSize() - this->labelPadding;
glm::vec4(0, 0, 0, height + (this->border.getBorderSize().y * 2)),
0 for(i = this->label.measure.getLineCount(); i > 0; --i) {
); if(innerSize.y >= this->label.measure.getHeightOfLineCount(i)) {
} return i;
}
void VisualNovelTextbox::drawSelf(UIShader &shader, glm::mat4 self) {} }
return this->label.measure.getLineCount();
void VisualNovelTextbox::setBorder(Texture *texture, glm::vec2 dimensions) { }
this->border.texture = texture;
this->border.setBorderSize(dimensions); void VisualNovelTextbox::drawSelf(UIShader &shader, glm::mat4 self) {}
this->updatePositions();
} void VisualNovelTextbox::setBorder(Texture *texture, glm::vec2 dimensions) {
this->border.texture = texture;
void VisualNovelTextbox::setFont(Font *font) { this->border.setBorderSize(dimensions);
this->label.setFont(font); this->updatePositions();
this->label.updateMesh(); }
this->updateSelfTransform();
} void VisualNovelTextbox::setFont(Font *font) {
this->label.setFont(font);
void VisualNovelTextbox::setText(std::string text, float_t fontSize) { this->label.updateMesh();
this->label.setText(text); }
this->label.setFontSize(fontSize);
this->label.updateMesh(); void VisualNovelTextbox::setText(std::string text, float_t fontSize) {
this->updateSelfTransform(); this->label.setText(text);
} this->label.setFontSize(fontSize);
this->label.updateMesh();
bool_t VisualNovelTextbox::hasRevealedAllCurrentCharacters() { }
int32_t quadsTotal = 0;
for( bool_t VisualNovelTextbox::hasRevealedAllCurrentCharacters() {
int32_t i = this->lineCurrent; int32_t quadsTotal = 0;
i < mathMin<int32_t>( for(
this->label.measure.getLineCount(), int32_t i = this->lineCurrent;
this->lineCurrent + VISUAL_NOVEL_TEXTBOX_LINES_MAX i < mathMin<int32_t>(
); this->label.measure.getLineCount(),
i++ this->lineCurrent + this->getCountOfVisibleLines()
) { );
quadsTotal += this->label.measure.getQuadsOnLine(i); i++
} ) {
return mathFloorFloat(this->timeCharacter) >= quadsTotal; quadsTotal += this->label.measure.getQuadsOnLine(i);
} }
return mathFloorFloat(this->timeCharacter) >= quadsTotal;
bool_t VisualNovelTextbox::hasRevealedAllCharacters() { }
return (
this->lineCurrent + VISUAL_NOVEL_TEXTBOX_LINES_MAX >= bool_t VisualNovelTextbox::hasRevealedAllCharacters() {
this->label.measure.getLineCount() return (
); this->lineCurrent + this->getCountOfVisibleLines() >=
} this->label.measure.getLineCount()
);
VisualNovelTextbox::~VisualNovelTextbox() { }
this->canvas.getScene().eventSceneUnpausedUpdate.removeListener(
this, &VisualNovelTextbox::textboxOnSceneUpdate VisualNovelTextbox::~VisualNovelTextbox() {
); this->canvas.getScene().eventSceneUnpausedUpdate.removeListener(
this, &VisualNovelTextbox::textboxOnSceneUpdate
);
} }

View File

@ -1,43 +1,60 @@
// Copyright (c) 2022 Dominic Masters // Copyright (c) 2022 Dominic Masters
// //
// This software is released under the MIT License. // This software is released under the MIT License.
// https://opensource.org/licenses/MIT // https://opensource.org/licenses/MIT
#pragma once #pragma once
#include "ui/UISprite.hpp" #include "ui/UISprite.hpp"
#include "ui/UIBorder.hpp" #include "ui/UIBorder.hpp"
#include "ui/UILabel.hpp" #include "ui/UILabel.hpp"
#include "util/mathutils.hpp" #include "util/mathutils.hpp"
#define VISUAL_NOVEL_TEXTBOX_SPEED 25.0f #define VISUAL_NOVEL_TEXTBOX_SPEED 25.0f
#define VISUAL_NOVEL_TEXTBOX_SPEED_FASTER 40.0f #define VISUAL_NOVEL_TEXTBOX_SPEED_FASTER 40.0f
#define VISUAL_NOVEL_TEXTBOX_LINES_MAX 4
namespace Dawn {
namespace Dawn { class VisualNovelTextbox : public UIComponent {
class VisualNovelTextbox : public UIComponent { private:
private: int32_t lineCurrent = 0;
int32_t lineCurrent = 0; glm::vec2 labelPadding = glm::vec2(0, 0);
glm::vec2 labelPadding = glm::vec2(0, 0); UIBorder border;
UIBorder border; UILabel label;
UILabel label; float_t timeCharacter = 0.0f;
float_t timeCharacter = 0.0f;
void updatePositions() override;
void updatePositions() override; void drawSelf(UIShader &shader, glm::mat4 selfTransform) override;
void textboxOnSceneUpdate();
void updateSelfTransform(); /**
* Listens for scene updates.
public: */
VisualNovelTextbox(UICanvas &canvas); void textboxOnSceneUpdate();
void drawSelf(UIShader &shader, glm::mat4 selfTransform) override; /**
* Returns the count of visible lines within the textbox. Mostly used for
void setFont(Font *font); * when we need to decide how to wrap.
void setBorder(Texture *texture, glm::vec2 dimensions); *
void setText(std::string text, float_t fontSize); * @return The count of visible lines.
*/
bool_t hasRevealedAllCurrentCharacters(); int32_t getCountOfVisibleLines();
bool_t hasRevealedAllCharacters();
public:
~VisualNovelTextbox(); Event<> eventCharacterRevealed;
}; Event<> eventCurrentCharactersRevealed;
Event<> eventNewPage;
Event<> eventAllCharactersRevealed;
Event<> eventClose;
VisualNovelTextbox(UICanvas &canvas);
void setFont(Font *font);
void setBorder(Texture *texture, glm::vec2 dimensions);
void setText(std::string text, float_t fontSize);
bool_t hasRevealedAllCurrentCharacters();
bool_t hasRevealedAllCharacters();
~VisualNovelTextbox();
};
} }

View File

@ -1,19 +1,20 @@
# Copyright (c) 2022 Dominic Masters # Copyright (c) 2022 Dominic Masters
# #
# This software is released under the MIT License. # This software is released under the MIT License.
# https://opensource.org/licenses/MIT # https://opensource.org/licenses/MIT
# Set up the executable # Set up the executable
set(DAWN_TARGET_NAME "PokerGame" CACHE INTERNAL ${DAWN_CACHE_TARGET}) set(DAWN_TARGET_NAME "PokerGame" CACHE INTERNAL ${DAWN_CACHE_TARGET})
# Build Project # Build Project
add_executable(${DAWN_TARGET_NAME}) add_executable(${DAWN_TARGET_NAME})
# Includes # Includes
target_include_directories(${DAWN_TARGET_NAME} target_include_directories(${DAWN_TARGET_NAME}
PUBLIC PUBLIC
${CMAKE_CURRENT_LIST_DIR} ${CMAKE_CURRENT_LIST_DIR}
) )
# Subdirs # Subdirs
add_subdirectory(game) add_subdirectory(game)
add_subdirectory(ui)

View File

@ -1,14 +1,14 @@
# Copyright (c) 2022 Dominic Masters # Copyright (c) 2022 Dominic Masters
# #
# This software is released under the MIT License. # This software is released under the MIT License.
# https://opensource.org/licenses/MIT # https://opensource.org/licenses/MIT
# Sources # Sources
target_sources(${DAWN_TARGET_NAME} target_sources(${DAWN_TARGET_NAME}
PRIVATE PRIVATE
DawnPokerGame.cpp DawnGame.cpp
) )
tool_texture(texture_test texture_test.png texture_test) tool_texture(texture_test texture_test.png texture_test)
add_dependencies(${DAWN_TARGET_NAME} texture_test) add_dependencies(${DAWN_TARGET_NAME} texture_test)

View File

@ -1,72 +1,64 @@
// Copyright (c) 2022 Dominic Masters // Copyright (c) 2022 Dominic Masters
// //
// This software is released under the MIT License. // This software is released under the MIT License.
// https://opensource.org/licenses/MIT // https://opensource.org/licenses/MIT
#include "DawnPokerGame.hpp" #include "DawnGame.hpp"
#include "asset/assets/TextureAsset.hpp" #include "asset/assets/TextureAsset.hpp"
#include "asset/assets/TrueTypeAsset.hpp" #include "asset/assets/TrueTypeAsset.hpp"
#include "visualnovel/ui/VisualNovelTextbox.hpp" #include "visualnovel/ui/VisualNovelTextbox.hpp"
using namespace Dawn; using namespace Dawn;
std::shared_ptr<TrueTypeAsset> assetFont; std::shared_ptr<TrueTypeAsset> assetFont;
std::shared_ptr<TextureAsset> assetTexture; std::shared_ptr<TextureAsset> assetTexture;
DawnGame::DawnGame(DawnHost &host) : DawnGame::DawnGame(DawnHost &host) :
host(host), host(host),
renderManager(*this), renderManager(*this),
inputManager(*this) inputManager(*this)
{ {
} }
int32_t DawnGame::init() { int32_t DawnGame::init() {
this->assetManager.init(); this->assetManager.init();
this->renderManager.init(); this->renderManager.init();
this->scene = std::make_shared<Scene>(*this); this->scene = std::make_shared<Scene>(*this);
auto cameraObject = this->scene->createSceneItem(); auto cameraObject = this->scene->createSceneItem();
auto camera = cameraObject->addComponent<Camera>(); auto camera = cameraObject->addComponent<Camera>();
camera->transform.lookAt(glm::vec3(50, 50, 50), glm::vec3(0, 0, 0)); camera->transform.lookAt(glm::vec3(50, 50, 50), glm::vec3(0, 0, 0));
auto canvas = UICanvas::createCanvas(this->scene); auto canvas = UICanvas::createCanvas(this->scene);
assetFont = this->assetManager.load<TrueTypeAsset>("truetype_ark"); assetFont = this->assetManager.load<TrueTypeAsset>("truetype_ark");
assetTexture = this->assetManager.load<TextureAsset>("texture_test"); assetTexture = this->assetManager.load<TextureAsset>("texture_test");
while(!assetFont->loaded || !assetTexture->loaded) { while(!assetFont->loaded || !assetTexture->loaded) {
this->assetManager.update(); this->assetManager.update();
} }
auto textbox = canvas->addElement<VisualNovelTextbox>(); auto textbox = canvas->addElement<VisualNovelTextbox>();
textbox->setBorder(assetTexture->texture.get(), glm::vec2(16, 16)); textbox->setBorder(assetTexture->texture.get(), glm::vec2(16, 16));
textbox->setFont(&assetFont->font); textbox->setFont(&assetFont->font);
textbox->setText("1\n2\n3\n4\n5\n6\n7\n8\n9\n10", 40); textbox->setText("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus leo odio, egestas nec imperdiet ac, placerat eget quam. Nam tellus justo, aliquam sed porta quis, ullamcorper in libero. Proin auctor eget elit nec rutrum. Vestibulum tincidunt sem vel nisi sagittis, sed imperdiet eros aliquet. Fusce a ultrices augue, at auctor lacus. Sed lobortis, ante vitae vehicula egestas, lorem turpis cursus dui, sit amet egestas mauris ligula non ipsum. Pellentesque scelerisque posuere lorem sit amet tempor. Praesent ac hendrerit mi. Nulla mollis diam vitae vestibulum aliquam. Nullam metus justo, viverra sed risus eu, tincidunt sodales lacus. Quisque efficitur accumsan posuere. Aliquam posuere volutpat diam quis lacinia. Nullam blandit nulla vestibulum mi placerat varius. Proin egestas lacus nec pellentesque iaculis. Vestibulum ex metus, congue in eleifend et, scelerisque a nulla. Pellentesque cursus lectus sed arcu efficitur tincidunt. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nulla a felis non velit fermentum ullamcorper.", 40);
textbox->setTransform(
// auto sprite = canvas->addElement<UISprite>(); UI_COMPONENT_ALIGN_START, UI_COMPONENT_ALIGN_START,
// sprite->setTransform( glm::vec4(100, 100, 300, 300),
// UI_COMPONENT_ALIGN_START, 0.0f
// UI_COMPONENT_ALIGN_START, );
// glm::vec4(0, 0, 200, 200),
// 0 return DAWN_GAME_INIT_RESULT_SUCCESS;
// ); }
// sprite->texture = &asset->font.getTexture();
int32_t DawnGame::update(float_t delta) {
return DAWN_GAME_INIT_RESULT_SUCCESS; this->assetManager.update();
} this->inputManager.update();
this->timeManager.update(delta);
int32_t DawnGame::update(float_t delta) {
this->assetManager.update(); if(this->scene != nullptr) this->scene->update();
this->inputManager.update();
this->timeManager.update(delta); this->renderManager.update();
if(this->scene != nullptr) this->scene->update(); return DAWN_GAME_UPDATE_RESULT_SUCCESS;
this->renderManager.update();
return DAWN_GAME_UPDATE_RESULT_SUCCESS;
}
DawnGame::~DawnGame() {
} }

View File

@ -0,0 +1,23 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "game/_DawnGame.hpp"
#include "scene/components/Components.hpp"
namespace Dawn {
class DawnGame : public IDawnGame {
public:
DawnHost &host;
RenderManager renderManager;
AssetManager assetManager;
InputManager inputManager;
TimeManager timeManager;
DawnGame(DawnHost &host);
int32_t init() override;
int32_t update(float_t delta) override;
};
}

View File

@ -0,0 +1,10 @@
# Copyright (c) 2022 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Sources
target_sources(${DAWN_TARGET_NAME}
PRIVATE
PokerGameTextbox.cpp
)

View File

@ -0,0 +1,12 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "PokerGameTextbox.hpp"
using namespace Dawn;
std::shared_ptr<VisualNovelTextbox> PokerGameTextbox::makeTextbox() {
return nullptr;
}

View File

@ -0,0 +1,14 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "visualnovel/ui/VisualNovelTextbox.hpp"
namespace Dawn {
class PokerGameTextbox {
public:
static std::shared_ptr<VisualNovelTextbox> makeTextbox();
};
}