Removed the link between the font textures resolution and the size of the characters displayed. That allows to use very high resolution fonts similarly to card pictures...

This commit is contained in:
Xawotihs@gmail.com
2013-03-23 17:21:17 +00:00
parent b6a4197d88
commit 2c0e0c7251
2 changed files with 8 additions and 6 deletions

View File

@@ -172,6 +172,7 @@ private:
float mHeight; float mHeight;
float mScale; float mScale;
float mTextureScale;
float mRotation; float mRotation;
float mTracking; float mTracking;
float mSpacing; float mSpacing;

View File

@@ -49,12 +49,13 @@ JLBFont::JLBFont(const char *fontname, int lineheight, bool useVideoRAM)
sprintf(filename, "%s.png", fontname); sprintf(filename, "%s.png", fontname);
mTexture = mRenderer->LoadTexture(filename, useVideoRAM); mTexture = mRenderer->LoadTexture(filename, useVideoRAM);
mTextureScale = (float) lineheight/ (mTexture->mHeight/16);
if (mTexture == NULL) return; if (mTexture == NULL) return;
mHeight = (float) lineheight; mHeight = (float) lineheight;
mQuad = new JQuad(mTexture, 0.0f, 0.0f, 16.0f, mHeight); mQuad = new JQuad(mTexture, 0.0f, 0.0f, 16.0f/mTextureScale, mHeight/mTextureScale);
float a, b, c; float a, b, c;
@@ -158,7 +159,7 @@ void JLBFont::DrawString(const char *string, float x, float y, int align, float
index = (*p - 32)+mBase; index = (*p - 32)+mBase;
float charWidth = mCharWidth[index]; float charWidth = mCharWidth[index]*mTextureScale;
float delta = (charWidth + mTracking) * mScale; float delta = (charWidth + mTracking) * mScale;
float xPos = mXPos[index]; float xPos = mXPos[index];
if (leftOffset) if (leftOffset)
@@ -194,8 +195,8 @@ void JLBFont::DrawString(const char *string, float x, float y, int align, float
charWidth = (delta/mScale) - mTracking; charWidth = (delta/mScale) - mTracking;
} }
} }
mQuad->SetTextureRect(xPos, mYPos[index], charWidth , mHeight); mQuad->SetTextureRect(xPos, mYPos[index], charWidth/mTextureScale, mHeight/mTextureScale);
mRenderer->RenderQuad(mQuad, dx, dy, mRotation, mScale, mScale); mRenderer->RenderQuad(mQuad, dx, dy, mRotation, mScale*mTextureScale, mScale*mTextureScale);
dx += delta; dx += delta;
p++; p++;
} }
@@ -235,7 +236,7 @@ float JLBFont::GetStringWidth(const char *string) const
ch = *p - 32; ch = *p - 32;
p++; p++;
if (ch < 0) continue; if (ch < 0) continue;
len += mCharWidth[ch+mBase] + mTracking; len += (mCharWidth[ch+mBase]*mTextureScale) + mTracking;
} }
len -= mTracking; len -= mTracking;
return len*mScale; return len*mScale;