Part one - removed references and smart pointers

This commit is contained in:
2022-11-11 19:08:46 -08:00
parent 4c2fc4cfcf
commit 42645883cd
76 changed files with 3899 additions and 3707 deletions

View File

@ -7,7 +7,7 @@
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->texture = new Texture();
@ -111,12 +111,12 @@ void UIBorder::updatePositions() {
);
}
void UIBorder::drawSelf(UIShader &shader, glm::mat4 transform) {
void UIBorder::drawSelf(UIShader *shader, glm::mat4 transform) {
if(this->texture == nullptr) return;
shader.setUIColor(COLOR_WHITE);
shader.setUIModel(transform);
shader.setUITexture(this->texture);
shader->setUIColor(COLOR_WHITE);
shader->setUIModel(transform);
shader->setUITexture(this->texture);
this->mesh.draw(MESH_DRAW_MODE_TRIANGLES, 0, -1);
}

View File

@ -17,12 +17,12 @@ namespace Dawn {
glm::vec2 uv1 = glm::vec2(1.0f, 1.0f);
void updatePositions() override;
void drawSelf(UIShader &shader, glm::mat4 selfTransform) override;
void drawSelf(UIShader *shader, glm::mat4 selfTransform) override;
public:
Texture *texture;
UIBorder(UICanvas &canvas);
UIBorder(UICanvas *canvas);
/**
* Changes the dimensions of the border.

View File

@ -7,16 +7,15 @@
using namespace Dawn;
UIComponent::UIComponent(UICanvas &canvas) :
canvas(canvas)
{
UIComponent::UIComponent(UICanvas *canvas) {
this->canvas = canvas;
}
void UIComponent::updatePositions() {
// X Alignment
if(this->alignX == UI_COMPONENT_ALIGN_STRETCH) {
if(this->parent == nullptr) {
this->width = this->canvas.getWidth();
this->width = this->canvas->getWidth();
} else {
this->width = this->parent->getWidth();
}
@ -28,7 +27,7 @@ void UIComponent::updatePositions() {
} else if(this->alignX == UI_COMPONENT_ALIGN_END) {
this->width = this->alignment[0];
if(this->parent == nullptr) {
this->relativeX = this->canvas.getWidth();
this->relativeX = this->canvas->getWidth();
} else {
this->relativeX = this->parent->getWidth();
}
@ -37,7 +36,7 @@ void UIComponent::updatePositions() {
} else if(this->alignX == UI_COMPONENT_ALIGN_MIDDLE) {
this->width = this->alignment[2];
if(this->parent == nullptr) {
this->relativeX = this->canvas.getWidth();
this->relativeX = this->canvas->getWidth();
} else {
this->relativeX = this->parent->getWidth();
}
@ -47,7 +46,7 @@ void UIComponent::updatePositions() {
// Y Alignment
if(this->alignY == UI_COMPONENT_ALIGN_STRETCH) {
if(this->parent == nullptr) {
this->height = this->canvas.getHeight();
this->height = this->canvas->getHeight();
} else {
this->height = this->parent->getHeight();
}
@ -59,7 +58,7 @@ void UIComponent::updatePositions() {
} else if(this->alignY == UI_COMPONENT_ALIGN_END) {
this->height = this->alignment[1];
if(this->parent == nullptr) {
this->relativeY = this->canvas.getHeight();
this->relativeY = this->canvas->getHeight();
} else {
this->relativeY = this->parent->getHeight();
}
@ -68,7 +67,7 @@ void UIComponent::updatePositions() {
} else if(this->alignY == UI_COMPONENT_ALIGN_MIDDLE) {
this->height = this->alignment[3];
if(this->parent == nullptr) {
this->relativeY = this->canvas.getHeight();
this->relativeY = this->canvas->getHeight();
} else {
this->relativeY = this->parent->getHeight();
}
@ -117,7 +116,7 @@ void UIComponent::setTransform(
this->updatePositions();
}
void UIComponent::draw(UIShader &uiShader, glm::mat4 parentTransform) {
void UIComponent::draw(UIShader *uiShader, glm::mat4 parentTransform) {
// Calculate self transform matrix
glm::mat4 selfTransform = parentTransform * glm::translate(
glm::mat4(1.0f), glm::vec3(this->relativeX, this->relativeY, this->z)

View File

@ -56,12 +56,12 @@ namespace Dawn {
* @param uiShader UI Shader for the child to use.
* @param selfTransform Self alignment transform.
*/
virtual void drawSelf(UIShader &uiShader, glm::mat4 selfTransform) = 0;
virtual void drawSelf(UIShader *uiShader, glm::mat4 selfTransform) = 0;
public:
UICanvas &canvas;
UICanvas *canvas;
UIComponent(UICanvas &canvas);
UIComponent(UICanvas *canvas);
/**
* Returns the calculated width, based on the internal alignment values.
@ -106,7 +106,7 @@ namespace Dawn {
float_t z
);
void draw(UIShader &uiShader, glm::mat4 parentTransform);
void draw(UIShader *uiShader, glm::mat4 parentTransform);
/**
* Adds a child to this UI Component.

View File

@ -7,7 +7,7 @@
using namespace Dawn;
UILabel::UILabel(UICanvas &canvas) : UIComponent(canvas) {
UILabel::UILabel(UICanvas *canvas) : UIComponent(canvas) {
}
@ -21,11 +21,14 @@ void UILabel::updateMesh() {
if(this->font == nullptr) return;
if(this->text.size() == 0) return;
float_t width = this->getWidth();
if(width == 0) width = -1;
this->font->buffer(
this->text,
this->fontSize,
this->getWidth(),
this->mesh,
width,
&this->mesh,
&this->measure
);
@ -51,15 +54,15 @@ void UILabel::setFontSize(float_t fontSize) {
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;
this->updateMesh();
shader.setUIColor(this->textColor);
shader.setUIModel(selfTransform);
shader.setUITexture(&this->font->getTexture());
shader->setUIColor(this->textColor);
shader->setUIModel(selfTransform);
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(

View File

@ -27,8 +27,8 @@ namespace Dawn {
/** The colour of this label */
struct Color textColor = COLOR_MAGENTA;
UILabel(UICanvas &canvas);
void drawSelf(UIShader &shader, glm::mat4 selfTransform) override;
UILabel(UICanvas *canvas);
void drawSelf(UIShader *shader, glm::mat4 selfTransform) override;
void setTransform(
UIComponentAlign xAlign,
UIComponentAlign yAlign,

View File

@ -1,33 +1,33 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "UISprite.hpp"
using namespace Dawn;
UISprite::UISprite(UICanvas &canvas) : UIComponent(canvas) {
this->mesh.createBuffers(QUAD_VERTICE_COUNT, QUAD_INDICE_COUNT);
}
void UISprite::updatePositions() {
UIComponent::updatePositions();
QuadMesh::bufferQuadMesh(
&this->mesh,
glm::vec2(0, 0), glm::vec2(0, 0),
glm::vec2(this->width, this->height), glm::vec2(1, 1),
0, 0
);
}
void UISprite::drawSelf(UIShader &uiShader, glm::mat4 selfTransform) {
uiShader.setUITexture(nullptr);
uiShader.setUIModel(selfTransform);
uiShader.setUIModel(glm::mat4(1.0f));
uiShader.setUIColor(COLOR_WHITE);
uiShader.setUITexture(this->texture);
this->mesh.draw(MESH_DRAW_MODE_TRIANGLES, 0, -1);
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "UISprite.hpp"
using namespace Dawn;
UISprite::UISprite(UICanvas *canvas) : UIComponent(canvas) {
this->mesh.createBuffers(QUAD_VERTICE_COUNT, QUAD_INDICE_COUNT);
}
void UISprite::updatePositions() {
UIComponent::updatePositions();
QuadMesh::bufferQuadMesh(
&this->mesh,
glm::vec2(0, 0), glm::vec2(0, 0),
glm::vec2(this->width, this->height), glm::vec2(1, 1),
0, 0
);
}
void UISprite::drawSelf(UIShader *uiShader, glm::mat4 selfTransform) {
uiShader->setUITexture(nullptr);
uiShader->setUIModel(selfTransform);
uiShader->setUIModel(glm::mat4(1.0f));
uiShader->setUIColor(COLOR_WHITE);
uiShader->setUITexture(this->texture);
this->mesh.draw(MESH_DRAW_MODE_TRIANGLES, 0, -1);
}

View File

@ -12,7 +12,7 @@ namespace Dawn {
class UISprite : public UIComponent {
protected:
void updatePositions() override;
void drawSelf(UIShader &uiShader, glm::mat4 selfTransform) override;
void drawSelf(UIShader *uiShader, glm::mat4 selfTransform) override;
public:
Mesh mesh;
@ -23,6 +23,6 @@ namespace Dawn {
*
* @param canvas Canvas that this sprite belongs to.
*/
UISprite(UICanvas &canvas);
UISprite(UICanvas *canvas);
};
}