Mouse motion within the event loop

Hi all,

Below is a code fragment that tries to sample the mouse from
within a mouse-down event. I’m trying to implement a drag-scroll
mechanism. Unfortunately, the variable ‘btn’ is permanently set
to 1, even though I’m calling SDL_GetMouseState() within the
loop…

The docs say you can call SDL_GetMouseState() at any time, but
does that depend on the event loop ? This is with the latest
.tar.gz file from the CVS page, running on Redhat 6.1.

Thanks in advance for any help,

ATB,
Simon.

case PART_IMAGES:
{
int ox = -1;
Part *thePart = _skin->getPart(part);
int pw = thePart->getW();
int px = thePart->getX();

int mx,my;
int btn       = SDL_GetMouseState(&mx, &my);
while ((btn & SDL_BUTTON_LMASK) == SDL_BUTTON_LMASK)
    {
    cerr << "[" << btn << "]";
    if (mx < px)        mx = px;
    if (mx >= pw+px)    mx = px + pw;

    if (ox != mx)
        {
        ox = mx;
        float prange     = ((float)mx - px)/pw;
        int currentFrame = (int)(frange * prange);
        if (currentFrame >=0 && currentFrame < frange)
            _frameIdx    = currentFrame;
        }

    btn = SDL_GetMouseState(&mx, &my);
    cerr << "(" << btn << ") ";
    }
}-- 

Physicists get hadrons!

Below is a code fragment that tries to sample the mouse from
within a mouse-down event. I’m trying to implement a drag-scroll
mechanism. Unfortunately, the variable ‘btn’ is permanently set
to 1, even though I’m calling SDL_GetMouseState() within the
loop…

The docs say you can call SDL_GetMouseState() at any time, but
does that depend on the event loop ?

Yes, you need to call SDL_PumpEvents(), since SDL_GetMouseState()
just returns what SDL already knows.

See ya!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software

Hello Simon,

Monday, May 29, 2028, 10:12:29 AM, you wrote:

SG> Hi all,

SG> Below is a code fragment that tries to sample the mouse from
SG> within a mouse-down event. I’m trying to implement a drag-scroll
SG> mechanism. Unfortunately, the variable ‘btn’ is permanently set
SG> to 1, even though I’m calling SDL_GetMouseState() within the
SG> loop…

SG> The docs say you can call SDL_GetMouseState() at any time, but
SG> does that depend on the event loop ? This is with the latest
SG> .tar.gz file from the CVS page, running on Redhat 6.1.

SG> Thanks in advance for any help,

SG> ATB,
SG> Simon.

SG> case PART_IMAGES:
SG> {
SG> int ox = -1;
SG> Part *thePart = _skin->getPart(part);
SG> int pw = thePart->getW();
SG> int px = thePart->getX();

SG> int mx,my;
SG> int btn = SDL_GetMouseState(&mx, &my);
SG> while ((btn & SDL_BUTTON_LMASK) == SDL_BUTTON_LMASK)
SG> {
SG> cerr << “[” << btn << “]”;
SG> if (mx < px) mx = px;
SG> if (mx >= pw+px) mx = px + pw;

SG> if (ox != mx)
SG> {
SG> ox = mx;
SG> float prange = ((float)mx - px)/pw;
SG> int currentFrame = (int)(frange * prange);
SG> if (currentFrame >=0 && currentFrame < frange)
SG> _frameIdx = currentFrame;
SG> }

SG> btn = SDL_GetMouseState(&mx, &my);
SG> cerr << “(” << btn << ") ";
SG> }
SG> }

This snippet worked for me. It checks when the mouse is moved and
button 3 pressed. But i also want to know more about mousebutton
checking when not done in an event routine.

if ( event.type == SDL_MOUSEMOTION) {
if ( SDL_BUTTON(3)==event.motion.state ) {
xRotSpeed= GLfloat (event.motion.yrel * MOUSE_Y_SENSIVITY /50);
yRotSpeed= GLfloat (event.motion.xrel * MOUSE_X_SENSIVITY /50);
SDL_ShowCursor (false);
}
…–
Best regards,
Joern mailto:@Joern_Woerdehoff