#include "text.h" #include 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); }