diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2011-01-28 23:32:31 +0100 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2011-01-28 23:33:06 +0100 |
commit | 2d916efa7963e6c247a451f3046f7bfce683737d (patch) | |
tree | 30be684110275c63a4577b411f7d6e0c51fe2105 /text.cpp | |
parent | 75182acf727092775ff5f94d4a42799cafa2bff7 (diff) |
Added the Text class.
Diffstat (limited to 'text.cpp')
-rw-r--r-- | text.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/text.cpp b/text.cpp new file mode 100644 index 0000000..82aa606 --- /dev/null +++ b/text.cpp @@ -0,0 +1,41 @@ +#include "text.h" + +#include <SFML/Graphics/RenderWindow.hpp> + +extern sf::RenderWindow *renderwindow; + +sf::Font *font = NULL; + +Text::Text(std::string str, int x, int y) { + if(!font) { + font = new sf::Font(); + font->LoadFromFile("fonts/VeraMono.ttf"); + } + string.SetSize(20); + string.SetFont(*font); + set_text(str); + set_position(x, y); +} + +void Text::draw() { + renderwindow->Draw(string); +} + +void Text::set_text(std::string str) { + string.SetText(str); +} + +void Text::set_position(int x, int y) { + float wf = (float)renderwindow->GetWidth() / 1024; + float hf = (float)renderwindow->GetHeight() / 768; + float xf = x * wf; + float yf = y * hf; + string.SetPosition(xf, yf); +} + +void Text::subtract_height() { + sf::FloatRect fr = string.GetRect(); + sf::Vector2f pos = string.GetPosition(); + pos.y -= fr.GetHeight(); + string.SetPosition(pos); +} |