Please help with mouse input

high,

im trying to make a map-editor for my pacman clone. i have never worked with
mouse input before, so im kind of lost as to how to do it. ive read the
docs, but they dont really help much. also, the book Focus on SDL that i
have, doesnt really tell you how either. the book only tells you about the
structure SDL_MouseButtonEvent. i know it stores the x and y position of the
mouse and also the button,type,state variables. ive tried using these to
determine the mouse position but it doenst seem to be working. at cone3d i
read the tutorial for “Clickomania” but it doesnt even use the
SDL_MouseButtonEvent structure, in fact i didnt even find info for this in
the SDL docs. the SDL docs only talks of getCurser and stuff.

anyway, if someone could give me an example on how to determine where the
user clicked on the screen, it would be helpfull. ive tried doing this:

int tempx;
int tempy;
SDL_GetMouseState(&tempx, &tempy); // Get the mouse coords

DrawIMG(data.wall,tempx,tempy);

DrawIMG receives a surface to be drawn, and the x and y pos to draw it. i
tried doing the above, but when i clicked all over the place nothing
happend. i even tried it in combination with

SDL_MouseButtonEvent mouse;

if (mouse.type = SDL_MOUSEBUTTONDOWN)

but this didnt work. ive also tried it with

if(!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))

but this also didnt work. please someone give me an example and how to do
this, or maybe a brief explantion. thank you for any help you can give me!!_________________________________________________________________
Free up your inbox with MSN Hotmail Extra Storage. Multiple plans available.
http://click.atdmt.com/AVE/go/onm00200362ave/direct/01/

Hello,

In my case (a point & click adventure engine) I’m over using the mouse, it
is fully mouse input.

So the way I managed it is that everytime I eed the mouse position I’ll
use the GetMouseState function, which is correct and give me the position.

For the click button part I use a standard event.

I poll an SDL_Event and look it’s type, if it is a MOUSEBUTTONDOWN then I
look with GetMouseState if it is the mouse button which I’m looking for
click and if it is the case then I do the appropriate action.

I’m doing something that look like this :

SDL_Event event;

while(SDL_PollEvent(&event)) //Event testing loop
{
if(event . type == SDL_MOUSEBUTTONDOWN &&
SDL_BUTTON(SDL_GetMouseState(NULL,NULL)) == SDL_BUTTON_LEFT)
{
//here the action you have when left mouse button is click
}
}

I hope this will help you.

Aurelien Vandoorine> high,

im trying to make a map-editor for my pacman clone. i have never worked
with
mouse input before, so im kind of lost as to how to do it. ive read the
docs, but they dont really help much. also, the book Focus on SDL that i
have, doesnt really tell you how either. the book only tells you about the
structure SDL_MouseButtonEvent. i know it stores the x and y position of
the
mouse and also the button,type,state variables. ive tried using these to
determine the mouse position but it doenst seem to be working. at cone3d i
read the tutorial for “Clickomania” but it doesnt even use the
SDL_MouseButtonEvent structure, in fact i didnt even find info for this in
the SDL docs. the SDL docs only talks of getCurser and stuff.

anyway, if someone could give me an example on how to determine where the
user clicked on the screen, it would be helpfull. ive tried doing this:

int tempx;
int tempy;
SDL_GetMouseState(&tempx, &tempy); // Get the mouse coords

DrawIMG(data.wall,tempx,tempy);

DrawIMG receives a surface to be drawn, and the x and y pos to draw it. i
tried doing the above, but when i clicked all over the place nothing
happend. i even tried it in combination with

SDL_MouseButtonEvent mouse;

if (mouse.type = SDL_MOUSEBUTTONDOWN)

but this didnt work. ive also tried it with

if(!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))

but this also didnt work. please someone give me an example and how to do
this, or maybe a brief explantion. thank you for any help you can give
me!!


Free up your inbox with MSN Hotmail Extra Storage. Multiple plans
available.
http://click.atdmt.com/AVE/go/onm00200362ave/direct/01/


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

anyway, if someone could give me an example on how to determine where
the user clicked on the screen, it would be helpfull.

As far as mouse coordinates are concerned, I’m using this:

SDL_Event    event;

// Grab all the events off the queue.
while( SDL_PollEvent( &event ) )
{
    switch( event.type )
    {
    case SDL_MOUSEMOTION:
        g_MouseX = event.motion.x;
        g_MouseY = event.motion.y;
        break;
    }
}

And then for the mouse buttons:

mouseButtons = SDL_GetRelativeMouseState( &g_MouseDeltaX,

&g_MouseDeltaY );

if( mouseButtons & SDL_BUTTON_LMASK ) {
    // Left Mouse Button
}
if( mouseButtons & SDL_BUTTON_RMASK ) {
    // Right Mouse Button
}
if( mouseButtons & SDL_BUTTON_MMASK ) {
    // Middle Mouse Button
}

This isn’t exactly the best way because, since my input function is
called once per frame, my game can miss fast mouse clicks. But over
than that, it works.On 22/03/2004, Graveyard Filla, you wrote:


Please remove “.ARGL.invalid” from my email when replying.
Incoming HTML mails are automatically deleted.

Here is a link to the “Programming Linux Games” book that also covers SDL.
It has been awhile since I read it, but as I recall it did cover mouse input
as well as many other things. As it is SDL, most of it is cross-platform.

