Commit a27afa6d authored by anotherguest's avatar anotherguest

Wrong spacing in font for Scenes. Add functions to get font height and text width of a string.

parent afbc33f9
...@@ -340,6 +340,10 @@ int Font::showString (char * s, int x, int y) { ...@@ -340,6 +340,10 @@ int Font::showString (char * s, int x, int y) {
// Determine the character's position on the screen // Determine the character's position on the screen
src.w = w[(int)(map[(int)(s[count])])]; src.w = w[(int)(map[(int)(s[count])])];
if(s[count] == 32) {
src.w = src.w /2;
}
dst.y = yOffset; dst.y = yOffset;
dst.x = xOffset; dst.x = xOffset;
...@@ -350,8 +354,7 @@ int Font::showString (char * s, int x, int y) { ...@@ -350,8 +354,7 @@ int Font::showString (char * s, int x, int y) {
// Draw the character to the screen // Draw the character to the screen
SDL_BlitSurface(surface, &src, screen, &dst); SDL_BlitSurface(surface, &src, screen, &dst);
xOffset += w[(int)(map[(int)(s[count])])]; xOffset += src.w-1;
} }
} }
...@@ -463,3 +466,27 @@ void Font::restorePalette () { ...@@ -463,3 +466,27 @@ void Font::restorePalette () {
} }
int Font::calcStringWidth(char *s)
{
int count;
int stringwidth = 0;
// Go through each character of the string
for (count = 0; s[count]; count++) {
if (s[count] == '\n') {
} else {
int width = w[(int)(map[(int)(s[count])])];
if(s[count] == 32) {
width = width/2;
}
stringwidth += (width-1);
}
}
return stringwidth;
}
...@@ -51,7 +51,8 @@ class Font { ...@@ -51,7 +51,8 @@ class Font {
void mapPalette (int start, int length, int newStart, void mapPalette (int start, int length, int newStart,
int newLength); int newLength);
void restorePalette (); void restorePalette ();
int fontHeight() { return h; }
int calcStringWidth(char *s);
}; };
// Variables // Variables
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment