Creating a cursor from a surface

Can somebody give me a help with this? I want to load several cursors from
png files. Is there some way to convert pixel data into a cursor?–
Roger D. Vargas
ICQ: 117641572
Linux User: 180787

  • Much to learn you still have *
    Master Yoda, AOTC


Este mensaje ha sido analizado por MailScanner
en busca de virus y otros contenidos peligrosos,
y se considera que est? limpio.

if you are using fullscreen mode, its suggested to use your own cursor, than you
can of course use any bitmap you want (maybe look at the archives)> ----- Original Message -----

From: roger@eht.scu.tur.cu (Roger D. Vargas)
To:
Sent: Thursday, July 10, 2003 11:28 PM
Subject: [SDL] creating a cursor from a surface

Can somebody give me a help with this? I want to load several cursors from
png files. Is there some way to convert pixel data into a cursor?


Roger D. Vargas
ICQ: 117641572
Linux User: 180787

  • Much to learn you still have *
    Master Yoda, AOTC


Este mensaje ha sido analizado por MailScanner
en busca de virus y otros contenidos peligrosos,
y se considera que est? limpio.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

you could disable the cursor and draw a surface at the mousecoordinates.> ----- Original Message -----

From: thomas.eder@nmi.at (Thomas Eder)
To:
Sent: Friday, July 11, 2003 9:53 AM
Subject: Re: [SDL] creating a cursor from a surface

if you are using fullscreen mode, its suggested to use your own cursor,
than you
can of course use any bitmap you want (maybe look at the archives)

----- Original Message -----
From: “Roger D. Vargas”
To:
Sent: Thursday, July 10, 2003 11:28 PM
Subject: [SDL] creating a cursor from a surface

Can somebody give me a help with this? I want to load several cursors
from

png files. Is there some way to convert pixel data into a cursor?


Roger D. Vargas
ICQ: 117641572
Linux User: 180787

  • Much to learn you still have *
    Master Yoda, AOTC


Este mensaje ha sido analizado por MailScanner
en busca de virus y otros contenidos peligrosos,
y se considera que est? limpio.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Isn’t the bmp cursor method to much expansive in display terms ?
Doesn’t this requier to update Fullscreen on each mouvement ?

Carlos> ----- Original Message -----

From: fhufsky@phorus.at (Florian Hufsky)
To:
Sent: Friday, July 11, 2003 11:56 AM
Subject: Re: [SDL] creating a cursor from a surface

you could disable the cursor and draw a surface at the mousecoordinates.

----- Original Message -----
From: “Thomas Eder” <Thomas.Eder at nmi.at>
To:
Sent: Friday, July 11, 2003 9:53 AM
Subject: Re: [SDL] creating a cursor from a surface

if you are using fullscreen mode, its suggested to use your own cursor,
than you
can of course use any bitmap you want (maybe look at the archives)

----- Original Message -----
From: “Roger D. Vargas”
To:
Sent: Thursday, July 10, 2003 11:28 PM
Subject: [SDL] creating a cursor from a surface

Can somebody give me a help with this? I want to load several cursors
from

png files. Is there some way to convert pixel data into a cursor?


Roger D. Vargas
ICQ: 117641572
Linux User: 180787

  • Much to learn you still have *
    Master Yoda, AOTC


Este mensaje ha sido analizado por MailScanner
en busca de virus y otros contenidos peligrosos,
y se considera que est? limpio.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

maybe better do the reverse:
in your mainloop at each screen update print your mouse-bmp at the current mouse
position (hint: see docs for SDL_MOUSEMOTION, SDL_MouseMotionEvent),
if you have >30fps this should be sufficient.> ----- Original Message -----

From: citrouille@wanadoo.fr (Carlos Alvarez)
To:
Sent: Friday, July 11, 2003 12:09 PM
Subject: Re: [SDL] creating a cursor from a surface

Isn’t the bmp cursor method to much expansive in display terms ?
Doesn’t this requier to update Fullscreen on each mouvement ?

Carlos

----- Original Message -----
From: “Florian Hufsky”
To:
Sent: Friday, July 11, 2003 11:56 AM
Subject: Re: [SDL] creating a cursor from a surface

you could disable the cursor and draw a surface at the mousecoordinates.

----- Original Message -----
From: “Thomas Eder” <Thomas.Eder at nmi.at>
To:
Sent: Friday, July 11, 2003 9:53 AM
Subject: Re: [SDL] creating a cursor from a surface

if you are using fullscreen mode, its suggested to use your own cursor,
than you
can of course use any bitmap you want (maybe look at the archives)

----- Original Message -----
From: “Roger D. Vargas”
To:
Sent: Thursday, July 10, 2003 11:28 PM
Subject: [SDL] creating a cursor from a surface

Can somebody give me a help with this? I want to load several cursors
from

png files. Is there some way to convert pixel data into a cursor?


Roger D. Vargas
ICQ: 117641572
Linux User: 180787

  • Much to learn you still have *
    Master Yoda, AOTC


Este mensaje ha sido analizado por MailScanner
en busca de virus y otros contenidos peligrosos,
y se considera que est? limpio.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

I posted the message bellow some time ago in response to this very same
question. It uses a function getpixel that does exactly that. Enjoy.

Andre de Leiradella
http://www.geocities.com/andre_leiradella/> ----- Original Message -----

From: @Andre_de_Leiradella (Andre de Leiradella)
To:
Sent: Thursday, April 10, 2003 4:48 PM
Subject: SDL_Surface -> SDL_Cursor

That’s what I use to build a cursor from a surface (no dithering):

SDL_Cursor *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 = 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;
}

Andre de Leiradella
http://www.geocities.com/andre_leiradella/

No, you only have to update previous & actual mouse area :wink:
It can be done really fast

Pirata

Isn't the bmp cursor method to much expansive in display terms ?
Doesn't this requier to update Fullscreen on each mouvement ?

CarlosOn Fri, 2003-07-11 at 07:09, Carlos wrote:

----- Original Message -----
From: "Florian Hufsky" <fhufsky at phorus.at>
To: <sdl at libsdl.org>
Sent: Friday, July 11, 2003 11:56 AM
Subject: Re: [SDL] creating a cursor from a surface


> you could disable the cursor and draw a surface at the mousecoordinates.
>
> ----- Original Message -----
> From: "Thomas Eder" <Thomas.Eder at nmi.at>
> To: <sdl at libsdl.org>
> Sent: Friday, July 11, 2003 9:53 AM
> Subject: Re: [SDL] creating a cursor from a surface
>
>
> >
> > if  you are using fullscreen mode, its suggested to use your own cursor,
> than you
> > can of course use any bitmap you want (maybe look at the archives)
> >
> > ----- Original Message -----
> > From: "Roger D. Vargas" <roger at eht.scu.tur.cu>
> > To: <SDL at libsdl.org>
> > Sent: Thursday, July 10, 2003 11:28 PM
> > Subject: [SDL] creating a cursor from a surface
> >
> >
> > >
> > > Can somebody give me a help with this? I want to load several cursors
> from
> > > png files. Is there some way to convert pixel data into a  cursor?
> > >
> > >
> > > --
> > > Roger D. Vargas
> > > ICQ: 117641572
> > > Linux User: 180787
> > > * Much to learn you still have *
> > > Master Yoda, AOTC
> > >
> > >
> > > --
> > > Este mensaje ha sido analizado por MailScanner
> > > en busca de virus y otros contenidos peligrosos,
> > > y se considera que est? limpio.
> > >
> > >
> > > _______________________________________________
> > > SDL mailing list
> > > SDL at libsdl.org
> > > http://www.libsdl.org/mailman/listinfo/sdl
> >
> >
> >
> > _______________________________________________
> > SDL mailing list
> > SDL at libsdl.org
> > http://www.libsdl.org/mailman/listinfo/sdl
> >
> >
>
>
>
> _______________________________________________
> SDL mailing list
> SDL at libsdl.org
> http://www.libsdl.org/mailman/listinfo/sdl
>


_______________________________________________
SDL mailing list
SDL at libsdl.org

http://www.libsdl.org/mailman/listinfo/sdl

I posted the message bellow some time ago in response to this very same
question. It uses a function getpixel that does exactly that. Enjoy.

Andre de Leiradella
http://www.geocities.com/andre_leiradella/
thanks a lot.On Fri, 11 Jul 2003, Andre de Leiradella wrote:

----- Original Message -----
From: Andre de Leiradella
To:
Sent: Thursday, April 10, 2003 4:48 PM
Subject: SDL_Surface -> SDL_Cursor

That’s what I use to build a cursor from a surface (no dithering):

SDL_Cursor *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 = 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;
}

Andre de Leiradella
http://www.geocities.com/andre_leiradella/


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Roger D. Vargas
ICQ: 117641572
Linux User: 180787

  • Much to learn you still have *
    Master Yoda, AOTC


Este mensaje ha sido analizado por MailScanner
en busca de virus y otros contenidos peligrosos,
y se considera que est? limpio.