diff options
author | tomsmeding <tom.smeding@gmail.com> | 2016-12-30 22:53:42 +0100 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2016-12-30 22:53:42 +0100 |
commit | 1002b8640b80c0ec4ba5c242ca2873ee1fc591d5 (patch) | |
tree | 66a34e66c3a078d9a7adc4593fa057dc0d8334dc /library.cpp | |
parent | da86e33dcba7d66e2e5b55efa8a7265c5d2989b9 (diff) |
Drawing text (also added Liberation font with license)
Diffstat (limited to 'library.cpp')
-rw-r--r-- | library.cpp | 33 |
1 files changed, 21 insertions, 12 deletions
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); |