X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=SFont.c;h=4e110d917a0083957c7a1a4c9f84e5e73364b83c;hp=407ef9906462ad2836a2f7f956c0d1c81eba27b4;hb=bd38899d7d8cd4043bfee85fcdb55159ca5ba1a2;hpb=2ed89c59f0efcd0a2763f47c7d3455663241e623 diff --git a/SFont.c b/SFont.c index 407ef990..4e110d91 100644 --- a/SFont.c +++ b/SFont.c @@ -1,22 +1,10 @@ /* * Copyright (C) Karl Bartel WWW: http://www.linux-games.com * - * 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, USA. + * Licensed under the GPL v2. For licencing details see COPYING. */ -/*Modified 2003 by Andre Noll */ +/*Modified 2003, 2006 by Andre Noll */ #include #include "SFont.h" @@ -24,7 +12,7 @@ #include /* strlen */ SFont_FontInfo InternalFont; -Uint32 GetPixel(SDL_Surface * Surface, Sint32 X, Sint32 Y) +static Uint32 GetPixel(SDL_Surface *Surface, Sint32 X, Sint32 Y) { Uint8 *bits; @@ -45,8 +33,7 @@ Uint32 GetPixel(SDL_Surface * Surface, Sint32 X, Sint32 Y) return *((Uint8 *) Surface->pixels + Y * Surface->pitch + X); break; case 2: - return *((Uint16 *) Surface->pixels + Y * Surface->pitch / 2 + - X); + return *((Uint16 *) Surface->pixels + Y * Surface->pitch / 2 + X); break; case 3:{ /* Format/endian independent */ Uint8 r, g, b; @@ -57,8 +44,7 @@ Uint32 GetPixel(SDL_Surface * Surface, Sint32 X, Sint32 Y) } break; case 4: - return *((Uint32 *) Surface->pixels + Y * Surface->pitch / 4 + - X); + return *((Uint32 *) Surface->pixels + Y * Surface->pitch / 4 + X); break; } @@ -79,12 +65,11 @@ void InitFont2(SFont_FontInfo * Font) while (x < Font->Surface->w) { if (GetPixel(Font->Surface, x, 0) == - SDL_MapRGB(Font->Surface->format, 255, 0, 255)) { + SDL_MapRGB(Font->Surface->format, 255, 0, 255)) { Font->CharPos[i++] = x; - while ((x < Font->Surface->w - 1) - && (GetPixel(Font->Surface, x, 0) == - SDL_MapRGB(Font->Surface->format, 255, 0, - 255))) + while ((x < Font->Surface->w - 1) && + (GetPixel(Font->Surface, x, 0) == + SDL_MapRGB(Font->Surface->format, 255, 0, 255))) x++; Font->CharPos[i++] = x; } @@ -98,19 +83,8 @@ void InitFont2(SFont_FontInfo * Font) GetPixel(Font->Surface, 0, Font->Surface->h - 1)); } -#if 0 -void InitFont(SDL_Surface * Font) -{ - InternalFont.Surface = Font; - InitFont2(&InternalFont); -} - -#endif - - - void PutString2(SDL_Surface * Surface, SFont_FontInfo * Font, int x, int y, - char *text) + const char *text) { int ofs; int i = 0; @@ -124,15 +98,14 @@ void PutString2(SDL_Surface * Surface, SFont_FontInfo * Font, int x, int y, ofs = ((unsigned char) text[i] - 33) * 2 + 1; srcrect.w = dstrect.w = (Font->CharPos[ofs + 2] + Font->CharPos[ofs + 1]) / 2 - - (Font->CharPos[ofs] + Font->CharPos[ofs - 1]) - / 2; + - (Font->CharPos[ofs] + + Font->CharPos[ofs - 1]) / 2; srcrect.h = dstrect.h = Font->Surface->h - 1; - srcrect.x = - (Font->CharPos[ofs] + Font->CharPos[ofs - 1]) / 2; + srcrect.x = (Font->CharPos[ofs] + + Font->CharPos[ofs - 1]) / 2; srcrect.y = 1; - dstrect.x = - x - (float) (Font->CharPos[ofs] - - Font->CharPos[ofs - 1]) / 2; + dstrect.x = x - (float) (Font->CharPos[ofs] + - Font->CharPos[ofs - 1]) / 2; dstrect.y = y; SDL_BlitSurface(Font->Surface, &srcrect, Surface, &dstrect); @@ -141,13 +114,7 @@ void PutString2(SDL_Surface * Surface, SFont_FontInfo * Font, int x, int y, } } } -#if 0 -void PutString(SDL_Surface * Surface, int x, int y, char *text) -{ - PutString2(Surface, &InternalFont, x, y, text); -} -#endif int TextWidth2(SFont_FontInfo * Font, char *text) { int ofs = 0; @@ -166,29 +133,8 @@ int TextWidth2(SFont_FontInfo * Font, char *text) return x; } -#if 0 -int TextWidth(char *text) -{ - return TextWidth2(&InternalFont, text); -} -#endif - -void XCenteredString2(SDL_Surface * Surface, SFont_FontInfo * Font, int y, - char *text) -{ - PutString2(Surface, Font, Surface->w / 2 - TextWidth2(Font, text) / 2, - y, text); -} - -#if 0 -void XCenteredString(SDL_Surface * Surface, int y, char *text) -{ - XCenteredString2(Surface, &InternalFont, y, text); -} -#endif - -void SFont_InternalInput(SDL_Surface * Dest, SFont_FontInfo * Font, int x, - int y, int PixelWidth, char *text) +static void SFont_InternalInput(SDL_Surface * Dest, SFont_FontInfo * Font, int x, + int y, int PixelWidth, char *text) { SDL_Event event; int ch = -1, blink = 0; @@ -235,7 +181,7 @@ void SFont_InternalInput(SDL_Surface * Dest, SFont_FontInfo * Font, int x, blinktimer = SDL_GetTicks() + 500; if (blink) { PutString2(Dest, Font, - x + TextWidth2(Font, text), y, "|"); + x + TextWidth2(Font, text), y, "|"); SDL_UpdateRects(Dest, 1, &rect); } else { SDL_BlitSurface(Back, NULL, Dest, &rect); @@ -253,7 +199,7 @@ void SFont_InternalInput(SDL_Surface * Dest, SFont_FontInfo * Font, int x, } void SFont_Input2(SDL_Surface * Dest, SFont_FontInfo * Font, int x, int y, - int PixelWidth, char *text) + int PixelWidth, char *text) { SFont_InternalInput(Dest, Font, x, y, PixelWidth, text); }