1 
2 // Moved from sdl/i_system.cpp
3 
4 #include <string.h>
5 
6 #include <SDL.h>
7 
8 #include "bitmap.h"
9 #include "v_palette.h"
10 #include "textures.h"
11 
I_SetCursor(FTexture * cursorpic)12 bool I_SetCursor(FTexture *cursorpic)
13 {
14 	static SDL_Cursor *cursor;
15 	static SDL_Surface *cursorSurface;
16 
17 	if (cursorpic != NULL && cursorpic->UseType != FTexture::TEX_Null)
18 	{
19 		// Must be no larger than 32x32.
20 		if (cursorpic->GetWidth() > 32 || cursorpic->GetHeight() > 32)
21 		{
22 			return false;
23 		}
24 
25 		if (cursorSurface == NULL)
26 			cursorSurface = SDL_CreateRGBSurface (0, 32, 32, 32, MAKEARGB(0,255,0,0), MAKEARGB(0,0,255,0), MAKEARGB(0,0,0,255), MAKEARGB(255,0,0,0));
27 
28 		SDL_LockSurface(cursorSurface);
29 		BYTE buffer[32*32*4];
30 		memset(buffer, 0, 32*32*4);
31 		FBitmap bmp(buffer, 32*4, 32, 32);
32 		cursorpic->CopyTrueColorPixels(&bmp, 0, 0);
33 		memcpy(cursorSurface->pixels, bmp.GetPixels(), 32*32*4);
34 		SDL_UnlockSurface(cursorSurface);
35 
36 		if (cursor)
37 			SDL_FreeCursor (cursor);
38 		cursor = SDL_CreateColorCursor (cursorSurface, 0, 0);
39 		SDL_SetCursor (cursor);
40 	}
41 	else
42 	{
43 		if (cursor)
44 		{
45 			SDL_SetCursor (NULL);
46 			SDL_FreeCursor (cursor);
47 			cursor = NULL;
48 		}
49 		if (cursorSurface != NULL)
50 		{
51 			SDL_FreeSurface(cursorSurface);
52 			cursorSurface = NULL;
53 		}
54 	}
55 	return true;
56 }
57