FreeOrion

Forums for the FreeOrion project
It is currently Sun May 19, 2013 8:22 pm

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: SDL DOES support mouse wheel
PostPosted: Tue Jul 08, 2003 1:49 pm 
Offline
Space Kraken

Joined: Thu Jun 26, 2003 2:17 pm
Posts: 167
Location: Pittsburgh, PA
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.

Quote:

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)



_________________
FreeOrion Programmer


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 08, 2003 3:08 pm 
Offline
FreeOrion Lead Emeritus
User avatar

Joined: Thu Jun 26, 2003 6:23 am
Posts: 883
Location: Australia
Indeed, I should have mentioned that this was possible, as I have used it in previous exporations into SDL myself :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 08, 2003 5:19 pm 
Offline
Programming Lead Emeritus
User avatar

Joined: Thu Jun 26, 2003 1:33 pm
Posts: 1092
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:

Code:
      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);


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?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 08, 2003 6:41 pm 
Offline
Space Kraken

Joined: Thu Jun 26, 2003 2:17 pm
Posts: 167
Location: Pittsburgh, PA
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 :D

_________________
FreeOrion Programmer


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 08, 2003 7:30 pm 
Offline
Programming Lead Emeritus
User avatar

Joined: Thu Jun 26, 2003 1:33 pm
Posts: 1092
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.


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.

Quote:
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.


The mouse wheel is the same as the middle button (button 2).

Quote:
edit: Or we can rebuild SDL so that it stores the delta for the mouse wheel :D


If we need to, we may have to do this, but I really, really hope not.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 09, 2003 1:50 am 
Offline
FreeOrion Lead Emeritus
User avatar

Joined: Thu Jun 26, 2003 6:23 am
Posts: 883
Location: Australia
I had some code like this in another project of mine:

Code:
  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;
                }
        }


Please excuse how messy it is.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group