- some small font centering adjustments

This commit is contained in:
Mark Vejvoda 2011-06-12 01:32:02 +00:00
parent 1d5dcb4ded
commit 752dd26bcd
4 changed files with 62 additions and 34 deletions

View File

@ -332,7 +332,7 @@ int CoreData::computeFontSize(int size) {
rs = size * screenH / 1024;
}
else {
rs = ((float)size * 0.86);
rs = ((float)size * 0.80);
}
//FontSizeAdjustment
rs += config.getInt("FontSizeAdjustment");

View File

@ -1417,6 +1417,29 @@ void Renderer::renderText(const string &text, Font2D *font, float alpha, int x,
glPopAttrib();
}
Vec2f Renderer::getCentered3DPos(const string &text, Font3D *font, Vec2f &pos, int w, int h) {
float lineWidth = font->getTextHandler()->Advance(text.c_str());
if(lineWidth < w) {
pos.x += ((w / 2.f) - (lineWidth / 2.f));
}
//h /= 2.f;
float lineHeight = font->getTextHandler()->LineHeight(text.c_str());
if(lineHeight < h) {
//pos.y += ((float)h / 2.f);
//pos.y -= ((float(h) / 2.f) - (lineHeight / 2.f));
pos.y += (lineHeight / 2.f);
//pos.y -= h;
//printf("Center text [%s] h = %d, lineHeight = %f, pos.y = %f\n",text.c_str(),h,lineHeight,pos.y);
//printf("Center text [%s] h = %d, lineHeight = %f, pos.y = %f\n",text.c_str(),h,lineHeight,pos.y);
}
else {
pos.y += ((float)h / 2.f) - 2;
}
return pos;
}
void Renderer::renderTextBoundingBox3D(const string &text, Font3D *font, const Vec3f &color, int x, int y, int w, int h, bool centered) {
glPushAttrib(GL_CURRENT_BIT);
glColor3fv(color.ptr());
@ -1424,17 +1447,8 @@ void Renderer::renderTextBoundingBox3D(const string &text, Font3D *font, const V
Vec2f pos= Vec2f(x, y);
//Vec2i pos= centered? computeCenteredPos(text, font, x, y): Vec2i(x, y);
if(centered) {
float lineWidth = font->getTextHandler()->Advance(text.c_str());
if(lineWidth < w) {
pos.x += ((w / 2.f) - (lineWidth / 2.f));
}
float lineHeight = font->getTextHandler()->LineHeight(text.c_str());
if(lineHeight < h) {
//pos.y -= ((float(h) / 2.f) - (lineHeight / 2.f));
pos.y += (lineHeight / 2.f);
}
if(centered == true) {
getCentered3DPos(text, font, pos, w, h);
}
textRenderer3D->begin(font);
@ -1479,17 +1493,8 @@ void Renderer::renderTextBoundingBox3D(const string &text, Font3D *font, const V
Vec2f pos= Vec2f(x, y);
//Vec2i pos= centered? computeCenteredPos(text, font, x, y): Vec2i(x, y);
if(centered) {
float lineWidth = font->getTextHandler()->Advance(text.c_str());
if(lineWidth < w) {
pos.x += ((w / 2.f) - (lineWidth / 2.f));
}
float lineHeight = font->getTextHandler()->LineHeight(text.c_str());
if(lineHeight < h) {
//pos.y -= ((float(h) / 2.f) - (lineHeight / 2.f));
pos.y += (lineHeight / 2.f);
}
if(centered == true) {
getCentered3DPos(text, font, pos, w, h);
}
textRenderer3D->begin(font);
@ -5088,20 +5093,9 @@ void Renderer::renderProgressBar3D(int size, int x, int y, Font3D *font, int cus
//text
//glColor3fv(defColor.ptr());
//printf("Render progress bar3d renderText [%s] y = %d, centeredText = %d\n",renderText.c_str(),y, centeredText);
renderTextBoundingBox3D(renderText, font, defColor, x, y, maxSize, progressbarHeight, true);
/*
textRenderer3D->begin(font);
if(centeredText == true) {
textRenderer3D->render(renderText.c_str(), x + maxSize / 2, y, centeredText);
}
else {
textRenderer3D->render(renderText.c_str(), x, y, centeredText);
}
textRenderer3D->end();
*/
}
void Renderer::renderProgressBar(int size, int x, int y, Font2D *font, int customWidth,

View File

@ -368,6 +368,7 @@ public:
void renderTextShadow3D(const string &text, Font3D *font,const Vec4f &color, int x, int y, bool centered=false);
void renderProgressBar3D(int size, int x, int y, Font3D *font, int customWidth=-1, string prefixLabel="", bool centeredText=true);
Vec2f getCentered3DPos(const string &text, Font3D *font, Vec2f &pos, int w, int h);
void renderTextBoundingBox3D(const string &text, Font3D *font, const Vec4f &color, int x, int y, int w, int h, bool centered);
void renderTextBoundingBox3D(const string &text, Font3D *font, const Vec3f &color, int x, int y, int w, int h, bool centered);

View File

@ -211,7 +211,40 @@ float TextFTGL::Advance(const char* str, const int len) {
}
float TextFTGL::LineHeight(const char* str, const int len) {
//FTBBox box = ftFont->BBox(str);
//printf("String [%s] lineheight = %f upper_y = %f lower_y = %f\n",str,ftFont->LineHeight(),box.Upper().Y(),box.Lower().Y());
//return ftFont->Ascender() + ftFont->Descender();
return ftFont->LineHeight();
//FTBBox box = ftFont->BBox(str);
//float result = box.Upper().Y()- box.Lower().Y();
//printf("For str [%s] LineHeight = %f, result = %f\n",str, ftFont->LineHeight(),result);
//return result;
//float urx = box.Upper().X();
//float llx = box.Lower().X();
//float llx, lly, llz, urx, ury, urz;
//ftFont->BBox(str, llx, lly, llz, urx, ury, urz);
//return ury - lly;
//Short_t halign = fTextAlign/10;
//Short_t valign = fTextAlign - 10*halign;
//Float_t dx = 0, dy = 0;
// switch (halign) {
// case 1 : dx = 0 ; break;
// case 2 : dx = -urx/2; break;
// case 3 : dx = -urx ; break;
// }
// switch (valign) {
// case 1 : dy = 0 ; break;
// case 2 : dy = -ury/2; break;
// case 3 : dy = -ury ; break;
// }
//printf("For str [%s] advance = %f, urx = %f, llx = %f\n",str, ftFont->Advance(str, len),urx,llx);
//return urx;
}
void TextFTGL::Render(const wchar_t* str, const int len) {