62 lines
1.8 KiB
C++
Raw Normal View History

/*
* =====================================================================================
*
* OpenMiner
* Copyright (C) 2018-2020 Unarelith, Quentin Bazin <openminer@unarelith.net>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* =====================================================================================
*/
#ifndef TEXT_HPP_
#define TEXT_HPP_
#include <string>
2019-01-05 18:37:59 +01:00
#include <gk/graphics/Sprite.hpp>
2019-04-13 15:06:52 +02:00
class Text : public gk::Drawable, public gk::Transformable {
public:
Text();
2018-06-29 06:26:57 +02:00
const std::string &text() const { return m_text; }
2019-12-30 21:46:06 +09:00
void setText(const std::string &text);
const gk::Color &color() const { return m_color; }
2019-12-30 21:46:06 +09:00
void setColor(const gk::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-30 23:47:51 +01:00
gk::Color m_color = gk::Color::White;
};
#endif // TEXT_HPP_