|
|
@ -25,9 +25,11 @@ SDL_Surface *IMG_LoadBoost(const char *path) { |
|
|
|
struct gui_resource_t display_start() { |
|
|
|
struct gui_resource_t res; |
|
|
|
|
|
|
|
null_die(SDL_Init(SDL_INIT_VIDEO) != -1, "SDL initialization failed"); |
|
|
|
null_die(TTF_Init() != -1, "TTF initialization failed"); |
|
|
|
|
|
|
|
/* création fenêtre */ |
|
|
|
SDL_Init(SDL_INIT_VIDEO); |
|
|
|
res.screen = SDL_SetVideoMode(SCREEN_X, SCREEN_Y, 32, SDL_SWSURFACE); |
|
|
|
res.screen = SDL_SetVideoMode(SCREEN_X, SCREEN_Y, 32, SDL_HWSURFACE); |
|
|
|
SDL_WM_SetCaption("跳棋", NULL); |
|
|
|
|
|
|
|
/* chargement images */ |
|
|
@ -46,6 +48,10 @@ struct gui_resource_t display_start() { |
|
|
|
null_die(res.pawn_img[5] = IMG_LoadBoost("img/pawn5-green.png"), "cannot load green pawn img"); |
|
|
|
null_die(res.pawn_img[6] = IMG_LoadBoost("img/pawn6-purple.png"), "cannot load purple pawn img"); |
|
|
|
|
|
|
|
/* chargement police de caractères */ |
|
|
|
null_die(res.font_big = TTF_OpenFont("img/cmunbmr.otf", 34), "cannot load font"); |
|
|
|
null_die(res.font_small = TTF_OpenFont("img/cmunbmr.otf", 18), "cannot load font"); |
|
|
|
|
|
|
|
return res; |
|
|
|
} |
|
|
|
|
|
|
@ -217,7 +223,7 @@ int display_animove_pawn(struct gui_resource_t res, struct game_state_t gamestat |
|
|
|
SDL_Delay(PANIFRAMETIME - (time2-time1)); |
|
|
|
#ifdef rant |
|
|
|
else |
|
|
|
fprintf(stderr,"(rant) animation: the machine is slow, frame took %dms\n", time2-time1); |
|
|
|
fprintf(stderr,"(rant) pawn animation: the machine is slow, frame took %dms\n", time2-time1); |
|
|
|
#endif |
|
|
|
} |
|
|
|
SDL_FreeSurface(buffer); |
|
|
@ -233,7 +239,11 @@ int display_animsg(struct gui_resource_t res, struct game_state_t gamestate, enu |
|
|
|
|
|
|
|
/* mise en buffer de l'image du message */ |
|
|
|
SDL_Surface *msgbuffer = SDL_ConvertSurface(res.msgboard_img, res.msgboard_img->format, res.msgboard_img->flags); |
|
|
|
/* sdl ttf msg → msgbuffer TODO */ |
|
|
|
SDL_Color text_color = {20, 18, 17}; /* RGB */ |
|
|
|
SDL_Surface *text_img = TTF_RenderUTF8_Blended(res.font_big, msg, text_color); |
|
|
|
SDL_Rect textclip = { msgbuffer->w/2 - text_img->w/2, msgbuffer->h/2 - text_img->h/2 }; |
|
|
|
SDL_BlitSurface(text_img, NULL, msgbuffer, &textclip); /* dessin du texte */ |
|
|
|
SDL_FreeSurface(text_img); |
|
|
|
|
|
|
|
uint32_t time1, time2; /* mesure du temps de rendu de frame */ |
|
|
|
SDL_Event event; |
|
|
@ -245,13 +255,12 @@ int display_animsg(struct gui_resource_t res, struct game_state_t gamestate, enu |
|
|
|
if(event.type == SDL_QUIT) |
|
|
|
frame = duration/MANIFRAMETIME + 2; |
|
|
|
|
|
|
|
/* interpolation non-linéaire de progression 0→1 */ |
|
|
|
double progress = sin( ((double)frame)/((double)(duration/MANIFRAMETIME))*M_PI/2 ); |
|
|
|
|
|
|
|
SDL_BlitSurface(bgbuffer, NULL, res.screen, NULL); /* dessin du fond */ |
|
|
|
SDL_Surface *zoomed_msg_img = rotozoomSurface(msgbuffer, (1-progress)*30/M_PI, 2-progress, frame == duration/MANIFRAMETIME); |
|
|
|
SDL_SetAlpha(zoomed_msg_img, SDL_SRCALPHA|SDL_RLEACCEL, (char)round(progress*256)); |
|
|
|
SDL_Rect clip = { SCREEN_X/2 - zoomed_msg_img->w/2, SCREEN_Y/2 - zoomed_msg_img->h/2}; |
|
|
|
|
|
|
|
double progress = ((double)frame)/((double)(duration/MANIFRAMETIME)); /* 0→1 */ |
|
|
|
SDL_Surface *zoomed_msg_img = rotozoomSurface(msgbuffer, (1-progress)*10/M_PI, 1.5-progress, 1/*antialias*/); |
|
|
|
SDL_SetAlpha(zoomed_msg_img, SDL_SRCALPHA|SDL_RLEACCEL, (int)round(sin(progress*M_PI)*255)); |
|
|
|
SDL_Rect clip = { SCREEN_X/2 - zoomed_msg_img->w/2, SCREEN_Y/2 - zoomed_msg_img->h/2 }; |
|
|
|
SDL_BlitSurface(zoomed_msg_img, NULL, res.screen, &clip); /* dessin du message */ |
|
|
|
SDL_FreeSurface(zoomed_msg_img); |
|
|
|
|
|
|
@ -263,7 +272,7 @@ int display_animsg(struct gui_resource_t res, struct game_state_t gamestate, enu |
|
|
|
SDL_Delay(MANIFRAMETIME - (time2-time1)); |
|
|
|
#ifdef rant |
|
|
|
else |
|
|
|
fprintf(stderr,"(rant) animation: the machine is slow, frame took %dms\n", time2-time1); |
|
|
|
fprintf(stderr,"(rant) text animation: the machine is slow, frame took %dms\n", time2-time1); |
|
|
|
#endif |
|
|
|
} |
|
|
|
SDL_FreeSurface(bgbuffer); |
|
|
@ -285,4 +294,5 @@ void display_close(struct gui_resource_t res) { |
|
|
|
|
|
|
|
/* Fermeture fenêtre */ |
|
|
|
SDL_Quit(); |
|
|
|
TTF_Quit(); |
|
|
|
} |