OpenMiner/include/gui/Text.hpp

52 lines
1.1 KiB
C++
Raw Normal View History

/*
* =====================================================================================
*
* Filename: Text.hpp
*
* Description:
*
* Created: 24/06/2018 01:48:24
*
* Author: Quentin Bazin, <quent42340@gmail.com>
*
* =====================================================================================
*/
#ifndef TEXT_HPP_
#define TEXT_HPP_
#include <string>
2018-12-29 02:23:23 +01:00
#include <gk/gui/Sprite.hpp>
2018-12-29 02:23:23 +01:00
class Text : public gk::IDrawable, public gk::Transformable {
public:
Text();
2018-06-29 06:26:57 +02:00
const std::string &text() const { return m_text; }
2018-06-26 06:38:20 +02:00
void setText(const std::string &text) { m_text = text; updateTextSprites(); }
2018-12-29 02:23:23 +01:00
void setColor(const gk::Color &color) { m_color = color; }
2018-12-29 02:23:23 +01:00
const gk::Vector2i &getSize() const { return m_size; }
private:
2018-12-29 02:23:23 +01:00
void draw(gk::RenderTarget &target, gk::RenderStates states) const override;
2018-06-26 06:38:20 +02:00
void updateTextSprites();
void updateCharWidth();
std::string m_text;
2018-12-29 02:23:23 +01:00
std::vector<gk::Sprite> m_textSprites;
int m_charWidth[256];
2018-12-29 02:23:23 +01:00
gk::Texture &m_texture;
gk::VertexBuffer m_vbo;
2018-12-29 02:23:23 +01:00
gk::Vector2i m_size;
2018-12-29 02:23:23 +01:00
gk::Color m_color = gk::Color::white;
};
#endif // TEXT_HPP_