Adding bitmap fonts

This commit is contained in:
2023-03-14 18:55:10 -07:00
parent f5c5d1f49d
commit 9c9c64228a
17 changed files with 328 additions and 20 deletions

View File

@ -9,6 +9,7 @@ target_sources(${DAWN_TARGET_NAME}
UICanvas.cpp
UIComponent.cpp
UILabel.cpp
UIImage.cpp
)
add_subdirectory(menu)

View File

@ -28,8 +28,8 @@ UIComponentDimensional * UIComponent::getParentDimensional() {
void UIComponent::updateAlignment() {
if(!this->alignmentNeedsUpdating) return;
auto dimensional = this->getParentDimensional();
auto align = (glm::vec4)this->alignment;
auto dimensional = this->getParentDimensional();
auto translate = this->transform->getLocalPosition();
UIComponent::calculateDimensions(
@ -51,7 +51,6 @@ void UIComponent::updateAlignment() {
this->transform->setLocalPosition(translate);
this->alignmentNeedsUpdating = false;
this->eventAlignmentUpdated.invoke();
}

View 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
);
}

View File

@ -0,0 +1,30 @@
// Copyright (c) 2023 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"
namespace Dawn {
class UIImage : public UIComponent, public UIComponentRenderable {
private:
Mesh mesh;
public:
struct Color color = COLOR_WHITE;
// StateProperty<float_t> width;
// StateProperty<float_t> height;
StateProperty<Texture*> texture;
UIImage(SceneItem *item);
float_t getContentWidth() override;
float_t getContentHeight() override;
std::vector<struct ShaderPassItem> getPassItems(
glm::mat4 proj, glm::mat4 view
) override;
void onStart() override;
};
}

View File

@ -82,7 +82,6 @@ std::vector<struct ShaderPassItem> UILabel::getPassItems(
}
float_t UILabel::getContentWidth() {
if(this->maxWidth > 0) return this->maxWidth;
if(!this->hasText()) return 0;
this->updateMesh();
return this->measure.getWidth();