diff --git a/src/jngl/text.cpp b/src/jngl/text.cpp index b2dfdb12..c53a121f 100644 --- a/src/jngl/text.cpp +++ b/src/jngl/text.cpp @@ -12,25 +12,38 @@ #include "screen.hpp" namespace jngl { -class Line : public Drawable { +class Text::Line { public: Line(std::string text, std::shared_ptr font) : text(std::move(text)) { setFont(std::move(font)); } void setFont(std::shared_ptr font) { - width = static_cast(font->getTextWidth(text)); - height = static_cast(font->getLineHeight()); + width = font->getTextWidth(text); + height = font->getLineHeight(); this->font = std::move(font); } - void step() override { + void draw(Mat3 modelview) const { + font->print(modelview.translate(position), text); } - void draw() const override { - font->print(ScaleablePixels(getX()), ScaleablePixels(getY()), text); + double getWidth() const { + return static_cast(static_cast(width)); + } + double getHeight() const { + return static_cast(static_cast(height)); + } + void setX(double x) { + position.x = x; + } + void setY(double y) { + position.y = y; } private: std::string text; std::shared_ptr font; + Vec2 position; + Pixels width{ -1 }; + Pixels height{ -1 }; }; Text::Text(const std::string& text) : font(pWindow->getFontImpl()) { @@ -87,11 +100,10 @@ void Text::step() { } void Text::draw() const { - jngl::pushMatrix(); - jngl::translate(static_cast(getX()), static_cast(getY())); + auto mv = modelview().translate({ static_cast(static_cast(getX())), + static_cast(static_cast(getY())) }); for (auto& line : lines) { - line->draw(); + line->draw(mv); } - jngl::popMatrix(); } } // namespace jngl diff --git a/src/jngl/text.hpp b/src/jngl/text.hpp index cf33eb6d..77482116 100644 --- a/src/jngl/text.hpp +++ b/src/jngl/text.hpp @@ -17,7 +17,6 @@ enum class Alignment : uint8_t { LEFT, RIGHT, CENTER }; class Font; class FontImpl; -class Line; /// Rectangle shaped text block class Text : public Drawable { @@ -41,6 +40,7 @@ class Text : public Drawable { void draw() const override; private: + class Line; std::vector> lines; std::shared_ptr font; Alignment align = Alignment::LEFT;