diff 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
line wrap: on
line diff
--- a/test/graywin.c	Tue May 28 19:24:11 2002 +0000
+++ b/test/graywin.c	Tue May 28 19:31:32 2002 +0000
@@ -15,7 +15,7 @@
 #endif
 
 /* Draw a randomly sized and colored box centered about (X,Y) */
-void DrawBox(SDL_Surface *screen, int X, int Y)
+void DrawBox(SDL_Surface *screen, int X, int Y, int width, int height)
 {
 	static unsigned int seeded = 0;
 	SDL_Rect area;
@@ -28,8 +28,8 @@
 	}
 
 	/* Get the bounds of the rectangle */
-	area.w = (rand()%640);
-	area.h = (rand()%480);
+	area.w = (rand()%width);
+	area.h = (rand()%height);
 	area.x = X-(area.w/2);
 	area.y = Y-(area.h/2);
 	color = (rand()%NUM_COLORS);
@@ -72,7 +72,7 @@
 	}
 	buffer = (Uint8 *)screen->pixels;
 	for ( i=0; i<screen->h; ++i ) {
-		memset(buffer,(i*(NUM_COLORS-1))/screen->h, screen->w);
+		memset(buffer,(i*(NUM_COLORS-1))/screen->h, screen->w * screen->format->BytesPerPixel);
 		buffer += screen->pitch;
 	}
 	SDL_UnlockSurface(screen);
@@ -126,7 +126,7 @@
 		if ( argv[argc] && (strcmp(argv[argc], "-fullscreen") == 0) ) {
 			videoflags |= SDL_FULLSCREEN;
 		} else {
-			fprintf(stderr, "Usage: %s [-warp] [-fullscreen]\n",
+			fprintf(stderr, "Usage: %s [-width] [-height] [-bpp] [-hw] [-hwpalette] [-noframe] [-fullscreen]\n",
 								argv[0]);
 			exit(1);
 		}
@@ -143,7 +143,7 @@
 	while ( !done && SDL_WaitEvent(&event) ) {
 		switch (event.type) {
 			case SDL_MOUSEBUTTONDOWN:
-				DrawBox(screen, event.button.x, event.button.y);
+				DrawBox(screen, event.button.x, event.button.y, width, height);
 				break;
 			case SDL_KEYDOWN:
 				/* Ignore ALT-TAB for windows */
@@ -153,7 +153,7 @@
 				}
 				/* Center the mouse on <SPACE> */
 				if ( event.key.keysym.sym == SDLK_SPACE ) {
-					SDL_WarpMouse(640/2, 480/2);
+					SDL_WarpMouse(width/2, height/2);
 					break;
 				}
 				/* Toggle fullscreen mode on <RETURN> */