SDLGameEngine

src/sgefont.c

00001 /*
00002  * Copyright (c) 2007 Heiko Irrgang
00003  *
00004  * The license and distribution terms for this file may be
00005  * found in the file COPYING in this distribution or at
00006  * http://93-interactive.com/cms/products/software/sdl-game-engine/license/
00007  */
00008 
00009 #include <sge.h>
00010 
00011 typedef struct {
00012         int offset;
00013         int width;
00014 } SGEBITMAPFONTINFO;
00015 
00016 SGEFONT *sgeFontNew(int type) {
00017         SGEFONT *ret;
00018         sgeNew(ret, SGEFONT);
00019         ret->type=type;
00020         ret->alpha=0xff;
00021         ret->data=NULL;
00022         return ret;
00023 }
00024 
00025 SGEFONT *sgeFontNewFileBitmap(SGEFILE *f, const char *filename) {
00026         SGEFONT *ret=sgeFontNew(SGEFONT_BITMAP);
00027         SGEBITMAPFONT *data;
00028         int i=0;
00029         char *tmp;
00030         SGEPIXELINFO *pi;
00031         SGEBITMAPFONTINFO *fi;
00032         int offset=0;
00033 
00034         sgeMalloc(tmp,char,strlen(filename)+5);
00035         strcpy(tmp, filename);
00036         strcat(tmp,".map");
00037 
00038         sgeNew(data, SGEBITMAPFONT);
00039         data->bitmap=sgeReadImage(f,filename);
00040         data->charmap=(unsigned char *)sgeReadFile(f, tmp);
00041         data->info=sgeArrayNew();
00042 
00043         for (i=0;i<data->bitmap->w;i++) {
00044                 pi=sgeGetPixel(data->bitmap, i, 0);
00045                 if (
00046                                 (
00047                                  (pi->r==255) &&
00048                                  (pi->g==0) &&
00049                                  (pi->b==255) &&
00050                                  (pi->a==255)
00051                                 ) ||
00052                                 (i==data->bitmap->w-1)
00053                 ) {
00054                         sgeNew(fi,SGEBITMAPFONTINFO);
00055                         fi->offset=offset;
00056                         fi->width=i-offset-1;
00057                         sgeArrayAdd(data->info,fi);
00058                         offset=i+1;
00059                 }
00060                 sgePixelInfoDestroy(pi);
00061         }
00062 
00063         ret->data=data;
00064         return ret;
00065 }
00066 
00067 SGEFONT *sgeFontNewFile(SGEFILE *f, int type, const char *filename) {
00068         switch (type) {
00069                 case SGEFONT_BITMAP:
00070                         return sgeFontNewFileBitmap(f, filename);
00071         }
00072         return NULL;
00073 }
00074 
00075 static void sgeFontDestroyBitmap(SGEFONT *f) {
00076         SGEBITMAPFONT *bfont;
00077         SGEBITMAPFONTINFO *bfi;
00078 
00079         bfont=(SGEBITMAPFONT *)f->data;
00080         SDL_FreeSurface(bfont->bitmap);
00081         sgeFree(bfont->charmap);
00082         while (bfont->info->numberOfElements>0) {
00083                 bfi=sgeArrayGet(bfont->info,0);
00084                 sgeFree(bfi);
00085                 sgeArrayRemove(bfont->info,0);
00086         }
00087         sgeArrayDestroy(bfont->info);
00088         sgeFree(bfont);
00089 }
00090 
00091 void sgeFontDestroy(SGEFONT *f) {
00092 
00093         if (f->data!=NULL) {
00094                 switch (f->type) {
00095                         case SGEFONT_BITMAP:
00096                                 sgeFontDestroyBitmap(f);
00097                                 break;
00098                 }
00099         }
00100         sgeFree(f);
00101 }
00102 
00103 int sgeFontGetLineHeightBitmap(SGEFONT *f) {
00104         SGEBITMAPFONT *bfont;
00105         bfont=(SGEBITMAPFONT *)f->data;
00106         return bfont->bitmap->h;
00107 }
00108 
00109 int sgeFontGetLineHeight(SGEFONT *f) {
00110         if (f->data==NULL) return -1;
00111 
00112         switch (f->type) {
00113                 case SGEFONT_BITMAP:
00114                         return sgeFontGetLineHeightBitmap(f);
00115         }
00116         return -1;
00117 }
00118 
00119 int sgeFontPrintBitmap(SGEFONT *f, SDL_Surface *dest, int x, int y, const char *text) {
00120         SGEBITMAPFONT *bfont;
00121         SGEBITMAPFONTINFO *bfi;
00122         int i;
00123         int xx=x;
00124         int c, idx;
00125         char *pos;
00126         SDL_Rect src, dst;
00127         SDL_Surface *alphasurface;
00128 
00129         bfont=(SGEBITMAPFONT *)f->data;
00130 
00131         dst.y=y;
00132         src.h=bfont->bitmap->h;
00133         src.y=0;
00134 
00135         for (i=0;i<strlen(text);i++) {
00136                 c=text[i];
00137                 pos=strchr((const char *)bfont->charmap, c);
00138                 if (pos!=NULL) {
00139                         idx=pos-(char *)bfont->charmap;
00140                         bfi=sgeArrayGet(bfont->info, idx);
00141 
00142                         dst.x=xx;
00143                         src.x=bfi->offset;
00144                         src.w=bfi->width;
00145                         xx+=bfi->width;
00146 
00147                         if (f->alpha==0xff) {
00148                                 SDL_BlitSurface(bfont->bitmap, &src, dest, &dst);
00149                         } else {
00150                                 alphasurface=sgeChangeSDLSurfaceAlpha(bfont->bitmap, f->alpha);
00151                                 SDL_BlitSurface(alphasurface,&src,dest,&dst);
00152                                 SDL_FreeSurface(alphasurface);
00153                         }
00154                 }
00155         }
00156         return xx-x;
00157 }
00158 
00159 int sgeFontPrint(SGEFONT *f, SDL_Surface *dest, int x, int y, const char *text) {
00160         switch (f->type) {
00161                 case SGEFONT_BITMAP:
00162                         return sgeFontPrintBitmap(f, dest, x, y, text);
00163         }
00164         return 0;
00165 }
00166 
00167 int sgeFontGetWidth(SGEFONT *f, const char *text) {
00168         switch (f->type) {
00169                 case SGEFONT_BITMAP:
00170                         return sgeFontGetWidthBitmap(f, text);
00171         }
00172         return 0;
00173 }
00174 
00175 void sgeFontIgnoreAlpha(SGEFONT *f) {
00176         SGEBITMAPFONT *bfont;
00177         bfont=(SGEBITMAPFONT *)f->data;
00178         sgeIgnoreAlpha(bfont->bitmap);
00179 }
00180 
00181 void sgeFontUseAlpha(SGEFONT *f) {
00182         SGEBITMAPFONT *bfont;
00183         bfont=(SGEBITMAPFONT *)f->data;
00184         sgeUseAlpha(bfont->bitmap);
00185 }
00186 
00187 int sgeFontGetWidthBitmap(SGEFONT *f, const char *text) {
00188         SGEBITMAPFONT *bfont;
00189         SGEBITMAPFONTINFO *bfi;
00190         int i;
00191         int c, idx;
00192         char *pos;
00193         int ret=0;
00194 
00195         bfont=(SGEBITMAPFONT *)f->data;
00196 
00197         for (i=0;i<strlen(text);i++) {
00198                 c=text[i];
00199                 pos=strchr((const char *)bfont->charmap, c);
00200                 if (pos!=NULL) {
00201                         idx=pos-(char *)bfont->charmap;
00202                         bfi=sgeArrayGet(bfont->info, idx);
00203                         ret+=bfi->width;
00204                 }
00205         }
00206         return ret;
00207 }
00208 
00209 static void sgeFontFXFadeUpdateHelper(void *data, int inout) {
00210         SGEFONTFX *fx=(SGEFONTFX *)data;
00211         SGEFONTFXFADEINFO *fadeInfo=(SGEFONTFXFADEINFO *)fx->data;
00212         SGESPRITE *sprite;
00213         Uint32 current=SDL_GetTicks()-fx->startTime;
00214         int per10k;
00215         int difx, dify;
00216         int i;
00217         int charPos=0;
00218         int finished=0;
00219         float ymul;
00220         float ydiv;
00221 
00222         current+=fx->charOffset;
00223         for (i=0;i<fx->textSprites->numberOfElements;i++) {
00224                 if (current>fx->charOffset) {
00225                         current-=fx->charOffset;
00226                         per10k=sgeFontFXGetPer10K(fx, current, fadeInfo->runtime, i, fx->textSprites->numberOfElements);
00227                 } else {
00228                         per10k=sgeFontFXGetPer10K(fx, 0, fadeInfo->runtime, i, fx->textSprites->numberOfElements);
00229                 }
00230                 if ( (fx->preDelay>0) && (fx->hideOnPreDelay) ) {
00231                         return;
00232                 }
00233                 sprite=sgeArrayGet(fx->textSprites,i);
00234                 if (fadeInfo->fade) {
00235                         if (per10k>9999) {
00236                                 if (inout==1) {
00237                                         sprite->alpha=255;
00238                                 } else {
00239                                         sprite->alpha=0;
00240                                 }
00241                                 finished++;
00242                         } else {
00243                                 if (inout==1) {
00244                                         sprite->alpha=255*per10k/10000;
00245                                 } else {
00246                                         sprite->alpha=255-(255*per10k/10000);
00247                                 }
00248                         }
00249                 } else {
00250                         sprite->alpha=255;
00251                         if (per10k>9999) {
00252                                 finished++;
00253                         }
00254                 }
00255                 sgeSpriteDraw(sprite, fx->surface);
00256                 if (per10k<10000) {
00257                         difx=fx->endx-fx->startx;
00258                         dify=fx->endy-fx->starty;
00259                         sprite->x=fx->startx+charPos+(difx*per10k/10000);
00260                         if (fx->movement==SGEFONTFX_MOVE_BOUNCE) {
00261                                 if (per10k<4000) {
00262                                         ymul=cos(M_PI/180*((float)per10k*90/2000));
00263                                 } else if (per10k<8000) {
00264                                         ymul=cos(M_PI/180*((float)(per10k-4000)*90/2000));
00265                                 } else {
00266                                         ymul=cos(M_PI/180*((float)(per10k-8000)*90/2000));
00267                                 }
00268                                 if (per10k<2000) {
00269                                         ydiv=1;
00270                                 } else if (per10k<6000) {
00271                                         ydiv=.75;
00272                                 } else {
00273                                         ydiv=.4;
00274                                 }
00275                                 if (ymul<0) {
00276                                         ymul*=-1;
00277                                 }
00278                                 sprite->y=fx->endy-dify*ymul*ydiv;
00279                         } else {
00280                                 sprite->y=fx->starty+(dify*per10k/10000);
00281                         }
00282                 } else {
00283                         sprite->x=fx->endx+charPos;
00284                         sprite->y=fx->endy;
00285                 }
00286                 charPos+=sgeSpriteWidth(sprite);
00287         }
00288         if (finished==fx->textSprites->numberOfElements) {
00289                 sgeFontFXSetFinished(fx);
00290         }
00291 }
00292 
00293 void sgeFontFXFadeInUpdate(void *data) {
00294         sgeFontFXFadeUpdateHelper(data, 1);
00295 }
00296 
00297 void sgeFontFXFadeInDestroy(void *data) {
00298         SGEFONTFXFADEINFO *fadeInfo=(SGEFONTFXFADEINFO *)data;
00299         sgeFontFXFadeInfoDestroy(fadeInfo);
00300 }
00301 
00302 void sgeFontFXFadeOutUpdate(void *data) {
00303         sgeFontFXFadeUpdateHelper(data, 0);
00304 }
00305 
00306 void sgeFontFXFadeOutDestroy(void *data) {
00307         SGEFONTFXFADEINFO *fadeInfo=(SGEFONTFXFADEINFO *)data;
00308         sgeFontFXFadeInfoDestroy(fadeInfo);
00309 }
00310 
00311 void sgeFontFXFadeInOutUpdate(void *data) {
00312         SGEFONTFX *fx=(SGEFONTFX *)data;
00313         SGEFONTFXFADEINOUTINFO *info=(SGEFONTFXFADEINOUTINFO *)fx->data;
00314 
00315         if (info->fadeIn->finished==0) {
00316                 sgeFontFXDraw(info->fadeIn);
00317                 if (info->fadeIn->finished) {
00318                         info->fadeOut->startTime=SDL_GetTicks()-100;
00319                 }
00320         } else if (info->fadeOut->finished==0) {
00321                 sgeFontFXDraw(info->fadeOut);
00322         } else {
00323                 sgeFontFXSetFinished(fx);
00324         }
00325 }
00326 
00327 void sgeFontFXFadeInOutDestroy(void *data) {
00328         SGEFONTFXFADEINOUTINFO *fadeInfo=(SGEFONTFXFADEINOUTINFO *)data;
00329         sgeFontFXFadeInOutInfoDestroy(fadeInfo);
00330 }
00331 
00332 int sgeFontFXGetPer10K(SGEFONTFX *fx, Uint32 current, Uint32 runtime, Uint32 currentElement, Uint32 numberOfElements) {
00333         Uint32 ticks;
00334         if (fx->preDelay>0) {
00335                 ticks=SDL_GetTicks();
00336                 if (ticks<fx->startTime+fx->preDelay-current) {
00337                         return 0;
00338                 }
00339                 if (currentElement==numberOfElements-1) {
00340                         fx->startTime=ticks;
00341                         fx->preDelay=0;
00342                 }
00343                 return 0;
00344         }
00345         if (current>runtime) return 10000;
00346         if (fx->movement==SGEFONTFX_MOVE_SLOWDOWN) {
00347                 return (int) (10000*sin(M_PI/180*((float)current*10000/(float)runtime*90/10000)));
00348         }
00349         if (fx->movement==SGEFONTFX_MOVE_ACCELERATE) {
00350                 return 10000-(int)(10000*cos(M_PI/180*((float)current*10000/(float)runtime*90/10000)));
00351         }
00352         return (int) (current*10000/runtime);
00353 }
00354 
00355 SGEFONTFX *sgeFontFXNew(SGEFONT *f, Uint32 fxtype, Uint8 movement, Uint32 runtime, Uint32 charOffset, int startx, int starty, int endx, int endy, const char *text) {
00356         SGEFONTFX *ret;
00357         SDL_Surface *tmp;
00358         SGESPRITE *sprite;
00359         SGEFONTFXFADEINFO *fadeInfo;
00360         SGEFONTFXFADEINOUTINFO *fadeInOutInfo;
00361         SGEFONTFXCOUNTDOWNINFO *countdownInfo;
00362         int i;
00363         int lineheight;
00364         char buf[2];
00365         int charPos=0;
00366         int charWidth;
00367         const char *usedText;
00368         Uint32 tmpruntime;
00369 
00370         if (fxtype==SGEFONTFX_COUNTDOWN) {
00371                 charOffset=0;
00372                 usedText=(const char *)&"000000000000";
00373         } else {
00374                 usedText=text;
00375         }
00376 
00377         sgeNew(ret,SGEFONTFX);
00378 
00379         ret->type=fxtype;
00380         ret->runtime=runtime;
00381         ret->startx=startx;
00382         ret->starty=starty;
00383         ret->endx=endx;
00384         ret->endy=endy;
00385         ret->charOffset=charOffset;
00386         ret->finished=0;
00387         ret->startTime=SDL_GetTicks();
00388         ret->font=f;
00389         ret->surface=screen;
00390         ret->text=strdup(usedText);
00391         ret->textSprites=sgeArrayNew();
00392         ret->movement=movement;
00393         ret->preDelay=0;
00394         ret->postDelay=0;
00395         ret->hideOnPreDelay=0;
00396 
00397         lineheight=sgeFontGetLineHeight(ret->font);
00398         sgeFontIgnoreAlpha(ret->font);
00399         if (ret->charOffset==0) {
00400                 tmp=sgeCreateSDLSurface(sgeFontGetWidth(ret->font,ret->text),lineheight,32,SDL_HWSURFACE);
00401                 sgeFontPrint(ret->font, tmp, 0, 0, ret->text);
00402                 sprite=sgeSpriteNewSDLSurface(tmp);
00403                 sprite->x=startx;
00404                 sprite->y=starty;
00405                 sgeArrayAdd(ret->textSprites, sprite);
00406         } else {
00407                 strcpy(buf," ");
00408                 for (i=0;i<strlen(text);i++) {
00409                         sprintf(buf, "%c",ret->text[i]);
00410                         charWidth=sgeFontGetWidth(ret->font,buf);
00411                         tmp=sgeCreateSDLSurface(charWidth,lineheight,32,SDL_HWSURFACE);
00412                         sgeFontPrint(ret->font, tmp, 0, 0, buf);
00413                         sprite=sgeSpriteNewSDLSurface(tmp);
00414                         sprite->x=startx+charPos;
00415                         sprite->y=starty;
00416                         sgeArrayAdd(ret->textSprites, sprite);
00417                         charPos+=charWidth;
00418                 }
00419         }
00420         sgeFontUseAlpha(ret->font);
00421 
00422         switch (fxtype) {
00423                 case SGEFONTFX_FADE_IN:
00424                         fadeInfo=sgeFontFXFadeInfoNew(runtime);
00425                         ret->data=(void *)fadeInfo;
00426                         ret->updateFunction=sgeFontFXFadeInUpdate;
00427                         ret->freeFunction=sgeFontFXFadeInDestroy;
00428                         break;
00429                 case SGEFONTFX_FADE_OUT:
00430                         fadeInfo=sgeFontFXFadeInfoNew(runtime);
00431                         ret->data=(void *)fadeInfo;
00432                         ret->updateFunction=sgeFontFXFadeOutUpdate;
00433                         ret->freeFunction=sgeFontFXFadeOutDestroy;
00434                         break;
00435                 case SGEFONTFX_FADE_INOUT:
00436                         tmpruntime=runtime>>1;
00437                         fadeInOutInfo=sgeFontFXFadeInOutInfoNew(ret,tmpruntime,runtime-tmpruntime,1);
00438                         ret->data=(void *)fadeInOutInfo;
00439                         ret->updateFunction=sgeFontFXFadeInOutUpdate;
00440                         ret->freeFunction=sgeFontFXFadeInOutDestroy;
00441                         break;
00442                 case SGEFONTFX_MOVE_IN:
00443                         fadeInfo=sgeFontFXFadeInfoNew(runtime);
00444                         fadeInfo->fade=0;
00445                         ret->data=(void *)fadeInfo;
00446                         ret->updateFunction=sgeFontFXFadeInUpdate;
00447                         ret->freeFunction=sgeFontFXFadeInDestroy;
00448                         break;
00449                 case SGEFONTFX_MOVE_OUT:
00450                         fadeInfo=sgeFontFXFadeInfoNew(runtime);
00451                         fadeInfo->fade=0;
00452                         ret->data=(void *)fadeInfo;
00453                         ret->updateFunction=sgeFontFXFadeOutUpdate;
00454                         ret->freeFunction=sgeFontFXFadeOutDestroy;
00455                         break;
00456                 case SGEFONTFX_MOVE_INOUT:
00457                         tmpruntime=runtime>>1;
00458                         fadeInOutInfo=sgeFontFXFadeInOutInfoNew(ret,tmpruntime,runtime-tmpruntime,0);
00459                         ret->data=(void *)fadeInOutInfo;
00460                         ret->updateFunction=sgeFontFXFadeInOutUpdate;
00461                         ret->freeFunction=sgeFontFXFadeInOutDestroy;
00462                         break;
00463                 case SGEFONTFX_COUNTDOWN:
00464                         countdownInfo=sgeFontFXCountdownInfoNew(runtime);
00465                         ret->data=(void *)countdownInfo;
00466                         ret->updateFunction=sgeFontFXCountdownUpdate;
00467                         ret->freeFunction=sgeFontFXCountdownDestroy;
00468                         break;
00469                 default:
00470                         sgeBailOut("Unknown font effect: %d\n", fxtype);
00471         }
00472         return ret;
00473 }
00474 
00475 void sgeFontFXDraw(SGEFONTFX *fx) {
00476         (fx->updateFunction)((void *)fx);
00477 }
00478 
00479 void sgeFontFXDestroy(SGEFONTFX *fx) {
00480         int i;
00481         SGESPRITE *sprite;
00482 
00483         for (i=fx->textSprites->numberOfElements-1;i>-1;i--) {
00484                 sprite=sgeArrayGet(fx->textSprites,i);
00485                 sgeSpriteDestroy(sprite);
00486                 sgeArrayRemove(fx->textSprites,i);
00487         }
00488         sgeArrayDestroy(fx->textSprites);
00489         sgeFree(fx->text);
00490         (fx->freeFunction)(fx->data);
00491         sgeFree(fx);
00492 }
00493 
00494 SGEFONTFXFADEINFO *sgeFontFXFadeInfoNew(Uint32 runtime) {
00495         SGEFONTFXFADEINFO *ret;
00496         sgeNew(ret, SGEFONTFXFADEINFO);
00497         ret->runtime=runtime;
00498         ret->fade=1;
00499         return ret;
00500 }
00501 
00502 void sgeFontFXFadeInfoDestroy(SGEFONTFXFADEINFO *fi) {
00503         sgeFree(fi);
00504 }
00505 
00506 SGEFONTFXFADEINOUTINFO *sgeFontFXFadeInOutInfoNew(SGEFONTFX *fx, Uint32 runtimein, Uint32 runtimeout,Uint8 fade) {
00507         SGEFONTFXFADEINOUTINFO *ret;
00508         int difxhalf, difyhalf;
00509         Uint8 movementin;
00510         Uint8 movementout;
00511         Uint32 effectin,effectout;
00512 
00513         difxhalf=(fx->endx-fx->startx)/2;
00514         difyhalf=(fx->endy-fx->starty)/2;
00515 
00516         switch (fx->movement) {
00517                 case SGEFONTFX_MOVE_SLOWDOWN:
00518                         movementin=SGEFONTFX_MOVE_SLOWDOWN;
00519                         movementout=SGEFONTFX_MOVE_ACCELERATE;
00520                         break;
00521                 case SGEFONTFX_MOVE_ACCELERATE:
00522                         movementin=SGEFONTFX_MOVE_ACCELERATE;
00523                         movementout=SGEFONTFX_MOVE_SLOWDOWN;
00524                         break;
00525                 default:
00526                         movementin=fx->movement;
00527                         movementout=fx->movement;
00528                         break;
00529         }
00530 
00531         sgeNew(ret, SGEFONTFXFADEINOUTINFO);
00532         if (fade) {
00533                 effectin=SGEFONTFX_FADE_IN;
00534                 effectout=SGEFONTFX_FADE_OUT;
00535         } else {
00536                 effectin=SGEFONTFX_MOVE_IN;
00537                 effectout=SGEFONTFX_MOVE_OUT;
00538         }
00539         ret->fadeIn=sgeFontFXNew(fx->font, effectin, movementin, runtimein, fx->charOffset, fx->startx, fx->starty, fx->startx+difxhalf, fx->starty+difyhalf, fx->text);
00540         ret->fadeOut=sgeFontFXNew(fx->font, effectout, movementout, runtimeout, fx->charOffset, fx->startx+difxhalf, fx->starty+difyhalf, fx->endx, fx->endy, fx->text);
00541         return ret;
00542 }
00543 
00544 void sgeFontFXFadeInOutInfoDestroy(SGEFONTFXFADEINOUTINFO *fi) {
00545         sgeFontFXDestroy(fi->fadeIn);
00546         sgeFontFXDestroy(fi->fadeOut);
00547         sgeFree(fi);
00548 }
00549 
00550 SGEFONTFXCOUNTDOWNINFO *sgeFontFXCountdownInfoNew(Uint32 runtime) {
00551         SGEFONTFXCOUNTDOWNINFO *ret;
00552         sgeNew(ret, SGEFONTFXCOUNTDOWNINFO);
00553         ret->start=10;
00554         ret->end=0;
00555         ret->runtime=runtime;
00556         return ret;
00557 }
00558 
00559 void sgeFontFXCountdownInfoDestroy(SGEFONTFXCOUNTDOWNINFO *fi) {
00560         sgeFree(fi);
00561 }
00562 
00563 void sgeFontFXCountdownUpdate(void *data) {
00564         SGEFONTFX *fx=(SGEFONTFX *)data;
00565         SGEFONTFXCOUNTDOWNINFO *info=(SGEFONTFXCOUNTDOWNINFO *)fx->data;
00566         Sint32 tmp=info->end-info->start;
00567         Uint32 current=SDL_GetTicks()-fx->startTime;
00568         int per10k;
00569         char buf[256];
00570         SGESPRITE *sprite;
00571         SDL_Surface *surface;
00572         int difx, dify;
00573 
00574         per10k=sgeFontFXGetPer10K(fx, current, info->runtime, 0, 1);
00575         if ( (fx->preDelay>0) && (fx->hideOnPreDelay) ) {
00576                 return;
00577         }
00578         if (per10k>9999) {
00579                 sgeFontFXSetFinished(fx);
00580                 sprintf(buf, "%d", info->end);
00581         } else {
00582                 if (abs(tmp)>100000) {
00583                         sprintf(buf, "%d", (int) (info->start+(tmp/10000*per10k)));
00584                 } else {
00585                         sprintf(buf, "%d", (int) (info->start+(tmp*per10k/10000)));
00586                 }
00587         }
00588         sprite=sgeArrayGet(fx->textSprites,0);
00589         difx=fx->endx-fx->startx;
00590         dify=fx->endy-fx->starty;
00591         sprite->x=fx->startx+(difx*per10k/10000);
00592         sprite->y=fx->starty+(dify*per10k/10000);
00593 
00594         surface=sgeSpriteGetSDLSurface(sprite);
00595         sgeFillRect(surface, 0, 0, surface->w, surface->h, sgeMakeColor(surface,0x00,0x00,0x00,0x00));
00596         sgeFontIgnoreAlpha(fx->font);
00597         sgeFontPrint(fx->font, surface, 0, 0, buf);
00598         sgeSpriteDraw(sprite, fx->surface);
00599         sgeFontUseAlpha(fx->font);
00600 }
00601 
00602 void sgeFontFXCountdownDestroy(void *data) {
00603         SGEFONTFXCOUNTDOWNINFO *info=(SGEFONTFXCOUNTDOWNINFO *)data;
00604         sgeFontFXCountdownInfoDestroy(info);
00605 }
00606 
00607 void sgeFontFXCountdownSetValues(SGEFONTFX *fx, Sint32 start, Sint32 end) {
00608         SGEFONTFXCOUNTDOWNINFO *fi=(SGEFONTFXCOUNTDOWNINFO *)fx->data;
00609         fi->start=start;
00610         fi->end=end;
00611 }
00612 
00613 void sgeFontFXPreDelay(SGEFONTFX *fx, Uint32 delay) {
00614         fx->preDelay=delay;
00615 }
00616 
00617 void sgeFontFXPostDelay(SGEFONTFX *fx, Uint32 delay) {
00618         fx->postDelay=delay;
00619 }
00620 
00621 void sgeFontFXSetFinished(SGEFONTFX *fx) {
00622         if (!fx->finished) fx->finishTime=SDL_GetTicks();
00623         fx->finished=1;
00624 }
00625 
00626 int sgeFontFXFinished(SGEFONTFX *fx) {
00627         if ( (fx->finished) && (SDL_GetTicks()>=fx->finishTime+fx->postDelay) ) {
00628                 return 1;
00629         }
00630         return 0;
00631 }
00632 
00633 void sgeFontFXHideOnPreDelay(SGEFONTFX *fx, Uint8 yesno) {
00634         fx->hideOnPreDelay=yesno;
00635 }
00636 
00637 void sgeFontFXSetTarget(SGEFONTFX *fx, SDL_Surface *surface) {
00638         fx->surface=surface;
00639 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines