diff options
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); |