Mercurial > sdl-ios-xcode
comparison test/graywin.c @ 380:bce7171e7a85
Date: Wed, 22 May 2002 22:30:58 +0300
From: "Mike Gorchak" <mike@malva.com.ua>
Subject: One more QNX patch
Hi !
- Fixed graywin test application. Added properly support for
window size not equal to 640x480.
- Added support for not aligned pitch of image in SDL_SWSURFACE
and SDL_HWSURFACE. Using Photon builtin alignes.
- Added memory clear after each malloc to avoid problems in the
future :)
- Removed unused variables and static variables, fixed some warnings.
- Updated readme.QNX file.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 28 May 2002 19:31:32 +0000 |
parents | 74212992fb08 |
children | d3abe873e3f7 |
comparison
equal
deleted
inserted
replaced
379:11c8a7684f74 | 380:bce7171e7a85 |
---|---|
13 #else | 13 #else |
14 #define NUM_COLORS 256 | 14 #define NUM_COLORS 256 |
15 #endif | 15 #endif |
16 | 16 |
17 /* Draw a randomly sized and colored box centered about (X,Y) */ | 17 /* Draw a randomly sized and colored box centered about (X,Y) */ |
18 void DrawBox(SDL_Surface *screen, int X, int Y) | 18 void DrawBox(SDL_Surface *screen, int X, int Y, int width, int height) |
19 { | 19 { |
20 static unsigned int seeded = 0; | 20 static unsigned int seeded = 0; |
21 SDL_Rect area; | 21 SDL_Rect area; |
22 Uint32 color; | 22 Uint32 color; |
23 | 23 |
26 srand(time(NULL)); | 26 srand(time(NULL)); |
27 seeded = 1; | 27 seeded = 1; |
28 } | 28 } |
29 | 29 |
30 /* Get the bounds of the rectangle */ | 30 /* Get the bounds of the rectangle */ |
31 area.w = (rand()%640); | 31 area.w = (rand()%width); |
32 area.h = (rand()%480); | 32 area.h = (rand()%height); |
33 area.x = X-(area.w/2); | 33 area.x = X-(area.w/2); |
34 area.y = Y-(area.h/2); | 34 area.y = Y-(area.h/2); |
35 color = (rand()%NUM_COLORS); | 35 color = (rand()%NUM_COLORS); |
36 | 36 |
37 /* Do it! */ | 37 /* Do it! */ |
70 SDL_GetError()); | 70 SDL_GetError()); |
71 return(NULL); | 71 return(NULL); |
72 } | 72 } |
73 buffer = (Uint8 *)screen->pixels; | 73 buffer = (Uint8 *)screen->pixels; |
74 for ( i=0; i<screen->h; ++i ) { | 74 for ( i=0; i<screen->h; ++i ) { |
75 memset(buffer,(i*(NUM_COLORS-1))/screen->h, screen->w); | 75 memset(buffer,(i*(NUM_COLORS-1))/screen->h, screen->w * screen->format->BytesPerPixel); |
76 buffer += screen->pitch; | 76 buffer += screen->pitch; |
77 } | 77 } |
78 SDL_UnlockSurface(screen); | 78 SDL_UnlockSurface(screen); |
79 SDL_UpdateRect(screen, 0, 0, 0, 0); | 79 SDL_UpdateRect(screen, 0, 0, 0, 0); |
80 | 80 |
124 videoflags |= SDL_NOFRAME; | 124 videoflags |= SDL_NOFRAME; |
125 } else | 125 } else |
126 if ( argv[argc] && (strcmp(argv[argc], "-fullscreen") == 0) ) { | 126 if ( argv[argc] && (strcmp(argv[argc], "-fullscreen") == 0) ) { |
127 videoflags |= SDL_FULLSCREEN; | 127 videoflags |= SDL_FULLSCREEN; |
128 } else { | 128 } else { |
129 fprintf(stderr, "Usage: %s [-warp] [-fullscreen]\n", | 129 fprintf(stderr, "Usage: %s [-width] [-height] [-bpp] [-hw] [-hwpalette] [-noframe] [-fullscreen]\n", |
130 argv[0]); | 130 argv[0]); |
131 exit(1); | 131 exit(1); |
132 } | 132 } |
133 } | 133 } |
134 | 134 |
141 /* Wait for a keystroke */ | 141 /* Wait for a keystroke */ |
142 done = 0; | 142 done = 0; |
143 while ( !done && SDL_WaitEvent(&event) ) { | 143 while ( !done && SDL_WaitEvent(&event) ) { |
144 switch (event.type) { | 144 switch (event.type) { |
145 case SDL_MOUSEBUTTONDOWN: | 145 case SDL_MOUSEBUTTONDOWN: |
146 DrawBox(screen, event.button.x, event.button.y); | 146 DrawBox(screen, event.button.x, event.button.y, width, height); |
147 break; | 147 break; |
148 case SDL_KEYDOWN: | 148 case SDL_KEYDOWN: |
149 /* Ignore ALT-TAB for windows */ | 149 /* Ignore ALT-TAB for windows */ |
150 if ( (event.key.keysym.sym == SDLK_LALT) || | 150 if ( (event.key.keysym.sym == SDLK_LALT) || |
151 (event.key.keysym.sym == SDLK_TAB) ) { | 151 (event.key.keysym.sym == SDLK_TAB) ) { |
152 break; | 152 break; |
153 } | 153 } |
154 /* Center the mouse on <SPACE> */ | 154 /* Center the mouse on <SPACE> */ |
155 if ( event.key.keysym.sym == SDLK_SPACE ) { | 155 if ( event.key.keysym.sym == SDLK_SPACE ) { |
156 SDL_WarpMouse(640/2, 480/2); | 156 SDL_WarpMouse(width/2, height/2); |
157 break; | 157 break; |
158 } | 158 } |
159 /* Toggle fullscreen mode on <RETURN> */ | 159 /* Toggle fullscreen mode on <RETURN> */ |
160 if ( event.key.keysym.sym == SDLK_RETURN ) { | 160 if ( event.key.keysym.sym == SDLK_RETURN ) { |
161 videoflags ^= SDL_FULLSCREEN; | 161 videoflags ^= SDL_FULLSCREEN; |