- i think this fixes the y centering for all resolutions, after testing we can remove lots of unused properties and code
This commit is contained in:
parent
97e19785a9
commit
1b72bcafe8
|
@ -67,6 +67,9 @@ int Metrics::toVirtualY(int h) const{
|
|||
if(screenH == 0) {
|
||||
throw runtime_error("div by 0 screenH == 0");
|
||||
}
|
||||
|
||||
//printf("h [%d] virtualH [%d] screenH [%d] result = %d\n",h,virtualH,screenH,(h*virtualH/screenH));
|
||||
|
||||
return h*virtualH/screenH;
|
||||
}
|
||||
|
||||
|
|
|
@ -1446,9 +1446,11 @@ Vec2f Renderer::getCentered3DPos(const string &text, Font3D *font, Vec2f &pos, i
|
|||
}
|
||||
const Metrics &metrics= Metrics::getInstance();
|
||||
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);
|
||||
pos.y += (h / 2.f) - (lineHeight / 2.f);
|
||||
//pos.y += (h / 2.f) - (lineHeight / 2.f);
|
||||
//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
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
|
|
@ -67,6 +67,7 @@ public:
|
|||
static bool fontIsRightToLeft;
|
||||
static float scaleFontValue;
|
||||
static int baseSize;
|
||||
static int faceResolution;
|
||||
//static int scaleFontYOffset;
|
||||
|
||||
public:
|
||||
|
|
|
@ -28,6 +28,8 @@ class TextFTGL : public Text
|
|||
{
|
||||
public:
|
||||
|
||||
static int faceResolution;
|
||||
|
||||
TextFTGL(FontTextHandlerType type);
|
||||
virtual ~TextFTGL();
|
||||
virtual void init(string fontName, int fontSize);
|
||||
|
|
|
@ -40,6 +40,7 @@ float FontMetrics::DEFAULT_Y_OFFSET_FACTOR = 2.0f;
|
|||
bool Font::fontIsRightToLeft = false;
|
||||
float Font::scaleFontValue = 1.0;
|
||||
int Font::baseSize = 0;
|
||||
int Font::faceResolution = 72;
|
||||
//int Font::scaleFontYOffset = 0;
|
||||
//
|
||||
|
||||
|
@ -129,6 +130,7 @@ Font::Font(FontTextHandlerType type) {
|
|||
try {
|
||||
textHandler = NULL;
|
||||
textHandler = new TextFTGL(type);
|
||||
TextFTGL::faceResolution = faceResolution;
|
||||
metrics.setTextHandler(this->textHandler);
|
||||
}
|
||||
catch(exception &ex) {
|
||||
|
|
|
@ -32,6 +32,8 @@ using namespace Shared::PlatformCommon;
|
|||
namespace Shared { namespace Graphics { namespace Gl {
|
||||
|
||||
|
||||
int TextFTGL::faceResolution = 72;
|
||||
|
||||
//====================================================================
|
||||
TextFTGL::TextFTGL(FontTextHandlerType type) : Text(type) {
|
||||
|
||||
|
@ -77,7 +79,7 @@ TextFTGL::TextFTGL(FontTextHandlerType type) : Text(type) {
|
|||
free((void*)fontFile);
|
||||
fontFile = NULL;
|
||||
|
||||
ftFont->FaceSize(24);
|
||||
ftFont->FaceSize(24,TextFTGL::faceResolution);
|
||||
if(ftFont->Error()) {
|
||||
throw runtime_error("FTGL: error setting face size");
|
||||
}
|
||||
|
@ -143,10 +145,10 @@ void TextFTGL::init(string fontName, int fontSize) {
|
|||
fontFile = NULL;
|
||||
|
||||
if(fontSize > 0) {
|
||||
ftFont->FaceSize(fontSize);
|
||||
ftFont->FaceSize(fontSize,TextFTGL::faceResolution);
|
||||
}
|
||||
else {
|
||||
ftFont->FaceSize(24);
|
||||
ftFont->FaceSize(24,TextFTGL::faceResolution);
|
||||
}
|
||||
|
||||
if(ftFont->Error()) {
|
||||
|
@ -170,7 +172,7 @@ void TextFTGL::init(string fontName, int fontSize) {
|
|||
}
|
||||
|
||||
void TextFTGL::SetFaceSize(int value) {
|
||||
ftFont->FaceSize(value);
|
||||
ftFont->FaceSize(value,TextFTGL::faceResolution);
|
||||
if(ftFont->Error()) {
|
||||
throw runtime_error("FTGL: error setting face size");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue