Text.cpp
Text.cpp
CPP1/* Copyright Statement:2 *3 * (C) 2021-2024 Cubios Inc. All rights reserved.4 */5#include <cstdarg>6#include "Text.h"78namespace Cubios9{10namespace Gfx11{12Text::Text(std::string text, const Cubios::Math::Transform& t, uint32_t fontSize, const Cubios::Math::Color& color, Cubios::text_align_t al)13{14 this->Transform = t;15 this->Color = color;1617 this->Alignment = al;18 this->FontSize = fontSize;1920 this->Content = text;21}2223Text::Text(std::string text, const Cubios::Math::Transform& t, uint32_t fontSize, Cubios::text_align_t al)24{25 this->Transform = t;26 this->Alignment = al;27 this->FontSize = fontSize;2829 this->Content = text;30}3132Text::Text(std::string text, float x, float y,uint32_t fontSize)33{34 this->Transform.Position.X = x;35 this->Transform.Position.Y = y;3637 this->Alignment = Cubios::text_align_t::TEXT_ALIGN_CENTER;38 this->FontSize = fontSize;3940 this->Content = text;41}4243Text::Text(std::string text, float x, float y, uint32_t fontSize, const Cubios::Math::Color& color)44{45 this->Transform.Position.X = x;46 this->Transform.Position.Y = y;47 this->Color = color;4849 this->Alignment = Cubios::text_align_t::TEXT_ALIGN_CENTER;50 this->FontSize = fontSize;5152 this->Content = text;53}5455Text::~Text() { }565758Cubios::SceneObject* Text::SetContent(std::string text)59{60 this->Content = text;61 return this;62}6364Cubios::SceneObject* Text::FormatContent(char const* format,...)65{66 va_list args;67 va_start(args, format);6869 va_list copy;70 va_copy(copy, args);71 int len = std::vsnprintf(nullptr, 0, format, copy);72 va_end(copy);7374 if (len >= 0)75 {76 std::string s(std::size_t(len) + 1, '\0');77 std::vsnprintf(&s[0], s.size(), format, args);78 s.resize(len);7980 this->Content = s;81 }8283 va_end(args);84 return this;85}8687Cubios::SceneObject* Text::SetFontSize(uint32_t fontSize)88{89 this->FontSize = fontSize;90 return this;91}9293void Text::Render()94{95 Math::Vec2 pos = this->ScreenPosition();96 Cubios::GFX_drawText(pos.X, pos.Y, this->FontSize, Transform.SafeRotation()+ScreenAngle, this->Alignment, Color.Value(), this->Content.c_str());97}98}99}100
Wrapped for easier reading. Turn wrap off to inspect exact line lengths.