|  | @@ -149,3 +149,68 @@ SDL_Surface * CSDL_Ext::rotate03(SDL_Surface * toRot)
 | 
	
		
			
				|  |  |  	SDL_FreeSurface(first);
 | 
	
		
			
				|  |  |  	return ret;
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  | + //converts surface to cursor
 | 
	
		
			
				|  |  | +SDL_Cursor * CSDL_Ext::SurfaceToCursor(SDL_Surface *image, int hx, int hy)
 | 
	
		
			
				|  |  | +{
 | 
	
		
			
				|  |  | +	int             w, x, y;
 | 
	
		
			
				|  |  | +	Uint8           *data, *mask, *d, *m, r, g, b;
 | 
	
		
			
				|  |  | +	Uint32          color;
 | 
	
		
			
				|  |  | +	SDL_Cursor      *cursor;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	w = (image->w + 7) / 8;
 | 
	
		
			
				|  |  | +	data = (Uint8 *)alloca(w * image->h * 2);
 | 
	
		
			
				|  |  | +	if (data == NULL)
 | 
	
		
			
				|  |  | +		return NULL;
 | 
	
		
			
				|  |  | +	memset(data, 0, w * image->h * 2);
 | 
	
		
			
				|  |  | +	mask = data + w * image->h;
 | 
	
		
			
				|  |  | +	if (SDL_MUSTLOCK(image))
 | 
	
		
			
				|  |  | +		SDL_LockSurface(image);
 | 
	
		
			
				|  |  | +	for (y = 0; y < image->h; y++)
 | 
	
		
			
				|  |  | +	{
 | 
	
		
			
				|  |  | +		d = data + y * w;
 | 
	
		
			
				|  |  | +		m = mask + y * w;
 | 
	
		
			
				|  |  | +		for (x = 0; x < image->w; x++)
 | 
	
		
			
				|  |  | +		{
 | 
	
		
			
				|  |  | +			color = CSDL_Ext::SDL_GetPixel(image, x, y);
 | 
	
		
			
				|  |  | +			if ((image->flags & SDL_SRCCOLORKEY) == 0 || color != image->format->colorkey)
 | 
	
		
			
				|  |  | +			{
 | 
	
		
			
				|  |  | +				SDL_GetRGB(color, image->format, &r, &g, &b);
 | 
	
		
			
				|  |  | +				color = (r + g + b) / 3;
 | 
	
		
			
				|  |  | +				m[x / 8] |= 128 >> (x & 7);
 | 
	
		
			
				|  |  | +				if (color < 128)
 | 
	
		
			
				|  |  | +					d[x / 8] |= 128 >> (x & 7);
 | 
	
		
			
				|  |  | +			}
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +	if (SDL_MUSTLOCK(image))
 | 
	
		
			
				|  |  | +		SDL_UnlockSurface(image);
 | 
	
		
			
				|  |  | +	cursor = SDL_CreateCursor(data, mask, w, image->h, hx, hy);
 | 
	
		
			
				|  |  | +	return cursor;
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +Uint32 CSDL_Ext::SDL_GetPixel(SDL_Surface *surface, int x, int y)
 | 
	
		
			
				|  |  | +{
 | 
	
		
			
				|  |  | +    int bpp = surface->format->BytesPerPixel;
 | 
	
		
			
				|  |  | +    /* Here p is the address to the pixel we want to retrieve */
 | 
	
		
			
				|  |  | +    Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    switch(bpp) {
 | 
	
		
			
				|  |  | +    case 1:
 | 
	
		
			
				|  |  | +        return *p;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    case 2:
 | 
	
		
			
				|  |  | +        return *(Uint16 *)p;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    case 3:
 | 
	
		
			
				|  |  | +        if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
 | 
	
		
			
				|  |  | +            return p[0] << 16 | p[1] << 8 | p[2];
 | 
	
		
			
				|  |  | +        else
 | 
	
		
			
				|  |  | +            return p[0] | p[1] << 8 | p[2] << 16;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    case 4:
 | 
	
		
			
				|  |  | +        return *(Uint32 *)p;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    default:
 | 
	
		
			
				|  |  | +        return 0;       /* shouldn't happen, but avoids warnings */
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +}
 |