test/testcursor.c
author Patrice Mandin <patmandin@gmail.com>
Wed, 14 Jun 2006 19:03:01 +0000
changeset 1859 2fce7697adca
parent 1858 d3ac464fb3c1
child 1862 fe99535ac064
permissions -rw-r--r--
Oops, reverted single/double buffer update
patmandin@1858
     1
#include <stdio.h>
patmandin@1858
     2
#include <stdlib.h>
patmandin@1858
     3
patmandin@1858
     4
#include "SDL.h"
patmandin@1858
     5
patmandin@1858
     6
/* This is an example 16x16 cursor
patmandin@1858
     7
	top left :	black
patmandin@1858
     8
	top right : inverted color or black
patmandin@1858
     9
	bottom left: white
patmandin@1858
    10
	bottom right: transparent
patmandin@1858
    11
	(swap left and right for different endianness)
patmandin@1858
    12
*/
patmandin@1858
    13
patmandin@1858
    14
Uint16 cursor_data[16]={
patmandin@1858
    15
	0xffff,
patmandin@1858
    16
	0xffff,
patmandin@1858
    17
	0xffff,
patmandin@1858
    18
	0xffff,	
patmandin@1858
    19
patmandin@1858
    20
	0xffff,
patmandin@1858
    21
	0xffff,
patmandin@1858
    22
	0xffff,
patmandin@1858
    23
	0xffff,	
patmandin@1858
    24
patmandin@1858
    25
	0x0000,
patmandin@1858
    26
	0x0000,
patmandin@1858
    27
	0x0000,
patmandin@1858
    28
	0x0000,
patmandin@1858
    29
patmandin@1858
    30
	0x0000,
patmandin@1858
    31
	0x0000,
patmandin@1858
    32
	0x0000,
patmandin@1858
    33
	0x0000
patmandin@1858
    34
};
patmandin@1858
    35
patmandin@1858
    36
Uint16 cursor_mask[16]={
patmandin@1858
    37
	0xff00,
patmandin@1858
    38
	0xff00,
patmandin@1858
    39
	0xff00,
patmandin@1858
    40
	0xff00,
patmandin@1858
    41
patmandin@1858
    42
	0xff00,
patmandin@1858
    43
	0xff00,
patmandin@1858
    44
	0xff00,
patmandin@1858
    45
	0xff00,
patmandin@1858
    46
patmandin@1858
    47
	0xff00,
patmandin@1858
    48
	0xff00,
patmandin@1858
    49
	0xff00,
patmandin@1858
    50
	0xff00,
patmandin@1858
    51
patmandin@1858
    52
	0xff00,
patmandin@1858
    53
	0xff00,
patmandin@1858
    54
	0xff00,
patmandin@1858
    55
	0xff00
patmandin@1858
    56
};
patmandin@1858
    57
patmandin@1858
    58
int main(int argc, char *argv[])
patmandin@1858
    59
{
patmandin@1858
    60
	SDL_Surface *screen;
patmandin@1858
    61
	SDL_bool quit = SDL_FALSE, first_time = SDL_TRUE;
patmandin@1858
    62
	SDL_Cursor *cursor;
patmandin@1858
    63
	SDL_Rect update_area;
patmandin@1858
    64
patmandin@1858
    65
	/* Load the SDL library */
patmandin@1858
    66
	if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
patmandin@1858
    67
		fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
patmandin@1858
    68
		return(1);
patmandin@1858
    69
	}
patmandin@1858
    70
patmandin@1858
    71
	screen = SDL_SetVideoMode(320,200,8,SDL_ANYFORMAT);
patmandin@1858
    72
	if (screen==NULL) {
patmandin@1858
    73
		fprintf(stderr, "Couldn't initialize video mode: %s\n",SDL_GetError());
patmandin@1858
    74
		return(1);
patmandin@1858
    75
	}
patmandin@1858
    76
patmandin@1858
    77
	update_area.x = update_area.y = 0;
patmandin@1858
    78
	update_area.w = screen->w;
patmandin@1858
    79
	update_area.h = screen->h;
patmandin@1858
    80
patmandin@1858
    81
	SDL_FillRect(screen, NULL, 0x664422);
patmandin@1858
    82
patmandin@1858
    83
	cursor = SDL_CreateCursor((Uint8 *)cursor_data, (Uint8 *)cursor_mask,
patmandin@1858
    84
		16, 16, 8, 8);
patmandin@1858
    85
	if (cursor==NULL) {
patmandin@1858
    86
		fprintf(stderr, "Couldn't initialize cursor: %s\n",SDL_GetError());
patmandin@1858
    87
		return(1);
patmandin@1858
    88
	}
patmandin@1858
    89
patmandin@1858
    90
	SDL_SetCursor(cursor);
patmandin@1858
    91
patmandin@1858
    92
	while (!quit) {
patmandin@1858
    93
		SDL_Event	event;
patmandin@1858
    94
		while (SDL_PollEvent(&event)) {
patmandin@1858
    95
			switch(event.type) {
patmandin@1858
    96
				case SDL_KEYDOWN:
patmandin@1858
    97
					if (event.key.keysym.sym == SDLK_ESCAPE) {
patmandin@1858
    98
						quit = SDL_TRUE;
patmandin@1858
    99
					}
patmandin@1858
   100
					break;
patmandin@1858
   101
				case SDL_QUIT:
patmandin@1858
   102
					quit = SDL_TRUE;
patmandin@1858
   103
					break;
patmandin@1858
   104
			}
patmandin@1858
   105
		}	
patmandin@1858
   106
		if (screen->flags & SDL_DOUBLEBUF) {
patmandin@1859
   107
			SDL_Flip(screen);
patmandin@1859
   108
		} else {
patmandin@1858
   109
			if (first_time) {
patmandin@1858
   110
				SDL_UpdateRects(screen, 1, &update_area);
patmandin@1858
   111
				first_time = SDL_FALSE;
patmandin@1858
   112
			}
patmandin@1858
   113
		}	
patmandin@1858
   114
		SDL_Delay(1);
patmandin@1858
   115
	}
patmandin@1858
   116
patmandin@1858
   117
	SDL_FreeCursor(cursor);
patmandin@1858
   118
patmandin@1858
   119
	SDL_Quit();
patmandin@1858
   120
	return(0);
patmandin@1858
   121
}