rendered paste body#include <SDL/SDL.h>
#include <stdio.h>
#include <unistd.h>
#define WIDTH 800
#define HEIGHT 600
#define DEPTH 8
#define ICON_NAME "SDL_is-teh-pwn"
#define TITLE "Axis Test"
#define BUFFER 20
#define AXIS 50
#define DOT 15
int main(void){
int x,y;
char axis[AXIS];
SDL_Surface *screen;
SDL_Rect dot;
Uint32 color, dotcolor;
dot.w = dot.h = DOT;
if (SDL_Init(SDL_INIT_VIDEO)){
fprintf(stderr,"Error: %s\n", SDL_GetError());
exit(1);
}
screen = SDL_SetVideoMode(WIDTH, HEIGHT, DEPTH, SDL_SWSURFACE | SDL_RESIZABLE);
if(!screen){
fprintf(stderr,"Error: %s\n", SDL_GetError());
exit(1);
}
SDL_WM_SetCaption(TITLE, NULL);
color = SDL_MapRGB(screen->format, 51, 74, 157); /* Maps screen format to blu-ish something... */
dotcolor = SDL_MapRGB(screen->format , 0, 0, 0); /* Maps format to black */
while(1){
SDL_PumpEvents();
SDL_GetMouseState(&x,&y);
snprintf(axis, BUFFER, "%s %dx%d", TITLE, x, y);
SDL_WM_SetCaption(axis, ICON_NAME);
(x + DOT > WIDTH)?(dot.x = (WIDTH - DOT)):(dot.x = x);
(y + DOT > HEIGHT)?(dot.y = HEIGHT - DOT):(dot.y = y);
SDL_FillRect(screen,NULL,color);
SDL_FillRect(screen, &dot, dotcolor);
SDL_Flip(screen);
if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(1) || SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(3)){
printf("A mouse button was used, exiting!\n");
break;
}
/* Just isn't as fast as the above, though you can resize...
SDL_PollEvent(&event);
switch (event.type) {
case SDL_MOUSEBUTTONDOWN:
printf("A mouse button press was detected. Quitting!\n");
SDL_Quit();
exit(0);
case SDL_VIDEORESIZE:
screen = SDL_SetVideoMode(event.resize.w, event.resize.h, 8, SDL_SWSURFACE | SDL_RESIZABLE);
SDL_Flip(screen);
continue;
case SDL_MOUSEMOTION:
snprintf(axis ,BUFFER,"%s %dx%d", TITLE, event.motion.x, event.motion.y);
SDL_WM_SetCaption(axis , ICON_NAME );
SDL_Flip(screen);
continue;
default:
continue;
}*/
}
SDL_FreeSurface(screen);
SDL_Quit();
return (0);
}