Label rendering a bit better
This commit is contained in:
@ -11,8 +11,27 @@
|
||||
namespace Dawn {
|
||||
class UIComponent {
|
||||
protected:
|
||||
/**
|
||||
* Virtual method overridden by the UIComponent to get the quads for the
|
||||
* component.
|
||||
*
|
||||
* @param t The translation of this component already applied.
|
||||
* @param ctx The canvas to add the quads to.
|
||||
*/
|
||||
virtual void getSelfQuads(const glm::vec2 t, UICanvas &ctx) = 0;
|
||||
|
||||
/**
|
||||
* Virtual method overridden by the UIComponent to get the children of
|
||||
* this component.
|
||||
*/
|
||||
virtual std::vector<std::shared_ptr<UIComponent>> getChildren();
|
||||
|
||||
/**
|
||||
* Method called by the UICanvas to get the quads for this component.
|
||||
*
|
||||
* @param parent The parent translation to apply to the component.
|
||||
* @param ctx The canvas to add the quads to.
|
||||
*/
|
||||
void getQuads(const glm::vec2 parent, UICanvas &ctx);
|
||||
|
||||
public:
|
||||
|
@ -9,9 +9,8 @@ using namespace Dawn;
|
||||
|
||||
void UILabel::getSelfQuads(const glm::vec2 t, UICanvas &ctx) {
|
||||
std::vector<struct UIShaderQuad> quads;
|
||||
if(this->texture == nullptr) return;
|
||||
if(this->texture == nullptr || this->text.empty()) return;
|
||||
|
||||
const std::wstring text = L"Hello World";
|
||||
glm::vec2 position = t;
|
||||
glm::vec4 quad;
|
||||
|
||||
@ -19,19 +18,37 @@ void UILabel::getSelfQuads(const glm::vec2 t, UICanvas &ctx) {
|
||||
auto info = texture->getCharacterData(c);
|
||||
ctx.addQuad(
|
||||
{
|
||||
position.x,
|
||||
position.y,
|
||||
position.x + info.size.x,
|
||||
position.y + info.size.y
|
||||
position.x + info.offset.x,
|
||||
position.y + info.offset.y,
|
||||
position.x + info.size.x + info.offset.x,
|
||||
position.y + info.size.y + info.offset.y
|
||||
},
|
||||
{
|
||||
info.quad.x,
|
||||
info.quad.y,
|
||||
info.quad.z,
|
||||
info.quad.w
|
||||
},
|
||||
info.quad,
|
||||
COLOR_WHITE,
|
||||
UIShaderQuadStyle::FONT,
|
||||
texture->texture
|
||||
);
|
||||
position += info.advance;
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<TrueTypeTexture> UILabel::getFont() {
|
||||
return this->texture;
|
||||
}
|
||||
|
||||
std::wstring UILabel::getText() {
|
||||
return this->text;
|
||||
}
|
||||
|
||||
void UILabel::setFont(std::shared_ptr<TrueTypeTexture> texture) {
|
||||
this->texture = texture;
|
||||
}
|
||||
|
||||
void UILabel::setText(const std::wstring &text) {
|
||||
this->text = text;
|
||||
}
|
@ -11,11 +11,38 @@ namespace Dawn {
|
||||
class UILabel final : public UIComponent {
|
||||
private:
|
||||
std::shared_ptr<TrueTypeTexture> texture = nullptr;
|
||||
std::wstring text = L"Hello World";
|
||||
|
||||
protected:
|
||||
void getSelfQuads(const glm::vec2 t, UICanvas &ctx) override;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Returns the font used for this label.
|
||||
*
|
||||
* @return The font used for this label.
|
||||
*/
|
||||
std::shared_ptr<TrueTypeTexture> getFont();
|
||||
|
||||
/**
|
||||
* Returns the text used for this label.
|
||||
*
|
||||
* @return The text used for this label.
|
||||
*/
|
||||
std::wstring getText();
|
||||
|
||||
/**
|
||||
* Sets the font to use for this label.
|
||||
*
|
||||
* @param texture TrueType texture to use for this label.
|
||||
*/
|
||||
void setFont(std::shared_ptr<TrueTypeTexture> texture);
|
||||
|
||||
/**
|
||||
* Sets the text to use for this label.
|
||||
*
|
||||
* @param text The text to use for this label.
|
||||
*/
|
||||
void setText(const std::wstring &text);
|
||||
};
|
||||
}
|
@ -13,6 +13,7 @@ void UIRectangle::getSelfQuads(const glm::vec2 t, UICanvas &ctx) {
|
||||
glm::vec4(t, t + size),
|
||||
uv,
|
||||
color,
|
||||
nullptr
|
||||
UIShaderQuadStyle::TEXTURED,
|
||||
texture
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user