Lots of UI Component Updates
This commit is contained in:
@ -21,4 +21,5 @@ add_subdirectory(asset)
|
||||
add_subdirectory(display)
|
||||
add_subdirectory(input)
|
||||
add_subdirectory(scene)
|
||||
add_subdirectory(ui)
|
||||
add_subdirectory(ui)
|
||||
add_subdirectory(visualnovel)
|
@ -146,8 +146,6 @@ namespace Dawn {
|
||||
++bindIt;
|
||||
}
|
||||
|
||||
std::cout << "Bind " << it->first << ": " << value << std::endl;
|
||||
|
||||
// Set into current values
|
||||
if(this->currentIsLeft) {
|
||||
this->valuesLeft[it->first] = value;
|
||||
|
@ -16,7 +16,42 @@ SceneItem::SceneItem(Scene &scene, sceneitemid_t id) :
|
||||
}
|
||||
|
||||
void SceneItem::init() {
|
||||
|
||||
// Keep checking all components until they have all inited
|
||||
int32_t waitingOn;
|
||||
do {
|
||||
waitingOn = 0;
|
||||
|
||||
// For each component
|
||||
auto it = this->components.begin();
|
||||
while(it != this->components.end()) {
|
||||
// Has this component already inited?
|
||||
if((*it)->hasInitialized) {
|
||||
++it;
|
||||
continue;
|
||||
}
|
||||
|
||||
// For each dependency.
|
||||
auto deps = (*it)->getDependencies();
|
||||
bool_t waiting = false;
|
||||
auto it2 = deps.begin();
|
||||
while(it2 != deps.end()) {
|
||||
// Has the dep not yet inited?
|
||||
if(!(*it2)->hasInitialized) {
|
||||
waiting = true;
|
||||
break;
|
||||
}
|
||||
++it2;
|
||||
}
|
||||
|
||||
// Are we waiting for a dep?
|
||||
if(waiting) {
|
||||
waitingOn++;
|
||||
} else {
|
||||
(*it)->init();
|
||||
}
|
||||
++it;
|
||||
}
|
||||
} while(waitingOn != 0);
|
||||
}
|
||||
|
||||
SceneItem::~SceneItem() {
|
||||
|
@ -6,6 +6,7 @@
|
||||
#pragma once
|
||||
#include "SceneItemComponent.hpp"
|
||||
#include "display/Transform.hpp"
|
||||
#include "event/Event.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
typedef int32_t sceneitemid_t;
|
||||
|
@ -16,6 +16,15 @@ SceneItemComponent::SceneItemComponent(SceneItem &item) :
|
||||
{
|
||||
}
|
||||
|
||||
void SceneItemComponent::init() {
|
||||
this->onStart();
|
||||
this->hasInitialized = true;
|
||||
}
|
||||
|
||||
std::vector<SceneItemComponent*> SceneItemComponent::getDependencies() {
|
||||
return std::vector<SceneItemComponent*>();
|
||||
}
|
||||
|
||||
Scene & SceneItemComponent::getScene() {
|
||||
return this->item.scene;
|
||||
}
|
||||
@ -24,6 +33,10 @@ DawnGame & SceneItemComponent::getGame() {
|
||||
return this->item.scene.game;
|
||||
}
|
||||
|
||||
void SceneItemComponent::onStart() {
|
||||
|
||||
}
|
||||
|
||||
SceneItemComponent::~SceneItemComponent() {
|
||||
|
||||
}
|
@ -16,6 +16,7 @@ namespace Dawn {
|
||||
public:
|
||||
SceneItem &item;
|
||||
Transform &transform;
|
||||
bool_t hasInitialized = false;
|
||||
|
||||
/**
|
||||
* Constructs a new SceneItemComponent. Components are attached to
|
||||
@ -28,9 +29,17 @@ namespace Dawn {
|
||||
|
||||
/**
|
||||
* Requested on the first frame that the parent scene item has become
|
||||
* active.
|
||||
* active, after all of my dependencies are ready.
|
||||
*/
|
||||
virtual void start() = 0;
|
||||
void init();
|
||||
|
||||
/**
|
||||
* Optionally return all dependencies for this component to wait for init
|
||||
* for before the component will be initialized.
|
||||
*
|
||||
* @return Array of dependencies.
|
||||
*/
|
||||
virtual std::vector<SceneItemComponent*> getDependencies();
|
||||
|
||||
/**
|
||||
* Shorthand to return the scene that this component's item belongs to.
|
||||
@ -44,6 +53,11 @@ namespace Dawn {
|
||||
*/
|
||||
DawnGame & getGame();
|
||||
|
||||
/**
|
||||
* Same as init, but intended for your subclass to override.
|
||||
*/
|
||||
virtual void onStart();
|
||||
|
||||
/**
|
||||
* Cleanup the SceneItemComponent.
|
||||
*/
|
||||
|
@ -65,7 +65,7 @@ float_t Camera::getAspect() {
|
||||
return target.getWidth() / target.getHeight();
|
||||
}
|
||||
|
||||
void Camera::start() {
|
||||
void Camera::onStart() {
|
||||
this->updateProjection();
|
||||
}
|
||||
|
||||
|
@ -73,7 +73,7 @@ namespace Dawn {
|
||||
/**
|
||||
* Event triggered by the scene item when the item is added to the scene.
|
||||
*/
|
||||
void start() override;
|
||||
void onStart() override;
|
||||
|
||||
/**
|
||||
* Disposes a previously initialized camera.
|
||||
|
@ -65,7 +65,4 @@ std::shared_ptr<Shader> Material::getShader() {
|
||||
void Material::setShader(std::shared_ptr<Shader> shader) {
|
||||
this->shader = shader;
|
||||
this->updateShaderParameters();
|
||||
}
|
||||
|
||||
void Material::start() {
|
||||
}
|
@ -58,10 +58,5 @@ namespace Dawn {
|
||||
* This method assumes that the shader has already been bound.
|
||||
*/
|
||||
void setShaderParameters();
|
||||
|
||||
/**
|
||||
* Overrides the default SceneItemComponent start method.
|
||||
*/
|
||||
void start() override;
|
||||
};
|
||||
}
|
@ -11,8 +11,4 @@ MeshRenderer::MeshRenderer(SceneItem &item) :
|
||||
SceneItemComponent(item)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void MeshRenderer::start() {
|
||||
|
||||
}
|
@ -18,10 +18,5 @@ namespace Dawn {
|
||||
* @param item Scene Item this mesh renderer belongs to.
|
||||
*/
|
||||
MeshRenderer(SceneItem &item);
|
||||
|
||||
/**
|
||||
* Overrides the default SceneItemComponent start method.
|
||||
*/
|
||||
void start() override;
|
||||
};
|
||||
}
|
@ -16,7 +16,6 @@ std::shared_ptr<UICanvas> UICanvas::createCanvas(std::shared_ptr<Scene> scene) {
|
||||
}
|
||||
|
||||
UICanvas::UICanvas(SceneItem &item) : SceneItemComponent(item) {
|
||||
|
||||
}
|
||||
|
||||
float_t UICanvas::getWidth() {
|
||||
@ -27,6 +26,27 @@ float_t UICanvas::getHeight() {
|
||||
return this->getGame().renderManager.getBackBuffer().getHeight();
|
||||
}
|
||||
|
||||
void UICanvas::start() {
|
||||
void UICanvas::onStart() {
|
||||
std::cout << "Canvas event" << std::endl;
|
||||
this->getGame().renderManager.getBackBuffer()
|
||||
.eventRenderTargetResized.addListener(this, &UICanvas::onBackBufferResize)
|
||||
;
|
||||
}
|
||||
|
||||
void UICanvas::onBackBufferResize(
|
||||
RenderTarget &target,
|
||||
float_t width,
|
||||
float_t height
|
||||
) {
|
||||
auto it = this->children.begin();
|
||||
while(it != this->children.end()) {
|
||||
(*it)->updatePositions();
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
UICanvas::~UICanvas() {
|
||||
this->getGame().renderManager.getBackBuffer()
|
||||
.eventRenderTargetResized.removeListener(this, &UICanvas::onBackBufferResize)
|
||||
;
|
||||
}
|
@ -5,6 +5,7 @@
|
||||
|
||||
#pragma once
|
||||
#include "scene/SceneItemComponent.hpp"
|
||||
#include "display/RenderTarget.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
enum UIDrawType {
|
||||
@ -16,6 +17,13 @@ namespace Dawn {
|
||||
class UIComponent;
|
||||
|
||||
class UICanvas : public SceneItemComponent {
|
||||
protected:
|
||||
void onBackBufferResize(
|
||||
RenderTarget &target,
|
||||
float_t width,
|
||||
float_t height
|
||||
);
|
||||
|
||||
public:
|
||||
static std::shared_ptr<UICanvas> createCanvas(
|
||||
std::shared_ptr<Scene> scene
|
||||
@ -37,6 +45,8 @@ namespace Dawn {
|
||||
float_t getWidth();
|
||||
float_t getHeight();
|
||||
|
||||
void start() override;
|
||||
void onStart() override;
|
||||
|
||||
~UICanvas();
|
||||
};
|
||||
}
|
@ -6,6 +6,7 @@
|
||||
# Sources
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
UIBorder.cpp
|
||||
UIComponent.cpp
|
||||
UILabel.cpp
|
||||
UISprite.cpp
|
||||
|
130
src/dawn/ui/UIBorder.cpp
Normal file
130
src/dawn/ui/UIBorder.cpp
Normal file
@ -0,0 +1,130 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "UIBorder.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
UIBorder::UIBorder(UICanvas &canvas) : UIComponent(canvas) {
|
||||
this->mesh.createBuffers(QUAD_VERTICE_COUNT * 9, QUAD_INDICE_COUNT * 9);
|
||||
|
||||
this->texture = new Texture();
|
||||
this->texture->setSize(3, 3);
|
||||
struct Color pixels[9] = {
|
||||
COLOR_WHITE, COLOR_RED, COLOR_BLUE,
|
||||
COLOR_GREEN, COLOR_MAGENTA, COLOR_BLACK,
|
||||
COLOR_CORNFLOWER_BLUE, COLOR_WHITE, COLOR_MAGENTA
|
||||
};
|
||||
this->texture->buffer(pixels);
|
||||
|
||||
this->updatePositions();
|
||||
}
|
||||
|
||||
void UIBorder::updatePositions() {
|
||||
UIComponent::updatePositions();
|
||||
|
||||
glm::vec2 oneThird = this->uv1 / 3.0f;
|
||||
glm::vec2 overallDimensions = glm::vec2(this->getWidth(), this->getHeight());
|
||||
glm::vec2 innerDimensions = overallDimensions - (this->edgeDimensions * 2.0f);
|
||||
|
||||
// Top Left.
|
||||
QuadMesh::bufferQuadMesh(this->mesh,
|
||||
glm::vec2(0, 0),
|
||||
this->uv0,
|
||||
edgeDimensions,
|
||||
this->uv0 + oneThird,
|
||||
0, 0
|
||||
);
|
||||
|
||||
// Top Center
|
||||
QuadMesh::bufferQuadMesh(this->mesh,
|
||||
glm::vec2(edgeDimensions.x, 0),
|
||||
this->uv0 + glm::vec2(oneThird.x, 0),
|
||||
glm::vec2(edgeDimensions.x + innerDimensions.x, edgeDimensions.y),
|
||||
this->uv0 + glm::vec2(oneThird.x * 2.0f, oneThird.y),
|
||||
QUAD_VERTICE_COUNT, QUAD_INDICE_COUNT
|
||||
);
|
||||
|
||||
// Top Right
|
||||
QuadMesh::bufferQuadMesh(this->mesh,
|
||||
glm::vec2(edgeDimensions.x + innerDimensions.x, 0),
|
||||
this->uv0 + glm::vec2(oneThird.x * 2.0f, 0),
|
||||
glm::vec2(overallDimensions.x, edgeDimensions.y),
|
||||
glm::vec2(this->uv1.x, this->uv0.y + oneThird.y),
|
||||
QUAD_VERTICE_COUNT * 2, QUAD_INDICE_COUNT * 2
|
||||
);
|
||||
|
||||
// Middle Left
|
||||
QuadMesh::bufferQuadMesh(this->mesh,
|
||||
glm::vec2(0, edgeDimensions.y),
|
||||
this->uv0 + glm::vec2(0, oneThird.y),
|
||||
glm::vec2(edgeDimensions.x, edgeDimensions.y + innerDimensions.y),
|
||||
this->uv0 + glm::vec2(oneThird.x, oneThird.y * 2.0f),
|
||||
QUAD_VERTICE_COUNT * 3, QUAD_INDICE_COUNT * 3
|
||||
);
|
||||
|
||||
// Center
|
||||
QuadMesh::bufferQuadMesh(this->mesh,
|
||||
edgeDimensions,
|
||||
this->uv0 + oneThird,
|
||||
edgeDimensions + innerDimensions,
|
||||
this->uv0 + (oneThird * 2.0f),
|
||||
QUAD_VERTICE_COUNT * 4, QUAD_INDICE_COUNT * 4
|
||||
);
|
||||
|
||||
// Middle Right
|
||||
QuadMesh::bufferQuadMesh(this->mesh,
|
||||
edgeDimensions + glm::vec2(innerDimensions.x, 0),
|
||||
this->uv0 + glm::vec2(oneThird.x * 2.0f, oneThird.y),
|
||||
edgeDimensions + innerDimensions + glm::vec2(edgeDimensions.x, 0),
|
||||
this->uv1 - glm::vec2(0.0f, oneThird.y),
|
||||
QUAD_VERTICE_COUNT * 5, QUAD_INDICE_COUNT * 5
|
||||
);
|
||||
|
||||
// Bottom Left
|
||||
QuadMesh::bufferQuadMesh(this->mesh,
|
||||
glm::vec2(0.0f, edgeDimensions.y + innerDimensions.y),
|
||||
this->uv0 + glm::vec2(0.0f, uv1.y - oneThird.y),
|
||||
glm::vec2(edgeDimensions.x, overallDimensions.y),
|
||||
this->uv1 - glm::vec2(oneThird.x * 2.0f, 0.0f),
|
||||
QUAD_VERTICE_COUNT * 6, QUAD_INDICE_COUNT * 6
|
||||
);
|
||||
|
||||
// Bottom Center
|
||||
QuadMesh::bufferQuadMesh(this->mesh,
|
||||
edgeDimensions + glm::vec2(0.0f, innerDimensions.y),
|
||||
this->uv1 - oneThird,
|
||||
overallDimensions - glm::vec2(edgeDimensions.x, 0.0f),
|
||||
this->uv1 - glm::vec2(oneThird.x, 0.0f),
|
||||
QUAD_VERTICE_COUNT * 7, QUAD_INDICE_COUNT * 7
|
||||
);
|
||||
|
||||
// Bottom Right
|
||||
QuadMesh::bufferQuadMesh(this->mesh,
|
||||
overallDimensions - edgeDimensions,
|
||||
this->uv1 - oneThird,
|
||||
overallDimensions,
|
||||
this->uv1,
|
||||
QUAD_VERTICE_COUNT * 8, QUAD_INDICE_COUNT * 8
|
||||
);
|
||||
}
|
||||
|
||||
void UIBorder::drawSelf(UIShader &shader, glm::mat4 transform) {
|
||||
if(this->texture == nullptr) return;
|
||||
|
||||
shader.setUIColor(COLOR_WHITE);
|
||||
shader.setUIModel(transform);
|
||||
shader.setUITexture(this->texture);
|
||||
this->mesh.draw(MESH_DRAW_MODE_TRIANGLES, 0, -1);
|
||||
}
|
||||
|
||||
void UIBorder::setBorderSize(glm::vec2 borderSize) {
|
||||
this->edgeDimensions = borderSize;
|
||||
this->updatePositions();
|
||||
}
|
||||
|
||||
glm::vec2 UIBorder::getBorderSize() {
|
||||
return this->edgeDimensions;
|
||||
}
|
30
src/dawn/ui/UIBorder.hpp
Normal file
30
src/dawn/ui/UIBorder.hpp
Normal file
@ -0,0 +1,30 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "UIComponent.hpp"
|
||||
#include "display/mesh/QuadMesh.hpp"
|
||||
#include "display/Texture.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class UIBorder : public UIComponent {
|
||||
private:
|
||||
Mesh mesh;
|
||||
glm::vec2 edgeDimensions = glm::vec2(8.0f, 8.0f);
|
||||
glm::vec2 uv0 = glm::vec2(0.0f, 0.0f);
|
||||
glm::vec2 uv1 = glm::vec2(1.0f, 1.0f);
|
||||
|
||||
void updatePositions() override;
|
||||
|
||||
public:
|
||||
Texture *texture;
|
||||
|
||||
UIBorder(UICanvas &canvas);
|
||||
void drawSelf(UIShader &shader, glm::mat4 selfTransform) override;
|
||||
|
||||
void setBorderSize(glm::vec2 borderSize);
|
||||
glm::vec2 getBorderSize();
|
||||
};
|
||||
}
|
@ -22,9 +22,26 @@ void UIComponent::updatePositions() {
|
||||
}
|
||||
this->relativeX = this->alignment[0];
|
||||
this->width -= (this->alignment[0] + this->alignment[2]);
|
||||
} else {
|
||||
} else if(this->alignX == UI_COMPONENT_ALIGN_START) {
|
||||
this->relativeX = this->alignment[0];
|
||||
this->width = this->alignment[2];
|
||||
} else if(this->alignX == UI_COMPONENT_ALIGN_END) {
|
||||
this->width = this->alignment[0];
|
||||
if(this->parent == nullptr) {
|
||||
this->relativeX = this->canvas.getWidth();
|
||||
} else {
|
||||
this->relativeX = this->parent->getWidth();
|
||||
}
|
||||
this->relativeX -= this->width;
|
||||
this->relativeX -= this->alignment[2];
|
||||
} else if(this->alignX == UI_COMPONENT_ALIGN_MIDDLE) {
|
||||
this->width = this->alignment[2];
|
||||
if(this->parent == nullptr) {
|
||||
this->relativeX = this->canvas.getWidth();
|
||||
} else {
|
||||
this->relativeX = this->parent->getWidth();
|
||||
}
|
||||
this->relativeX = (this->relativeX / 2.0f) - (this->width / 2.0f) + this->alignment[0];
|
||||
}
|
||||
|
||||
// Y Alignment
|
||||
@ -36,9 +53,26 @@ void UIComponent::updatePositions() {
|
||||
}
|
||||
this->relativeY = this->alignment[1];
|
||||
this->height -= (this->alignment[1] + this->alignment[3]);
|
||||
} else {
|
||||
} else if(this->alignY == UI_COMPONENT_ALIGN_START) {
|
||||
this->relativeY = this->alignment[1];
|
||||
this->height = this->alignment[3];
|
||||
} else if(this->alignY == UI_COMPONENT_ALIGN_END) {
|
||||
this->height = this->alignment[1];
|
||||
if(this->parent == nullptr) {
|
||||
this->relativeY = this->canvas.getHeight();
|
||||
} else {
|
||||
this->relativeY = this->parent->getHeight();
|
||||
}
|
||||
this->relativeY -= this->height;
|
||||
this->relativeY -= this->alignment[3];
|
||||
} else if(this->alignY == UI_COMPONENT_ALIGN_MIDDLE) {
|
||||
this->height = this->alignment[3];
|
||||
if(this->parent == nullptr) {
|
||||
this->relativeY = this->canvas.getHeight();
|
||||
} else {
|
||||
this->relativeY = this->parent->getHeight();
|
||||
}
|
||||
this->relativeY = (this->relativeY / 2.0f) - (this->height / 2.0f) + this->alignment[1];
|
||||
}
|
||||
|
||||
// Update children
|
||||
@ -95,18 +129,18 @@ void UIComponent::draw(UIShader &uiShader, glm::mat4 parentTransform) {
|
||||
}
|
||||
}
|
||||
|
||||
void UIComponent::addChild(std::shared_ptr<UIComponent> child) {
|
||||
void UIComponent::addChild(UIComponent *child) {
|
||||
if(child->parent == this) return;
|
||||
if(child->parent != nullptr) child->parent->removeChild(child);
|
||||
this->children.push_back(child);
|
||||
child->parent = this;
|
||||
}
|
||||
|
||||
void UIComponent::removeChild(std::shared_ptr<UIComponent> child) {
|
||||
void UIComponent::removeChild(UIComponent *child) {
|
||||
if(child->parent != this) throw "Invalid child";
|
||||
auto it = this->children.begin();
|
||||
while(it != this->children.end()) {
|
||||
if(it->get() == child.get()) {
|
||||
if(*it == child) {
|
||||
this->children.erase(it);
|
||||
break;
|
||||
}
|
||||
|
@ -28,9 +28,9 @@ namespace Dawn {
|
||||
// Setting values
|
||||
UIComponentAlign alignX = UI_COMPONENT_ALIGN_START;
|
||||
UIComponentAlign alignY = UI_COMPONENT_ALIGN_START;
|
||||
glm::vec4 alignment = glm::vec4(0, 0, 1, 1);
|
||||
glm::vec4 alignment = glm::vec4(0, 0, 32, 32);
|
||||
float_t z = 0;
|
||||
std::vector<std::shared_ptr<UIComponent>> children;
|
||||
std::vector<UIComponent*> children;
|
||||
UIComponent *parent = nullptr;
|
||||
|
||||
// I currently don't support rotation or scale. Not because I can't but
|
||||
@ -51,6 +51,11 @@ namespace Dawn {
|
||||
|
||||
UIComponent(UICanvas &canvas);
|
||||
|
||||
/**
|
||||
* Returns the calculated width, based on the internal alignment values.
|
||||
*
|
||||
* @return Width of the component.
|
||||
*/
|
||||
float_t getWidth();
|
||||
float_t getHeight();
|
||||
float_t getRelativeX();
|
||||
@ -67,9 +72,11 @@ namespace Dawn {
|
||||
void draw(UIShader &uiShader, glm::mat4 parentTransform);
|
||||
virtual void drawSelf(UIShader &uiShader, glm::mat4 selfTransform) = 0;
|
||||
|
||||
void addChild(std::shared_ptr<UIComponent> chidl);
|
||||
void removeChild(std::shared_ptr<UIComponent> child);
|
||||
void addChild(UIComponent *child);
|
||||
void removeChild(UIComponent *child);
|
||||
|
||||
virtual ~UIComponent();
|
||||
|
||||
friend class UICanvas;
|
||||
};
|
||||
}
|
8
src/dawn/visualnovel/CMakeLists.txt
Normal file
8
src/dawn/visualnovel/CMakeLists.txt
Normal file
@ -0,0 +1,8 @@
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(ui)
|
10
src/dawn/visualnovel/ui/CMakeLists.txt
Normal file
10
src/dawn/visualnovel/ui/CMakeLists.txt
Normal 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
|
||||
VisualNovelTextbox.cpp
|
||||
)
|
21
src/dawn/visualnovel/ui/VisualNovelTextbox.cpp
Normal file
21
src/dawn/visualnovel/ui/VisualNovelTextbox.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "VisualNovelTextbox.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
VisualNovelTextbox::VisualNovelTextbox(UICanvas &canvas) :
|
||||
UIComponent(canvas),
|
||||
border(canvas),
|
||||
label(canvas)
|
||||
{
|
||||
this->addChild(&this->border);
|
||||
this->addChild(&this->label);
|
||||
}
|
||||
|
||||
void VisualNovelTextbox::drawSelf(UIShader &shader, glm::mat4 self) {
|
||||
|
||||
}
|
22
src/dawn/visualnovel/ui/VisualNovelTextbox.hpp
Normal file
22
src/dawn/visualnovel/ui/VisualNovelTextbox.hpp
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "ui/UISprite.hpp"
|
||||
#include "ui/UIBorder.hpp"
|
||||
#include "ui/UILabel.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class VisualNovelTextbox : public UIComponent {
|
||||
private:
|
||||
UIBorder border;
|
||||
UILabel label;
|
||||
glm::vec2 labelPadding = glm::vec2(0, 0);
|
||||
|
||||
public:
|
||||
VisualNovelTextbox(UICanvas &canvas);
|
||||
void drawSelf(UIShader &shader, glm::mat4 selfTransform) override;
|
||||
};
|
||||
}
|
@ -50,16 +50,16 @@ int32_t DawnHost::init(DawnGame &game) {
|
||||
glfwSwapInterval(0);
|
||||
gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
|
||||
|
||||
// Initialize the game
|
||||
auto result = game.init();
|
||||
if(result != DAWN_GAME_INIT_RESULT_SUCCESS) return result;
|
||||
|
||||
// Override the defaults
|
||||
game.renderManager.backBuffer.setSize(
|
||||
DAWN_GLFW_WINDOW_WIDTH_DEFAULT,
|
||||
DAWN_GLFW_WINDOW_HEIGHT_DEFAULT
|
||||
);
|
||||
|
||||
// Initialize the game
|
||||
auto result = game.init();
|
||||
if(result != DAWN_GAME_INIT_RESULT_SUCCESS) return result;
|
||||
|
||||
// Set up event listeners
|
||||
glfwSetWindowSizeCallback(this->data->window, &glfwOnResize);
|
||||
glfwSetKeyCallback(this->data->window, &glfwOnKey);
|
||||
|
@ -5,13 +5,12 @@
|
||||
|
||||
#include "DawnPokerGame.hpp"
|
||||
#include "asset/assets/TextureAsset.hpp"
|
||||
#include "ui/UIBorder.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
std::shared_ptr<TrueTypeAsset> asset;
|
||||
std::shared_ptr<TextureAsset> assetTexture;
|
||||
std::shared_ptr<UILabel> label;
|
||||
float_t fs = 1.0f;
|
||||
|
||||
DawnGame::DawnGame(DawnHost &host) :
|
||||
host(host),
|
||||
@ -38,6 +37,13 @@ int32_t DawnGame::init() {
|
||||
this->assetManager.update();
|
||||
}
|
||||
|
||||
auto border = canvas->addElement<UIBorder>();
|
||||
border->texture = assetTexture->texture.get();
|
||||
border->setTransform(
|
||||
UI_COMPONENT_ALIGN_STRETCH, UI_COMPONENT_ALIGN_STRETCH,
|
||||
glm::vec4(32, 32, 32, 32), 0.0f
|
||||
);
|
||||
|
||||
// auto sprite = canvas->addElement<UISprite>();
|
||||
// sprite->setTransform(
|
||||
// UI_COMPONENT_ALIGN_START,
|
||||
@ -47,17 +53,6 @@ int32_t DawnGame::init() {
|
||||
// );
|
||||
// sprite->texture = &asset->font.getTexture();
|
||||
|
||||
|
||||
label = canvas->addElement<UILabel>();
|
||||
label->setTransform(
|
||||
UI_COMPONENT_ALIGN_START,
|
||||
UI_COMPONENT_ALIGN_START,
|
||||
glm::vec4(0, 0, 200, 200),
|
||||
0
|
||||
);
|
||||
label->setText("Hello World\nHow are you today?");
|
||||
label->setFont(&asset->font);
|
||||
|
||||
return DAWN_GAME_INIT_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
@ -66,8 +61,6 @@ int32_t DawnGame::update(float_t delta) {
|
||||
this->inputManager.update();
|
||||
|
||||
if(this->scene != nullptr) this->scene->update();
|
||||
|
||||
label->setFontSize(fs += delta);
|
||||
|
||||
this->renderManager.update();
|
||||
|
||||
|
Reference in New Issue
Block a user