summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--application.cpp8
-rw-r--r--text.cpp41
-rw-r--r--text.h20
3 files changed, 67 insertions, 2 deletions
diff --git a/application.cpp b/application.cpp
index 8ef9197..a21b4e2 100644
--- a/application.cpp
+++ b/application.cpp
@@ -1,8 +1,11 @@
#include "application.h"
+#include <SFML/Graphics/RenderWindow.hpp>
+
#include <stdexcept>
extern const sf::Input* input_backend;
+sf::RenderWindow *renderwindow;
Application::Application() {
please_quit = false;
@@ -13,7 +16,8 @@ Application::~Application() {
}
void Application::init_window(unsigned int w, unsigned int h, bool fs) {
- window = new sf::Window(sf::VideoMode(w, h, 32), "Foo");
+ renderwindow = new sf::RenderWindow(sf::VideoMode(w, h, 32), "Foo");
+ window = renderwindow;
window->UseVerticalSync(true);
@@ -62,4 +66,4 @@ void Application::event_keypress(sf::Key::Code key) {
default:
break;
}
-} \ No newline at end of file
+}
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);
+}
diff --git a/text.h b/text.h
new file mode 100644
index 0000000..88053af
--- /dev/null
+++ b/text.h
@@ -0,0 +1,20 @@
+#ifndef TEXT_H
+#define TEXT_H
+
+#include <SFML/Graphics.hpp>
+
+#include <string>
+
+class Text {
+ private:
+ sf::String string;
+
+ public:
+ Text(std::string str, int x = 0, int y = 0);
+ void draw();
+ void set_text(std::string str);
+ void set_position(int x, int y);
+ void subtract_height();
+};
+
+#endif