Hi,
How do I catch a mouse-wheel up/down event ? Does SDL support this ? Or is
there any other work around for this problem ?
-Meetul
Hi,
How do I catch a mouse-wheel up/down event ? Does SDL support this ? Or is
there any other work around for this problem ?
-Meetul
Hi all, these tested snippets might be very helpful to convert any surface
to 8 bit Indexed, given a common shared palette. SDL’s algo
SDL_DisplayFormat() is speed optimized but severely damages quality. These
are quality optimized, lacks speed. Feel free to use / post:)
-Meetul-------------------------------------------
//pre-computed shared palette
SDL_Color Palette[256];
//load precomputed shared palette in Palette[]
//Macromedia Fireworks does a great job of computing optimized shared
palette from several images
.
.
.
//returns the closest index into the shared palette for a given r,g,b color
Uint32 FindClosestIndex(unsigned char r,unsigned char g, unsigned char b)
{
int MinDistance=0xFFFFFF; //init to large value
Uint32 Index=0;
//find index with minimum spatial distance to given r,g,b
for (int i=0; i<256; ++i)
{
int Distance = (int(Palette[i].r)-int(r))*(int(Palette[i].r)-int(r))
+(int(Palette[i].g)-int(g))*(int(Palette[i].g)-int(g))
+(int(Palette[i].b)-int(b))*(int(Palette[i].b)-int(b));
if (MinDistance>Distance)
{
MinDistance=Distance;
Index=i;
if (MinDistance==0) break; //colour match !!
}
}
return Index;
}
//converts any surface -> 8 bit indexed, using shared palette
//quality optimized but slow
//uses FindClosestIndex(..)
//also uses putpixel(..) and getpixel(..) from SDL docs
//returns NULL on error
SDL_Surface *ConvertTo8BitIndexed(SDL_Surface *Source)
{
//create 8 bit surface
SDL_Surface
*Dest=SDL_CreateRGBSurface(Source->flags,Source->w,Source->h,8,0,0,0,0);
//error ?
if (Dest==NULL) return Dest;
for (int y=0; y<Source->h; ++y)
for (int x=0;x<Source->w;++x)
{
Uint32 Pixel=getpixel(Source, x, y);
unsigned char r,g,b;
SDL_GetRGB(Pixel,Source->format,&r,&g,&b);
putpixel(Dest,x,y,FindClosestIndex(r,g,b));
}
return Dest;
}
How do I catch a mouse-wheel up/down event ? Does SDL support this
? Or is there any other work around for this problem ?
On most (all ?) mice, button 4 are wheel up, and button 5 are wheel
down. So just check for those.–
Trick
Linux User #229006 * http://counter.li.org