Adding bitmap fonts
This commit is contained in:
66
src/dawn/scene/components/ui/UIImage.cpp
Normal file
66
src/dawn/scene/components/ui/UIImage.cpp
Normal file
@ -0,0 +1,66 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "UIImage.hpp"
|
||||
#include "game/DawnGame.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
UIImage::UIImage(SceneItem *item) :
|
||||
texture(nullptr),
|
||||
UIComponent(item)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
float_t UIImage::getContentWidth() {
|
||||
if(this->texture != nullptr) return this->texture->getWidth();
|
||||
return this->width;
|
||||
}
|
||||
|
||||
float_t UIImage::getContentHeight() {
|
||||
if(this->texture != nullptr) return this->texture->getHeight();
|
||||
return this->height;
|
||||
}
|
||||
|
||||
std::vector<struct ShaderPassItem> UIImage::getPassItems(
|
||||
glm::mat4 proj, glm::mat4 view
|
||||
) {
|
||||
struct ShaderPassItem item;
|
||||
auto shader = &getGame()->renderManager.uiShaderProgram;
|
||||
item.shaderProgram = shader;
|
||||
item.colorValues[shader->paramColor] = this->color;
|
||||
item.matrixValues[shader->paramProjection] = proj;
|
||||
item.matrixValues[shader->paramView] = view;
|
||||
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 UIImage::onStart() {
|
||||
UIComponent::onStart();
|
||||
|
||||
useEvent([&]{
|
||||
QuadMesh::bufferPositions(&mesh,
|
||||
glm::vec2(0, 0), glm::vec2(width, height), 0
|
||||
);
|
||||
}, this->eventAlignmentUpdated);
|
||||
|
||||
QuadMesh::initQuadMesh(&mesh,
|
||||
glm::vec2(0, 0), glm::vec2(0, 0),
|
||||
glm::vec2(width, height), glm::vec2(1, 1),
|
||||
0.0f
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user