git repos / blockattack-game

commit 925b7e58

sago007 · 2011-04-25 16:35
925b7e58d2f955694036cd0c6b1f3fd3472510e3 patch · browse files
parent b80c8ed3e9734c04ffd1c04f26b894eebfa29715

SFont replaced by NFont with TTF. Not as good looking as SFont but will allow internationalization


git-svn-id: https://blockattack.svn.sourceforge.net/svnroot/blockattack/trunk@115 9d7177f8-192b-0410-8f35-a16a89829b06

Changed files

A Game/fonts/FreeSerif.ttf
D Game/gfx/14P_Arial_Angle_Red.png before
D Game/gfx/24P_Arial_Blue.png before
D Game/gfx/SmallStone.png before
M packdata.sh before
M source/AUTH before
A source/code/Libs/NFont.cpp
A source/code/Libs/NFont.h
M source/code/SConscript before
D source/code/SFont.c before
D source/code/SFont.h before
M source/code/block.make before
M source/code/main.cpp before
M source/code/mainVars.hpp before
diff --git a/Game/fonts/FreeSerif.ttf b/Game/fonts/FreeSerif.ttf new file mode 100644 index 0000000..2f3dfc3
Binary files /dev/null and b/Game/fonts/FreeSerif.ttf differ
diff --git a/Game/gfx/14P_Arial_Angle_Red.png b/Game/gfx/14P_Arial_Angle_Red.png deleted file mode 100644 index 4944afe..0000000
Binary files a/Game/gfx/14P_Arial_Angle_Red.png and /dev/null differ
diff --git a/Game/gfx/24P_Arial_Blue.png b/Game/gfx/24P_Arial_Blue.png deleted file mode 100755 index d934169..0000000
Binary files a/Game/gfx/24P_Arial_Blue.png and /dev/null differ
diff --git a/Game/gfx/SmallStone.png b/Game/gfx/SmallStone.png deleted file mode 100644 index d64fc87..0000000
Binary files a/Game/gfx/SmallStone.png and /dev/null differ
diff --git a/packdata.sh b/packdata.sh index 9e6a9ea..b4a50fa 100755 --- a/packdata.sh +++ b/packdata.sh
@@ -4,5 +4,6 @@ cd Game
zip -9r blockattack.data gfx -x \*svn*
zip -9r blockattack.data music -x \*svn*
zip -9r blockattack.data sound -x \*svn*
+zip -9r blockattack.data fonts -x \*svn*
exit 0
diff --git a/source/AUTH b/source/AUTH index 8dfb576..3a227dd 100644 --- a/source/AUTH +++ b/source/AUTH
@@ -7,6 +7,9 @@ Data from the OpenArena team is under GPL v2
Data from the Trackballs team is under GPL v2
Poul Sander's files are multi licensed under "GPL v2 or later" OR "CC-BY-SA any version"
+/fonts/
+FreeSerif.ttf Free Software Foundation
+
/gfx/
14P_Arial_Angle_Red.png Karl Bartel - http://user.cs.tu-berlin.de/~karlb/sfont/fonts.html
b1024.png Poul Sander
@@ -44,8 +47,6 @@ bTwoPlayers.png qubodup
blockAttack.ico Poul Sander
changeButtonsBack1.png Poul Sander
iDraw.png Poul Sander
-SmallStone.png Karl Bartel - http://user.cs.tu-berlin.de/~karlb/sfont/fonts.html
-24P_Arial_Blue.png Karl Bartel - http://user.cs.tu-berlin.de/~karlb/sfont/fonts.html
changeButtonsBack.png Poul Sander
iGameOver.png Poul Sander
iLevelCheckBox.png Poul Sander
diff --git a/source/code/Libs/NFont.cpp b/source/code/Libs/NFont.cpp new file mode 100644 index 0000000..55a04cd --- /dev/null +++ b/source/code/Libs/NFont.cpp
@@ -0,0 +1,1106 @@
+/*
+NFont v2.0.0: A bitmap font class for SDL
+by Jonathan Dearborn 2-4-10
+(class adapted from Florian Hufsky)
+
+License:
+ The short:
+ Use it however you'd like, but keep the copyright and license notice
+ whenever these files or parts of them are distributed in uncompiled form.
+
+ The long:
+Copyright (c) 2010 Jonathan Dearborn
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+#include "NFont.h"
+
+char* NFont::buffer = NULL;
+NFont::AnimData NFont::data;
+
+#define MIN(a,b) (a < b? a : b)
+#define MAX(a,b) (a > b? a : b)
+
+// Static setters
+void NFont::setAnimData(void* data)
+{
+ NFont::data.userVar = data;
+}
+
+void NFont::setBuffer(unsigned int size)
+{
+ delete[] buffer;
+ if(size > 0)
+ buffer = new char[size];
+ else
+ buffer = new char[1024];
+}
+
+
+// Static functions
+char* NFont::copyString(const char* c)
+{
+ if(c == NULL) return NULL;
+
+ int count = 0;
+ for(; c[count] != '\0'; count++);
+
+ char* result = new char[count+1];
+
+ for(int i = 0; i < count; i++)
+ {
+ result[i] = c[i];
+ }
+
+ result[count] = '\0';
+ return result;
+}
+
+Uint32 NFont::getPixel(SDL_Surface *Surface, int x, int y) // No Alpha?
+{
+ Uint8* bits;
+ Uint32 bpp;
+
+ if(x < 0 || x >= Surface->w)
+ return 0; // Best I could do for errors
+
+ bpp = Surface->format->BytesPerPixel;
+ bits = ((Uint8*)Surface->pixels) + y*Surface->pitch + x*bpp;
+
+ switch (bpp)
+ {
+ case 1:
+ return *((Uint8*)Surface->pixels + y * Surface->pitch + x);
+ break;
+ case 2:
+ return *((Uint16*)Surface->pixels + y * Surface->pitch/2 + x);
+ break;
+ case 3:
+ // Endian-correct, but slower
+ Uint8 r, g, b;
+ r = *((bits)+Surface->format->Rshift/8);
+ g = *((bits)+Surface->format->Gshift/8);
+ b = *((bits)+Surface->format->Bshift/8);
+ return SDL_MapRGB(Surface->format, r, g, b);
+ break;
+ case 4:
+ return *((Uint32*)Surface->pixels + y * Surface->pitch/4 + x);
+ break;
+ }
+
+ return 0; // Best I could do for errors
+}
+
+SDL_Rect NFont::rectUnion(const SDL_Rect& A, const SDL_Rect& B)
+{
+ Sint16 x,x2,y,y2;
+ x = MIN(A.x, B.x);
+ y = MIN(A.y, B.y);
+ x2 = MAX(A.x+A.w, B.x+B.w);
+ y2 = MAX(A.y+A.h, B.y+B.h);
+ SDL_Rect result = {x, y, x2 - x, y2 - y};
+ return result;
+}
+
+SDL_Surface* NFont::copySurface(SDL_Surface *Surface)
+{
+ return SDL_ConvertSurface(Surface, Surface->format, Surface->flags);
+}
+
+SDL_Surface* NFont::verticalGradient(SDL_Surface* targetSurface, Uint32 top, Uint32 bottom, int heightAdjust)
+{
+ SDL_Surface* surface = targetSurface;
+ if(surface == NULL)
+ return NULL;
+
+ Uint8 tr, tg, tb;
+
+ SDL_GetRGB(top, surface->format, &tr, &tg, &tb);
+
+ Uint8 br, bg, bb;
+
+ SDL_GetRGB(bottom, surface->format, &br, &bg, &bb);
+
+ bool useCK = (surface->flags & SDL_SRCALPHA) != SDL_SRCALPHA; // colorkey if no alpha
+ Uint32 colorkey = surface->format->colorkey;
+
+ Uint8 r, g, b, a;
+ float ratio;
+ Uint32 color;
+ int temp;
+
+ for (int x = 0, y = 0; y < surface->h; x++)
+ {
+ if (x >= surface->w)
+ {
+ x = 0;
+ y++;
+
+ if (y >= surface->h)
+ break;
+ }
+
+ ratio = (y - 2)/float(surface->h - heightAdjust); // the neg 3s are for full color at top and bottom
+
+ if(!useCK)
+ {
+ color = getPixel(surface, x, y);
+ SDL_GetRGBA(color, surface->format, &r, &g, &b, &a); // just getting alpha
+ }
+ else
+ a = SDL_ALPHA_OPAQUE;
+
+ // Get and clamp the new values
+ temp = int(tr*(1-ratio) + br*ratio);
+ r = temp < 0? 0 : temp > 255? 255 : temp;
+
+ temp = int(tg*(1-ratio) + bg*ratio);
+ g = temp < 0? 0 : temp > 255? 255 : temp;
+
+ temp = int(tb*(1-ratio) + bb*ratio);
+ b = temp < 0? 0 : temp > 255? 255 : temp;
+
+
+ color = SDL_MapRGBA(surface->format, r, g, b, a);
+
+
+ if(useCK)
+ {
+ if(getPixel(surface, x, y) == colorkey)
+ continue;
+ if(color == colorkey)
+ color == 0? color++ : color--;
+ }
+
+ // make sure it isn't pink
+ if(color == SDL_MapRGBA(surface->format, 0xFF, 0, 0xFF, a))
+ color--;
+ if(getPixel(surface, x, y) == SDL_MapRGBA(surface->format, 0xFF, 0, 0xFF, SDL_ALPHA_OPAQUE))
+ continue;
+
+ int bpp = surface->format->BytesPerPixel;
+ Uint8* bits = ((Uint8 *)surface->pixels) + y*surface->pitch + x*bpp;
+
+ /* Set the pixel */
+ switch(bpp) {
+ case 1:
+ *((Uint8 *)(bits)) = (Uint8)color;
+ break;
+ case 2:
+ *((Uint16 *)(bits)) = (Uint16)color;
+ break;
+ case 3: { /* Format/endian independent */
+ r = (color >> surface->format->Rshift) & 0xFF;
+ g = (color >> surface->format->Gshift) & 0xFF;
+ b = (color >> surface->format->Bshift) & 0xFF;
+ *((bits)+surface->format->Rshift/8) = r;
+ *((bits)+surface->format->Gshift/8) = g;
+ *((bits)+surface->format->Bshift/8) = b;
+ }
+ break;
+ case 4:
+ *((Uint32 *)(bits)) = (Uint32)color;
+ break;
+ }
+
+ }
+ return surface;
+}
+
+
+// Constructors
+NFont::NFont()
+{
+ init();
+}
+
+NFont::NFont(SDL_Surface* src)
+{
+ init();
+ load(src);
+}
+
+NFont::NFont(SDL_Surface* dest, SDL_Surface* src)
+{
+ init();
+ load(src);
+ setDest(dest);
+}
+
+#ifdef NFONT_USE_TTF
+NFont::NFont(TTF_Font* ttf, SDL_Color fg)
+{
+ init();
+ load(ttf, fg);
+}
+NFont::NFont(TTF_Font* ttf, SDL_Color fg, SDL_Color bg)
+{
+ init();
+ load(ttf, fg, bg);
+}
+NFont::NFont(const char* filename_ttf, Uint32 pointSize, SDL_Color fg, int style)
+{
+ init();
+ load(filename_ttf, pointSize, fg, style);
+}
+NFont::NFont(const char* filename_ttf, Uint32 pointSize, SDL_Color fg, SDL_Color bg, int style)
+{
+ init();
+ load(filename_ttf, pointSize, fg, bg, style);
+}
+
+NFont::NFont(SDL_Surface* dest, TTF_Font* ttf, SDL_Color fg)
+{
+ init();
+ load(ttf, fg);
+ setDest(dest);
+}
+NFont::NFont(SDL_Surface* dest, TTF_Font* ttf, SDL_Color fg, SDL_Color bg)
+{
+ init();
+ load(ttf, fg, bg);
+ setDest(dest);
+}
+NFont::NFont(SDL_Surface* dest, const char* filename_ttf, Uint32 pointSize, SDL_Color fg, int style)
+{
+ init();
+ load(filename_ttf, pointSize, fg, style);
+ setDest(dest);
+}
+NFont::NFont(SDL_Surface* dest, const char* filename_ttf, Uint32 pointSize, SDL_Color fg, SDL_Color bg, int style)
+{
+ init();
+ load(filename_ttf, pointSize, fg, bg, style);
+ setDest(dest);
+}
+#endif
+
+void NFont::init()
+{
+ src = NULL;
+ dest = NULL;
+
+ maxPos = 0;
+
+ height = 0; // ascent+descent
+
+ maxWidth = 0;
+ baseline = 0;
+ ascent = 0;
+ descent = 0;
+
+ lineSpacing = 0;
+ letterSpacing = 0;
+
+ if(buffer == NULL)
+ buffer = new char[1024];
+}
+
+NFont::~NFont()
+{}
+
+
+// Loading
+bool NFont::load(SDL_Surface* FontSurface)
+{
+ src = FontSurface;
+ if (src == NULL)
+ {
+ printf("\n ERROR: NFont given a NULL surface\n");
+ return false;
+ }
+
+ int x = 1, i = 0;
+
+ // memset would be faster
+ for(int j = 0; j < 256; j++)
+ {
+ charWidth[j] = 0;
+ charPos[j] = 0;
+ }
+
+ SDL_LockSurface(src);
+
+ Uint32 pixel = SDL_MapRGB(src->format, 255, 0, 255); // pink pixel
+
+ maxWidth = 0;
+
+ // Get the character positions and widths
+ while (x < src->w)
+ {
+ if(getPixel(src, x, 0) != pixel)
+ {
+ charPos[i] = x;
+ charWidth[i] = x;
+ while(x < src->w && getPixel(src, x, 0) != pixel)
+ x++;
+ charWidth[i] = x - charWidth[i];
+ if(charWidth[i] > maxWidth)
+ maxWidth = charWidth[i];
+ i++;
+ }
+
+ x++;
+ }
+
+ maxPos = x - 1;
+
+
+ pixel = getPixel(src, 0, src->h - 1);
+ int j;
+ setBaseline();
+
+ // Get the max ascent
+ j = 1;
+ while(j < baseline && j < src->h)
+ {
+ x = 0;
+ while(x < src->w)
+ {
+ if(getPixel(src, x, j) != pixel)
+ {
+ ascent = baseline - j;
+ j = src->h;
+ break;
+ }
+ x++;
+ }
+ j++;
+ }
+
+ // Get the max descent
+ j = src->h - 1;
+ while(j > 0 && j > baseline)
+ {
+ x = 0;
+ while(x < src->w)
+ {
+ if(getPixel(src, x, j) != pixel)
+ {
+ descent = j - baseline+1;
+ j = 0;
+ break;
+ }
+ x++;
+ }
+ j--;
+ }
+
+
+ height = ascent + descent;
+
+
+ if((src->flags & SDL_SRCALPHA) != SDL_SRCALPHA)
+ {
+ pixel = getPixel(src, 0, src->h - 1);
+ SDL_UnlockSurface(src);
+ SDL_SetColorKey(src, SDL_SRCCOLORKEY, pixel);
+ }
+ else
+ SDL_UnlockSurface(src);
+
+ return true;
+}
+
+bool NFont::load(SDL_Surface* destSurface, SDL_Surface* FontSurface)
+{
+ setDest(destSurface);
+ return load(FontSurface);
+}
+
+#ifdef NFONT_USE_TTF
+bool NFont::load(TTF_Font* ttf, SDL_Color fg, SDL_Color bg)
+{
+ if(ttf == NULL)
+ return false;
+ SDL_Surface* surfs[127 - 33];
+ int width = 0;
+ int height = 0;
+
+ char buff[2];
+ buff[1] = '\0';
+ for(int i = 0; i < 127 - 33; i++)
+ {
+ buff[0] = i + 33;
+ surfs[i] = TTF_RenderText_Shaded(ttf, buff, fg, bg);
+ width += surfs[i]->w;
+ height = (height < surfs[i]->h)? surfs[i]->h : height;
+ }
+
+ #if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ SDL_Surface* result = SDL_CreateRGBSurface(SDL_SWSURFACE,width + 127 - 33 + 1,height,24, 0xFF0000, 0x00FF00, 0x0000FF, 0);
+ #else
+ SDL_Surface* result = SDL_CreateRGBSurface(SDL_SWSURFACE,width + 127 - 33 + 1,height,24, 0x0000FF, 0x00FF00, 0xFF0000, 0);
+ #endif
+ Uint32 pink = SDL_MapRGB(result->format, 255, 0, 255);
+ Uint32 bgcolor = SDL_MapRGB(result->format, bg.r, bg.g, bg.b);
+
+ SDL_Rect pixel = {1, 0, 1, 1};
+ SDL_Rect line = {1, 0, 1, result->h};
+
+ int x = 1;
+ SDL_Rect dest = {x, 0, 0, 0};
+ for(int i = 0; i < 127 - 33; i++)
+ {
+ pixel.x = line.x = x-1;
+ SDL_FillRect(result, &line, bgcolor);
+ SDL_FillRect(result, &pixel, pink);
+
+ SDL_BlitSurface(surfs[i], NULL, result, &dest);
+
+ x += surfs[i]->w + 1;
+ dest.x = x;
+
+ SDL_FreeSurface(surfs[i]);
+ }
+ pixel.x = line.x = x-1;
+ SDL_FillRect(result, &line, bgcolor);
+ SDL_FillRect(result, &pixel, pink);
+
+ return load(result);
+}
+
+
+bool NFont::load(TTF_Font* ttf, SDL_Color fg)
+{
+ if(ttf == NULL)
+ return false;
+ SDL_Surface* surfs[127 - 33];
+ int width = 0;
+ int height = 0;
+
+ char buff[2];
+ buff[1] = '\0';
+ for(int i = 0; i < 127 - 33; i++)
+ {
+ buff[0] = i + 33;
+ surfs[i] = TTF_RenderText_Blended(ttf, buff, fg);
+ width += surfs[i]->w;
+ height = (height < surfs[i]->h)? surfs[i]->h : height;
+ }
+
+ #if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ SDL_Surface* result = SDL_CreateRGBSurface(SDL_SWSURFACE,width + 127 - 33 + 1,height,32, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF);
+ #else
+ SDL_Surface* result = SDL_CreateRGBSurface(SDL_SWSURFACE,width + 127 - 33 + 1,height,32, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000);
+ #endif
+ Uint32 pink = SDL_MapRGBA(result->format, 255, 0, 255, SDL_ALPHA_OPAQUE);
+
+ SDL_SetAlpha(result, 0, SDL_ALPHA_OPAQUE);
+
+ SDL_Rect pixel = {1, 0, 1, 1};
+
+ int x = 1;
+ SDL_Rect dest = {x, 0, 0, 0};
+ for(int i = 0; i < 127 - 33; i++)
+ {
+ pixel.x = x-1;
+ SDL_FillRect(result, &pixel, pink);
+
+ SDL_SetAlpha(surfs[i], 0, SDL_ALPHA_OPAQUE);
+ SDL_BlitSurface(surfs[i], NULL, result, &dest);
+
+ x += surfs[i]->w + 1;
+ dest.x = x;
+
+ SDL_FreeSurface(surfs[i]);
+ }
+ pixel.x = x-1;
+ SDL_FillRect(result, &pixel, pink);
+
+ SDL_SetAlpha(result, SDL_SRCALPHA, SDL_ALPHA_OPAQUE);
+
+ return load(result);
+}
+
+
+bool NFont::load(const char* filename_ttf, Uint32 pointSize, SDL_Color fg, int style)
+{
+ if(!TTF_WasInit() && TTF_Init() < 0)
+ {
+ printf("Unable to initialize SDL_ttf: %s \n", TTF_GetError());
+ return false;
+ }
+
+ TTF_Font* ttf = TTF_OpenFont(filename_ttf, pointSize);
+
+ if(ttf == NULL)
+ {
+ printf("Unable to load TrueType font: %s \n", TTF_GetError());
+ return false;
+ }
+ TTF_SetFontStyle(ttf, style);
+ bool result = load(ttf, fg);
+ TTF_CloseFont(ttf);
+ return result;
+}
+
+bool NFont::load(const char* filename_ttf, Uint32 pointSize, SDL_Color fg, SDL_Color bg, int style)
+{
+ if(!TTF_WasInit() && TTF_Init() < 0)
+ {
+ printf("Unable to initialize SDL_ttf: %s \n", TTF_GetError());
+ return false;
+ }
+
+ TTF_Font* ttf = TTF_OpenFont(filename_ttf, pointSize);
+
+ if(ttf == NULL)
+ {
+ printf("Unable to load TrueType font: %s \n", TTF_GetError());
+ return false;
+ }
+ TTF_SetFontStyle(ttf, style);
+ bool result = load(ttf, fg, bg);
+ TTF_CloseFont(ttf);
+ return result;
+}
+
+#endif
+
+
+
+void NFont::freeSurface()
+{
+ SDL_FreeSurface(src);
+}
+
+
+
+// Drawing
+SDL_Rect NFont::drawToSurface(int x, int y, const char* text) const
+{
+ const char* c = text;
+ unsigned char num;
+ SDL_Rect srcRect, dstRect, copyS, copyD;
+ data.dirtyRect = makeRect(x, y, 0, 0);
+
+ if(c == NULL || src == NULL || dest == NULL)
+ return data.dirtyRect;
+
+ srcRect.y = baseline - ascent;
+ srcRect.h = dstRect.h = height;
+ dstRect.x = x;
+ dstRect.y = y;
+
+ int newlineX = x;
+
+ for(; *c != '\0'; c++)
+ {
+ if(*c == '\n')
+ {
+ dstRect.x = newlineX;
+ dstRect.y += height + lineSpacing;
+ continue;
+ }
+
+ if (*c == ' ')
+ {
+ dstRect.x += charWidth[0] + letterSpacing;
+ continue;
+ }
+ unsigned char ctest = (unsigned char)(*c);
+ // Skip bad characters
+ if(ctest < 33 || (ctest > 126 && ctest < 161))
+ continue;
+ if(dstRect.x >= dest->w)
+ continue;
+ if(dstRect.y >= dest->h)
+ continue;
+
+ num = ctest - 33; // Get array index
+ if(num > 126) // shift the extended characters down to the correct index
+ num -= 34;
+ srcRect.x = charPos[num];
+ srcRect.w = dstRect.w = charWidth[num];
+ copyS = srcRect;
+ copyD = dstRect;
+ SDL_BlitSurface(src, &srcRect, dest, &dstRect);
+ if(data.dirtyRect.w == 0 || data.dirtyRect.h == 0)
+ data.dirtyRect = dstRect;
+ else
+ data.dirtyRect = rectUnion(data.dirtyRect, dstRect);
+ srcRect = copyS;
+ dstRect = copyD;
+
+ dstRect.x += dstRect.w + letterSpacing;
+ }
+
+ return data.dirtyRect;
+}
+
+SDL_Rect NFont::drawToSurfacePos(int x, int y, NFont::AnimFn posFn) const
+{
+ data.font = this;
+ data.dest = dest;
+ data.src = src;
+ data.text = buffer; // Buffer for efficient drawing
+ data.height = height;
+ data.charPos = charPos;
+ data.charWidth = charWidth;
+ data.maxX = maxPos;
+ data.dirtyRect = makeRect(x,y,0,0);
+
+ data.index = -1;
+ data.letterNum = 0;
+ data.wordNum = 1;
+ data.lineNum = 1;
+ data.startX = x; // used as reset value for line feed
+ data.startY = y;
+
+ int preFnX = x;
+ int preFnY = y;
+
+ const char* c = buffer;
+ unsigned char num;
+ SDL_Rect srcRect, dstRect, copyS, copyD;
+
+ if(c == NULL || src == NULL || dest == NULL)
+ return makeRect(x,y,0,0);
+
+ srcRect.y = baseline - ascent;
+ srcRect.h = dstRect.h = height;
+ dstRect.x = x;
+ dstRect.y = y;
+
+ for(; *c != '\0'; c++)
+ {
+ data.index++;
+ data.letterNum++;
+
+ if(*c == '\n')
+ {
+ data.letterNum = 1;
+ data.wordNum = 1;
+ data.lineNum++;
+
+ x = data.startX; // carriage return
+ y += height + lineSpacing;
+ continue;
+ }
+ if (*c == ' ')
+ {
+ data.letterNum = 1;
+ data.wordNum++;
+
+ x += charWidth[0] + letterSpacing;
+ continue;
+ }
+ unsigned char ctest = (unsigned char)(*c);
+ // Skip bad characters
+ if(ctest < 33 || (ctest > 126 && ctest < 161))
+ continue;
+ //if(x >= dest->w) // This shouldn't be used with position control
+ // continue;
+ num = ctest - 33;
+ if(num > 126) // shift the extended characters down to the array index
+ num -= 34;
+ srcRect.x = charPos[num];
+ srcRect.w = dstRect.w = charWidth[num];
+
+ preFnX = x; // Save real position
+ preFnY = y;
+
+ // Use function pointer to get final x, y values
+ posFn(x, y, data);
+
+ dstRect.x = x;
+ dstRect.y = y;
+
+ copyS = srcRect;
+ copyD = dstRect;
+ SDL_BlitSurface(src, &srcRect, dest, &dstRect);
+ if(data.dirtyRect.w == 0 || data.dirtyRect.h == 0)
+ data.dirtyRect = dstRect;
+ else
+ data.dirtyRect = rectUnion(data.dirtyRect, dstRect);
+ srcRect = copyS;
+ dstRect = copyD;
+
+ x = preFnX; // Restore real position
+ y = preFnY;
+
+ x += dstRect.w + letterSpacing;
+ }
+
+ return data.dirtyRect;
+}
+
+SDL_Rect NFont::draw(int x, int y, const char* formatted_text, ...) const
+{
+ if(formatted_text == NULL)
+ return makeRect(x, y, 0, 0);
+
+ va_list lst;
+ va_start(lst, formatted_text);
+ vsprintf(buffer, formatted_text, lst);
+ va_end(lst);
+
+ return drawToSurface(x, y, buffer);
+}
+
+SDL_Rect NFont::drawCenter(int x, int y, const char* formatted_text, ...) const
+{
+ if(formatted_text == NULL)
+ return makeRect(x, y, 0, 0);
+
+ va_list lst;
+ va_start(lst, formatted_text);
+ vsprintf(buffer, formatted_text, lst);
+ va_end(lst);
+
+ char* str = copyString(buffer);
+ char* del = str;
+
+ // Go through str, when you find a \n, replace it with \0 and print it
+ // then move down, back, and continue.
+ for(char* c = str; *c != '\0';)
+ {
+ if(*c == '\n')
+ {
+ *c = '\0';
+ drawToSurface(x - getWidth("%s", str)/2, y, str);
+ *c = '\n';
+ c++;
+ str = c;
+ y += height;
+ }
+ else
+ c++;
+ }
+ char s[strlen(str)+1];
+ strcpy(s, str);
+ delete[] del;
+
+ return drawToSurface(x - getWidth("%s", s)/2, y, s);
+}
+
+SDL_Rect NFont::drawRight(int x, int y, const char* formatted_text, ...) const
+{
+ if(formatted_text == NULL)
+ return makeRect(x, y, 0, 0);
+
+ va_list lst;
+ va_start(lst, formatted_text);
+ vsprintf(buffer, formatted_text, lst);
+ va_end(lst);
+
+ char* str = copyString(buffer);
+ char* del = str;
+
+ for(char* c = str; *c != '\0';)
+ {
+ if(*c == '\n')
+ {
+ *c = '\0';
+ drawToSurface(x - getWidth("%s", str), y, str);
+ *c = '\n';
+ c++;
+ str = c;
+ y += height;
+ }
+ else
+ c++;
+ }
+ char s[strlen(str)+1];
+ strcpy(s, str);
+ delete[] del;
+
+ return drawToSurface(x - getWidth("%s", s), y, s);
+}
+
+SDL_Rect NFont::drawPos(int x, int y, NFont::AnimFn posFn, const char* text, ...) const
+{
+ va_list lst;
+ va_start(lst, text);
+ vsprintf(buffer, text, lst);
+ va_end(lst);
+
+ return drawToSurfacePos(x, y, posFn);
+}
+
+SDL_Rect NFont::drawAll(int x, int y, NFont::AnimFn allFn, const char* text, ...) const
+{
+ va_list lst;
+ va_start(lst, text);
+ vsprintf(buffer, text, lst);
+ va_end(lst);
+
+ allFn(x, y, data);
+ return data.dirtyRect;
+}
+
+
+
+
+// Getters
+SDL_Surface* NFont::getDest() const
+{
+ return dest;
+}
+
+SDL_Surface* NFont::getSurface() const
+{
+ return src;
+}
+
+int NFont::getHeight(const char* formatted_text, ...) const
+{
+ if(formatted_text == NULL)
+ return height;
+
+ va_list lst;
+ va_start(lst, formatted_text);
+ vsprintf(buffer, formatted_text, lst);
+ va_end(lst);
+
+ int numLines = 1;
+ const char* c;
+
+ for (c = buffer; *c != '\0'; c++)
+ {
+ if(*c == '\n')
+ numLines++;
+ }
+
+ // Actual height of letter region + line spacing
+ return height*numLines + lineSpacing*(numLines - 1); //height*numLines;
+}
+
+int NFont::getWidth(const char* formatted_text, ...) const
+{
+ if (formatted_text == NULL)
+ return 0;
+
+ va_list lst;
+ va_start(lst, formatted_text);
+ vsprintf(buffer, formatted_text, lst);
+ va_end(lst);
+
+ const char* c;
+ int charnum = 0;
+ int width = 0;
+ int bigWidth = 0; // Allows for multi-line strings
+
+ for (c = buffer; *c != '\0'; c++)
+ {
+ charnum = (unsigned char)(*c) - 33;
+
+ // skip spaces and nonprintable characters
+ if(*c == '\n')
+ {
+ bigWidth = bigWidth >= width? bigWidth : width;
+ width = 0;
+ }
+ else if (*c == ' ' || charnum > 222)
+ {
+ width += charWidth[0];
+ continue;
+ }
+
+ width += charWidth[charnum];
+ }
+ bigWidth = bigWidth >= width? bigWidth : width;
+
+ return bigWidth;
+}
+
+int NFont::getAscent(const char character) const
+{
+ unsigned char test = (unsigned char)character;
+ if(test < 33 || test > 222 || (test > 126 && test < 161))
+ return 0;
+ unsigned char num = (unsigned char)character - 33;
+ // Get the max ascent
+ int x = charPos[num];
+ int i, j = 1, result = 0;
+ Uint32 pixel = getPixel(src, 0, src->h - 1); // bg pixel
+ while(j < baseline && j < src->h)
+ {
+ i = charPos[num];
+ while(i < x + charWidth[num])
+ {
+ if(getPixel(src, i, j) != pixel)
+ {
+ result = baseline - j;
+ j = src->h;
+ break;
+ }
+ i++;
+ }
+ j++;
+ }
+ return result;
+}
+
+int NFont::getAscent(const char* formatted_text, ...) const
+{
+ if(formatted_text == NULL)
+ return ascent;
+
+ va_list lst;
+ va_start(lst, formatted_text);
+ vsprintf(buffer, formatted_text, lst);
+ va_end(lst);
+
+ int max = 0;
+ const char* c = buffer;
+
+ for (; *c != '\0'; c++)
+ {
+ int asc = getAscent(*c);
+ if(asc > max)
+ max = asc;
+ }
+ return max;
+}
+
+int NFont::getDescent(const char character) const
+{
+ unsigned char test = (unsigned char)character;
+ if(test < 33 || test > 222 || (test > 126 && test < 161))
+ return 0;
+ unsigned char num = (unsigned char)character - 33;
+ // Get the max descent
+ int x = charPos[num];
+ int i, j = src->h - 1, result = 0;
+ Uint32 pixel = getPixel(src, 0, src->h - 1); // bg pixel
+ while(j > 0 && j > baseline)
+ {
+ i = charPos[num];
+ while(i < x + charWidth[num])
+ {
+ if(getPixel(src, i, j) != pixel)
+ {
+ result = j - baseline;
+ j = 0;
+ break;
+ }
+ i++;
+ }
+ j--;
+ }
+ return result;
+}
+
+int NFont::getDescent(const char* formatted_text, ...) const
+{
+ if(formatted_text == NULL)
+ return descent;
+
+ va_list lst;
+ va_start(lst, formatted_text);
+ vsprintf(buffer, formatted_text, lst);
+ va_end(lst);
+
+ int max = 0;
+ const char* c = buffer;
+
+ for (; *c != '\0'; c++)
+ {
+ int des = getDescent(*c);
+ if(des > max)
+ max = des;
+ }
+ return max;
+}
+
+int NFont::getSpacing() const
+{
+ return letterSpacing;
+}
+
+int NFont::getLineSpacing() const
+{
+ return lineSpacing;
+}
+
+int NFont::getBaseline() const
+{
+ return baseline;
+}
+
+int NFont::getMaxWidth() const
+{
+ return maxWidth;
+}
+
+
+
+
+
+// Setters
+void NFont::setSpacing(int LetterSpacing)
+{
+ letterSpacing = LetterSpacing;
+}
+
+void NFont::setLineSpacing(int LineSpacing)
+{
+ lineSpacing = LineSpacing;
+}
+
+void NFont::setDest(SDL_Surface* Dest)
+{
+ dest = Dest;
+}
+
+int NFont::setBaseline(int Baseline)
+{
+ if(Baseline >= 0)
+ baseline = Baseline;
+ else
+ {
+ // Get the baseline by checking a, b, and c and averaging their lowest y-value.
+ // Is there a better way?
+ Uint32 pixel = getPixel(src, 0, src->h - 1);
+ int heightSum = 0;
+ int x, i, j;
+ for(unsigned char avgChar = 64; avgChar < 67; avgChar++)
+ {
+ x = charPos[avgChar];
+
+ j = src->h - 1;
+ while(j > 0)
+ {
+ i = x;
+ while(i - x < charWidth[64])
+ {
+ if(getPixel(src, i, j) != pixel)
+ {
+ heightSum += j;
+ j = 0;
+ break;
+ }
+ i++;
+ }
+ j--;
+ }
+ }
+ baseline = int(heightSum/3.0f + 0.5f); // Round up and cast
+ }
+ return baseline;
+}
+
+
+
+
+
+
+
diff --git a/source/code/Libs/NFont.h b/source/code/Libs/NFont.h new file mode 100644 index 0000000..14036e5 --- /dev/null +++ b/source/code/Libs/NFont.h
@@ -0,0 +1,224 @@
+
+// Define this here or in your project settings if you want to use the SDL_ttf features.
+#define NFONT_USE_TTF
+
+/*
+NFont v2.0.0: A bitmap font class for SDL
+by Jonathan Dearborn 2-4-10
+(class originally adapted from Florian Hufsky)
+
+Requires:
+ SDL ("SDL.h") [www.libsdl.org]
+
+Optionally Requires:
+ SDL_ttf ("SDL_ttf.h") [www.libsdl.org]
+
+Notes:
+ NFont is a bitmap font class with text-block alignment, full
+ support for the newline character ('\n'), animation, and extended ASCII
+ support. It accepts SDL_Surfaces so that any image format you can load
+ can be used as an NFont.
+
+ NFont has the ability to animate the font in two ways: It's position or
+ it's everything. By using drawPos(), you can use a function you create
+ to handle the final positions of the drawn characters. With drawAll(),
+ you can handle everything that the font does (please use my
+ drawToSurface() function as a reference).
+
+ Internally, NFont uses a pointer (SDL_Surface*) to handle the destination
+ surface. You have to set the destination before the font can be used. Be
+ aware that you will need to use setDest() if you replace the memory that
+ it points to (like when using screen = SDL_SetVideoMode()).
+
+ NFont can use standard SFont bitmaps or extended bitmaps. The standard bitmaps
+ have the following characters (ASCII 33-126) separated by pink (255, 0, 255) pixels in the topmost
+ row:
+ ! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~
+
+ And the extended bitmaps have these (ASCII 161-255):
+ ! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~ � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � �
+
+ NFont can also load SDL_ttf fonts. Define NFONT_USE_TTF before including
+ NFont.h to use the flexibility of NFont with TrueType fonts.
+
+ If you come up with something cool using NFont, I'd love to hear about it.
+ Any comments can be sent to GrimFang4 [at] gmail [dot] com
+
+License:
+ The short:
+ Use it however you'd like, but keep the copyright and license notice
+ whenever these files or parts of them are distributed in uncompiled form.
+
+ The long:
+Copyright (c) 2010 Jonathan Dearborn
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+
+*/
+
+#ifndef _NFONT_H__
+#define _NFONT_H__
+
+#include "SDL.h"
+#include "stdarg.h"
+
+#ifdef NFONT_USE_TTF
+ #include "SDL_ttf.h"
+#endif
+
+class NFont
+{
+public:
+
+ // Nested struct
+ struct AnimData
+ {
+ const NFont* font;
+
+ SDL_Surface* dest;
+ SDL_Surface* src;
+ char* text; // Buffer for efficient drawing
+ int height;
+ const int* charPos;
+ const int* charWidth;
+ int maxX;
+
+ int index;
+ int letterNum;
+ int wordNum;
+ int lineNum;
+ int startX;
+ int startY;
+ void* userVar;
+
+ SDL_Rect dirtyRect;
+ };
+
+ // Function pointer
+ typedef void (*AnimFn)(int&, int&, AnimData&);
+
+protected:
+
+
+ SDL_Surface* src; // bitmap source of characters
+ SDL_Surface* dest; // Destination to blit to
+
+ int height;
+
+ int maxWidth;
+ int baseline;
+ int ascent;
+ int descent;
+
+ int lineSpacing;
+ int letterSpacing;
+
+ int charPos[256];
+ int charWidth[256];
+ int maxPos;
+
+ void init();
+
+ SDL_Rect drawToSurface(int x, int y, const char* text) const;
+ SDL_Rect drawToSurfacePos(int x, int y, NFont::AnimFn posFn) const;
+
+ // Static variables
+ static char* buffer; // Buffer for efficient drawing
+ static AnimData data; // Data is wrapped in a struct so it can all be passed to
+ // the function pointers for animation
+
+public:
+
+ // Static functions
+ static char* copyString(const char* c);
+ static Uint32 getPixel(SDL_Surface *Surface, int x, int y);
+ static inline SDL_Rect makeRect(Sint16 x, Sint16 y, Uint16 w, Uint16 h)
+ {
+ SDL_Rect r = {x, y, w, h};
+ return r;
+ }
+ static SDL_Rect rectUnion(const SDL_Rect& A, const SDL_Rect& B);
+ static SDL_Surface* copySurface(SDL_Surface *Surface);
+ static SDL_Surface* verticalGradient(SDL_Surface* targetSurface, Uint32 topColor, Uint32 bottomColor, int heightAdjust = 0);
+
+ // Static accessors
+ static void setAnimData(void* data);
+ static void setBuffer(unsigned int size);
+
+ // Constructors
+ NFont();
+ NFont(SDL_Surface* src);
+ NFont(SDL_Surface* dest, SDL_Surface* src);
+ #ifdef NFONT_USE_TTF
+ NFont(TTF_Font* ttf, SDL_Color fg); // Alpha bg
+ NFont(TTF_Font* ttf, SDL_Color fg, SDL_Color bg);
+ NFont(const char* filename_ttf, Uint32 pointSize, SDL_Color fg, int style = TTF_STYLE_NORMAL); // Alpha bg
+ NFont(const char* filename_ttf, Uint32 pointSize, SDL_Color fg, SDL_Color bg, int style = TTF_STYLE_NORMAL);
+ NFont(SDL_Surface* dest, TTF_Font* ttf, SDL_Color fg); // Alpha bg
+ NFont(SDL_Surface* dest, TTF_Font* ttf, SDL_Color fg, SDL_Color bg);
+ NFont(SDL_Surface* dest, const char* filename_ttf, Uint32 pointSize, SDL_Color fg, int style = TTF_STYLE_NORMAL); // Alpha bg
+ NFont(SDL_Surface* dest, const char* filename_ttf, Uint32 pointSize, SDL_Color fg, SDL_Color bg, int style = TTF_STYLE_NORMAL);
+ #endif
+
+ ~NFont();
+
+ // Loading
+ bool load(SDL_Surface* FontSurface);
+ bool load(SDL_Surface* destSurface, SDL_Surface* FontSurface);
+ #ifdef NFONT_USE_TTF
+ bool load(TTF_Font* ttf, SDL_Color fg); // Alpha bg
+ bool load(TTF_Font* ttf, SDL_Color fg, SDL_Color bg);
+ bool load(const char* filename_ttf, Uint32 pointSize, SDL_Color fg, int style = TTF_STYLE_NORMAL); // Alpha bg
+ bool load(const char* filename_ttf, Uint32 pointSize, SDL_Color fg, SDL_Color bg, int style = TTF_STYLE_NORMAL);
+ #endif
+
+ void freeSurface();
+
+ // Drawing
+ SDL_Rect draw(int x, int y, const char* formatted_text, ...) const;
+ SDL_Rect drawCenter(int x, int y, const char* formatted_text, ...) const;
+ SDL_Rect drawRight(int x, int y, const char* formatted_text, ...) const;
+ SDL_Rect drawPos(int x, int y, NFont::AnimFn posFn, const char* text, ...) const;
+ SDL_Rect drawAll(int x, int y, NFont::AnimFn allFn, const char* text, ...) const;
+
+ // Getters
+ SDL_Surface* getDest() const;
+ SDL_Surface* getSurface() const;
+ int getHeight(const char* formatted_text = NULL, ...) const;
+ int getWidth(const char* formatted_text, ...) const;
+ int getSpacing() const;
+ int getLineSpacing() const;
+ int getBaseline() const;
+ int getAscent(const char character) const;
+ int getAscent(const char* formatted_text = NULL, ...) const;
+ int getDescent(const char character) const;
+ int getDescent(const char* formatted_text = NULL, ...) const;
+ int getMaxWidth() const;
+
+ // Setters
+ void setDest(SDL_Surface* Dest);
+ void setSpacing(int LetterSpacing);
+ void setLineSpacing(int LineSpacing);
+ int setBaseline(int Baseline = -1);
+
+};
+
+
+
+#endif // _NFONT_H__
diff --git a/source/code/SConscript b/source/code/SConscript index ed28147..8ec1095 100644 --- a/source/code/SConscript +++ b/source/code/SConscript
@@ -6,7 +6,7 @@ Import('*')
# Sources #
src = Split("""main.cpp
highscore.cpp
-SFont.c
+Libs/NFont.c
ReadKeyboard.cpp
joypad.cpp
listFiles.cpp
diff --git a/source/code/SFont.c b/source/code/SFont.c deleted file mode 100644 index db4c041..0000000 --- a/source/code/SFont.c +++ /dev/null
@@ -1,178 +0,0 @@
-/* SFont: a simple font-library that uses special .pngs as fonts
- Copyright (C) 2003 Karl Bartel
-
- License: GPL or LGPL (at your choice)
- WWW: http://www.linux-games.com/sfont/
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
- Karl Bartel
- Cecilienstr. 14
- 12307 Berlin
- GERMANY
- karlb@gmx.net
-*/
-#include <SDL.h>
-
-#include <assert.h>
-#include <stdlib.h>
-#include "SFont.h"
-
-static long GetPixel(SDL_Surface *Surface, Sint32 X, Sint32 Y)
-{
- Uint8 *bits;
- Uint32 Bpp;
-
- assert(X>=0);
- assert(X<Surface->w);
-
- Bpp = Surface->format->BytesPerPixel;
- bits = ((Uint8 *)Surface->pixels)+Y*Surface->pitch+X*Bpp;
-
- // Get the pixel
- switch(Bpp) {
- case 1:
- return *((Uint8 *)Surface->pixels + Y * Surface->pitch + X);
- break;
- case 2:
- return *((Uint16 *)Surface->pixels + Y * Surface->pitch/2 + X);
- break;
- case 3: { // Format/endian independent
- Uint8 r, g, b;
- r = *((bits)+Surface->format->Rshift/8);
- g = *((bits)+Surface->format->Gshift/8);
- b = *((bits)+Surface->format->Bshift/8);
- return SDL_MapRGB(Surface->format, r, g, b);
- }
- break;
- case 4:
- return *((Uint32 *)Surface->pixels + Y * Surface->pitch/4 + X);
- break;
- }
-
- return -1;
-}
-
-SFont_Font* SFont_InitFont(SDL_Surface* Surface)
-{
- int x = 0, i = 0;
- Uint32 pixel;
- SFont_Font* Font;
- Uint32 pink;
-
- if (Surface == NULL)
- return NULL;
-
- Font = (SFont_Font *) malloc(sizeof(SFont_Font));
- Font->Surface = Surface;
-
- SDL_LockSurface(Surface);
-
- pink = SDL_MapRGB(Surface->format, 255, 0, 255);
- while (x < Surface->w) {
- if (GetPixel(Surface, x, 0) == pink) {
- Font->CharPos[i++]=x;
- while((x < Surface->w) && (GetPixel(Surface, x, 0)== pink))
- x++;
- Font->CharPos[i++]=x;
- }
- x++;
- }
- Font->MaxPos = x-1;
-
- pixel = GetPixel(Surface, 0, Surface->h-1);
- SDL_UnlockSurface(Surface);
- SDL_SetColorKey(Surface, SDL_SRCCOLORKEY, pixel);
-
- return Font;
-}
-
-void SFont_FreeFont(SFont_Font* FontInfo)
-{
- SDL_FreeSurface(FontInfo->Surface);
- free(FontInfo);
-}
-
-void SFont_Write(SDL_Surface *Surface, const SFont_Font *Font,
- int x, int y, const char *text)
-{
- const char* c;
- int charoffset;
- SDL_Rect srcrect, dstrect;
-
- if(text == NULL)
- return;
-
- // these values won't change in the loop
- srcrect.y = 1;
- dstrect.y = y;
- srcrect.h = dstrect.h = Font->Surface->h - 1;
-
- for(c = text; *c != '\0' && x <= Surface->w ; c++) {
- charoffset = ((int) (*c - 33)) * 2 + 1;
- // skip spaces and nonprintable characters
- if (*c == ' ' || charoffset < 0 || charoffset > Font->MaxPos) {
- x += Font->CharPos[2]-Font->CharPos[1];
- continue;
- }
-
- srcrect.w = dstrect.w =
- (Font->CharPos[charoffset+2] + Font->CharPos[charoffset+1])/2 -
- (Font->CharPos[charoffset] + Font->CharPos[charoffset-1])/2;
- srcrect.x = (Font->CharPos[charoffset]+Font->CharPos[charoffset-1])/2;
- dstrect.x = x - (int)(Font->CharPos[charoffset]
- - Font->CharPos[charoffset-1])/2;
-
- SDL_BlitSurface(Font->Surface, &srcrect, Surface, &dstrect);
-
- x += Font->CharPos[charoffset+1] - Font->CharPos[charoffset];
- }
-}
-
-int SFont_TextWidth(const SFont_Font *Font, const char *text)
-{
- const char* c;
- int charoffset=0;
- int width = 0;
-
- if(text == NULL)
- return 0;
-
- for(c = text; *c != '\0'; c++) {
- charoffset = ((int) *c - 33) * 2 + 1;
- // skip spaces and nonprintable characters
- if (*c == ' ' || charoffset < 0 || charoffset > Font->MaxPos) {
- width += Font->CharPos[2]-Font->CharPos[1];
- continue;
- }
-
- width += Font->CharPos[charoffset+1] - Font->CharPos[charoffset];
- }
-
- return width;
-}
-
-int SFont_TextHeight(const SFont_Font* Font)
-{
- return Font->Surface->h - 1;
-}
-
-void SFont_WriteCenter(SDL_Surface *Surface, const SFont_Font *Font,
- int y, const char *text)
-{
- SFont_Write(Surface, Font, Surface->w/2 - SFont_TextWidth(Font, text)/2,
- y, text);
-}
-
diff --git a/source/code/SFont.h b/source/code/SFont.h deleted file mode 100644 index d8f9de8..0000000 --- a/source/code/SFont.h +++ /dev/null
@@ -1,83 +0,0 @@
-/* SFont: a simple font-library that uses special bitmaps as fonts
- Copyright (C) 2003 Karl Bartel
-
- License: GPL or LGPL (at your choice)
- WWW: http://www.linux-games.com/sfont/
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
- Karl Bartel
- Cecilienstr. 14
- 12307 Berlin
- GERMANY
- karlb@gmx.net
-*/
-
-/************************************************************************
-* SFONT - SDL Font Library by Karl Bartel <karlb@gmx.net> *
-* *
-* All functions are explained below. For further information, take a *
-* look at the example files, the links at the SFont web site, or *
-* contact me, if you problem isn' addressed anywhere. *
-* *
-************************************************************************/
-#ifndef SFONT_H
-#define SFONT_H
-
-#include <SDL.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-// Delcare one variable of this type for each font you are using.
-// To load the fonts, load the font image into YourFont->Surface
-// and call InitFont( YourFont );
- typedef struct {
- SDL_Surface *Surface;
- int CharPos[512];
- int MaxPos;
- } SFont_Font;
-
-// Initializes the font
-// Font: this contains the suface with the font.
-// The Surface must be loaded before calling this function
- SFont_Font* SFont_InitFont (SDL_Surface *Font);
-
-// Frees the font
-// Font: The font to free
-// The font must be loaded before using this function.
- void SFont_FreeFont(SFont_Font* Font);
-
-// Blits a string to a surface
-// Destination: the suface you want to blit to
-// text: a string containing the text you want to blit.
- void SFont_Write(SDL_Surface *Surface, const SFont_Font *Font, int x, int y,
- const char *text);
-
-// Returns the width of "text" in pixels
- int SFont_TextWidth(const SFont_Font* Font, const char *text);
-// Returns the height of "text" in pixels (which is always equal to Font->Surface->h)
- int SFont_TextHeight(const SFont_Font* Font);
-
-// Blits a string to Surface with centered x position
- void SFont_WriteCenter(SDL_Surface *Surface, const SFont_Font* Font, int y,
- const char *text);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* SFONT_H */
diff --git a/source/code/block.make b/source/code/block.make index b3660ad..01826c3 100644 --- a/source/code/block.make +++ b/source/code/block.make
@@ -16,8 +16,7 @@ ifndef BUILDDIR
BUILDDIR=build
endif
-BASE_LIBS=$(shell sdl-config --libs) -lSDL_image -lSDL_mixer
-#-lSDL_ttf
+BASE_LIBS=$(shell sdl-config --libs) -lSDL_image -lSDL_mixer -lSDL_ttf
#For developement only
ifndef DEBUG
@@ -44,9 +43,9 @@ endif
BASE_LIBS += -lphysfs
-$(BINARY): $(BUILDDIR)/main.o $(BUILDDIR)/highscore.o $(BUILDDIR)/SFont.o $(BUILDDIR)/ReadKeyboard.o $(BUILDDIR)/joypad.o $(BUILDDIR)/listFiles.o $(BUILDDIR)/replay.o $(BUILDDIR)/common.o $(BUILDDIR)/stats.o
+$(BINARY): $(BUILDDIR)/main.o $(BUILDDIR)/highscore.o $(BUILDDIR)/ReadKeyboard.o $(BUILDDIR)/joypad.o $(BUILDDIR)/listFiles.o $(BUILDDIR)/replay.o $(BUILDDIR)/common.o $(BUILDDIR)/stats.o $(BUILDDIR)/nfont.o
@make -C CppSdl
- $(CPP) -O -o $(BINARY) $(BUILDDIR)/main.o $(BUILDDIR)/highscore.o $(BUILDDIR)/SFont.o $(BUILDDIR)/ReadKeyboard.o $(BUILDDIR)/joypad.o $(BUILDDIR)/listFiles.o $(BUILDDIR)/replay.o $(BUILDDIR)/common.o $(BUILDDIR)/stats.o $(BUILDDIR)/CppSdlException.o $(BUILDDIR)/CppSdlImageHolder.o $(BASE_LIBS)
+ $(CPP) -O -o $(BINARY) $(BUILDDIR)/main.o $(BUILDDIR)/highscore.o $(BUILDDIR)/ReadKeyboard.o $(BUILDDIR)/joypad.o $(BUILDDIR)/listFiles.o $(BUILDDIR)/replay.o $(BUILDDIR)/common.o $(BUILDDIR)/stats.o $(BUILDDIR)/CppSdlException.o $(BUILDDIR)/CppSdlImageHolder.o $(BUILDDIR)/nfont.o $(BASE_LIBS)
#-lphysfs
$(BUILDDIR)/main.o: main.cpp mainVars.hpp common.h
@@ -58,8 +57,6 @@ $(BUILDDIR)/blockgame.o: BlockGame.hpp BlockGame.cpp
$(BUILDDIR)/highscore.o: highscore.h highscore.cpp
$(CPP) $(BASE_CFLAGS) highscore.cpp -o $(BUILDDIR)/highscore.o
-$(BUILDDIR)/SFont.o: SFont.h SFont.c
- $(CC) $(BASE_CFLAGS) SFont.c -o $(BUILDDIR)/SFont.o
$(BUILDDIR)/ReadKeyboard.o: ReadKeyboard.h ReadKeyboard.cpp
$(CPP) $(BASE_CFLAGS) ReadKeyboard.cpp -o $(BUILDDIR)/ReadKeyboard.o
@@ -79,6 +76,9 @@ $(BUILDDIR)/stats.o: stats.h stats.cc
$(BUILDDIR)/common.o: common.h common.cc
$(CPP) $(BASE_CFLAGS) common.cc -o $(BUILDDIR)/common.o
+$(BUILDDIR)/nfont.o: Libs/NFont.h Libs/NFont.cpp
+ $(CPP) $(BASE_CFLAGS) Libs/NFont.cpp -o $(BUILDDIR)/nfont.o
+
#$(BUILDDIR)/uploadReplay.o: uploadReplay.cc uploadReplay.h
# $(CPP) $(BASE_CFLAGS) uploadReplay.cc -o $(BUILDDIR)/uploadReplay.o
diff --git a/source/code/main.cpp b/source/code/main.cpp index 2dd7b72..703fdb2 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp
@@ -65,10 +65,13 @@ Copyright (C) 2008 Poul Sander
#include <SDL_image.h> //To load PNG images!
#include <physfs.h> //Abstract file system. To use containers
#include "physfs_stream.hpp" //To use C++ style file streams
+#include "Libs/NFont.h"
//#include "ttfont.h" //To use True Type Fonts in SDL
//#include "config.h"
#include <vector>
#include <SDL/SDL_timer.h>
+#include <SDL/SDL_video.h>
+#include <SDL/SDL_ttf.h>
#include "CppSdl/CppSdlImageHolder.hpp"
//#include "MenuSystem.h"
@@ -85,7 +88,7 @@ Copyright (C) 2008 Poul Sander
#endif
//enet things end
-#include "SFont.h" //Used to write on screen
+//#include "SFont.h" //Used to write on screen
#include "highscore.h" //Stores highscores
#include "ReadKeyboard.h" //Reads text from keyboard
#include "joypad.h" //Used for joypads
@@ -246,26 +249,60 @@ void loadTheme(string themeName)
loaded = true;
}
-/*TTF_Font * TTF_OpenFont2(char* path, int ptsize) {
- char * tmp;
- TTF_Font * ret=NULL;
- tmp = (char*)malloc (sizeof(char)*(strlen(path)+strlen(sharedir)+2));
- strcpy(tmp, sharedir);
- strcat(tmp, "/");
- strcat(tmp, path);
-#if DEBUG
- printf("loading %s\n",tmp);
-#endif
+long NFont_OpenFont(NFont *target, string path,int ptsize, SDL_Color color, int style=TTF_STYLE_NORMAL) {
+ if (!PHYSFS_exists(path.c_str()))
+ {
+ cout << "File not in blockattack.data: " << path << endl;
+ return -1; //file doesn't exist
+ }
+
if(!(TTF_WasInit()))
TTF_Init();
- if (!(ret = TTF_OpenFont(tmp, ptsize)))
- ret = TTF_OpenFont(path, ptsize);
- if(!ret)
- cout << "failed to load font: " << TTF_GetError() << endl;
- free(tmp);
- return ret;
-}*/
+
+ PHYSFS_file* myfile = PHYSFS_openRead(path.c_str());
+
+ // Get the lenght of the file
+ unsigned int m_size = PHYSFS_fileLength(myfile);
+
+ // Get the file data.
+ char *m_data = new char[m_size];
+ int length_read = PHYSFS_read (myfile, m_data, 1, m_size);
+
+ if (length_read != (int)m_size)
+ {
+ delete [] m_data;
+ m_data = 0;
+ PHYSFS_close(myfile);
+ cout << "Error. Curropt data file!" << endl;
+ return NULL;
+ }
+
+ PHYSFS_close(myfile);
+
+// And this is how you load from a memory buffer with SDL
+ SDL_RWops *rw = SDL_RWFromMem (m_data, m_size);
+
+ //The above might fail an return null.
+ if(!rw)
+ {
+ delete [] m_data;
+ m_data = 0;
+ PHYSFS_close(myfile);
+ cout << "Error. Curropt data file!" << endl;
+ return -2;
+ }
+
+ TTF_Font *font;
+ font=TTF_OpenFontRW(rw, 1, ptsize);
+ TTF_SetFontStyle(font,style);
+
+ target->load(font,color);
+
+ TTF_CloseFont(font); //Once loaded we don't care anymore!
+
+ return 0;
+}
Mix_Music * Mix_LoadMUS2(string path)
@@ -427,8 +464,8 @@ static int InitImages()
&& (iDraw = IMG_Load2((char*)"gfx/iDraw.png"))
&& (iLoser = IMG_Load2((char*)"gfx/iLoser.png"))
&& (iChainBack = IMG_Load2((char*)"gfx/chainFrame.png"))
- && (iBlueFont = IMG_Load2((char*)"gfx/24P_Arial_Blue.png"))
- && (iSmallFont = IMG_Load2((char*)"gfx/14P_Arial_Angle_Red.png"))
+ //&& (iBlueFont = IMG_Load2((char*)"gfx/24P_Arial_Blue.png"))
+ // && (iSmallFont = IMG_Load2((char*)"gfx/14P_Arial_Angle_Red.png"))
&& (optionsBack = IMG_Load2((char*)"gfx/options.png"))
&& (bOn = IMG_Load2((char*)"gfx/bOn.png"))
&& (bOff = IMG_Load2((char*)"gfx/bOff.png"))
@@ -585,8 +622,8 @@ static int InitImages()
CONVERTA(iDraw);
CONVERTA(iLoser);
CONVERTA(iChainBack);
- CONVERTA(iBlueFont);
- CONVERTA(iSmallFont);
+ //CONVERTA(iBlueFont);
+ //CONVERTA(iSmallFont);
CONVERTA(iGameOver);
// CONVERTA(mouse);
mouse.OptimizeForBlit(true);
@@ -612,13 +649,24 @@ static int InitImages()
#endif
//Here comes the fonts:
- fBlueFont = SFont_InitFont(iBlueFont);
- fSmallFont = SFont_InitFont(iSmallFont);
+ //fBlueFont = SFont_InitFont(iBlueFont);
+ //fSmallFont = SFont_InitFont(iSmallFont);
//And the ttf font:
/*TTF_Font *ttFont1 = TTF_OpenFont2((char*)"fonts/FreeSerif.ttf", 24);
TTF_SetFontStyle(ttFont1,TTF_STYLE_BOLD);
ttfont = TTFont(ttFont1);*/
+ SDL_Color nf_button_color, nf_standard_blue_color, nf_standard_small_color;
+ memset(&nf_button_color,0,sizeof(SDL_Color));
+ nf_button_color.b = 255; nf_button_color.g = 255; nf_button_color.r = 255;
+ nf_standard_blue_color.b = 255; nf_standard_blue_color.g = 0; nf_standard_blue_color.r = 0;
+ nf_standard_small_color.b = 0; nf_standard_small_color.g = 0; nf_standard_small_color.r = 200;
+ NFont_OpenFont(&nf_button_font,"fonts/FreeSerif.ttf",24,nf_button_color);
+ nf_button_font.setDest(screen);
+ NFont_OpenFont(&nf_standard_blue_font,"fonts/FreeSerif.ttf",30,nf_standard_blue_color);
+ nf_standard_blue_font.setDest(screen);
+ NFont_OpenFont(&nf_standard_small_font,"fonts/FreeSerif.ttf",16,nf_standard_small_color);
+ nf_standard_small_font.setDest(screen);
//Loads the sound if sound present
if (!NoSound)
@@ -644,8 +692,8 @@ void UnloadImages()
{
cout << "Unloading data..." << endl;
//Fonts and Sounds needs to be freed
- SFont_FreeFont(fBlueFont);
- SFont_FreeFont(fSmallFont);
+ //SFont_FreeFont(fBlueFont);
+ //SFont_FreeFont(fSmallFont);
if (!NoSound) //Only unload then it has been loaded!
{
Mix_HaltMusic();
@@ -818,6 +866,12 @@ void DrawIMG(SDL_Surface *img, SDL_Surface * target, int x, int y, int w, int h,
SDL_BlitSurface(img, &dest2, target, &dest);
}
+void NFont_Write(SDL_Surface *target,int x,int y,string text) {
+ nf_standard_blue_font.setDest(target);
+ nf_standard_blue_font.draw(x,y,text.c_str());
+ nf_standard_blue_font.setDest(screen);
+}
+
//Menu
/*void PrintHi()
{
@@ -1204,7 +1258,6 @@ static textManeger theTextManeger;
//Here comes the Block Game object
#include "BlockGame.hpp"
#include "BlockGame.cpp"
-#include "SFont.h"
class BlockGameSdl : public BlockGame {
public:
@@ -1466,6 +1519,7 @@ public:
//Draws everything
void DoPaintJob() {
DrawIMG(backBoard, sBoard, 0, 0);
+ nf_standard_blue_font.setDest(sBoard); //reset to screen at the end of this funciton!
#if NETWORK
if ((!bReplaying)&&(!bNetworkPlayer))
#else
@@ -1478,7 +1532,9 @@ public:
if (puzzleMode&&(!bGameOver)) {
//We need to write nr. of moves left!
strHolder = "Moves left: " + itoa(MovesLeft);
- SFont_Write(sBoard, fBlueFont, 5, 5, strHolder.c_str());
+ //NFont_Write(sBoard, 5, 5, strHolder.c_str());
+ nf_standard_blue_font.draw(5,5,strHolder.c_str());
+
}
if(puzzleMode && stageButtonStatus == SBpuzzleMode)
{
@@ -1493,7 +1549,8 @@ public:
else
{
strHolder = "Last puzzle";
- SFont_Write(sBoard, fBlueFont, 5, 5, strHolder.c_str());
+ //NFont_Write(sBoard, 5, 5, strHolder.c_str());
+ nf_standard_blue_font.draw(5,5,strHolder.c_str());
}
}
if(stageClear && stageButtonStatus == SBstageClear)
@@ -1509,14 +1566,16 @@ public:
else
{
strHolder = "Last stage";
- SFont_Write(sBoard, fBlueFont, 5, 5, strHolder.c_str());
+ //NFont_Write(sBoard, 5, 5, strHolder.c_str());
+ nf_standard_blue_font.draw(5,5,strHolder.c_str());
}
}
#if DEBUG
if (AI_Enabled&&(!bGameOver)) {
strHolder = "AI_status: " + itoa(AIstatus)+ ", "+ itoa(AIlineToClear);
- SFont_Write(sBoard, fBlueFont, 5, 5, strHolder.c_str());
+ //NFont_Write(sBoard, 5, 5, strHolder.c_str());
+ nf_standard_blue_font.draw(5,5,strHolder.c_str());
}
#endif
if (!bGameOver)DrawIMG(cursor[(ticks/600)%2],sBoard,cursorx*bsize-4,11*bsize-cursory*bsize-pixels-4);
@@ -1567,6 +1626,7 @@ public:
else if (bDraw) DrawIMG(iDraw, sBoard, 0, 5*bsize);
else
DrawIMG(iGameOver, sBoard, 0, 5*bsize);
+ nf_standard_blue_font.setDest(screen);
}
@@ -1628,34 +1688,34 @@ int OpenControlsBox(int x, int y, int player)
DrawIMG(background, screen, 0, 0);
DrawIMG(changeButtonsBack,screen,x,y);
if (player == 0)
- SFont_Write(screen,fBlueFont,x+40,y+2,"Player 1 keys");
+ NFont_Write(screen, x+40,y+2,"Player 1 keys");
else
- SFont_Write(screen,fBlueFont,x+40,y+2,"Player 2 keys");
- SFont_Write(screen,fBlueFont,x+6,y+50,"Up");
+ NFont_Write(screen, x+40,y+2,"Player 2 keys");
+ NFont_Write(screen, x+6,y+50,"Up");
keyname = getKeyName(keySettings[player].up);
- SFont_Write(screen,fBlueFont,x+200,y+50,keyname.c_str());
- SFont_Write(screen,fBlueFont,x+6,y+100,"Down");
+ NFont_Write(screen, x+200,y+50,keyname.c_str());
+ NFont_Write(screen, x+6,y+100,"Down");
keyname = getKeyName(keySettings[player].down);
- SFont_Write(screen,fBlueFont,x+200,y+100,keyname.c_str());
- SFont_Write(screen,fBlueFont,x+6,y+150,"Left");
+ NFont_Write(screen, x+200,y+100,keyname.c_str());
+ NFont_Write(screen, x+6,y+150,"Left");
keyname = getKeyName(keySettings[player].left);
- SFont_Write(screen,fBlueFont,x+200,y+150,keyname.c_str());
- SFont_Write(screen,fBlueFont,x+6,y+200,"Right");
+ NFont_Write(screen, x+200,y+150,keyname.c_str());
+ NFont_Write(screen, x+6,y+200,"Right");
keyname = getKeyName(keySettings[player].right);
- SFont_Write(screen,fBlueFont,x+200,y+200,keyname.c_str());
- SFont_Write(screen,fBlueFont,x+6,y+250,"Push");
+ NFont_Write(screen, x+200,y+200,keyname.c_str());
+ NFont_Write(screen, x+6,y+250,"Push");
keyname = getKeyName(keySettings[player].push);
- SFont_Write(screen,fBlueFont,x+200,y+250,keyname.c_str());
- SFont_Write(screen,fBlueFont,x+6,y+300,"Change");
+ NFont_Write(screen, x+200,y+250,keyname.c_str());
+ NFont_Write(screen, x+6,y+300,"Change");
keyname = getKeyName(keySettings[player].change);
- SFont_Write(screen,fBlueFont,x+200,y+300,keyname.c_str());
+ NFont_Write(screen, x+200,y+300,keyname.c_str());
//Ask for mouse play
- SFont_Write(screen,fBlueFont,x+6,y+350,"Mouse play?");
+ NFont_Write(screen, x+6,y+350,"Mouse play?");
DrawIMG(iLevelCheckBox,screen,x+220,y+350);
if (((player==0)&&(mouseplay1))||((player==2)&&(mouseplay2)))
DrawIMG(iLevelCheck,screen,x+220,y+350); //iLevelCheck witdh is 42
//Ask for joypad play
- SFont_Write(screen,fBlueFont,x+300,y+350,"Joypad?");
+ NFont_Write(screen, x+300,y+350,"Joypad?");
DrawIMG(iLevelCheckBox,screen,x+460,y+350);
if (((player==0)&&(joyplay1))||((player==2)&&(joyplay2)))
DrawIMG(iLevelCheck,screen,x+460,y+350); //iLevelCheck witdh is 42
@@ -1831,12 +1891,12 @@ bool OpenDialogbox(int x, int y, char *name)
while (!done)
{
DrawIMG(dialogBox,screen,x,y);
- SFont_Write(screen,fBlueFont,x+40,y+72,rk.GetString());
+ NFont_Write(screen, x+40,y+72,rk.GetString());
strHolder = rk.GetString();
strHolder.erase((int)rk.CharsBeforeCursor());
if (((SDL_GetTicks()/600)%2)==1)
- SFont_Write(screen,fBlueFont,x+40+SFont_TextWidth(fBlueFont,strHolder.c_str()),y+69,"|");
+ NFont_Write(screen, x+40+nf_standard_blue_font.getWidth( strHolder.c_str()),y+69,"|");
SDL_Event event;
@@ -1895,8 +1955,8 @@ void DrawHighscores(int x, int y, bool endless)
{
MakeBackground(xsize,ysize);
DrawIMG(background,screen,0,0);
- if (endless) SFont_Write(screen,fBlueFont,x+100,y+100,"Endless:");
- else SFont_Write(screen,fBlueFont,x+100,y+100,"Time Trial:");
+ if (endless) nf_standard_blue_font.draw(x+100,y+100,"Endless:");
+ else nf_standard_blue_font.draw(x+100,y+100,"Time Trial:");
for (int i =0;i<10;i++)
{
char playerScore[32];
@@ -1917,8 +1977,8 @@ void DrawHighscores(int x, int y, bool endless)
{
strcpy(playerName,theTopScoresTimeTrial.getScoreName(i));
}
- SFont_Write(screen,fBlueFont,x+420,y+150+i*35,playerScore);
- SFont_Write(screen,fBlueFont,x+60,y+150+i*35,playerName);
+ nf_standard_blue_font.draw(x+420,y+150+i*35,playerScore);
+ nf_standard_blue_font.draw(x+60,y+150+i*35,playerName);
}
}
@@ -1928,62 +1988,62 @@ void DrawStats()
DrawIMG(background,screen,0,0);
int y = 5;
const int y_spacing = 30;
- SFont_Write(screen,fBlueFont,10,y,"Stats");
+ NFont_Write(screen, 10,y,"Stats");
y+=y_spacing*2;
- SFont_Write(screen,fBlueFont,10,y,"Chains");
+ NFont_Write(screen, 10,y,"Chains");
for(int i=2;i<13;i++)
{
y+=y_spacing;
- SFont_Write(screen,fBlueFont,10,y,(itoa(i)+"X").c_str());
+ NFont_Write(screen, 10,y,(itoa(i)+"X").c_str());
string numberAsString = itoa(Stats::getInstance()->getNumberOf("chainX"+itoa(i)));
- SFont_Write(screen,fBlueFont,300,y,numberAsString.c_str());
+ NFont_Write(screen, 300,y,numberAsString.c_str());
}
y+=y_spacing*2;
- SFont_Write(screen,fBlueFont,10,y,"Lines Pushed: ");
+ NFont_Write(screen, 10,y,"Lines Pushed: ");
string numberAsString = itoa(Stats::getInstance()->getNumberOf("linesPushed"));
- SFont_Write(screen,fBlueFont,300,y,numberAsString.c_str());
+ NFont_Write(screen, 300,y,numberAsString.c_str());
y+=y_spacing;
- SFont_Write(screen,fBlueFont,10,y,"Puzzles solved: ");
+ NFont_Write(screen, 10,y,"Puzzles solved: ");
numberAsString = itoa(Stats::getInstance()->getNumberOf("puzzlesSolved"));
- SFont_Write(screen,fBlueFont,300,y,numberAsString.c_str());
+ NFont_Write(screen, 300,y,numberAsString.c_str());
y+=y_spacing*2;
- SFont_Write(screen,fBlueFont,10,y,"Run time: ");
+ NFont_Write(screen, 10,y,"Run time: ");
commonTime ct = TimeHandler::peekTime("totalTime",TimeHandler::ms2ct(SDL_GetTicks()));
y+=y_spacing;
- SFont_Write(screen,fBlueFont,10,y,((string)("Days: "+itoa(ct.days))).c_str());
+ NFont_Write(screen, 10,y,((string)("Days: "+itoa(ct.days))).c_str());
y+=y_spacing;
- SFont_Write(screen,fBlueFont,10,y,((string)("Hours: "+itoa(ct.hours))).c_str());
+ NFont_Write(screen, 10,y,((string)("Hours: "+itoa(ct.hours))).c_str());
y+=y_spacing;
- SFont_Write(screen,fBlueFont,10,y,((string)("Minutes: "+itoa(ct.minutes))).c_str());
+ NFont_Write(screen, 10,y,((string)("Minutes: "+itoa(ct.minutes))).c_str());
y+=y_spacing;
- SFont_Write(screen,fBlueFont,10,y,((string)("Seconds: "+itoa(ct.seconds))).c_str());
+ NFont_Write(screen, 10,y,((string)("Seconds: "+itoa(ct.seconds))).c_str());
y-=y_spacing*4; //Four rows back
const int x_offset3 = xsize/3+10; //Ofset for three rows
- SFont_Write(screen,fBlueFont,x_offset3,y,"Play time: ");
+ NFont_Write(screen, x_offset3,y,"Play time: ");
ct = TimeHandler::getTime("playTime");
y+=y_spacing;
- SFont_Write(screen,fBlueFont,x_offset3,y,((string)("Days: "+itoa(ct.days))).c_str());
+ NFont_Write(screen, x_offset3,y,((string)("Days: "+itoa(ct.days))).c_str());
y+=y_spacing;
- SFont_Write(screen,fBlueFont,x_offset3,y,((string)("Hours: "+itoa(ct.hours))).c_str());
+ NFont_Write(screen, x_offset3,y,((string)("Hours: "+itoa(ct.hours))).c_str());
y+=y_spacing;
- SFont_Write(screen,fBlueFont,x_offset3,y,((string)("Minutes: "+itoa(ct.minutes))).c_str());
+ NFont_Write(screen, x_offset3,y,((string)("Minutes: "+itoa(ct.minutes))).c_str());
y+=y_spacing;
- SFont_Write(screen,fBlueFont,x_offset3,y,((string)("Seconds: "+itoa(ct.seconds))).c_str());
+ NFont_Write(screen, x_offset3,y,((string)("Seconds: "+itoa(ct.seconds))).c_str());
const int x_offset = xsize/2+10;
y = 5+y_spacing*2;
- SFont_Write(screen,fBlueFont,x_offset,y,"VS CPU (win/loss)");
+ NFont_Write(screen, x_offset,y,"VS CPU (win/loss)");
for(int i=0;i<7;i++)
{
y += y_spacing;
- SFont_Write(screen,fBlueFont,x_offset,y,("AI "+itoa(i+1)).c_str());
+ NFont_Write(screen, x_offset,y,("AI "+itoa(i+1)).c_str());
numberAsString = itoa(Stats::getInstance()->getNumberOf("defeatedAI"+itoa(i)));
string numberAsString2 = itoa(Stats::getInstance()->getNumberOf("defeatedByAI"+itoa(i)));
string toPrint = numberAsString + "/" + numberAsString2;
- SFont_Write(screen,fBlueFont,x_offset+230,y,toPrint.c_str());
+ NFont_Write(screen, x_offset+230,y,toPrint.c_str());
}
}
@@ -2024,7 +2084,7 @@ void OpenScoresDisplay()
//Draw page number
string pageXofY = ((string)"Page ")+itoa(page+1)+((string)" of ")+itoa(numberOfPages);
- SFont_Write(screen,fBlueFont,xsize/2-SFont_TextWidth(fBlueFont,pageXofY.c_str())/2,ysize-60,pageXofY.c_str());
+ NFont_Write(screen, xsize/2-nf_standard_blue_font.getWidth( pageXofY.c_str())/2,ysize-60,pageXofY.c_str());
SDL_Delay(10);
SDL_Event event;
@@ -2138,7 +2198,7 @@ bool OpenFileDialogbox(int x, int y, char *name)
DrawIMG(changeButtonsBack,screen,x,y);
for (int i=0;i<nrOfFiles;i++)
{
- SFont_Write(screen,fBlueFont,x+10,y+10+36*i,lf.getFileName(i).c_str());
+ NFont_Write(screen, x+10,y+10+36*i,lf.getFileName(i).c_str());
}
SDL_Event event;
@@ -2235,7 +2295,7 @@ bool SelectThemeDialogbox(int x, int y, char *name)
DrawIMG(changeButtonsBack,screen,x,y);
for (int i=0;i<nrOfFiles;i++)
{
- SFont_Write(screen,fBlueFont,x+10,y+10+36*i,lf.getFileName(i).c_str());
+ NFont_Write(screen, x+10,y+10+36*i,lf.getFileName(i).c_str());
}
SDL_Event event;
@@ -2336,7 +2396,7 @@ bool OpenReplayDialogbox(int x, int y, char *name)
DrawIMG(changeButtonsBack,screen,x,y);
for (int i=0;i<nrOfFiles;i++)
{
- SFont_Write(screen,fBlueFont,x+10,y+10+36*i,lf.getFileName(i).c_str());
+ NFont_Write(screen, x+10,y+10+36*i,lf.getFileName(i).c_str());
}
SDL_Event event;
@@ -2443,10 +2503,10 @@ static void DrawBalls()
if (theTextManeger.textUsed[i])
{
//cout << "Printing text: " << theTextManeger.textArray[i].getText() << endl;
- int x = theTextManeger.textArray[i].getX()-SFont_TextWidth(fSmallFont,theTextManeger.textArray[i].getText())/2;
- int y = theTextManeger.textArray[i].getY()-SFont_TextHeight(fSmallFont)/2;
+ int x = theTextManeger.textArray[i].getX()-12;
+ int y = theTextManeger.textArray[i].getY()-12;
DrawIMG(iChainBack,screen,x,y);
- SFont_Write(screen,fSmallFont,x+(25-SFont_TextWidth(fSmallFont,theTextManeger.textArray[i].getText()))/2,y+(25-SFont_TextHeight(fSmallFont))/2,theTextManeger.textArray[i].getText());
+ nf_standard_small_font.drawCenter(x+12,y+7,theTextManeger.textArray[i].getText());
}
} //for
} //DrawBalls
@@ -2466,8 +2526,8 @@ void UndrawBalls()
}
if (theTextManeger.oldTextUsed[i])
{
- int x = theTextManeger.oldTextArray[i].getX()-SFont_TextWidth(fSmallFont,theTextManeger.oldTextArray[i].getText())/2;
- int y = theTextManeger.oldTextArray[i].getY()-SFont_TextHeight(fSmallFont)/2;
+ int x = theTextManeger.oldTextArray[i].getX()-12;
+ int y = theTextManeger.oldTextArray[i].getY()-12;
DrawIMG(background,screen,x,y,25,25,x,y);
}
} //for
@@ -2519,15 +2579,15 @@ void DrawEverything(int xsize, int ysize,BlockGameSdl *theGame, BlockGameSdl *th
DrawIMG(theGame->sBoard,screen,theGame->GetTopX(),theGame->GetTopY());
string strHolder;
strHolder = itoa(theGame->GetScore()+theGame->GetHandicap());
- SFont_Write(screen,fBlueFont,theGame->GetTopX()+310,theGame->GetTopY()+100,strHolder.c_str());
+ NFont_Write(screen, theGame->GetTopX()+310,theGame->GetTopY()+100,strHolder.c_str());
if (theGame->GetAIenabled())
- SFont_Write(screen,fBlueFont,theGame->GetTopX()+10,theGame->GetTopY()-40,"CPU");
+ NFont_Write(screen, theGame->GetTopX()+10,theGame->GetTopY()-40,"CPU");
else
if (editorMode)
- SFont_Write(screen,fBlueFont,theGame->GetTopX()+10,theGame->GetTopY()-40,"Playing field");
+ NFont_Write(screen, theGame->GetTopX()+10,theGame->GetTopY()-40,"Playing field");
else
if (!singlePuzzle)
- SFont_Write(screen,fBlueFont,theGame->GetTopX()+10,theGame->GetTopY()-40,player1name);
+ NFont_Write(screen, theGame->GetTopX()+10,theGame->GetTopY()-40,player1name);
if (theGame->isTimeTrial())
{
int tid = (int)SDL_GetTicks()-theGame->GetGameStartedAt();
@@ -2549,7 +2609,7 @@ void DrawEverything(int xsize, int ysize,BlockGameSdl *theGame, BlockGameSdl *th
strHolder = itoa(minutes)+":"+itoa(seconds);
else strHolder = itoa(minutes)+":0"+itoa(seconds);
//if ((SoundEnabled)&&(!NoSound)&&(tid>0)&&(seconds<5)&&(minutes == 0)&&(seconds>1)&&(!(Mix_Playing(6)))) Mix_PlayChannel(6,heartBeat,0);
- SFont_Write(screen,fBlueFont,theGame->GetTopX()+310,theGame->GetTopY()+150,strHolder.c_str());
+ NFont_Write(screen, theGame->GetTopX()+310,theGame->GetTopY()+150,strHolder.c_str());
}
else
{
@@ -2561,13 +2621,13 @@ void DrawEverything(int xsize, int ysize,BlockGameSdl *theGame, BlockGameSdl *th
strHolder = itoa(minutes)+":"+itoa(seconds);
else
strHolder = itoa(minutes)+":0"+itoa(seconds);
- SFont_Write(screen,fBlueFont,theGame->GetTopX()+310,theGame->GetTopY()+150,strHolder.c_str());
+ NFont_Write(screen, theGame->GetTopX()+310,theGame->GetTopY()+150,strHolder.c_str());
}
strHolder = itoa(theGame->GetChains());
- SFont_Write(screen,fBlueFont,theGame->GetTopX()+310,theGame->GetTopY()+200,strHolder.c_str());
+ NFont_Write(screen, theGame->GetTopX()+310,theGame->GetTopY()+200,strHolder.c_str());
//drawspeedLevel:
strHolder = itoa(theGame->GetSpeedLevel());
- SFont_Write(screen,fBlueFont,theGame->GetTopX()+310,theGame->GetTopY()+250,strHolder.c_str());
+ NFont_Write(screen, theGame->GetTopX()+310,theGame->GetTopY()+250,strHolder.c_str());
if ((theGame->isStageClear()) &&(theGame->GetTopY()+700+50*(theGame->GetStageClearLimit()-theGame->GetLinesCleared())-theGame->GetPixels()-1<600+theGame->GetTopY()))
{
oldBubleX = theGame->GetTopX()+280;
@@ -2588,55 +2648,55 @@ void DrawEverything(int xsize, int ysize,BlockGameSdl *theGame, BlockGameSdl *th
//Write a description:
if(theGame->isTimeTrial())
{
- SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+10,"Time Trial");
- SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160,"Objective:");
- SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160+32, "Score as much");
- SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28, "as possible in");
- SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28*2,"2 minutes");
+ NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+10,"Time Trial");
+ NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160,"Objective:");
+ NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32, "Score as much");
+ NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28, "as possible in");
+ NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28*2,"2 minutes");
} else if(theGame->isStageClear())
{
- SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+10,"Stage Clear");
- SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160,"Objective:");
- SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160+32, "You must clear a");
- SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28, "number of lines.");
- SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28*2,"Speed is rapidly");
- SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28*3,"increased.");
+ NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+10,"Stage Clear");
+ NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160,"Objective:");
+ NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32, "You must clear a");
+ NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28, "number of lines.");
+ NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28*2,"Speed is rapidly");
+ NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28*3,"increased.");
} else if(theGame->isPuzzleMode())
{
- SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+10,"Puzzle");
- SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160,"Objective:");
- SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160+32, "Clear the entire");
- SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28, "board with a");
- SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28*2,"limited number of");
- SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28*3,"moves.");
+ NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+10,"Puzzle");
+ NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160,"Objective:");
+ NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32, "Clear the entire");
+ NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28, "board with a");
+ NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28*2,"limited number of");
+ NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28*3,"moves.");
} else
{
- SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+10,"Endless");
- SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160,"Objective:");
- SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160+32, "Score as much as");
- SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28, "possible. No time");
- SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28*2,"limit.");
+ NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+10,"Endless");
+ NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160,"Objective:");
+ NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32, "Score as much as");
+ NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28, "possible. No time");
+ NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32+28*2,"limit.");
}
//Write the keys that are in use
int y = theGame2->GetTopY()+400;
- SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,y,"Movement keys:" );
- SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,y+40,(getKeyName(keySettings[0].left)+", "+getKeyName(keySettings[0].right)+"," ).c_str() );
- SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,y+76,(getKeyName(keySettings[0].up)+", "+getKeyName(keySettings[0].down)).c_str() );
- SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,y+120,("Switch: "+getKeyName(keySettings[0].change) ).c_str() );
+ NFont_Write(screen, theGame2->GetTopX()+7,y,"Movement keys:" );
+ NFont_Write(screen, theGame2->GetTopX()+7,y+40,(getKeyName(keySettings[0].left)+", "+getKeyName(keySettings[0].right)+"," ).c_str() );
+ NFont_Write(screen, theGame2->GetTopX()+7,y+76,(getKeyName(keySettings[0].up)+", "+getKeyName(keySettings[0].down)).c_str() );
+ NFont_Write(screen, theGame2->GetTopX()+7,y+120,("Switch: "+getKeyName(keySettings[0].change) ).c_str() );
if(theGame->isPuzzleMode())
- SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,y+160,("Restart: "+getKeyName(keySettings[0].push) ).c_str() );
+ NFont_Write(screen, theGame2->GetTopX()+7,y+160,("Restart: "+getKeyName(keySettings[0].push) ).c_str() );
else
- SFont_Write(screen,fBlueFont,theGame2->GetTopX()+7,y+160,("Push line: "+getKeyName(keySettings[0].push) ).c_str() );
+ NFont_Write(screen, theGame2->GetTopX()+7,y+160,("Push line: "+getKeyName(keySettings[0].push) ).c_str() );
}
else
DrawIMG(theGame2->sBoard,screen,theGame2->GetTopX(),theGame2->GetTopY());
strHolder = itoa(theGame2->GetScore()+theGame2->GetHandicap());
- SFont_Write(screen,fBlueFont,theGame2->GetTopX()+310,theGame2->GetTopY()+100,strHolder.c_str());
+ NFont_Write(screen, theGame2->GetTopX()+310,theGame2->GetTopY()+100,strHolder.c_str());
if (theGame2->GetAIenabled())
- SFont_Write(screen,fBlueFont,theGame2->GetTopX()+10,theGame2->GetTopY()-40,"CPU");
+ NFont_Write(screen, theGame2->GetTopX()+10,theGame2->GetTopY()-40,"CPU");
else
- SFont_Write(screen,fBlueFont,theGame2->GetTopX()+10,theGame2->GetTopY()-40,theGame2->name);
+ NFont_Write(screen, theGame2->GetTopX()+10,theGame2->GetTopY()-40,theGame2->name);
if (theGame2->isTimeTrial())
{
int tid = (int)SDL_GetTicks()-theGame2->GetGameStartedAt();
@@ -2659,7 +2719,7 @@ void DrawEverything(int xsize, int ysize,BlockGameSdl *theGame, BlockGameSdl *th
else
strHolder = itoa(minutes)+":0"+itoa(seconds);
//if ((SoundEnabled)&&(!NoSound)&&(tid>0)&&(seconds<5)&&(minutes == 0)&&(seconds>1)&&(!(Mix_Playing(6)))) Mix_PlayChannel(6,heartBeat,0);
- SFont_Write(screen,fBlueFont,theGame2->GetTopX()+310,theGame2->GetTopY()+150,strHolder.c_str());
+ NFont_Write(screen, theGame2->GetTopX()+310,theGame2->GetTopY()+150,strHolder.c_str());
}
else
{
@@ -2671,12 +2731,12 @@ void DrawEverything(int xsize, int ysize,BlockGameSdl *theGame, BlockGameSdl *th
strHolder = itoa(minutes)+":"+itoa(seconds);
else
strHolder = itoa(minutes)+":0"+itoa(seconds);
- SFont_Write(screen,fBlueFont,theGame2->GetTopX()+310,theGame2->GetTopY()+150,strHolder.c_str());
+ NFont_Write(screen, theGame2->GetTopX()+310,theGame2->GetTopY()+150,strHolder.c_str());
}
strHolder = itoa(theGame2->GetChains());
- SFont_Write(screen,fBlueFont,theGame2->GetTopX()+310,theGame2->GetTopY()+200,strHolder.c_str());
+ NFont_Write(screen, theGame2->GetTopX()+310,theGame2->GetTopY()+200,strHolder.c_str());
strHolder = itoa(theGame2->GetSpeedLevel());
- SFont_Write(screen,fBlueFont,theGame2->GetTopX()+310,theGame2->GetTopY()+250,strHolder.c_str());
+ NFont_Write(screen, theGame2->GetTopX()+310,theGame2->GetTopY()+250,strHolder.c_str());
}
//player2 finnish
@@ -2736,7 +2796,8 @@ void DrawEverything(int xsize, int ysize,BlockGameSdl *theGame, BlockGameSdl *th
Ticks = SDL_GetTicks();
}
- SFont_Write(screen,fBlueFont,800,4,FPS);
+ //NFont_Write(screen, 800,4,FPS);
+ nf_standard_blue_font.draw(800,4,FPS);
#endif
//SDL_Flip(screen); Update screen is now called outside DrawEvrything, bacause the mouse needs to be painted
@@ -2812,7 +2873,7 @@ int PuzzleLevelSelect()
DrawIMG(background, screen, 0, 0);
DrawIMG(iCheckBoxArea,screen,xplace,yplace);
- SFont_Write(screen,fBlueFont,xplace+12,yplace+2,"Select Puzzle");
+ NFont_Write(screen, xplace+12,yplace+2,"Select Puzzle");
//Now drow the fields you click in (and a V if clicked):
for (int i = 0; i < nrOfPuzzles;i++)
{
@@ -2939,7 +3000,7 @@ int StageLevelSelect()
//nowTime=SDL_GetTicks();
DrawIMG(background, screen, 0, 0);
DrawIMG(iCheckBoxArea,screen,xplace,yplace);
- SFont_Write(screen,fBlueFont,xplace+12,yplace+2,"Stage Clear Level Select");
+ NFont_Write(screen, xplace+12,yplace+2,"Stage Clear Level Select");
for (int i = 0; i < nrOfStageLevels;i++)
{
DrawIMG(iLevelCheckBox,screen,xplace+10+(i%10)*50, yplace+60+(i/10)*50);
@@ -3005,13 +3066,13 @@ int StageLevelSelect()
if(stageTimes[overLevel]>0)
timeString = "Time used: "+itoa(stageTimes[overLevel]/1000/60)+" : "+itoa2((stageTimes[overLevel]/1000)%60);
- SFont_Write(screen,fBlueFont,200,200,scoreString.c_str());
- SFont_Write(screen,fBlueFont,200,250,timeString.c_str());
+ NFont_Write(screen, 200,200,scoreString.c_str());
+ NFont_Write(screen, 200,250,timeString.c_str());
overLevel;
}
string totalString = "Total score: " +itoa(totalScore) + " in " + itoa(totalTime/1000/60) + " : " + itoa2((totalTime/1000)%60);
- SFont_Write(screen,fBlueFont,200,600,totalString.c_str());
+ NFont_Write(screen, 200,600,totalString.c_str());
//DrawIMG(mouse,screen,mousex,mousey);
mouse.PaintTo(screen,mousex,mousey);
@@ -3034,13 +3095,13 @@ int startSingleVs()
MakeBackground(xsize,ysize);
DrawIMG(changeButtonsBack,background,xplace,yplace);
- SFont_Write(background,fBlueFont,xplace+10,yplace+10,"1 : Very Easy");
- SFont_Write(background,fBlueFont,xplace+10,yplace+40,"2 : Easy");
- SFont_Write(background,fBlueFont,xplace+10,yplace+70,"3 : Below Normal");
- SFont_Write(background,fBlueFont,xplace+10,yplace+100,"4 : Normal");
- SFont_Write(background,fBlueFont,xplace+10,yplace+130,"5 : Above Normal");
- SFont_Write(background,fBlueFont,xplace+10,yplace+160,"6 : Hard");
- SFont_Write(background,fBlueFont,xplace+10,yplace+190,"7 : Hardest");
+ NFont_Write(background, xplace+10,yplace+10,"1 : Very Easy");
+ NFont_Write(background, xplace+10,yplace+40,"2 : Easy");
+ NFont_Write(background, xplace+10,yplace+70,"3 : Below Normal");
+ NFont_Write(background, xplace+10,yplace+100,"4 : Normal");
+ NFont_Write(background, xplace+10,yplace+130,"5 : Above Normal");
+ NFont_Write(background, xplace+10,yplace+160,"6 : Hard");
+ NFont_Write(background, xplace+10,yplace+190,"7 : Hardest");
DrawIMG(background, screen, 0, 0);
SDL_Flip(screen);
do
@@ -3118,23 +3179,23 @@ void startVsMenu()
//int nowTime=SDL_GetTicks();
MakeBackground(xsize,ysize);
- SFont_Write(background,fBlueFont,360,650,"Press ESC to accept");
+ NFont_Write(background, 360,650,"Press ESC to accept");
DrawIMG(bBack,background,xsize/2-120/2,600);
do
{
//nowTime=SDL_GetTicks();
DrawIMG(background, screen, 0, 0);
DrawIMG(changeButtonsBack,screen,xplace,yplace);
- SFont_Write(screen,fBlueFont,xplace+50,yplace+20,"Player 1");
- SFont_Write(screen,fBlueFont,xplace+300+50,yplace+20,"Player 2");
- SFont_Write(screen,fBlueFont,xplace+50,yplace+70,"Speed:");
- SFont_Write(screen,fBlueFont,xplace+50+300,yplace+70,"Speed:");
+ NFont_Write(screen, xplace+50,yplace+20,"Player 1");
+ NFont_Write(screen, xplace+300+50,yplace+20,"Player 2");
+ NFont_Write(screen, xplace+50,yplace+70,"Speed:");
+ NFont_Write(screen, xplace+50+300,yplace+70,"Speed:");
for (int i=0; i<5;i++)
{
char levelS[2]; //level string;
levelS[0]='1'+i;
levelS[1]=0;
- SFont_Write(screen,fBlueFont,xplace+50+i*40,yplace+110,levelS);
+ NFont_Write(screen, xplace+50+i*40,yplace+110,levelS);
DrawIMG(iLevelCheckBox,screen,xplace+50+i*40,yplace+150);
if (player1Speed==i)
DrawIMG(iLevelCheck,screen,xplace+50+i*40,yplace+150);
@@ -3144,27 +3205,27 @@ void startVsMenu()
char levelS[2]; //level string;
levelS[0]='1'+i;
levelS[1]=0;
- SFont_Write(screen,fBlueFont,xplace+300+50+i*40,yplace+110,levelS);
+ NFont_Write(screen, xplace+300+50+i*40,yplace+110,levelS);
DrawIMG(iLevelCheckBox,screen,xplace+300+50+i*40,yplace+150);
if (player2Speed==i)
DrawIMG(iLevelCheck,screen,xplace+300+50+i*40,yplace+150);
}
- SFont_Write(screen,fBlueFont,xplace+50,yplace+200,"AI: ");
+ NFont_Write(screen, xplace+50,yplace+200,"AI: ");
DrawIMG(iLevelCheckBox,screen,xplace+50+70,yplace+200);
if (player1AI)
DrawIMG(iLevelCheck,screen,xplace+50+70,yplace+200);
- SFont_Write(screen,fBlueFont,xplace+50,yplace+250,"TT Handicap: ");
- SFont_Write(screen,fBlueFont,xplace+50+300,yplace+200,"AI: ");
+ NFont_Write(screen, xplace+50,yplace+250,"TT Handicap: ");
+ NFont_Write(screen, xplace+50+300,yplace+200,"AI: ");
DrawIMG(iLevelCheckBox,screen,xplace+50+70+300,yplace+200);
if (player2AI)
DrawIMG(iLevelCheck,screen,xplace+50+70+300,yplace+200);
- SFont_Write(screen,fBlueFont,xplace+50+300,yplace+250,"TT Handicap: ");
+ NFont_Write(screen, xplace+50+300,yplace+250,"TT Handicap: ");
for (int i=0; i<5;i++)
{
char levelS[2]; //level string;
levelS[0]='1'+i;
levelS[1]=0;
- SFont_Write(screen,fBlueFont,xplace+50+i*40,yplace+290,levelS);
+ NFont_Write(screen, xplace+50+i*40,yplace+290,levelS);
DrawIMG(iLevelCheckBox,screen,xplace+50+i*40,yplace+330);
if (player1handicap==i)
DrawIMG(iLevelCheck,screen,xplace+50+i*40,yplace+330);
@@ -3174,7 +3235,7 @@ void startVsMenu()
char levelS[2]; //level string;
levelS[0]='1'+i;
levelS[1]=0;
- SFont_Write(screen,fBlueFont,xplace+50+i*40+300,yplace+290,levelS);
+ NFont_Write(screen, xplace+50+i*40+300,yplace+290,levelS);
DrawIMG(iLevelCheckBox,screen,xplace+50+i*40+300,yplace+330);
if (player2handicap==i)
DrawIMG(iLevelCheck,screen,xplace+50+i*40+300,yplace+330);
diff --git a/source/code/mainVars.hpp b/source/code/mainVars.hpp index 25a1a11..284c766 100644 --- a/source/code/mainVars.hpp +++ b/source/code/mainVars.hpp
@@ -92,8 +92,8 @@ static SDL_Surface *counter[3]; //Counts down from 3
static SDL_Surface *bricks[7]; //The bricks, saved in an array of pointers
static SDL_Surface *crossover; //Cross the bricks that will be cleared soon
static SDL_Surface *balls[7]; //The balls (the small ones that jump around)
-static SDL_Surface *iBlueFont; //Contains the blue font used
-static SDL_Surface *iSmallFont; //Small font used for the chain text
+//static SDL_Surface *iBlueFont; //Contains the blue font used
+//static SDL_Surface *iSmallFont; //Small font used for the chain text
static SDL_Surface *optionsBack;
static SDL_Surface *changeButtonsBack;
static SDL_Surface *dialogBox;
@@ -154,9 +154,12 @@ static CppSdl::CppSdlImageHolder mouse;
static SDL_Surface *tmp; //a temporary surface to use DisplayFormat
-static SFont_Font *fBlueFont; //Stores the blue font (SFont)
-static SFont_Font *fSmallFont; //Stores the small font (SFont)
+//static SFont_Font *fBlueFont; //Stores the blue font (SFont)
+//static SFont_Font *fSmallFont; //Stores the small font (SFont)
//TTFont ttfont; //Stores the TTF font (TTFSDL)
+static NFont nf_button_font; //Font used for buttons!
+static NFont nf_standard_blue_font; //Font used instead of the old blue SFont
+static NFont nf_standard_small_font;
static Mix_Music *bgMusic; //backgroundMusic
static Mix_Music *highbeatMusic; //Background music with higher beat