1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
#include <stdio.h>
#include <stdlib.h>
#include <SDL/SDL.h>
#include <SDL/SDL_rotozoom.h>
#define WNDP 32
//#define WNDA 24
#define WNDA 32
#define BORDERWIDTH 2
int main(int argc,char *argv[])
{
int done;
double angle;
Uint32 red;
SDL_Surface *wnd,*abc,*a;
SDL_Event event;
SDL_Rect coo;
putenv("SDL_VIDEO_WINDOW_POS=center");
if(SDL_Init(SDL_INIT_VIDEO)!=0) exit(0);
wnd=SDL_SetVideoMode(1000,800,WNDP,SDL_HWSURFACE|SDL_DOUBLEBUF);
SDL_FillRect(wnd,NULL,SDL_MapRGB(wnd->format,255,255,255));
SDL_Flip(wnd);
abc=SDL_CreateRGBSurface(SDL_HWSURFACE,500,500,WNDA,0,0,0,0);
SDL_FillRect(abc,NULL,SDL_MapRGB(abc->format,255,255,255));
red=SDL_MapRGB(abc->format,0xff,0,0);
coo.x=0;
coo.y=0;
coo.w=abc->w;
coo.h=BORDERWIDTH;
SDL_FillRect(abc,&coo,red); // up
coo.y=abc->h-BORDERWIDTH;
SDL_FillRect(abc,&coo,red); // down
coo.y=0;
coo.w=BORDERWIDTH;
coo.h=abc->h;
SDL_FillRect(abc,&coo,red); // left
coo.x=abc->w-BORDERWIDTH;
SDL_FillRect(abc,&coo,red); // right
a=SDL_CreateRGBSurface(SDL_HWSURFACE,50,50,WNDA,0,0,0,0);
SDL_FillRect(a,NULL,SDL_MapRGB(a->format,0x4e,0x98,0x98));
coo.x=10;
coo.y=(abc->h-a->h)/2;
SDL_BlitSurface(a,NULL,abc,&coo);
SDL_FillRect(a,NULL,SDL_MapRGB(a->format,0xff,0,0));
coo.x=(abc->w-a->w)/2;
coo.y=10;
SDL_BlitSurface(a,NULL,abc,&coo);
SDL_FillRect(a,NULL,SDL_MapRGB(a->format,0,0xff,0));
coo.x=abc->w-10-a->w;
coo.y=(abc->h-a->h)/2;
SDL_BlitSurface(a,NULL,abc,&coo);
SDL_FillRect(a,NULL,SDL_MapRGB(a->format,0,0,0xff));
coo.x=(abc->w-a->w)/2;
coo.y=(abc->h-a->h)-10;
SDL_BlitSurface(a,NULL,abc,&coo);
SDL_FreeSurface(a);
done=0;
angle=1.;
coo.x=(wnd->w-abc->w)/2;
coo.y=(wnd->h-abc->h)/2;
while(!done)
{
SDL_FillRect(wnd,NULL,SDL_MapRGB(wnd->format,0xff,0xff,0xff));
angle=0.;
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT: done=1; break;
case SDL_KEYDOWN:
switch(event.key.keysym.sym)
{
case SDLK_ESCAPE: done=1; break;
case SDLK_LEFT: angle=-90.; break;
case SDLK_RIGHT: angle=90.; break;
default: break;
}
break;
default: break;
}
SDL_Surface *tmp;
tmp=rotozoomSurface(abc,angle,1,0);
SDL_BlitSurface(tmp,NULL,wnd,&coo);
printf("abc->w=%d, abc->h=%d\n",tmp->w,tmp->h);
SDL_FreeSurface(tmp);
SDL_Flip(wnd);
}
SDL_FreeSurface(abc);
SDL_FreeSurface(wnd);
SDL_Quit();
return(0);
} |
Partager