mirror of
https://github.com/glest/glest-source.git
synced 2025-10-04 03:11:53 +02:00
- cleanup of font work:
- removed uneeded code - set default scale font value to 0.8 to fit nicely on screen - added two new optional settings for ini or lng files to control scale and y centering: FONT_SCALE_SIZE=0.8 FONT_SCALE_CENTERH_FACTOR=3.0
This commit is contained in:
@@ -152,12 +152,12 @@ void CoreData::load() {
|
|||||||
displayFont= renderer.newFont(rsGlobal);
|
displayFont= renderer.newFont(rsGlobal);
|
||||||
displayFont->setType(displayFontName,config.getString("FontDisplay",""));
|
displayFont->setType(displayFontName,config.getString("FontDisplay",""));
|
||||||
displayFont->setSize(displayFontSize);
|
displayFont->setSize(displayFontSize);
|
||||||
displayFont->setYOffsetFactor(config.getFloat("FontDisplayYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
//displayFont->setYOffsetFactor(config.getFloat("FontDisplayYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
||||||
|
|
||||||
displayFont3D= renderer.newFont3D(rsGlobal);
|
displayFont3D= renderer.newFont3D(rsGlobal);
|
||||||
displayFont3D->setType(displayFontName,config.getString("FontDisplay",""));
|
displayFont3D->setType(displayFontName,config.getString("FontDisplay",""));
|
||||||
displayFont3D->setSize(displayFontSize);
|
displayFont3D->setSize(displayFontSize);
|
||||||
displayFont3D->setYOffsetFactor(config.getFloat("FontDisplayYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
//displayFont3D->setYOffsetFactor(config.getFloat("FontDisplayYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
||||||
|
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] displayFontName = [%s] displayFontSize = %d\n",__FILE__,__FUNCTION__,__LINE__,displayFontName.c_str(),displayFontSize);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] displayFontName = [%s] displayFontSize = %d\n",__FILE__,__FUNCTION__,__LINE__,displayFontName.c_str(),displayFontSize);
|
||||||
|
|
||||||
@@ -181,12 +181,12 @@ void CoreData::load() {
|
|||||||
displayFontSmall= renderer.newFont(rsGlobal);
|
displayFontSmall= renderer.newFont(rsGlobal);
|
||||||
displayFontSmall->setType(displayFontNameSmall,config.getString("FontSmallDisplay",""));
|
displayFontSmall->setType(displayFontNameSmall,config.getString("FontSmallDisplay",""));
|
||||||
displayFontSmall->setSize(displayFontNameSmallSize);
|
displayFontSmall->setSize(displayFontNameSmallSize);
|
||||||
displayFontSmall->setYOffsetFactor(config.getFloat("FontSmallDisplayYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
//displayFontSmall->setYOffsetFactor(config.getFloat("FontSmallDisplayYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
||||||
|
|
||||||
displayFontSmall3D= renderer.newFont3D(rsGlobal);
|
displayFontSmall3D= renderer.newFont3D(rsGlobal);
|
||||||
displayFontSmall3D->setType(displayFontNameSmall,config.getString("FontSmallDisplay",""));
|
displayFontSmall3D->setType(displayFontNameSmall,config.getString("FontSmallDisplay",""));
|
||||||
displayFontSmall3D->setSize(displayFontNameSmallSize);
|
displayFontSmall3D->setSize(displayFontNameSmallSize);
|
||||||
displayFontSmall3D->setYOffsetFactor(config.getFloat("FontSmallDisplayYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
//displayFontSmall3D->setYOffsetFactor(config.getFloat("FontSmallDisplayYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
||||||
|
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] displayFontSmallName = [%s] displayFontSmallNameSize = %d\n",__FILE__,__FUNCTION__,__LINE__,displayFontNameSmall.c_str(),displayFontNameSmallSize);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] displayFontSmallName = [%s] displayFontSmallNameSize = %d\n",__FILE__,__FUNCTION__,__LINE__,displayFontNameSmall.c_str(),displayFontNameSmallSize);
|
||||||
|
|
||||||
@@ -210,13 +210,13 @@ void CoreData::load() {
|
|||||||
menuFontNormal->setType(menuFontNameNormal,config.getString("FontMenuNormal",""));
|
menuFontNormal->setType(menuFontNameNormal,config.getString("FontMenuNormal",""));
|
||||||
menuFontNormal->setSize(menuFontNameNormalSize);
|
menuFontNormal->setSize(menuFontNameNormalSize);
|
||||||
menuFontNormal->setWidth(Font::wBold);
|
menuFontNormal->setWidth(Font::wBold);
|
||||||
menuFontNormal->setYOffsetFactor(config.getFloat("FontMenuNormalYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
//menuFontNormal->setYOffsetFactor(config.getFloat("FontMenuNormalYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
||||||
|
|
||||||
menuFontNormal3D= renderer.newFont3D(rsGlobal);
|
menuFontNormal3D= renderer.newFont3D(rsGlobal);
|
||||||
menuFontNormal3D->setType(menuFontNameNormal,config.getString("FontMenuNormal",""));
|
menuFontNormal3D->setType(menuFontNameNormal,config.getString("FontMenuNormal",""));
|
||||||
menuFontNormal3D->setSize(menuFontNameNormalSize);
|
menuFontNormal3D->setSize(menuFontNameNormalSize);
|
||||||
menuFontNormal3D->setWidth(Font::wBold);
|
menuFontNormal3D->setWidth(Font::wBold);
|
||||||
menuFontNormal3D->setYOffsetFactor(config.getFloat("FontMenuNormalYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
//menuFontNormal3D->setYOffsetFactor(config.getFloat("FontMenuNormalYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
||||||
|
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] menuFontNormalName = [%s] menuFontNormalNameSize = %d\n",__FILE__,__FUNCTION__,__LINE__,menuFontNameNormal.c_str(),menuFontNameNormalSize);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] menuFontNormalName = [%s] menuFontNormalNameSize = %d\n",__FILE__,__FUNCTION__,__LINE__,menuFontNameNormal.c_str(),menuFontNameNormalSize);
|
||||||
|
|
||||||
@@ -239,12 +239,12 @@ void CoreData::load() {
|
|||||||
menuFontBig= renderer.newFont(rsGlobal);
|
menuFontBig= renderer.newFont(rsGlobal);
|
||||||
menuFontBig->setType(menuFontNameBig,config.getString("FontMenuBig",""));
|
menuFontBig->setType(menuFontNameBig,config.getString("FontMenuBig",""));
|
||||||
menuFontBig->setSize(menuFontNameBigSize);
|
menuFontBig->setSize(menuFontNameBigSize);
|
||||||
menuFontBig->setYOffsetFactor(config.getFloat("FontMenuBigYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
//menuFontBig->setYOffsetFactor(config.getFloat("FontMenuBigYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
||||||
|
|
||||||
menuFontBig3D= renderer.newFont3D(rsGlobal);
|
menuFontBig3D= renderer.newFont3D(rsGlobal);
|
||||||
menuFontBig3D->setType(menuFontNameBig,config.getString("FontMenuBig",""));
|
menuFontBig3D->setType(menuFontNameBig,config.getString("FontMenuBig",""));
|
||||||
menuFontBig3D->setSize(menuFontNameBigSize);
|
menuFontBig3D->setSize(menuFontNameBigSize);
|
||||||
menuFontBig3D->setYOffsetFactor(config.getFloat("FontMenuBigYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
//menuFontBig3D->setYOffsetFactor(config.getFloat("FontMenuBigYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
||||||
|
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] menuFontNameBig = [%s] menuFontNameBigSize = %d\n",__FILE__,__FUNCTION__,__LINE__,menuFontNameBig.c_str(),menuFontNameBigSize);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] menuFontNameBig = [%s] menuFontNameBigSize = %d\n",__FILE__,__FUNCTION__,__LINE__,menuFontNameBig.c_str(),menuFontNameBigSize);
|
||||||
|
|
||||||
@@ -267,12 +267,12 @@ void CoreData::load() {
|
|||||||
menuFontVeryBig= renderer.newFont(rsGlobal);
|
menuFontVeryBig= renderer.newFont(rsGlobal);
|
||||||
menuFontVeryBig->setType(menuFontNameVeryBig,config.getString("FontMenuVeryBig",""));
|
menuFontVeryBig->setType(menuFontNameVeryBig,config.getString("FontMenuVeryBig",""));
|
||||||
menuFontVeryBig->setSize(menuFontNameVeryBigSize);
|
menuFontVeryBig->setSize(menuFontNameVeryBigSize);
|
||||||
menuFontVeryBig->setYOffsetFactor(config.getFloat("FontMenuVeryBigYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
//menuFontVeryBig->setYOffsetFactor(config.getFloat("FontMenuVeryBigYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
||||||
|
|
||||||
menuFontVeryBig3D= renderer.newFont3D(rsGlobal);
|
menuFontVeryBig3D= renderer.newFont3D(rsGlobal);
|
||||||
menuFontVeryBig3D->setType(menuFontNameVeryBig,config.getString("FontMenuVeryBig",""));
|
menuFontVeryBig3D->setType(menuFontNameVeryBig,config.getString("FontMenuVeryBig",""));
|
||||||
menuFontVeryBig3D->setSize(menuFontNameVeryBigSize);
|
menuFontVeryBig3D->setSize(menuFontNameVeryBigSize);
|
||||||
menuFontVeryBig3D->setYOffsetFactor(config.getFloat("FontMenuVeryBigYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
//menuFontVeryBig3D->setYOffsetFactor(config.getFloat("FontMenuVeryBigYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
||||||
|
|
||||||
//printf("CoreData menuFontVeryBig3D [%d] menuFontVeryBig3D [%p]\n",menuFontVeryBig3D->getSize(),menuFontVeryBig3D);
|
//printf("CoreData menuFontVeryBig3D [%d] menuFontVeryBig3D [%p]\n",menuFontVeryBig3D->getSize(),menuFontVeryBig3D);
|
||||||
|
|
||||||
@@ -298,12 +298,12 @@ void CoreData::load() {
|
|||||||
consoleFont= renderer.newFont(rsGlobal);
|
consoleFont= renderer.newFont(rsGlobal);
|
||||||
consoleFont->setType(consoleFontName,config.getString("FontConsole",""));
|
consoleFont->setType(consoleFontName,config.getString("FontConsole",""));
|
||||||
consoleFont->setSize(consoleFontNameSize);
|
consoleFont->setSize(consoleFontNameSize);
|
||||||
consoleFont->setYOffsetFactor(config.getFloat("FontConsoleYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
//consoleFont->setYOffsetFactor(config.getFloat("FontConsoleYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
||||||
|
|
||||||
consoleFont3D= renderer.newFont3D(rsGlobal);
|
consoleFont3D= renderer.newFont3D(rsGlobal);
|
||||||
consoleFont3D->setType(consoleFontName,config.getString("FontConsole",""));
|
consoleFont3D->setType(consoleFontName,config.getString("FontConsole",""));
|
||||||
consoleFont3D->setSize(consoleFontNameSize);
|
consoleFont3D->setSize(consoleFontNameSize);
|
||||||
consoleFont3D->setYOffsetFactor(config.getFloat("FontConsoleYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
//consoleFont3D->setYOffsetFactor(config.getFloat("FontConsoleYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str()));
|
||||||
|
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] consoleFontName = [%s] consoleFontNameSize = %d\n",__FILE__,__FUNCTION__,__LINE__,consoleFontName.c_str(),consoleFontNameSize);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] consoleFontName = [%s] consoleFontNameSize = %d\n",__FILE__,__FUNCTION__,__LINE__,consoleFontName.c_str(),consoleFontNameSize);
|
||||||
|
|
||||||
|
@@ -1390,15 +1390,15 @@ Vec2i computeCenteredPos(const string &text, Font3D *font, int x, int y) {
|
|||||||
return textPos;
|
return textPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::renderTextBoundingBox3D(const string &text, Font3D *font, float alpha, int x, int y, int w, int h, bool centered) {
|
void Renderer::renderTextBoundingBox3D(const string &text, Font3D *font, float alpha, int x, int y, int w, int h, bool centeredW, bool centeredH) {
|
||||||
glPushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT);
|
glPushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT);
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glColor4fv(Vec4f(1.f, 1.f, 1.f, alpha).ptr());
|
glColor4fv(Vec4f(1.f, 1.f, 1.f, alpha).ptr());
|
||||||
|
|
||||||
Vec2f pos= Vec2f(x, y);
|
Vec2f pos= Vec2f(x, y);
|
||||||
//Vec2i pos= centered? computeCenteredPos(text, font, x, y): Vec2i(x, y);
|
//Vec2i pos= centered? computeCenteredPos(text, font, x, y): Vec2i(x, y);
|
||||||
if(centered == true) {
|
if(centeredW == true || centeredH == true) {
|
||||||
getCentered3DPos(text, font, pos, w, h);
|
getCentered3DPos(text, font, pos, w, h, centeredW, centeredH);
|
||||||
}
|
}
|
||||||
|
|
||||||
textRenderer3D->begin(font);
|
textRenderer3D->begin(font);
|
||||||
@@ -1439,32 +1439,48 @@ void Renderer::renderText(const string &text, Font2D *font, float alpha, int x,
|
|||||||
glPopAttrib();
|
glPopAttrib();
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec2f Renderer::getCentered3DPos(const string &text, Font3D *font, Vec2f &pos, int w, int h) {
|
Vec2f Renderer::getCentered3DPos(const string &text, Font3D *font, Vec2f &pos, int w, int h,bool centeredW, bool centeredH) {
|
||||||
|
if(centeredW == true) {
|
||||||
float lineWidth = (font->getTextHandler()->Advance(text.c_str()) * Font::scaleFontValue);
|
float lineWidth = (font->getTextHandler()->Advance(text.c_str()) * Font::scaleFontValue);
|
||||||
if(lineWidth < w) {
|
if(lineWidth < w) {
|
||||||
pos.x += ((w / 2.f) - (lineWidth / 2.f));
|
pos.x += ((w / 2.f) - (lineWidth / 2.f));
|
||||||
}
|
}
|
||||||
const Metrics &metrics= Metrics::getInstance();
|
}
|
||||||
|
|
||||||
|
if(centeredH) {
|
||||||
|
//const Metrics &metrics= Metrics::getInstance();
|
||||||
//float lineHeight = (font->getTextHandler()->LineHeight(text.c_str()) * Font::scaleFontValue);
|
//float lineHeight = (font->getTextHandler()->LineHeight(text.c_str()) * Font::scaleFontValue);
|
||||||
float lineHeight = (font->getTextHandler()->LineHeight(text.c_str()) * Font::scaleFontValue);
|
float lineHeight = (font->getTextHandler()->LineHeight(text.c_str()) * Font::scaleFontValue);
|
||||||
//lineHeight=metrics.toVirtualY(lineHeight);
|
//lineHeight=metrics.toVirtualY(lineHeight);
|
||||||
//lineHeight= lineHeight / (2.f + 0.2f * FontMetrics::DEFAULT_Y_OFFSET_FACTOR);
|
//lineHeight= lineHeight / (2.f + 0.2f * FontMetrics::DEFAULT_Y_OFFSET_FACTOR);
|
||||||
//pos.y += (h / 2.f) - (lineHeight / 2.f);
|
//pos.y += (h / 2.f) - (lineHeight / 2.f);
|
||||||
//pos.y += (h / 2.f) - (lineHeight);
|
//pos.y += (h / 2.f) - (lineHeight);
|
||||||
pos.y += (lineHeight / 2.f); // y starts at the middle of the render position, so only move up 1/2 the font height
|
//pos.y += (lineHeight / 2.f); // y starts at the middle of the render position, so only move up 1/2 the font height
|
||||||
|
|
||||||
|
if(lineHeight < h) {
|
||||||
|
//int realHeight = lineHeight + (h - lineHeight);
|
||||||
|
// First go to top of bounding box
|
||||||
|
pos.y += (h - lineHeight);
|
||||||
|
|
||||||
|
pos.y -= ((h - lineHeight) / Font::scaleFontValueCenterHFactor);
|
||||||
|
|
||||||
|
// Now calculate till we get text to middle
|
||||||
|
//pos.y -= (realHeight / 2);
|
||||||
|
//pos.y += (lineHeight / 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::renderTextBoundingBox3D(const string &text, Font3D *font, const Vec3f &color, int x, int y, int w, int h, bool centered) {
|
void Renderer::renderTextBoundingBox3D(const string &text, Font3D *font, const Vec3f &color, int x, int y, int w, int h, bool centeredW, bool centeredH) {
|
||||||
glPushAttrib(GL_CURRENT_BIT);
|
glPushAttrib(GL_CURRENT_BIT);
|
||||||
glColor3fv(color.ptr());
|
glColor3fv(color.ptr());
|
||||||
|
|
||||||
Vec2f pos= Vec2f(x, y);
|
Vec2f pos= Vec2f(x, y);
|
||||||
//Vec2i pos= centered? computeCenteredPos(text, font, x, y): Vec2i(x, y);
|
//Vec2i pos= centered? computeCenteredPos(text, font, x, y): Vec2i(x, y);
|
||||||
|
|
||||||
if(centered == true) {
|
if(centeredW == true || centeredH == true) {
|
||||||
getCentered3DPos(text, font, pos, w, h);
|
getCentered3DPos(text, font, pos, w, h,centeredW,centeredH);
|
||||||
}
|
}
|
||||||
|
|
||||||
textRenderer3D->begin(font);
|
textRenderer3D->begin(font);
|
||||||
@@ -1501,7 +1517,7 @@ void Renderer::renderText(const string &text, Font2D *font, const Vec3f &color,
|
|||||||
glPopAttrib();
|
glPopAttrib();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::renderTextBoundingBox3D(const string &text, Font3D *font, const Vec4f &color, int x, int y, int w, int h, bool centered) {
|
void Renderer::renderTextBoundingBox3D(const string &text, Font3D *font, const Vec4f &color, int x, int y, int w, int h, bool centeredW, bool centeredH) {
|
||||||
glPushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT);
|
glPushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT);
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glColor4fv(color.ptr());
|
glColor4fv(color.ptr());
|
||||||
@@ -1509,8 +1525,8 @@ void Renderer::renderTextBoundingBox3D(const string &text, Font3D *font, const V
|
|||||||
Vec2f pos= Vec2f(x, y);
|
Vec2f pos= Vec2f(x, y);
|
||||||
//Vec2i pos= centered? computeCenteredPos(text, font, x, y): Vec2i(x, y);
|
//Vec2i pos= centered? computeCenteredPos(text, font, x, y): Vec2i(x, y);
|
||||||
|
|
||||||
if(centered == true) {
|
if(centeredW == true || centeredH == true) {
|
||||||
getCentered3DPos(text, font, pos, w, h);
|
getCentered3DPos(text, font, pos, w, h,centeredW,centeredH);
|
||||||
}
|
}
|
||||||
|
|
||||||
textRenderer3D->begin(font);
|
textRenderer3D->begin(font);
|
||||||
@@ -1652,7 +1668,7 @@ void Renderer::renderLabel(GraphicLabel *label,const Vec4f *color) {
|
|||||||
//renderText3D(lines[i], label->getFont3D(), (*color), textPos.x, textPos.y, label->getCentered());
|
//renderText3D(lines[i], label->getFont3D(), (*color), textPos.x, textPos.y, label->getCentered());
|
||||||
//printf("Text Render3D [%s] font3d [%p]\n",lines[i].c_str(),label->getFont3D());
|
//printf("Text Render3D [%s] font3d [%p]\n",lines[i].c_str(),label->getFont3D());
|
||||||
|
|
||||||
renderTextBoundingBox3D(lines[i], label->getFont3D(), (*color), x, y, w, h, label->getCentered());
|
renderTextBoundingBox3D(lines[i], label->getFont3D(), (*color), x, y, w, h, label->getCentered(),label->getCentered());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
renderText(lines[i], label->getFont(), (*color), textPos.x, textPos.y, label->getCentered());
|
renderText(lines[i], label->getFont(), (*color), textPos.x, textPos.y, label->getCentered());
|
||||||
@@ -1663,7 +1679,7 @@ void Renderer::renderLabel(GraphicLabel *label,const Vec4f *color) {
|
|||||||
//renderText3D(lines[i], label->getFont3D(), GraphicComponent::getFade(), textPos.x, textPos.y, label->getCentered());
|
//renderText3D(lines[i], label->getFont3D(), GraphicComponent::getFade(), textPos.x, textPos.y, label->getCentered());
|
||||||
//printf("Text Render3D [%s] font3d [%p]\n",lines[i].c_str(),label->getFont3D());
|
//printf("Text Render3D [%s] font3d [%p]\n",lines[i].c_str(),label->getFont3D());
|
||||||
|
|
||||||
renderTextBoundingBox3D(lines[i], label->getFont3D(), GraphicComponent::getFade(), x, y, w, h, label->getCentered());
|
renderTextBoundingBox3D(lines[i], label->getFont3D(), GraphicComponent::getFade(), x, y, w, h, label->getCentered(),label->getCentered());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
renderText(lines[i], label->getFont(), GraphicComponent::getFade(), textPos.x, textPos.y, label->getCentered());
|
renderText(lines[i], label->getFont(), GraphicComponent::getFade(), textPos.x, textPos.y, label->getCentered());
|
||||||
@@ -1784,7 +1800,7 @@ void Renderer::renderButton(GraphicButton *button, const Vec4f *fontColorOverrid
|
|||||||
if(button->getEditable()) {
|
if(button->getEditable()) {
|
||||||
if(renderText3DEnabled == true) {
|
if(renderText3DEnabled == true) {
|
||||||
//renderText3D(button->getText(), button->getFont3D(), color,x + (w / 2), y + (h / 2), true);
|
//renderText3D(button->getText(), button->getFont3D(), color,x + (w / 2), y + (h / 2), true);
|
||||||
renderTextBoundingBox3D(button->getText(), button->getFont3D(), color, x, y, w, h, true);
|
renderTextBoundingBox3D(button->getText(), button->getFont3D(), color, x, y, w, h, true, true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
renderText(button->getText(), button->getFont(), color,x + (w / 2), y + (h / 2), true);
|
renderText(button->getText(), button->getFont(), color,x + (w / 2), y + (h / 2), true);
|
||||||
@@ -1795,7 +1811,7 @@ void Renderer::renderButton(GraphicButton *button, const Vec4f *fontColorOverrid
|
|||||||
//renderText3D(button->getText(), button->getFont3D(),disabledTextColor,
|
//renderText3D(button->getText(), button->getFont3D(),disabledTextColor,
|
||||||
// x + (w / 2), y + (h / 2), true);
|
// x + (w / 2), y + (h / 2), true);
|
||||||
renderTextBoundingBox3D(button->getText(), button->getFont3D(),disabledTextColor,
|
renderTextBoundingBox3D(button->getText(), button->getFont3D(),disabledTextColor,
|
||||||
x, y, w, h, true);
|
x, y, w, h, true, true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
renderText(button->getText(), button->getFont(),disabledTextColor,
|
renderText(button->getText(), button->getFont(),disabledTextColor,
|
||||||
@@ -5147,7 +5163,7 @@ void Renderer::renderProgressBar3D(int size, int x, int y, Font3D *font, int cus
|
|||||||
//glColor3fv(defColor.ptr());
|
//glColor3fv(defColor.ptr());
|
||||||
//printf("Render progress bar3d renderText [%s] y = %d, centeredText = %d\n",renderText.c_str(),y, centeredText);
|
//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);
|
renderTextBoundingBox3D(renderText, font, defColor, x, y, maxSize, progressbarHeight, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::renderProgressBar(int size, int x, int y, Font2D *font, int customWidth,
|
void Renderer::renderProgressBar(int size, int x, int y, Font2D *font, int customWidth,
|
||||||
|
@@ -368,10 +368,10 @@ public:
|
|||||||
void renderTextShadow3D(const string &text, Font3D *font,const Vec4f &color, int x, int y, bool centered=false);
|
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);
|
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);
|
Vec2f getCentered3DPos(const string &text, Font3D *font, Vec2f &pos, int w, int h, bool centeredW, bool centeredH);
|
||||||
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 Vec4f &color, int x, int y, int w, int h, bool centeredW, bool centeredH);
|
||||||
void renderTextBoundingBox3D(const string &text, Font3D *font, const Vec3f &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 centeredW, bool centeredH);
|
||||||
void renderTextBoundingBox3D(const string &text, Font3D *font, float alpha, int x, int y, int w, int h, bool centered);
|
void renderTextBoundingBox3D(const string &text, Font3D *font, float alpha, int x, int y, int w, int h, bool centeredW, bool centeredH);
|
||||||
|
|
||||||
void beginRenderToTexture(Texture2D **renderToTexture);
|
void beginRenderToTexture(Texture2D **renderToTexture);
|
||||||
void endRenderToTexture(Texture2D **renderToTexture);
|
void endRenderToTexture(Texture2D **renderToTexture);
|
||||||
|
@@ -2560,6 +2560,8 @@ int glestMain(int argc, char** argv) {
|
|||||||
Font::fontIsMultibyte = config.getBool("FONT_MULTIBYTE",intToStr(Font::fontIsMultibyte).c_str());
|
Font::fontIsMultibyte = config.getBool("FONT_MULTIBYTE",intToStr(Font::fontIsMultibyte).c_str());
|
||||||
Font::fontIsRightToLeft = config.getBool("FONT_RIGHTTOLEFT",intToStr(Font::fontIsRightToLeft).c_str());
|
Font::fontIsRightToLeft = config.getBool("FONT_RIGHTTOLEFT",intToStr(Font::fontIsRightToLeft).c_str());
|
||||||
Font::baseSize = config.getInt("FONT_BASE_SIZE",intToStr(Font::baseSize).c_str());
|
Font::baseSize = config.getInt("FONT_BASE_SIZE",intToStr(Font::baseSize).c_str());
|
||||||
|
Font::scaleFontValue = config.getFloat("FONT_SCALE_SIZE",floatToStr(Font::scaleFontValue).c_str());
|
||||||
|
Font::scaleFontValueCenterHFactor = config.getFloat("FONT_SCALE_CENTERH_FACTOR",floatToStr(Font::scaleFontValueCenterHFactor).c_str());
|
||||||
|
|
||||||
// Example values:
|
// Example values:
|
||||||
// DEFAULT_CHARSET (English) = 1
|
// DEFAULT_CHARSET (English) = 1
|
||||||
@@ -2654,6 +2656,14 @@ int glestMain(int argc, char** argv) {
|
|||||||
// 30000 for Chinese
|
// 30000 for Chinese
|
||||||
Font::baseSize = strToInt(lang.get("FONT_BASE_SIZE"));
|
Font::baseSize = strToInt(lang.get("FONT_BASE_SIZE"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( lang.hasString("FONT_SCALE_SIZE")) {
|
||||||
|
Font::scaleFontValue = strToFloat(lang.get("FONT_SCALE_SIZE"));
|
||||||
|
}
|
||||||
|
if( lang.hasString("FONT_SCALE_CENTERH_FACTOR")) {
|
||||||
|
Font::scaleFontValueCenterHFactor = strToFloat(lang.get("FONT_SCALE_CENTERH_FACTOR"));
|
||||||
|
}
|
||||||
|
|
||||||
if( lang.hasString("FONT_CHARCOUNT")) {
|
if( lang.hasString("FONT_CHARCOUNT")) {
|
||||||
// 256 for English
|
// 256 for English
|
||||||
// 30000 for Chinese
|
// 30000 for Chinese
|
||||||
@@ -2686,12 +2696,26 @@ int glestMain(int argc, char** argv) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if( lang.hasString("FONT_YOFFSET_FACTOR")) {
|
// if( lang.hasString("FONT_YOFFSET_FACTOR")) {
|
||||||
FontMetrics::DEFAULT_Y_OFFSET_FACTOR = strToFloat(lang.get("FONT_YOFFSET_FACTOR"));
|
// FontMetrics::DEFAULT_Y_OFFSET_FACTOR = strToFloat(lang.get("FONT_YOFFSET_FACTOR"));
|
||||||
}
|
// }
|
||||||
|
|
||||||
#if defined(WIN32)
|
#if defined(WIN32)
|
||||||
// Win32 overrides for fonts (just in case they must be different)
|
// Win32 overrides for fonts (just in case they must be different)
|
||||||
|
|
||||||
|
if( lang.hasString("FONT_BASE_SIZE_WINDOWS")) {
|
||||||
|
// 256 for English
|
||||||
|
// 30000 for Chinese
|
||||||
|
Font::baseSize = strToInt(lang.get("FONT_BASE_SIZE_WINDOWS"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if( lang.hasString("FONT_SCALE_SIZE_WINDOWS")) {
|
||||||
|
Font::scaleFontValue = strToFloat(lang.get("FONT_SCALE_SIZE_WINDOWS"));
|
||||||
|
}
|
||||||
|
if( lang.hasString("FONT_SCALE_CENTERH_FACTOR_WINDOWS")) {
|
||||||
|
Font::scaleFontValueCenterHFactor = strToFloat(lang.get("FONT_SCALE_CENTERH_FACTOR_WINDOWS"));
|
||||||
|
}
|
||||||
|
|
||||||
if( lang.hasString("FONT_CHARCOUNT_WINDOWS")) {
|
if( lang.hasString("FONT_CHARCOUNT_WINDOWS")) {
|
||||||
// 256 for English
|
// 256 for English
|
||||||
// 30000 for Chinese
|
// 30000 for Chinese
|
||||||
@@ -2719,9 +2743,9 @@ int glestMain(int argc, char** argv) {
|
|||||||
_putenv(newEnvValue.c_str());
|
_putenv(newEnvValue.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
if( lang.hasString("FONT_YOFFSET_FACTOR_WINDOWS")) {
|
// if( lang.hasString("FONT_YOFFSET_FACTOR_WINDOWS")) {
|
||||||
FontMetrics::DEFAULT_Y_OFFSET_FACTOR = strToFloat(lang.get("FONT_YOFFSET_FACTOR_WINDOWS"));
|
// FontMetrics::DEFAULT_Y_OFFSET_FACTOR = strToFloat(lang.get("FONT_YOFFSET_FACTOR_WINDOWS"));
|
||||||
}
|
// }
|
||||||
|
|
||||||
// end win32
|
// end win32
|
||||||
#endif
|
#endif
|
||||||
|
@@ -32,17 +32,17 @@ private:
|
|||||||
float *widths;
|
float *widths;
|
||||||
float height;
|
float height;
|
||||||
|
|
||||||
float yOffsetFactor;
|
//float yOffsetFactor;
|
||||||
Text *textHandler;
|
Text *textHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static float DEFAULT_Y_OFFSET_FACTOR;
|
//static float DEFAULT_Y_OFFSET_FACTOR;
|
||||||
|
|
||||||
FontMetrics(Text *textHandler=NULL);
|
FontMetrics(Text *textHandler=NULL);
|
||||||
~FontMetrics();
|
~FontMetrics();
|
||||||
|
|
||||||
void setYOffsetFactor(float yOffsetFactor);
|
//void setYOffsetFactor(float yOffsetFactor);
|
||||||
float getYOffsetFactor() const;
|
//float getYOffsetFactor() const;
|
||||||
|
|
||||||
void setTextHandler(Text *textHandler);
|
void setTextHandler(Text *textHandler);
|
||||||
Text * getTextHandler();
|
Text * getTextHandler();
|
||||||
@@ -66,9 +66,9 @@ public:
|
|||||||
static bool forceLegacyFonts;
|
static bool forceLegacyFonts;
|
||||||
static bool fontIsRightToLeft;
|
static bool fontIsRightToLeft;
|
||||||
static float scaleFontValue;
|
static float scaleFontValue;
|
||||||
|
static float scaleFontValueCenterHFactor;
|
||||||
static int baseSize;
|
static int baseSize;
|
||||||
static int faceResolution;
|
static int faceResolution;
|
||||||
//static int scaleFontYOffset;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum Width {
|
enum Width {
|
||||||
@@ -93,15 +93,12 @@ public:
|
|||||||
virtual void end()=0;
|
virtual void end()=0;
|
||||||
|
|
||||||
//get
|
//get
|
||||||
//string getType() const {return type;}
|
|
||||||
int getWidth() const;
|
int getWidth() const;
|
||||||
FontMetrics *getMetrics() {return &metrics;}
|
FontMetrics *getMetrics() {return &metrics;}
|
||||||
Text * getTextHandler() {return textHandler;}
|
Text * getTextHandler() {return textHandler;}
|
||||||
float getYOffsetFactor() const;
|
|
||||||
string getType() const;
|
string getType() const;
|
||||||
|
|
||||||
//set
|
//set
|
||||||
void setYOffsetFactor(float yOffsetFactor);
|
|
||||||
void setType(string typeX11, string typeGeneric);
|
void setType(string typeX11, string typeGeneric);
|
||||||
void setWidth(int width);
|
void setWidth(int width);
|
||||||
|
|
||||||
@@ -114,8 +111,6 @@ public:
|
|||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
class Font2D: public Font {
|
class Font2D: public Font {
|
||||||
protected:
|
|
||||||
//int size;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Font2D(FontTextHandlerType type=ftht_2D);
|
Font2D(FontTextHandlerType type=ftht_2D);
|
||||||
|
@@ -36,12 +36,18 @@ int Font::charCount = 256;
|
|||||||
std::string Font::fontTypeName = "Times New Roman";
|
std::string Font::fontTypeName = "Times New Roman";
|
||||||
bool Font::fontIsMultibyte = false;
|
bool Font::fontIsMultibyte = false;
|
||||||
bool Font::forceLegacyFonts = false;
|
bool Font::forceLegacyFonts = false;
|
||||||
float FontMetrics::DEFAULT_Y_OFFSET_FACTOR = 2.0f;
|
|
||||||
bool Font::fontIsRightToLeft = false;
|
bool Font::fontIsRightToLeft = false;
|
||||||
float Font::scaleFontValue = 1.0;
|
|
||||||
|
// This value is used to scale the font text rendering
|
||||||
|
// in 3D render mode
|
||||||
|
float Font::scaleFontValue = 0.80;
|
||||||
|
// This value is used for centering font text vertically (height)
|
||||||
|
float Font::scaleFontValueCenterHFactor = 3.0;
|
||||||
|
//float Font::scaleFontValue = 1.0;
|
||||||
|
//float Font::scaleFontValueCenterHFactor = 4.0;
|
||||||
|
|
||||||
int Font::baseSize = 0;
|
int Font::baseSize = 0;
|
||||||
int Font::faceResolution = 72;
|
int Font::faceResolution = 72;
|
||||||
//int Font::scaleFontYOffset = 0;
|
|
||||||
//
|
//
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
@@ -52,7 +58,6 @@ FontMetrics::FontMetrics(Text *textHandler) {
|
|||||||
this->textHandler = textHandler;
|
this->textHandler = textHandler;
|
||||||
this->widths = new float[Font::charCount];
|
this->widths = new float[Font::charCount];
|
||||||
this->height = 0;
|
this->height = 0;
|
||||||
this->yOffsetFactor = FontMetrics::DEFAULT_Y_OFFSET_FACTOR;
|
|
||||||
|
|
||||||
for(int i=0; i < Font::charCount; ++i) {
|
for(int i=0; i < Font::charCount; ++i) {
|
||||||
widths[i]= 0;
|
widths[i]= 0;
|
||||||
@@ -64,14 +69,6 @@ FontMetrics::~FontMetrics() {
|
|||||||
widths = NULL;
|
widths = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FontMetrics::setYOffsetFactor(float yOffsetFactor) {
|
|
||||||
this->yOffsetFactor = yOffsetFactor;
|
|
||||||
}
|
|
||||||
|
|
||||||
float FontMetrics::getYOffsetFactor() const {
|
|
||||||
return this->yOffsetFactor;
|
|
||||||
}
|
|
||||||
|
|
||||||
void FontMetrics::setTextHandler(Text *textHandler) {
|
void FontMetrics::setTextHandler(Text *textHandler) {
|
||||||
this->textHandler = textHandler;
|
this->textHandler = textHandler;
|
||||||
}
|
}
|
||||||
@@ -94,7 +91,6 @@ float FontMetrics::getTextWidth(const string &str) {
|
|||||||
//Treat 2 byte characters as spaces
|
//Treat 2 byte characters as spaces
|
||||||
if(str[i] < 0) {
|
if(str[i] < 0) {
|
||||||
width+= (widths[97]); // This is the letter a which is a normal wide character and good to use for spacing
|
width+= (widths[97]); // This is the letter a which is a normal wide character and good to use for spacing
|
||||||
//i++;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
width+= widths[str[i]];
|
width+= widths[str[i]];
|
||||||
@@ -149,14 +145,6 @@ Font::~Font() {
|
|||||||
textHandler = NULL;
|
textHandler = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Font::setYOffsetFactor(float yOffsetFactor) {
|
|
||||||
metrics.setYOffsetFactor(yOffsetFactor);
|
|
||||||
}
|
|
||||||
|
|
||||||
float Font::getYOffsetFactor() const {
|
|
||||||
return metrics.getYOffsetFactor();
|
|
||||||
}
|
|
||||||
|
|
||||||
string Font::getType() const {
|
string Font::getType() const {
|
||||||
return this->type;
|
return this->type;
|
||||||
}
|
}
|
||||||
|
@@ -88,7 +88,6 @@ Font3D * ConvertFont2DTo3D(Font2D *font) {
|
|||||||
Font3D *result = new Font3DGl();
|
Font3D *result = new Font3DGl();
|
||||||
result->setSize(font->getSize());
|
result->setSize(font->getSize());
|
||||||
result->setType("",font->getType());
|
result->setType("",font->getType());
|
||||||
result->setYOffsetFactor(font->getYOffsetFactor());
|
|
||||||
result->setWidth(font->getWidth());
|
result->setWidth(font->getWidth());
|
||||||
result->init();
|
result->init();
|
||||||
return result;
|
return result;
|
||||||
|
@@ -73,11 +73,11 @@ void TextRenderer2DGl::render(const string &text, float x, float y, bool centere
|
|||||||
|
|
||||||
if(centered) {
|
if(centered) {
|
||||||
rasterPos.x= x - font->getTextHandler()->Advance(renderText.c_str()) / 2.f;
|
rasterPos.x= x - font->getTextHandler()->Advance(renderText.c_str()) / 2.f;
|
||||||
rasterPos.y= y + font->getTextHandler()->LineHeight(renderText.c_str()) / font->getYOffsetFactor();
|
rasterPos.y= y + font->getTextHandler()->LineHeight(renderText.c_str()) / 2;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
rasterPos= Vec2f(static_cast<float>(x), static_cast<float>(y));
|
rasterPos= Vec2f(static_cast<float>(x), static_cast<float>(y));
|
||||||
rasterPos.y= y + (font->getTextHandler()->LineHeight(renderText.c_str()) / font->getYOffsetFactor());
|
rasterPos.y= y + font->getTextHandler()->LineHeight(renderText.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
Reference in New Issue
Block a user