Test case for bug #240
--HG-- extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%401856
This commit is contained in:
parent
f9881b12fa
commit
dd7009690f
1 changed files with 102 additions and 19 deletions
|
@ -55,12 +55,92 @@ Uint16 cursor_mask[16]={
|
|||
0xff00
|
||||
};
|
||||
|
||||
|
||||
/* XPM */
|
||||
static const char *arrow[] = {
|
||||
/* width height num_colors chars_per_pixel */
|
||||
" 32 32 3 1",
|
||||
/* colors */
|
||||
"X c #000000",
|
||||
". c #ffffff",
|
||||
" c None",
|
||||
/* pixels */
|
||||
"X ",
|
||||
"XX ",
|
||||
"X.X ",
|
||||
"X..X ",
|
||||
"X...X ",
|
||||
"X....X ",
|
||||
"X.....X ",
|
||||
"X......X ",
|
||||
"X.......X ",
|
||||
"X........X ",
|
||||
"X.....XXXXX ",
|
||||
"X..X..X ",
|
||||
"X.X X..X ",
|
||||
"XX X..X ",
|
||||
"X X..X ",
|
||||
" X..X ",
|
||||
" X..X ",
|
||||
" X..X ",
|
||||
" XX ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
"0,0"
|
||||
};
|
||||
|
||||
static SDL_Cursor *create_arrow_cursor()
|
||||
{
|
||||
int i, row, col;
|
||||
Uint8 data[4*32];
|
||||
Uint8 mask[4*32];
|
||||
int hot_x, hot_y;
|
||||
|
||||
i = -1;
|
||||
for ( row=0; row<32; ++row ) {
|
||||
for ( col=0; col<32; ++col ) {
|
||||
if ( col % 8 ) {
|
||||
data[i] <<= 1;
|
||||
mask[i] <<= 1;
|
||||
} else {
|
||||
++i;
|
||||
data[i] = mask[i] = 0;
|
||||
}
|
||||
switch (arrow[4+row][col]) {
|
||||
case 'X':
|
||||
data[i] |= 0x01;
|
||||
mask[i] |= 0x01;
|
||||
break;
|
||||
case '.':
|
||||
mask[i] |= 0x01;
|
||||
break;
|
||||
case ' ':
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
sscanf(arrow[4+row], "%d,%d", &hot_x, &hot_y);
|
||||
return SDL_CreateCursor(data, mask, 32, 32, hot_x, hot_y);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
SDL_Surface *screen;
|
||||
SDL_bool quit = SDL_FALSE, first_time = SDL_TRUE;
|
||||
SDL_Cursor *cursor;
|
||||
SDL_Rect update_area;
|
||||
SDL_Cursor *cursor[2];
|
||||
int current;
|
||||
|
||||
/* Load the SDL library */
|
||||
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
|
||||
|
@ -74,25 +154,34 @@ int main(int argc, char *argv[])
|
|||
return(1);
|
||||
}
|
||||
|
||||
update_area.x = update_area.y = 0;
|
||||
update_area.w = screen->w;
|
||||
update_area.h = screen->h;
|
||||
|
||||
SDL_FillRect(screen, NULL, 0x664422);
|
||||
|
||||
cursor = SDL_CreateCursor((Uint8 *)cursor_data, (Uint8 *)cursor_mask,
|
||||
cursor[0] = SDL_CreateCursor((Uint8 *)cursor_data, (Uint8 *)cursor_mask,
|
||||
16, 16, 8, 8);
|
||||
if (cursor==NULL) {
|
||||
fprintf(stderr, "Couldn't initialize cursor: %s\n",SDL_GetError());
|
||||
if (cursor[0]==NULL) {
|
||||
fprintf(stderr, "Couldn't initialize test cursor: %s\n",SDL_GetError());
|
||||
SDL_Quit();
|
||||
return(1);
|
||||
}
|
||||
cursor[1] = create_arrow_cursor();
|
||||
if (cursor[1]==NULL) {
|
||||
fprintf(stderr, "Couldn't initialize arrow cursor: %s\n",SDL_GetError());
|
||||
SDL_FreeCursor(cursor[0]);
|
||||
SDL_Quit();
|
||||
return(1);
|
||||
}
|
||||
|
||||
SDL_SetCursor(cursor);
|
||||
current = 0;
|
||||
SDL_SetCursor(cursor[current]);
|
||||
|
||||
while (!quit) {
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
switch(event.type) {
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
current = !current;
|
||||
SDL_SetCursor(cursor[current]);
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
if (event.key.keysym.sym == SDLK_ESCAPE) {
|
||||
quit = SDL_TRUE;
|
||||
|
@ -103,18 +192,12 @@ int main(int argc, char *argv[])
|
|||
break;
|
||||
}
|
||||
}
|
||||
if (screen->flags & SDL_DOUBLEBUF) {
|
||||
SDL_Flip(screen);
|
||||
} else {
|
||||
if (first_time) {
|
||||
SDL_UpdateRects(screen, 1, &update_area);
|
||||
first_time = SDL_FALSE;
|
||||
}
|
||||
}
|
||||
SDL_Flip(screen);
|
||||
SDL_Delay(1);
|
||||
}
|
||||
|
||||
SDL_FreeCursor(cursor);
|
||||
SDL_FreeCursor(cursor[0]);
|
||||
SDL_FreeCursor(cursor[1]);
|
||||
|
||||
SDL_Quit();
|
||||
return(0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue