122 lines
3.9 KiB
C++
122 lines
3.9 KiB
C++
// Copyright (c) 2023 Dominic Masters
|
|
//
|
|
// This software is released under the MIT License.
|
|
// https://opensource.org/licenses/MIT
|
|
|
|
#include "UIBorder.hpp"
|
|
#include "game/DawnGame.hpp"
|
|
|
|
using namespace Dawn;
|
|
|
|
UIBorder::UIBorder(SceneItem *item) :
|
|
texture(nullptr),
|
|
borderSize(glm::vec2(8, 8)),
|
|
UIComponentRenderable(item)
|
|
{
|
|
}
|
|
|
|
float_t UIBorder::getContentWidth() {
|
|
return this->width - this->borderSize._realValue.x * 2.0f;
|
|
}
|
|
|
|
float_t UIBorder::getContentHeight() {
|
|
return this->height - this->borderSize._realValue.y * 2.0f;
|
|
}
|
|
|
|
float_t UIBorder::getChildOffsetX() {
|
|
return this->borderSize._realValue.x;
|
|
}
|
|
|
|
float_t UIBorder::getChildOffsetY() {
|
|
return this->borderSize._realValue.y;
|
|
}
|
|
|
|
std::vector<struct ShaderPassItem> UIBorder::getUIRenderPasses() {
|
|
struct ShaderPassItem item;
|
|
auto shader = getGame()->renderManager.uiShader;
|
|
item.shader = shader;
|
|
item.colorValues[shader->paramColor] = COLOR_WHITE;
|
|
item.parameterBuffers[shader->bufferUiCanvas] = &this->getCanvas()->shaderBuffer;
|
|
item.matrixValues[shader->paramModel] = this->transform->getWorldTransform();
|
|
if(this->texture == nullptr) {
|
|
item.boolValues[shader->paramHasTexture] = false;
|
|
} else {
|
|
item.boolValues[shader->paramHasTexture] = true;
|
|
item.textureSlots[0] = this->texture;
|
|
item.textureValues[shader->paramTexture] = 0;
|
|
}
|
|
item.w = this->transform->getWorldPosition().z;
|
|
item.renderFlags = RENDER_MANAGER_RENDER_FLAG_BLEND;
|
|
item.mesh = &mesh;
|
|
|
|
return { item };
|
|
}
|
|
|
|
void UIBorder::onStart() {
|
|
UIComponent::onStart();
|
|
|
|
auto rebufferQuad = [&] {
|
|
glm::vec2 tSize = glm::vec2(1, 1) / 3.0f;
|
|
glm::vec2 bSize = (glm::vec2)borderSize;
|
|
glm::vec2 iSize = glm::vec2(this->getWidth(), this->getHeight()) - ( bSize * 2.0f );
|
|
|
|
QuadMesh::bufferQuadMesh(&mesh,
|
|
glm::vec2(0, 0), glm::vec2(0, 0),
|
|
bSize, tSize,
|
|
0, 0
|
|
);
|
|
QuadMesh::bufferQuadMesh(&mesh,
|
|
glm::vec2(bSize.x, 0), glm::vec2(tSize.x, 0),
|
|
glm::vec2(iSize.x + bSize.x, bSize.y), glm::vec2(tSize.x * 2, tSize.y),
|
|
QUAD_VERTICE_COUNT, QUAD_INDICE_COUNT
|
|
);
|
|
QuadMesh::bufferQuadMesh(&mesh,
|
|
glm::vec2(iSize.x + bSize.x, 0), glm::vec2(tSize.x + tSize.x, 0),
|
|
glm::vec2(this->getWidth(), bSize.y), glm::vec2(1.0f, tSize.y),
|
|
2 * QUAD_VERTICE_COUNT, 2 * QUAD_INDICE_COUNT
|
|
);
|
|
|
|
QuadMesh::bufferQuadMesh(&mesh,
|
|
glm::vec2(0, bSize.y), glm::vec2(0, tSize.y),
|
|
bSize + glm::vec2(0, iSize.y), tSize + glm::vec2(0, tSize.y),
|
|
3 * QUAD_VERTICE_COUNT, 3 * QUAD_INDICE_COUNT
|
|
);
|
|
QuadMesh::bufferQuadMesh(&mesh,
|
|
bSize, tSize,
|
|
bSize + iSize, tSize + tSize,
|
|
4 * QUAD_VERTICE_COUNT, 4 * QUAD_INDICE_COUNT
|
|
);
|
|
QuadMesh::bufferQuadMesh(&mesh,
|
|
glm::vec2(iSize.x + bSize.x, bSize.y), tSize + glm::vec2(tSize.x, 0),
|
|
glm::vec2(this->getWidth(), bSize.y + iSize.y), glm::vec2(1.0f, tSize.y + tSize.y),
|
|
5 * QUAD_VERTICE_COUNT, 5 * QUAD_INDICE_COUNT
|
|
);
|
|
|
|
QuadMesh::bufferQuadMesh(&mesh,
|
|
glm::vec2(0, iSize.y + bSize.y), glm::vec2(0, tSize.y + tSize.y),
|
|
glm::vec2(bSize.x, this->getHeight()), glm::vec2(tSize.x, 1.0f),
|
|
6 * QUAD_VERTICE_COUNT, 6 * QUAD_INDICE_COUNT
|
|
);
|
|
QuadMesh::bufferQuadMesh(&mesh,
|
|
glm::vec2(bSize.x, iSize.y + bSize.y), glm::vec2(tSize.x, tSize.y + tSize.y),
|
|
glm::vec2(iSize.x + bSize.x, this->getHeight()), glm::vec2(tSize.x * 2, 1.0f),
|
|
7 * QUAD_VERTICE_COUNT, 7 * QUAD_INDICE_COUNT
|
|
);
|
|
QuadMesh::bufferQuadMesh(&mesh,
|
|
bSize + iSize, tSize + tSize,
|
|
glm::vec2(this->getWidth(), this->getHeight()), glm::vec2(1.0f, 1.0f),
|
|
8 * QUAD_VERTICE_COUNT, 8 * QUAD_INDICE_COUNT
|
|
);
|
|
};
|
|
|
|
this->mesh.createBuffers(
|
|
QUAD_VERTICE_COUNT * UI_BORDER_QUAD_COUNT,
|
|
QUAD_INDICE_COUNT * UI_BORDER_QUAD_COUNT
|
|
);
|
|
rebufferQuad();
|
|
|
|
useEvent(rebufferQuad, this->eventAlignmentUpdated);
|
|
useEffect([&]{
|
|
this->alignmentNeedsUpdating = true;
|
|
}, this->borderSize);
|
|
} |