/******************************************************************** glcommon GL code & font stuff Copyright (c)2011 Mark Watkins License: GPL *********************************************************************/ #include #include #include #include "glcommon.h" #include "SleepLib/profiles.h" #include bool _font_init=false; QFont * defaultfont; QFont * mediumfont; QFont * bigfont; // Must be called from a thread inside the application. void InitFonts() { if (!_font_init) { defaultfont=new QFont("FreeSans",10); bigfont=new QFont("FreeSans",35); mediumfont=new QFont("FreeSans",18); _font_init=true; } } void DoneFonts() { if (_font_init) { delete bigfont; delete mediumfont; _font_init=false; } } void GetTextExtent(QString text, float & width, float & height, QFont *font) { QFontMetrics fm(*font); //QRect r=fm.tightBoundingRect(text); width=fm.width(text); //fm.width(text); height=fm.xHeight()+2; //fm.ascent(); } void DrawText(gGraphWindow & wid, QString text, float x, float y, float angle, QColor color,QFont *font) { //QFontMetrics fm(*font); float w,h; //GetTextExtent(text,w,h,font); //int a=fm.overlinePos(); //ascent(); //LinedRoundedRectangle(x,wid.GetScrY()-y,w,h,0,1,QColor("black")); if (!font) { qDebug("Font Problem. Forgot to call GraphInit() ?"); abort(); return; } glColor4ub(color.red(),color.green(),color.blue(),color.alpha()); if (angle==0) { wid.renderText(x,y,text,*font); // DrawText2(text,x,y,font); return; } QPainter painter(&wid); GetTextExtent(text, w, h, font); painter.translate(floor(x),floor(y)); painter.rotate(-90); painter.setFont(*font); painter.setPen(QPen(color)); painter.drawText(floor(-w/2.0),floor(-h/2.0),text); painter.translate(floor(-x),floor(-y)); painter.end(); glDisable(GL_TEXTURE_2D); glDisable(GL_DEPTH_TEST); } void RoundedRectangle(int x,int y,int w,int h,int radius,const QColor color) { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glColor4ub(color.red(),color.green(),color.blue(),color.alpha()); glBegin(GL_POLYGON); glVertex2i(x+radius,y); glVertex2i(x+w-radius,y); for(float i=(float)M_PI*1.5f;i