From 1002b8640b80c0ec4ba5c242ca2873ee1fc591d5 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Fri, 30 Dec 2016 22:53:42 +0100 Subject: Drawing text (also added Liberation font with license) --- library.cpp | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'library.cpp') diff --git a/library.cpp b/library.cpp index eda5628..12a9077 100644 --- a/library.cpp +++ b/library.cpp @@ -11,21 +11,25 @@ using namespace std; extern sf::RenderWindow window; -static void draw_text(int x,int y,const char *s,size_t len){ - static sf::Font font; - static bool fontLoaded=false; - static sf::Text text; - if(!fontLoaded){ - font.loadFromFile("/Library/Fonts/Arial.ttf"); - fontLoaded=true; +static const Font *currentFont=nullptr; +static sf::Text sharedSfText; + +class Init{ +public: + Init(){ + sharedSfText.setFillColor(sf::Color::Black); + sharedSfText.setCharacterSize(14); } +} init_object; - text.setFont(font); - text.setFillColor(sf::Color::Black); - text.setString(string(s,len)); - text.setPosition(x,y); - window.draw(text); +static void draw_text(int x,int y,const char *s,size_t len){ + if(currentFont!=nullptr){ + sharedSfText.setFont(currentFont->sf_font); + } + sharedSfText.setString(string(s,len)); + sharedSfText.setPosition(x,y); + window.draw(sharedSfText); } void draw_text(int x,int y,const char *s){ @@ -45,6 +49,11 @@ void draw_textf(int x,int y,const char *format,...){ } +void draw_set_font(const Font *font){ + currentFont=font; +} + + static void log(const char *buf,size_t len){ cerr<<"[LOG] "; cerr.write(buf,len); -- cgit v1.2.3-70-g09d2