SDL_events.h

Estructura SDL_MouseWheelEvent

Una estructura que contiene información de eventos de la rueda del ratón.

typedef struct SDL_MouseWheelEvent
{
    Uint32 type;        /**< ::SDL_MOUSEWHEEL */
    Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
    Uint32 windowID;    /**< The window with mouse focus, if any */
    Uint32 which;       /**< The mouse instance id, or SDL_TOUCH_MOUSEID */
    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;   /**< Set to one of the SDL_MOUSEWHEEL_* defines. When FLIPPED the values in X and Y will be opposite. Multiply by -1 to change them back */
    float preciseX;     /**< The amount scrolled horizontally, positive to the right and negative to the left, with float precision (added in 2.0.18) */
    float preciseY;     /**< The amount scrolled vertically, positive away from the user and negative toward the user, with float precision (added in 2.0.18) */
    Sint32 mouseX;      /**< X coordinate, relative to window (added in 2.26.0) */
    Sint32 mouseY;      /**< Y coordinate, relative to window (added in 2.26.0) */
} SDL_MouseWheelEvent;

Miembros

type
SDL_MOUSEWHEEL
timestamp
Marca de tiempo en milisegundos.
windowID
La ventana con el foco del teclado, si hay alguna.
which
El id de instancia del ratón, o SDL_TOUCH_MOUSEID, ver observaciones.
x
La cantidad desplazada horizontalmente, positivo a la derecha y negativo a la izquierda.
y
La cantidad desplazada verticalmente, positiva alejándose del usuario y negativa acercándose al usuario.
direction
SDL_MOUSEWHEEL_NORMAL o SDL_MOUSEWHEEL_FLIPPED; ver observaciones (>= SDL 2.0.4).
preciseX
La cantidad desplazada horizontalmente, positiva hacia la derecha y negativa hacia la izquierda, con precisión float (añadido en 2.0.18).
preciseY
La cantidad desplazada verticalmente, positiva alejándose del usuario y negativa acercándose al usuario, con precisión float (añadido en 2.0.18).

Observaciones

SDL_MouseWheelEvent es un miembro de la unión SDL_Event y se utiliza cuando se reporta un evento de tipo SDL_MOUSEWHEEL. Se accede a él a través del campo wheel del evento.

Un evento SDL_MOUSEWHEEL ocurre cada vez que un usuario mueve la rueda del ratón.

Los movimientos hacia la izquierda generan valores x negativos y hacia la derecha valores x positivos. Los movimientos hacia abajo (desplazamiento hacia atrás) generan valores y negativos y hacia arriba (desplazamiento hacia adelante) generan valores y positivos.

which puede ser SDL_TOUCH_MOUSEID, para eventos que fueron generados por un dispositivo de entrada táctil, y no un ratón real. Es posible que desee ignorar este tipo de eventos, si su aplicación ya maneja SDL_TouchFingerEvent.

SDL no abstrae las direcciones de desplazamiento de la rueda del ratón para que sean consistentes en todas las plataformas (SDL_MOUSEWHEEL_NORMAL). Si la dirección es SDL_MOUSEWHEEL_FLIPPED los valores en x e y serán opuestos. Multiplicar por -1 para cambiarlos de nuevo.

Ejemplo

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

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

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