The fruits of my labor
This commit is contained in:
@ -4,6 +4,7 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "UIBorder.hpp"
|
||||
#include "game/DawnGame.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
@ -20,6 +21,7 @@ void UIBorder::updatePositions() {
|
||||
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),
|
||||
@ -102,13 +104,25 @@ void UIBorder::updatePositions() {
|
||||
);
|
||||
}
|
||||
|
||||
void UIBorder::drawSelf(UIShader *shader, glm::mat4 transform) {
|
||||
if(this->texture == nullptr) return;
|
||||
std::vector<struct ShaderPassItem> UIBorder::getSelfPassItems(
|
||||
glm::mat4 projection,
|
||||
glm::mat4 view,
|
||||
glm::mat4 transform
|
||||
) {
|
||||
std::vector<struct ShaderPassItem> items;
|
||||
if(this->texture == nullptr) return items;
|
||||
|
||||
shader->setUIColor(COLOR_WHITE);
|
||||
shader->setUIModel(transform);
|
||||
shader->setUITexture(this->texture);
|
||||
this->mesh.draw(MESH_DRAW_MODE_TRIANGLES, 0, -1);
|
||||
items.push_back(this->getGame()->renderManager.uiShaderProgram.getUIPassItem(
|
||||
projection,
|
||||
view,
|
||||
transform,
|
||||
this->texture,
|
||||
COLOR_WHITE,
|
||||
&this->mesh,
|
||||
this->z
|
||||
));
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
void UIBorder::setBorderSize(glm::vec2 borderSize) {
|
||||
|
@ -17,7 +17,11 @@ namespace Dawn {
|
||||
glm::vec2 uv1 = glm::vec2(1.0f, 1.0f);
|
||||
|
||||
void updatePositions() override;
|
||||
void drawSelf(UIShader *shader, glm::mat4 selfTransform) override;
|
||||
std::vector<struct ShaderPassItem> getSelfPassItems(
|
||||
glm::mat4 projection,
|
||||
glm::mat4 view,
|
||||
glm::mat4 transform
|
||||
) override;
|
||||
|
||||
public:
|
||||
Texture *texture = nullptr;
|
||||
|
@ -138,21 +138,29 @@ void UIComponent::setTransform(
|
||||
this->updatePositions();
|
||||
}
|
||||
|
||||
void UIComponent::draw(UIShader *uiShader, glm::mat4 parentTransform) {
|
||||
std::vector<struct ShaderPassItem> UIComponent::getPassItems(
|
||||
glm::mat4 projection,
|
||||
glm::mat4 view,
|
||||
glm::mat4 parent
|
||||
) {
|
||||
|
||||
// Calculate self transform matrix
|
||||
glm::mat4 selfTransform = parentTransform * glm::translate(
|
||||
glm::mat4(1.0f), glm::vec3(this->relativeX, this->relativeY, this->z)
|
||||
glm::mat4 selfTransform = parent * glm::translate(
|
||||
glm::mat4(1.0f),
|
||||
glm::vec3(this->relativeX, this->relativeY, this->z)
|
||||
);
|
||||
|
||||
// Draw Self
|
||||
this->drawSelf(uiShader, selfTransform);
|
||||
auto items = this->getSelfPassItems(projection, view, selfTransform);
|
||||
|
||||
// Render children
|
||||
auto it = this->children.begin();
|
||||
while(it != this->children.end()) {
|
||||
(*it)->draw(uiShader, selfTransform);
|
||||
vectorAppend(&items, (*it)->getPassItems(projection, view, selfTransform));
|
||||
++it;
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
void UIComponent::addChild(UIComponent *child) {
|
||||
|
@ -7,7 +7,9 @@
|
||||
#include "scene/components/ui/UICanvas.hpp"
|
||||
#include "scene/Scene.hpp"
|
||||
#include "display/Color.hpp"
|
||||
#include "display/shader/UIShader.hpp"
|
||||
#include "util/array.hpp"
|
||||
#include "util/mathutils.hpp"
|
||||
#include "display/shader/Shader.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
enum UIComponentAlign {
|
||||
@ -53,10 +55,16 @@ namespace Dawn {
|
||||
* Intended to be overwritten by subclass. Called by the draw method to
|
||||
* ask this child to draw.
|
||||
*
|
||||
* @param uiShader UI Shader for the child to use.
|
||||
* @param selfTransform Self alignment transform.
|
||||
* @param projection Projection matrix of the camera.
|
||||
* @param view View matrix of the camera.
|
||||
* @param parent Matrix of the parent of this UI item.
|
||||
* @return The list of shader pass items.
|
||||
*/
|
||||
virtual void drawSelf(UIShader *uiShader, glm::mat4 selfTransform) = 0;
|
||||
virtual std::vector<struct ShaderPassItem> getSelfPassItems(
|
||||
glm::mat4 projection,
|
||||
glm::mat4 view,
|
||||
glm::mat4 transform
|
||||
) = 0;
|
||||
|
||||
public:
|
||||
UICanvas *canvas;
|
||||
@ -136,7 +144,21 @@ namespace Dawn {
|
||||
float_t z
|
||||
);
|
||||
|
||||
void draw(UIShader *uiShader, glm::mat4 parentTransform);
|
||||
/**
|
||||
* Returns the list of renderable shader pass items for this UI element.
|
||||
* This is basically how you get your UI item to draw, this is called by
|
||||
* the RenderPipeline.
|
||||
*
|
||||
* @param projection Projection matrix of the camera.
|
||||
* @param view View matrix of the camera.
|
||||
* @param parent Matrix of the parent of this UI item.
|
||||
* @return The list of shader pass items, including children.
|
||||
*/
|
||||
std::vector<struct ShaderPassItem> getPassItems(
|
||||
glm::mat4 projection,
|
||||
glm::mat4 view,
|
||||
glm::mat4 parent
|
||||
);
|
||||
|
||||
/**
|
||||
* Adds a child to this UI Component.
|
||||
|
@ -11,6 +11,10 @@ UIEmpty::UIEmpty(UICanvas *canvas) : UIComponent(canvas) {
|
||||
|
||||
}
|
||||
|
||||
void UIEmpty::drawSelf(UIShader *shader, glm::mat4 selfTrans) {
|
||||
|
||||
std::vector<struct ShaderPassItem> UIEmpty::getSelfPassItems(
|
||||
glm::mat4 projection,
|
||||
glm::mat4 view,
|
||||
glm::mat4 transform
|
||||
) {
|
||||
return std::vector<struct ShaderPassItem>();
|
||||
}
|
@ -8,8 +8,14 @@
|
||||
|
||||
namespace Dawn {
|
||||
class UIEmpty : public UIComponent {
|
||||
protected:
|
||||
std::vector<struct ShaderPassItem> getSelfPassItems(
|
||||
glm::mat4 projection,
|
||||
glm::mat4 view,
|
||||
glm::mat4 transform
|
||||
) override;
|
||||
|
||||
public:
|
||||
UIEmpty(UICanvas *canvas);
|
||||
void drawSelf(UIShader *uiShader, glm::mat4 selfTransform) override;
|
||||
};
|
||||
}
|
@ -71,15 +71,29 @@ float_t UILabel::getContentHeight() {
|
||||
return this->measure.getHeight();
|
||||
}
|
||||
|
||||
void UILabel::drawSelf(UIShader *shader, glm::mat4 selfTransform) {
|
||||
if(this->font == nullptr || !this->hasText) return;
|
||||
std::vector<struct ShaderPassItem> UILabel::getSelfPassItems(
|
||||
glm::mat4 projection,
|
||||
glm::mat4 view,
|
||||
glm::mat4 transform
|
||||
) {
|
||||
std::vector<struct ShaderPassItem> items;
|
||||
if(this->font == nullptr) return items;
|
||||
|
||||
// this has to go eventually
|
||||
this->updateMesh();
|
||||
shader->setUIColor(this->textColor);
|
||||
shader->setUIModel(selfTransform);
|
||||
shader->setUITexture(this->font->getTexture());
|
||||
|
||||
this->font->draw(&this->mesh, this->startQuad, this->quadCount);
|
||||
auto item = this->getGame()->renderManager.uiShaderProgram.getUIPassItem(
|
||||
projection,
|
||||
view,
|
||||
transform,
|
||||
this->font->getTexture(),
|
||||
this->textColor,
|
||||
&this->mesh,
|
||||
this->z
|
||||
);
|
||||
item.start = this->startQuad * QUAD_INDICE_COUNT;
|
||||
item.count = this->quadCount * QUAD_INDICE_COUNT;
|
||||
items.push_back(item);
|
||||
return items;
|
||||
}
|
||||
|
||||
void UILabel::setTransform(
|
||||
|
@ -23,6 +23,12 @@ namespace Dawn {
|
||||
/** Event for when the language strings are updated */
|
||||
void onLanguageUpdated();
|
||||
|
||||
std::vector<struct ShaderPassItem> getSelfPassItems(
|
||||
glm::mat4 projection,
|
||||
glm::mat4 view,
|
||||
glm::mat4 transform
|
||||
) override;
|
||||
|
||||
public:
|
||||
struct FontMeasure measure;
|
||||
int32_t startQuad = 0;
|
||||
@ -32,7 +38,6 @@ namespace Dawn {
|
||||
struct Color textColor = COLOR_MAGENTA;
|
||||
|
||||
UILabel(UICanvas *canvas);
|
||||
void drawSelf(UIShader *shader, glm::mat4 selfTransform) override;
|
||||
virtual float_t getContentWidth() override;
|
||||
virtual float_t getContentHeight() override;
|
||||
void setTransform(
|
||||
|
@ -4,6 +4,7 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "UISprite.hpp"
|
||||
#include "game/DawnGame.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
@ -22,12 +23,21 @@ void UISprite::updatePositions() {
|
||||
);
|
||||
}
|
||||
|
||||
void UISprite::drawSelf(UIShader *uiShader, glm::mat4 selfTransform) {
|
||||
uiShader->setUITexture(nullptr);
|
||||
uiShader->setUIModel(selfTransform);
|
||||
uiShader->setUIModel(glm::mat4(1.0f));
|
||||
uiShader->setUIColor(this->color);
|
||||
uiShader->setUITexture(this->texture);
|
||||
std::vector<struct ShaderPassItem> UISprite::getSelfPassItems(
|
||||
glm::mat4 projection,
|
||||
glm::mat4 view,
|
||||
glm::mat4 transform
|
||||
) {
|
||||
std::vector<struct ShaderPassItem> items;
|
||||
|
||||
this->mesh.draw(MESH_DRAW_MODE_TRIANGLES, 0, -1);
|
||||
items.push_back(this->getGame()->renderManager.uiShaderProgram.getUIPassItem(
|
||||
projection,
|
||||
view,
|
||||
transform,
|
||||
this->texture,
|
||||
this->color,
|
||||
&this->mesh,
|
||||
this->z
|
||||
));
|
||||
return items;
|
||||
}
|
@ -12,7 +12,11 @@ namespace Dawn {
|
||||
class UISprite : public UIComponent {
|
||||
protected:
|
||||
void updatePositions() override;
|
||||
void drawSelf(UIShader *uiShader, glm::mat4 selfTransform) override;
|
||||
std::vector<struct ShaderPassItem> getSelfPassItems(
|
||||
glm::mat4 projection,
|
||||
glm::mat4 view,
|
||||
glm::mat4 transform
|
||||
) override;
|
||||
|
||||
public:
|
||||
Mesh mesh;
|
||||
|
Reference in New Issue
Block a user