Revision 1.56 / (download) / (as text) - annotate - [select for diffs] , Mon Aug 19 18:09:44 2002 UTC (10 months, 2 weeks ago) by slouken
Changes since 1.55: +1 -0 lines
Diff to previous 1.55
Added SDL_BUTTON_WHEELUP (4) and SDL_BUTTON_WHEELDOWN (5)
SDL DOES support mouse wheel
Moderator: Committer
SDL DOES support mouse wheel
I found in the CVS repository for SDL that it has support for mouse buttons 4 and 5, which correspond to mouse wheel up and mouse wheel down.
FreeOrion Programmer
Let me guess. The only place this functionality is "documented" is in the SDL source code, right? If I can figure out how it works, I'll add mouse wheel support to GG, and our app can use that.
Edit: Specifically, how do you get the amount of scrolling up/down from the pair of flags SDL_BUTTON_WHEELUP and SDL_BUTTON_WHEELDOWN? Is there something else in the button state that indicates scrolled distance?
For the windows platform, here's how mouse wheel messages are generated.
From SDL's src/video/wincommon/SDL_sysevents.c:
Notice that move, which is an integer value, is converted effectively into a bool that means up or down. The distance is excluded. For the DirectX DirectInput code, it does the exact same thing; it takes the amount of movement of the wheel and converts it do up or down only.
Tyreth, do you remember how well this works under Linux? Is it pretty smooth?
Edit: Specifically, how do you get the amount of scrolling up/down from the pair of flags SDL_BUTTON_WHEELUP and SDL_BUTTON_WHEELDOWN? Is there something else in the button state that indicates scrolled distance?
For the windows platform, here's how mouse wheel messages are generated.
From SDL's src/video/wincommon/SDL_sysevents.c:
Code: Select all
case WM_MOUSEWHEEL:
if ( SDL_VideoSurface && ! DINPUT_FULLSCREEN() ) {
int move = (short)HIWORD(wParam);
if ( move ) {
Uint8 button;
if ( move > 0 )
button = SDL_BUTTON_WHEELUP;
else
button = SDL_BUTTON_WHEELDOWN;
posted = SDL_PrivateMouseButton(
SDL_PRESSED, button, 0, 0);
posted |= SDL_PrivateMouseButton(
SDL_RELEASED, button, 0, 0);
}
}
return(0);
Tyreth, do you remember how well this works under Linux? Is it pretty smooth?
The mouse driver defines the amount of movement for a wheel up or down in terms of lines of text, the default being 3.
If the value is converted to just "on" or "off" then we might actually have to set up a polling loop in a separate thread or something to make the mouse scroll smoothly.
What about pressing the mouse wheel as a mouse button? Anything in the source about that? I assume its just another constant...button 6 or something.
edit: Or we can rebuild SDL so that it stores the delta for the mouse wheel
If the value is converted to just "on" or "off" then we might actually have to set up a polling loop in a separate thread or something to make the mouse scroll smoothly.
What about pressing the mouse wheel as a mouse button? Anything in the source about that? I assume its just another constant...button 6 or something.
edit: Or we can rebuild SDL so that it stores the delta for the mouse wheel
FreeOrion Programmer
This is true; what I'm referring to though is the fact that you may move up two ticks of the wheel between each message that SDL generates if you spin it fast, but may get all the ticks at slower speeds. So that the faster you spin the wheel, the less responsive it is. I son't know if this will be an issue, but since the code is going from +/-n to +/-1 I think it might be.tsev wrote:The mouse driver defines the amount of movement for a wheel up or down in terms of lines of text, the default being 3.
The mouse wheel is the same as the middle button (button 2).If the value is converted to just "on" or "off" then we might actually have to set up a polling loop in a separate thread or something to make the mouse scroll smoothly.
What about pressing the mouse wheel as a mouse button? Anything in the source about that? I assume its just another constant...button 6 or something.
If we need to, we may have to do this, but I really, really hope not.edit: Or we can rebuild SDL so that it stores the delta for the mouse wheel
I had some code like this in another project of mine:
Please excuse how messy it is.
Code: Select all
SDL_Event event;
while ( SDL_PollEvent(&event) )
{
if (event.type == SDL_MOUSEBUTTONDOWN)
{
if (event.button.button == 4)
{
zoom += 0.4f;
if (zoom >= -0.4f)
zoom = -0.4f;
}
if (event.button.button == 5)
zoom -= 0.4f;
}
}