Adding bitmap fonts
This commit is contained in:
@ -9,6 +9,7 @@ target_sources(${DAWN_TARGET_NAME}
|
||||
UICanvas.cpp
|
||||
UIComponent.cpp
|
||||
UILabel.cpp
|
||||
UIImage.cpp
|
||||
)
|
||||
|
||||
add_subdirectory(menu)
|
@ -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();
|
||||
}
|
||||
|
||||
|
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
|
||||
);
|
||||
}
|
30
src/dawn/scene/components/ui/UIImage.hpp
Normal file
30
src/dawn/scene/components/ui/UIImage.hpp
Normal 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;
|
||||
};
|
||||
}
|
@ -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();
|
||||
|
Reference in New Issue
Block a user