Font working
This commit is contained in:
@ -7,5 +7,6 @@
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
UIComponent.cpp
|
||||
UILabel.cpp
|
||||
UISprite.cpp
|
||||
)
|
57
src/dawn/ui/UILabel.cpp
Normal file
57
src/dawn/ui/UILabel.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "UILabel.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
UILabel::UILabel(UICanvas &canvas) : UIComponent(canvas) {
|
||||
|
||||
}
|
||||
|
||||
void UILabel::updateMesh() {
|
||||
if(!this->needsRebuffering) return;
|
||||
if(this->font == nullptr) return;
|
||||
|
||||
this->font->buffer(
|
||||
this->text,
|
||||
this->fontSize,
|
||||
-1,
|
||||
this->mesh,
|
||||
&this->measure
|
||||
);
|
||||
|
||||
this->needsRebuffering = false;
|
||||
}
|
||||
|
||||
std::string UILabel::getText() {
|
||||
return this->text;
|
||||
}
|
||||
|
||||
void UILabel::setFont(Font *font) {
|
||||
this->font = font;
|
||||
this->needsRebuffering = true;
|
||||
}
|
||||
|
||||
void UILabel::setText(std::string text) {
|
||||
this->text = text;
|
||||
this->needsRebuffering = true;
|
||||
}
|
||||
|
||||
void UILabel::setFontSize(float_t fontSize) {
|
||||
this->fontSize = fontSize;
|
||||
this->needsRebuffering = true;
|
||||
}
|
||||
|
||||
void UILabel::drawSelf(UIShader &shader, glm::mat4 selfTransform) {
|
||||
if(this->font == nullptr) return;
|
||||
|
||||
this->updateMesh();
|
||||
shader.setUIColor(this->textColor);
|
||||
shader.setUIModel(selfTransform);
|
||||
shader.setUITexture(&this->font->getTexture());
|
||||
|
||||
this->font->draw(this->mesh, 0, -1);
|
||||
}
|
36
src/dawn/ui/UILabel.hpp
Normal file
36
src/dawn/ui/UILabel.hpp
Normal file
@ -0,0 +1,36 @@
|
||||
// Copyright (c) 2022 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"
|
||||
#include "display/font/Font.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class UILabel : public UIComponent {
|
||||
private:
|
||||
Mesh mesh;
|
||||
struct FontMeasure measure;
|
||||
bool_t needsRebuffering = true;
|
||||
Font *font = nullptr;
|
||||
std::string text = "";
|
||||
float_t fontSize = 10.0f;
|
||||
|
||||
void updateMesh();
|
||||
|
||||
public:
|
||||
struct Color textColor = COLOR_MAGENTA;
|
||||
|
||||
UILabel(UICanvas &canvas);
|
||||
|
||||
std::string getText();
|
||||
|
||||
void setFont(Font *font);
|
||||
void setText(std::string text);
|
||||
void setFontSize(float_t fontSize);
|
||||
|
||||
void drawSelf(UIShader &shader, glm::mat4 selfTransform);
|
||||
};
|
||||
}
|
@ -29,6 +29,7 @@ void UISprite::drawSelf(UIShader &uiShader, glm::mat4 selfTransform) {
|
||||
uiShader.setUIModel(selfTransform);
|
||||
uiShader.setUIModel(glm::mat4(1.0f));
|
||||
uiShader.setUIColor(COLOR_WHITE);
|
||||
uiShader.setUITexture(this->texture);
|
||||
|
||||
this->mesh.draw(MESH_DRAW_MODE_TRIANGLES, 0, -1);
|
||||
}
|
@ -6,6 +6,7 @@
|
||||
#pragma once
|
||||
#include "UIComponent.hpp"
|
||||
#include "display/mesh/QuadMesh.hpp"
|
||||
#include "display/Texture.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class UISprite : public UIComponent {
|
||||
@ -14,6 +15,7 @@ namespace Dawn {
|
||||
|
||||
public:
|
||||
Mesh mesh;
|
||||
Texture *texture;
|
||||
|
||||
UISprite(UICanvas &canvas);
|
||||
|
||||
|
Reference in New Issue
Block a user