http://www.overcode.net/~overcode/writing/plg/local/release/plg-final-pdf-no
-really-i-mean-it-this-time.pdf

Jason> ----- Original Message -----

From: sdl-admin@libsdl.org [mailto:sdl-admin at libsdl.org] On Behalf Of
Graveyard Filla
Sent: Monday, March 22, 2004 2:14 AM
To: sdl at libsdl.org
Subject: [SDL] please help with mouse input

high,

im trying to make a map-editor for my pacman clone. i have never worked with

mouse input before, so im kind of lost as to how to do it. ive read the
docs, but they dont really help much. also, the book Focus on SDL that i
have, doesnt really tell you how either. the book only tells you about the
structure SDL_MouseButtonEvent. i know it stores the x and y position of the

mouse and also the button,type,state variables. ive tried using these to
determine the mouse position but it doenst seem to be working. at cone3d i
read the tutorial for “Clickomania” but it doesnt even use the
SDL_MouseButtonEvent structure, in fact i didnt even find info for this in
the SDL docs. the SDL docs only talks of getCurser and stuff.

anyway, if someone could give me an example on how to determine where the
user clicked on the screen, it would be helpfull. ive tried doing this:

int tempx;
int tempy;
SDL_GetMouseState(&tempx, &tempy); // Get the mouse coords

DrawIMG(data.wall,tempx,tempy);

DrawIMG receives a surface to be drawn, and the x and y pos to draw it. i
tried doing the above, but when i clicked all over the place nothing
happend. i even tried it in combination with

SDL_MouseButtonEvent mouse;

if (mouse.type = SDL_MOUSEBUTTONDOWN)

but this didnt work. ive also tried it with

if(!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))

but this also didnt work. please someone give me an example and how to do
this, or maybe a brief explantion. thank you for any help you can give me!!


Free up your inbox with MSN Hotmail Extra Storage. Multiple plans available.

http://click.atdmt.com/AVE/go/onm00200362ave/direct/01/


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

After a second read, not sure if you are calling SDL_UpdateRects or the
SDL_Flip functions after the DrawIMG call. These will do the actual screen
update for them to display on the screen.

Jason> ----- Original Message -----

From: sdl-admin@libsdl.org [mailto:sdl-admin at libsdl.org] On Behalf Of
Graveyard Filla
Sent: Monday, March 22, 2004 2:14 AM
To: sdl at libsdl.org
Subject: [SDL] please help with mouse input

high,

im trying to make a map-editor for my pacman clone. i have never worked with

mouse input before, so im kind of lost as to how to do it. ive read the
docs, but they dont really help much. also, the book Focus on SDL that i
have, doesnt really tell you how either. the book only tells you about the
structure SDL_MouseButtonEvent. i know it stores the x and y position of the

mouse and also the button,type,state variables. ive tried using these to
determine the mouse position but it doenst seem to be working. at cone3d i
read the tutorial for “Clickomania” but it doesnt even use the
SDL_MouseButtonEvent structure, in fact i didnt even find info for this in
the SDL docs. the SDL docs only talks of getCurser and stuff.

anyway, if someone could give me an example on how to determine where the
user clicked on the screen, it would be helpfull. ive tried doing this:

int tempx;
int tempy;
SDL_GetMouseState(&tempx, &tempy); // Get the mouse coords

DrawIMG(data.wall,tempx,tempy);

DrawIMG receives a surface to be drawn, and the x and y pos to draw it. i
tried doing the above, but when i clicked all over the place nothing
happend. i even tried it in combination with

SDL_MouseButtonEvent mouse;

if (mouse.type = SDL_MOUSEBUTTONDOWN)

but this didnt work. ive also tried it with

if(!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))

but this also didnt work. please someone give me an example and how to do
this, or maybe a brief explantion. thank you for any help you can give me!!


Free up your inbox with MSN Hotmail Extra Storage. Multiple plans available.

http://click.atdmt.com/AVE/go/onm00200362ave/direct/01/


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

Graveyard Filla wrote:

anyway, if someone could give me an example on how to determine where
the user clicked on the screen, it would be helpfull.

All the information is in the event structure itself. For mouse click
events:

/* Mouse button event structure /
typedef struct {
Uint8 type; /
SDL_MOUSEBUTTONDOWN or SDL_MOUSEBUTTONUP /
Uint8 which; /
The mouse device index /
Uint8 button; /
The mouse button index /
Uint8 state; /
SDL_PRESSED or SDL_RELEASED /
Uint16 x, y; /
The X/Y coordinates of the mouse */
} SDL_MouseButtonEvent;

This structure may be accessed in the button member of an SDL_Event with
the appropriate type value (SDL_MOUSEBUTTONDOWN or SDL_MOUSEBUTTONUP).
The state field is a bit pointless, merely repeating the information in
the type. The x and y values in this structure will tell you where the
mouse was at the time of the click, even if it moved on between then and
the event being processed, so is slightly better for this purpose than
the general functions to obtain the mouse location.

Chris E.

P.S. Message sent at 16:56 22 March GMT, will probably arrive tomorrow
after someone else has posted the same info, and look rather foolish.
-------------- next part --------------
A non-text attachment was scrubbed…
Name: signature.asc
Type: application/pgp-signature
Size: 256 bytes
Desc: OpenPGP digital signature
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20040324/0474c3c0/attachment.pgp