#define _GNU_SOURCE //vasprintf #include #include #include #include #include "global.h" #include "library.h" using namespace std; extern sf::RenderWindow window; static const Font *currentFont=nullptr; static sf::Text sharedSfText; class Init{ public: Init(){ sharedSfText.setFillColor(sf::Color::Black); sharedSfText.setCharacterSize(14); } } init_object; 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){ draw_text(x,y,s,strlen(s)); } __attribute__((format (printf, 3, 4))) void draw_textf(int x,int y,const char *format,...){ va_list ap; va_start(ap,format); char *buf; int len=vasprintf(&buf,format,ap); va_end(ap); assert(len>=0); draw_text(x,y,buf,len); free(buf); } void draw_set_font(const Font *font){ currentFont=font; } static void log(const char *buf,size_t len){ cerr<<"[LOG] "; cerr.write(buf,len); cerr<=0); log(buf,len); free(buf); }