Pass Renderer2D to Renderable and have each subclass of Renderable decide what the Renderer should do (like drawText(), drawRect() etc). This makes the Renderable more flexible. right now, each renderable has a texture, vertices and indices. but what if some renderables does not use textures? or more than one? What if some renderables are just a group of other renderables? (Scene Graph's). If we instead just make Renderables implement render(Renderer2D& r) interface. we can make each renderable pass the data it holds to the renderer without a hard defined interface.
91 lines
1.7 KiB
C++
91 lines
1.7 KiB
C++
|
|
#ifndef SPECTRE_GRAPHICS_TEXT_H
|
|
#define SPECTRE_GRAPHICS_TEXT_H
|
|
|
|
#include <string>
|
|
#include <Spectre/Math/Color.h>
|
|
#include <Spectre/Graphics/Font.h>
|
|
#include <Spectre/Graphics/Transformable.h>
|
|
#include <Spectre/Graphics/Renderable.h>
|
|
|
|
class Text : public Renderable2D
|
|
{
|
|
public :
|
|
/* TODO
|
|
enum Properties
|
|
{
|
|
Regular = 0,
|
|
Bold = 1 << 0,
|
|
Italic = 1 << 1,
|
|
Underline = 1 << 2,
|
|
StrikeThrough = 1 << 3
|
|
};
|
|
|
|
enum Alignment
|
|
{
|
|
Left,
|
|
Right,
|
|
Center
|
|
}; */
|
|
|
|
Text();
|
|
|
|
Text(const std::string text, unsigned int size, const Font& font);
|
|
|
|
void setString(const std::string& string);
|
|
const std::string& getString() const;
|
|
|
|
void setCharacterSize(unsigned int size);
|
|
unsigned int getCharacteSize() const;
|
|
|
|
void setFont(const Font& font);
|
|
const Font* getFont() const;
|
|
|
|
void setColor(const Color& color);
|
|
const Color& getColor() const;
|
|
|
|
void setOutlineColor(const Color& color);
|
|
const Color& getOutlineColor() const;
|
|
|
|
void setOutlineSize(unsigned int size);
|
|
unsigned int getOutlineSize() const;
|
|
|
|
Vector2f getSize() const;
|
|
|
|
virtual const std::vector<Vertex2D>& getVertices() const;
|
|
|
|
virtual const std::vector<unsigned short>& getIndices() const;
|
|
|
|
virtual const RenderType getRenderType() const { return RenderType_UI; };
|
|
|
|
virtual const Texture* getTexture() const;
|
|
|
|
void render(Renderer2D& renderer) const;
|
|
|
|
private :
|
|
|
|
void updateGeometry() const;
|
|
|
|
private :
|
|
|
|
// String containing the text.
|
|
std::string m_string;
|
|
|
|
// Character size (in pixels, not points).
|
|
unsigned int m_size;
|
|
|
|
const Font* m_font;
|
|
|
|
Color m_color;
|
|
|
|
Color m_outlineColor;
|
|
|
|
unsigned int m_outlineWidth;
|
|
|
|
std::vector<unsigned short> m_indicies;
|
|
|
|
mutable bool m_geometryNeedsUpdate;
|
|
mutable std::vector<Vertex2D> m_vertices;
|
|
};
|
|
|
|
#endif /* SPECTRE_GRAPHICS_TEXT_H */
|