Wiki Page Content

Differences between revisions 19 and 20
Revision 19 as of 2017-09-02 07:33:02
Size: 2344
Editor: gerstrong
Comment:
Revision 20 as of 2018-03-21 03:11:27
Size: 2686
Editor: DanielG
Comment: Example: code should at least check if it's actually a mousewheel event; mention left/right scrolling as well
Deletions are marked like this. Additions are marked like this.
Line 21: Line 21:
SDL_Event Event; SDL_Event event;
while( SDL_PollEvent( &event ) )
{
    if(event.type == SDL_MOUSEWHEEL)
    {
        if(event.wheel.y > 0) // scroll up
        {
             // Pull up code here!
        }
        else if(event.wheel.y < 0) // scroll down
        {
             // Pull down code here!
        }
Line 23: Line 35:
while( SDL_PollEvent( &Event ) )
{
        if(event.wheel.x > 0) // scroll right
        {
             // ...
        }
        else if(event.wheel.x < 0) // scroll left
        {
             // ...
        }
    }
    else if(event.type == SDL_SDL_MOUSEBUTTONDOWN)
    {
        // ... handle mouse clicks ...
    }
Line 26: Line 49:
     // ..

     if(Event.wheel.y == 1) // scroll up
     {
          // Pull up code here!
     }
     else if(Event.wheel.y == -1) // scroll down
     {
          // Pull down code here!
     }
 
     // ...
    // ... handle other kinds of events ...
Line 39: Line 51:
You can add your code example here

SDL_MouseWheelEvent

A structure that contains mouse wheel event information.

Data Fields

Uint32

type

SDL_MOUSEWHEEL

Uint32

timestamp

timestamp of the event

Uint32

windowID

the window with mouse focus, if any

Uint32

which

the mouse instance id, or SDL_TOUCH_MOUSEID; see Remarks for details

Sint32

x

the amount scrolled horizontally, positive to the right and negative to the left

Sint32

y

the amount scrolled vertically, positive away from the user and negative toward the user

Uint32

direction

SDL_MOUSEWHEEL_NORMAL or SDL_MOUSEWHEEL_FLIPPED; see Remarks for details (>= SDL 2.0.4)

Code Examples

SDL_Event event;
while( SDL_PollEvent( &event ) )
{
    if(event.type == SDL_MOUSEWHEEL)
    {
        if(event.wheel.y > 0) // scroll up
        {
             // Pull up code here!
        }
        else if(event.wheel.y < 0) // scroll down
        {
             // Pull down code here!
        }

        if(event.wheel.x > 0) // scroll right
        {
             // ...
        }
        else if(event.wheel.x < 0) // scroll left
        {
             // ...
        }
    }
    else if(event.type == SDL_SDL_MOUSEBUTTONDOWN)
    {
        // ... handle mouse clicks ...
    }

    // ... handle other kinds of events ...
}

Remarks

SDL_MouseWheelEvent is a member of the SDL_Event union and is used when an event of type SDL_MOUSEWHEEL is reported. You would access it through the event's wheel field.

An SDL_MOUSEWHEEL event occurs whenever a user moves the mouse wheel.

Movements to the left generate negative x values and to the right generate positive x values. Movements down (scroll backward) generate negative y values and up (scroll forward) generate positive y values.

which may be SDL_TOUCH_MOUSEID, for events that were generated by a touch input device, and not a real mouse. You might want to ignore such events, if your application already handles SDL_TouchFingerEvent.

SDL does not abstract the mouse wheel scroll directions to be consistent across all platforms (SDL_MOUSEWHEEL_NORMAL). If direction is SDL_MOUSEWHEEL_FLIPPED the values in x and y will be opposite. Multiply by -1 to change them back.


CategoryStruct, CategoryEvents

None: SDL_MouseWheelEvent (last edited 2018-03-21 03:11:27 by DanielG)

Feedback
Please include your contact information if you'd like to receive a reply.
Submit