2 * This file was generated automatically by xsubpp version 1.9508 from the
3 * contents of SFont.xs. Do not edit this file, edit SFont.xs instead.
5 * ANY CHANGES MADE HERE WILL BE LOST!
13 // Original SFont code Copyright (C) Karl Bartel
14 // Copyright (C) 2005 David J. Goehrig <dgoehrig@cpan.org>
16 // ------------------------------------------------------------------------------
18 // This library is free software; you can redistribute it and/or
19 // modify it under the terms of the GNU Lesser General Public
20 // License as published by the Free Software Foundation; either
21 // version 2.1 of the License, or (at your option) any later version.
23 // This library is distributed in the hope that it will be useful,
24 // but WITHOUT ANY WARRANTY; without even the implied warranty of
25 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 // Lesser General Public License for more details.
28 // You should have received a copy of the GNU Lesser General Public
29 // License along with this library; if not, write to the Free Software
30 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
32 // ------------------------------------------------------------------------------
34 // Please feel free to send questions, suggestions or improvements to:
53 #define HAVE_TLS_CONTEXT
56 #include "../defines.h"
60 #include <SDL_image.h>
62 SFont_FontInfo InternalFont;
63 Uint32 SFont_GetPixel(SDL_Surface *Surface, Sint32 X, Sint32 Y)
68 if (X<0) puts("SFONT ERROR: x too small in SFont_GetPixel. Report this to <karlb@gmx.net>");
69 if (X>=Surface->w) puts("SFONT ERROR: x too big in SFont_GetPixel. Report this to <karlb@gmx.net>");
71 Bpp = Surface->format->BytesPerPixel;
73 bits = ((Uint8 *)Surface->pixels)+Y*Surface->pitch+X*Bpp;
78 return *((Uint8 *)Surface->pixels + Y * Surface->pitch + X);
81 return *((Uint16 *)Surface->pixels + Y * Surface->pitch/2 + X);
83 case 3: { // Format/endian independent
85 r = *((bits)+Surface->format->Rshift/8);
86 g = *((bits)+Surface->format->Gshift/8);
87 b = *((bits)+Surface->format->Bshift/8);
88 return SDL_MapRGB(Surface->format, r, g, b);
92 return *((Uint32 *)Surface->pixels + Y * Surface->pitch/4 + X);
99 void SFont_InitFont2(SFont_FontInfo *Font)
103 if ( Font->Surface==NULL ) {
104 printf("The font has not been loaded!\n");
108 if (SDL_MUSTLOCK(Font->Surface)) SDL_LockSurface(Font->Surface);
110 while ( x < Font->Surface->w ) {
111 if(SFont_GetPixel(Font->Surface,x,0)==SDL_MapRGB(Font->Surface->format,255,0,255)) {
112 Font->CharPos[i++]=x;
113 while (( x < Font->Surface->w-1) && (SFont_GetPixel(Font->Surface,x,0)==SDL_MapRGB(Font->Surface->format,255,0,255)))
115 Font->CharPos[i++]=x;
119 if (SDL_MUSTLOCK(Font->Surface)) SDL_UnlockSurface(Font->Surface);
121 Font->h=Font->Surface->h;
122 SDL_SetColorKey(Font->Surface, SDL_SRCCOLORKEY, SFont_GetPixel(Font->Surface, 0, Font->Surface->h-1));
125 void SFont_InitFont(SDL_Surface *Font)
127 InternalFont.Surface=Font;
128 SFont_InitFont2(&InternalFont);
131 void SFont_PutString2(SDL_Surface *Surface, SFont_FontInfo *Font, int x, int y, char *text)
135 SDL_Rect srcrect,dstrect;
137 while (text[i]!='\0') {
139 x+=Font->CharPos[2]-Font->CharPos[1];
143 // printf("-%c- %c - %u\n",228,text[i],text[i]);
144 ofs=(text[i]-33)*2+1;
145 // printf("printing %c %d\n",text[i],ofs);
146 srcrect.w = dstrect.w = (Font->CharPos[ofs+2]+Font->CharPos[ofs+1])/2-(Font->CharPos[ofs]+Font->CharPos[ofs-1])/2;
147 srcrect.h = dstrect.h = Font->Surface->h-1;
148 srcrect.x = (Font->CharPos[ofs]+Font->CharPos[ofs-1])/2;
150 dstrect.x = x-(float)(Font->CharPos[ofs]-Font->CharPos[ofs-1])/2;
153 SDL_BlitSurface( Font->Surface, &srcrect, Surface, &dstrect);
155 x+=Font->CharPos[ofs+1]-Font->CharPos[ofs];
161 void SFont_PutString(SDL_Surface *Surface, int x, int y, char *text)
163 SFont_PutString2(Surface, &InternalFont, x, y, text);
166 int SFont_TextWidth2(SFont_FontInfo *Font, char *text)
171 while (text[i]!='\0') {
173 x+=Font->CharPos[2]-Font->CharPos[1];
177 ofs=(text[i]-33)*2+1;
178 x+=Font->CharPos[ofs+1]-Font->CharPos[ofs];
182 // printf ("--%d\n",x);
186 int SFont_TextWidth(char *text)
188 return SFont_TextWidth2(&InternalFont, text);
191 void SFont_XCenteredString2(SDL_Surface *Surface, SFont_FontInfo *Font, int y, char *text)
193 SFont_PutString2(Surface, Font, Surface->w/2-SFont_TextWidth2(Font,text)/2, y, text);
196 void SFont_XCenteredString(SDL_Surface *Surface, int y, char *text)
198 SFont_XCenteredString2(Surface, &InternalFont, y, text);
201 void SFont_InternalInput( SDL_Surface *Dest, SFont_FontInfo *Font, int x, int y, int PixelWidth, char *text)
209 // int ofs=(text[0]-33)*2+1;
210 // int leftshift=(Font->CharPos[ofs]-Font->CharPos[ofs-1])/2;
212 Back = SDL_AllocSurface(Dest->flags,
215 Dest->format->BitsPerPixel,
218 Dest->format->Bmask, 0);
222 rect.h=Font->Surface->h;
223 SDL_BlitSurface(Dest, &rect, Back, NULL);
224 SFont_PutString2(Dest,Font,x,y,text);
225 SDL_UpdateRects(Dest, 1, &rect);
228 previous=SDL_EnableUNICODE(1);
229 blinktimer=SDL_GetTicks();
230 while (ch!=SDLK_RETURN) {
231 if (event.type==SDL_KEYDOWN) {
232 ch=event.key.keysym.unicode;
233 if (((ch>31)||(ch=='\b')) && (ch<128)) {
234 if ((ch=='\b')&&(strlen(text)>0))
235 text[strlen(text)-1]='\0';
237 sprintf(text,"%s%c",text,ch);
238 if (SFont_TextWidth2(Font,text)>PixelWidth) text[strlen(text)-1]='\0';
239 SDL_BlitSurface( Back, NULL, Dest, &rect);
240 SFont_PutString2(Dest, Font, x, y, text);
241 SDL_UpdateRects(Dest, 1, &rect);
242 // printf("%s ## %d\n",text,strlen(text));
243 SDL_WaitEvent(&event);
246 if (SDL_GetTicks()>blinktimer) {
248 blinktimer=SDL_GetTicks()+500;
250 SFont_PutString2(Dest, Font, x+SFont_TextWidth2(Font,text), y, "|");
251 SDL_UpdateRects(Dest, 1, &rect);
252 // SDL_UpdateRect(Dest, x+SFont_TextWidth2(Font,text), y, SFont_TextWidth2(Font,"|"), Font->Surface->h);
254 SDL_BlitSurface( Back, NULL, Dest, &rect);
255 SFont_PutString2(Dest, Font, x, y, text);
256 SDL_UpdateRects(Dest, 1, &rect);
257 // SDL_UpdateRect(Dest, x-(Font->CharPos[ofs]-Font->CharPos[ofs-1])/2, y, PixelWidth, Font->Surface->h);
261 SDL_PollEvent(&event);
263 text[strlen(text)]='\0';
264 SDL_FreeSurface(Back);
265 SDL_EnableUNICODE(previous); //restore the previous state
268 void SFont_Input2( SDL_Surface *Dest, SFont_FontInfo *Font, int x, int y, int PixelWidth, char *text)
270 SFont_InternalInput( Dest, Font, x, y, PixelWidth, text);
272 void SFont_Input( SDL_Surface *Dest, int x, int y, int PixelWidth, char *text)
274 SFont_Input2( Dest, &InternalFont, x, y, PixelWidth, text);
280 #ifdef HAVE_SDL_IMAGE
281 #define XSubPPtmpAAAA 1
283 XS(XS_SDL__SFont_NewFont); /* prototype to pass -Wmissing-prototypes */
284 XS(XS_SDL__SFont_NewFont)
288 Perl_croak(aTHX_ "Usage: SDL::SFont::NewFont(filename)");
290 char * filename = (char *)SvPV_nolen(ST(0));
291 SDL_Surface * RETVAL;
294 RETVAL = IMG_Load(filename);
295 SFont_InitFont(RETVAL);
297 XSprePUSH; PUSHi(PTR2IV(RETVAL));
302 XS(XS_SDL__SFont_UseFont); /* prototype to pass -Wmissing-prototypes */
303 XS(XS_SDL__SFont_UseFont)
307 Perl_croak(aTHX_ "Usage: SDL::SFont::UseFont(surface)");
309 SDL_Surface * surface = INT2PTR(SDL_Surface *,SvIV(ST(0)));
311 SFont_InitFont(surface);
317 XS(XS_SDL__SFont_PutString); /* prototype to pass -Wmissing-prototypes */
318 XS(XS_SDL__SFont_PutString)
322 Perl_croak(aTHX_ "Usage: SDL::SFont::PutString(surface, x, y, text)");
324 SDL_Surface * surface = INT2PTR(SDL_Surface *,SvIV(ST(0)));
325 int x = (int)SvIV(ST(1));
326 int y = (int)SvIV(ST(2));
327 char * text = (char *)SvPV_nolen(ST(3));
329 SFont_PutString( surface, x, y, text );
335 XS(XS_SDL__SFont_TextWidth); /* prototype to pass -Wmissing-prototypes */
336 XS(XS_SDL__SFont_TextWidth)
340 Perl_croak(aTHX_ "Usage: SDL::SFont::TextWidth(text)");
342 char * text = (char *)SvPV_nolen(ST(0));
346 RETVAL = SFont_TextWidth(text);
348 XSprePUSH; PUSHi((IV)RETVAL);
357 XS(boot_SDL__SFont); /* prototype to pass -Wmissing-prototypes */
361 char* file = __FILE__;
363 XS_VERSION_BOOTCHECK ;
366 newXS("SDL::SFont::NewFont", XS_SDL__SFont_NewFont, file);
367 newXS("SDL::SFont::UseFont", XS_SDL__SFont_UseFont, file);
368 newXS("SDL::SFont::PutString", XS_SDL__SFont_PutString, file);
369 newXS("SDL::SFont::TextWidth", XS_SDL__SFont_TextWidth, file);
372 /* Initialisation Section */
378 /* End of Initialisation Section */