Safe Haskell | None |
---|---|
Language | Haskell2010 |
SDL.Event exports an interface for working with the SDL event model. Event handling allows your application to receive input from the user. Internally, SDL stores all the events waiting to be handled in an event queue. Using functions like pollEvent
and waitEvent
you can observe and handle waiting input events.
The event queue itself is composed of a series of Event
values, one for each waiting event. Event
values are read from the queue with the pollEvent
function and it is then up to the application to process the information stored with them.
- pollEvent :: MonadIO m => m (Maybe Event)
- pollEvents :: (Functor m, MonadIO m) => m [Event]
- mapEvents :: MonadIO m => (Event -> m ()) -> m ()
- pumpEvents :: MonadIO m => m ()
- waitEvent :: MonadIO m => m Event
- waitEventTimeout :: MonadIO m => CInt -> m (Maybe Event)
- data RegisteredEventType a = RegisteredEventType {
- pushRegisteredEvent :: a -> IO EventPushResult
- getRegisteredEvent :: Event -> IO (Maybe a)
- data RegisteredEventData = RegisteredEventData {
- registeredEventWindow :: !(Maybe Window)
- registeredEventCode :: !Int32
- registeredEventData1 :: !(Ptr ())
- registeredEventData2 :: !(Ptr ())
- data EventPushResult
- emptyRegisteredEvent :: RegisteredEventData
- registerEvent :: MonadIO m => (RegisteredEventData -> Timestamp -> IO (Maybe a)) -> (a -> IO RegisteredEventData) -> m (Maybe (RegisteredEventType a))
- type EventWatchCallback = Event -> IO ()
- data EventWatch
- addEventWatch :: MonadIO m => EventWatchCallback -> m EventWatch
- delEventWatch :: MonadIO m => EventWatch -> m ()
- data Event = Event {}
- type Timestamp = Word32
- data EventPayload
- = WindowShownEvent !WindowShownEventData
- | WindowHiddenEvent !WindowHiddenEventData
- | WindowExposedEvent !WindowExposedEventData
- | WindowMovedEvent !WindowMovedEventData
- | WindowResizedEvent !WindowResizedEventData
- | WindowSizeChangedEvent !WindowSizeChangedEventData
- | WindowMinimizedEvent !WindowMinimizedEventData
- | WindowMaximizedEvent !WindowMaximizedEventData
- | WindowRestoredEvent !WindowRestoredEventData
- | WindowGainedMouseFocusEvent !WindowGainedMouseFocusEventData
- | WindowLostMouseFocusEvent !WindowLostMouseFocusEventData
- | WindowGainedKeyboardFocusEvent !WindowGainedKeyboardFocusEventData
- | WindowLostKeyboardFocusEvent !WindowLostKeyboardFocusEventData
- | WindowClosedEvent !WindowClosedEventData
- | KeyboardEvent !KeyboardEventData
- | TextEditingEvent !TextEditingEventData
- | TextInputEvent !TextInputEventData
- | KeymapChangedEvent
- | MouseMotionEvent !MouseMotionEventData
- | MouseButtonEvent !MouseButtonEventData
- | MouseWheelEvent !MouseWheelEventData
- | JoyAxisEvent !JoyAxisEventData
- | JoyBallEvent !JoyBallEventData
- | JoyHatEvent !JoyHatEventData
- | JoyButtonEvent !JoyButtonEventData
- | JoyDeviceEvent !JoyDeviceEventData
- | ControllerAxisEvent !ControllerAxisEventData
- | ControllerButtonEvent !ControllerButtonEventData
- | ControllerDeviceEvent !ControllerDeviceEventData
- | AudioDeviceEvent !AudioDeviceEventData
- | QuitEvent
- | UserEvent !UserEventData
- | SysWMEvent !SysWMEventData
- | TouchFingerEvent !TouchFingerEventData
- | TouchFingerMotionEvent !TouchFingerMotionEventData
- | MultiGestureEvent !MultiGestureEventData
- | DollarGestureEvent !DollarGestureEventData
- | DropEvent !DropEventData
- | ClipboardUpdateEvent
- | UnknownEvent !UnknownEventData
- newtype WindowShownEventData = WindowShownEventData {}
- newtype WindowHiddenEventData = WindowHiddenEventData {}
- newtype WindowExposedEventData = WindowExposedEventData {}
- data WindowMovedEventData = WindowMovedEventData {}
- data WindowResizedEventData = WindowResizedEventData {}
- data WindowSizeChangedEventData = WindowSizeChangedEventData {}
- newtype WindowMinimizedEventData = WindowMinimizedEventData {}
- newtype WindowMaximizedEventData = WindowMaximizedEventData {}
- newtype WindowRestoredEventData = WindowRestoredEventData {}
- newtype WindowGainedMouseFocusEventData = WindowGainedMouseFocusEventData {}
- newtype WindowLostMouseFocusEventData = WindowLostMouseFocusEventData {}
- newtype WindowGainedKeyboardFocusEventData = WindowGainedKeyboardFocusEventData {}
- newtype WindowLostKeyboardFocusEventData = WindowLostKeyboardFocusEventData {}
- newtype WindowClosedEventData = WindowClosedEventData {}
- newtype SysWMEventData = SysWMEventData {}
- data KeyboardEventData = KeyboardEventData {}
- data TextEditingEventData = TextEditingEventData {}
- data TextInputEventData = TextInputEventData {}
- data MouseMotionEventData = MouseMotionEventData {}
- data MouseButtonEventData = MouseButtonEventData {}
- data MouseWheelEventData = MouseWheelEventData {}
- data JoyAxisEventData = JoyAxisEventData {}
- data JoyBallEventData = JoyBallEventData {}
- data JoyHatEventData = JoyHatEventData {}
- data JoyButtonEventData = JoyButtonEventData {}
- data JoyDeviceEventData = JoyDeviceEventData {}
- data ControllerAxisEventData = ControllerAxisEventData {}
- data ControllerButtonEventData = ControllerButtonEventData {}
- data ControllerDeviceEventData = ControllerDeviceEventData {}
- data AudioDeviceEventData = AudioDeviceEventData {}
- data UserEventData = UserEventData {
- userEventType :: !Word32
- userEventWindow :: !(Maybe Window)
- userEventCode :: !Int32
- userEventData1 :: !(Ptr ())
- userEventData2 :: !(Ptr ())
- data TouchFingerEventData = TouchFingerEventData {}
- data TouchFingerMotionEventData = TouchFingerMotionEventData {}
- data MultiGestureEventData = MultiGestureEventData {}
- data DollarGestureEventData = DollarGestureEventData {}
- newtype DropEventData = DropEventData {}
- newtype UnknownEventData = UnknownEventData {}
- data InputMotion
- data MouseButton
Polling events
pollEvent :: MonadIO m => m (Maybe Event) Source #
Poll for currently pending events. You can only call this function in the thread that set the video mode.
pollEvents :: (Functor m, MonadIO m) => m [Event] Source #
Clear the event queue by polling for all pending events.
mapEvents :: MonadIO m => (Event -> m ()) -> m () Source #
Run a monadic computation, accumulating over all known Event
s.
This can be useful when used with a state monad, allowing you to fold all events together.
pumpEvents :: MonadIO m => m () Source #
Pump the event loop, gathering events from the input devices.
This function updates the event queue and internal input device state.
This should only be run in the thread that initialized the video subsystem, and for extra safety, you should consider only doing those things on the main thread in any case.
pumpEvents
gathers all the pending input information from devices and places it in the event queue. Without calls to pumpEvents
no events would ever be placed on the queue. Often the need for calls to pumpEvents
is hidden from the user since pollEvent
and waitEvent
implicitly call pumpEvents
. However, if you are not polling or waiting for events (e.g. you are filtering them), then you must call pumpEvents
to force an event queue update.
See SDL_PumpEvents
for C documentation.
Wait until the specified timeout for the next available amount.
Registering user events
data RegisteredEventType a Source #
A user defined event structure that has been registered with SDL.
Use registerEvent
, below, to obtain an instance.
RegisteredEventType | |
|
data RegisteredEventData Source #
A record used to convert between SDL Events and user-defined data structures.
Used for registerEvent
, below.
RegisteredEventData | |
|
data EventPushResult Source #
Possible results of an attempted push of an event to the queue.
emptyRegisteredEvent :: RegisteredEventData Source #
A registered event with no associated data.
This is a resonable baseline to modify for converting to
RegisteredEventData
.
registerEvent :: MonadIO m => (RegisteredEventData -> Timestamp -> IO (Maybe a)) -> (a -> IO RegisteredEventData) -> m (Maybe (RegisteredEventType a)) Source #
Register a new event type with SDL.
Provide functions that convert between UserEventData
and your structure.
You can then use pushRegisteredEvent
to add a custom event of the
registered type to the queue, and getRegisteredEvent
to test for such
events in the main loop.
Watching events
type EventWatchCallback = Event -> IO () Source #
An EventWatchCallback
can process and respond to an event
when it is added to the event queue.
data EventWatch Source #
addEventWatch :: MonadIO m => EventWatchCallback -> m EventWatch Source #
Trigger an EventWatchCallback
when an event is added to the SDL
event queue.
See https://wiki.libsdl.org/SDL_AddEventWatch
for C documentation.
delEventWatch :: MonadIO m => EventWatch -> m () Source #
Remove an EventWatch
.
See https://wiki.libsdl.org/SDL_DelEventWatch
for C documentation.
Event data
A single SDL event. This event occured at eventTimestamp
and carries data under eventPayload
.
Event | |
|
data EventPayload Source #
An enumeration of all possible SDL event types. This data type pairs up event types with their payload, where possible.
Window events
newtype WindowShownEventData Source #
A window has been shown.
WindowShownEventData | |
|
newtype WindowHiddenEventData Source #
A window has been hidden.
WindowHiddenEventData | |
|
newtype WindowExposedEventData Source #
A part of a window has been exposed - where exposure means to become visible (for example, an overlapping window no longer overlaps with the window).
WindowExposedEventData | |
|
data WindowMovedEventData Source #
A Window
has been moved.
WindowMovedEventData | |
|
data WindowResizedEventData Source #
Window has been resized. This is event is always preceded by WindowSizeChangedEvent
.
WindowResizedEventData | |
|
data WindowSizeChangedEventData Source #
The window size has changed, either as a result of an API call or through the system or user changing the window size; this event is followed by WindowResizedEvent
if the size was changed by an external event, i.e. the user or the window manager.
WindowSizeChangedEventData | |
|
newtype WindowMinimizedEventData Source #
The window has been minimized.
WindowMinimizedEventData | |
|
newtype WindowMaximizedEventData Source #
The window has been maximized.
WindowMaximizedEventData | |
|
newtype WindowRestoredEventData Source #
The window has been restored to normal size and position.
WindowRestoredEventData | |
|
newtype WindowGainedMouseFocusEventData Source #
The window has gained mouse focus.
WindowGainedMouseFocusEventData | |
|
newtype WindowLostMouseFocusEventData Source #
The window has lost mouse focus.
WindowLostMouseFocusEventData | |
|
newtype WindowGainedKeyboardFocusEventData Source #
The window has gained keyboard focus.
WindowGainedKeyboardFocusEventData | |
|
newtype WindowLostKeyboardFocusEventData Source #
The window has lost keyboard focus.
WindowLostKeyboardFocusEventData | |
|
newtype WindowClosedEventData Source #
The window manager requests that the window be closed.
WindowClosedEventData | |
|
newtype SysWMEventData Source #
A video driver dependent system event
Keyboard events
data KeyboardEventData Source #
A keyboard key has been pressed or released.
KeyboardEventData | |
|
data TextEditingEventData Source #
Keyboard text editing event information.
TextEditingEventData | |
|
data TextInputEventData Source #
Keyboard text input event information.
TextInputEventData | |
|
Mouse events
data MouseMotionEventData Source #
A mouse or pointer device was moved.
MouseMotionEventData | |
|
data MouseButtonEventData Source #
A mouse or pointer device button was pressed or released.
MouseButtonEventData | |
|
data MouseWheelEventData Source #
Mouse wheel event information.
MouseWheelEventData | |
|
Joystick events
data JoyAxisEventData Source #
Joystick axis motion event information
JoyAxisEventData | |
|
data JoyBallEventData Source #
Joystick trackball motion event information.
JoyBallEventData | |
|
data JoyHatEventData Source #
Joystick hat position change event information
JoyHatEventData | |
|
data JoyButtonEventData Source #
Joystick button event information.
JoyButtonEventData | |
|
data JoyDeviceEventData Source #
Joystick device event information.
JoyDeviceEventData | |
|
Controller events
data ControllerAxisEventData Source #
Game controller axis motion event information.
ControllerAxisEventData | |
|
data ControllerButtonEventData Source #
Game controller button event information
ControllerButtonEventData | |
|
data ControllerDeviceEventData Source #
Controller device event information
ControllerDeviceEventData | |
|
Audio events
data AudioDeviceEventData Source #
AudioDeviceEventData | |
|
User events
data UserEventData Source #
Event data for application-defined events.
UserEventData | |
|
Touch events
data TouchFingerEventData Source #
Finger touch event information.
TouchFingerEventData | |
|
data TouchFingerMotionEventData Source #
Finger motion event information.
TouchFingerMotionEventData | |
|
Gesture events
data MultiGestureEventData Source #
Multiple finger gesture event information
MultiGestureEventData | |
|
data DollarGestureEventData Source #
Complex gesture event information.
DollarGestureEventData | |
|
Drag and drop events
newtype DropEventData Source #
An event used to request a file open by the system
DropEventData | |
|
Unknown events
newtype UnknownEventData Source #
SDL reported an unknown event type.
UnknownEventData | |
|
Auxiliary event data
data InputMotion Source #
data MouseButton Source #
ButtonLeft | |
ButtonMiddle | |
ButtonRight | |
ButtonX1 | |
ButtonX2 | |
ButtonExtra !Int | An unknown mouse button. |