Create a cursor using the specified data and mask (in MSB format). The cursor width must be a multiple of 8 bits.
The cursor is created in black and white according to the following:
Data / Mask | Resulting pixel on screen |
---|---|
0 / 1 | White |
1 / 1 | Black |
0 / 0 | Transparent |
1 / 0 | Inverted color if possible, black if not. |
Cursors created with this function must be freed with SDL_FreeCursor.
// Stolen from the mailing list
// Creates a new mouse cursor from an XPM
// XPM
const
arrow : array of Byte = {
// 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"
};
function init_system_cursor( const image : array of Byte ) : PSDL_Cursor;
var
i, row, col : integer;
data : array[0..4 * 32 - 1] of UInt8;
mask : array[0..4 * 32 - 1] of UInt8;
hot_x, hot_y : integer;
begin
i := -1;
for row := 0 to 31 do
begin
for col := 0 to 31 do
begin
if ( ( col mod 8 ) = 0 ) then
begin
data[i] := data[i] shl 1;
mask[i] := mask[i] shl 1;
end
else
begin
inc( i );
data[i] := 0
mask[i] := 0;
end;
case image[4+row][col] of
'X':
begin
data[i] := data[i] or $01;
k[i] := k[i] or $01;
end;
'.':
begin
mask[i] := mask[i] or $01;
end;
' ':
begin
//
end;
end;
end;
end;
sscanf(image[4+row], "%d,%d", &hot_x, &hot_y);
result := SDL_CreateCursor( data, mask, 32, 32, hot_x, hot_y );
end;