Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
SDL.Event
Description
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.
Synopsis
- pollEvent :: MonadIO m => m (Maybe Event)
- pollEvents :: 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 OS thread that set the video mode.
pollEvents :: MonadIO m => m [Event] Source #
Clear the event queue by polling for all pending events.
Like pollEvent
this function should only be called in the OS thread which
set the video mode.
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 OS 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.
Constructors
RegisteredEventType | |
Fields
|
data RegisteredEventData Source #
A record used to convert between SDL Events and user-defined data structures.
Used for registerEvent
, below.
Constructors
RegisteredEventData | |
Fields
|
Instances
data EventPushResult Source #
Possible results of an attempted push of an event to the queue.
Constructors
EventPushSuccess | |
EventPushFiltered | |
EventPushFailure Text |
Instances
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 occurred at eventTimestamp
and carries data under eventPayload
.
Constructors
Event | |
Fields
|
Instances
Generic Event Source # | |
Show Event Source # | |
Eq Event Source # | |
Ord Event Source # | |
Defined in SDL.Event | |
type Rep Event Source # | |
Defined in SDL.Event type Rep Event = D1 ('MetaData "Event" "SDL.Event" "sdl2-2.5.5.0-inplace" 'False) (C1 ('MetaCons "Event" 'PrefixI 'True) (S1 ('MetaSel ('Just "eventTimestamp") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Timestamp) :*: S1 ('MetaSel ('Just "eventPayload") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 EventPayload))) |
data EventPayload Source #
An enumeration of all possible SDL event types. This data type pairs up event types with their payload, where possible.
Constructors
Instances
Window events
newtype WindowShownEventData Source #
A window has been shown.
Constructors
WindowShownEventData | |
Fields
|
Instances
newtype WindowHiddenEventData Source #
A window has been hidden.
Constructors
WindowHiddenEventData | |
Fields
|
Instances
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).
Constructors
WindowExposedEventData | |
Fields
|
Instances
data WindowMovedEventData Source #
A Window
has been moved.
Constructors
WindowMovedEventData | |
Fields
|
Instances
data WindowResizedEventData Source #
Window has been resized. This is event is always preceded by WindowSizeChangedEvent
.
Constructors
WindowResizedEventData | |
Fields
|
Instances
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.
Constructors
WindowSizeChangedEventData | |
Fields
|
Instances
newtype WindowMinimizedEventData Source #
The window has been minimized.
Constructors
WindowMinimizedEventData | |
Fields
|
Instances
newtype WindowMaximizedEventData Source #
The window has been maximized.
Constructors
WindowMaximizedEventData | |
Fields
|
Instances
newtype WindowRestoredEventData Source #
The window has been restored to normal size and position.
Constructors
WindowRestoredEventData | |
Fields
|
Instances
newtype WindowGainedMouseFocusEventData Source #
The window has gained mouse focus.
Constructors
WindowGainedMouseFocusEventData | |
Fields
|
Instances
newtype WindowLostMouseFocusEventData Source #
The window has lost mouse focus.
Constructors
WindowLostMouseFocusEventData | |
Fields
|
Instances
newtype WindowGainedKeyboardFocusEventData Source #
The window has gained keyboard focus.
Constructors
WindowGainedKeyboardFocusEventData | |
Fields
|
Instances
newtype WindowLostKeyboardFocusEventData Source #
The window has lost keyboard focus.
Constructors
WindowLostKeyboardFocusEventData | |
Fields
|
Instances
newtype WindowClosedEventData Source #
The window manager requests that the window be closed.
Constructors
WindowClosedEventData | |
Fields
|
Instances
newtype SysWMEventData Source #
A video driver dependent system event
Constructors
SysWMEventData | |
Fields |
Instances
Keyboard events
data KeyboardEventData Source #
A keyboard key has been pressed or released.
Constructors
KeyboardEventData | |
Fields
|
Instances
data TextEditingEventData Source #
Keyboard text editing event information.
Constructors
TextEditingEventData | |
Fields
|
Instances
data TextInputEventData Source #
Keyboard text input event information.
Constructors
TextInputEventData | |
Fields
|
Instances
Mouse events
data MouseMotionEventData Source #
A mouse or pointer device was moved.
Constructors
MouseMotionEventData | |
Fields
|
Instances
data MouseButtonEventData Source #
A mouse or pointer device button was pressed or released.
Constructors
MouseButtonEventData | |
Fields
|
Instances
data MouseWheelEventData Source #
Mouse wheel event information.
Constructors
MouseWheelEventData | |
Fields
|
Instances
Joystick events
data JoyAxisEventData Source #
Joystick axis motion event information
Constructors
JoyAxisEventData | |
Fields
|
Instances
data JoyBallEventData Source #
Joystick trackball motion event information.
Constructors
JoyBallEventData | |
Fields
|
Instances
data JoyHatEventData Source #
Joystick hat position change event information
Constructors
JoyHatEventData | |
Fields
|
Instances
data JoyButtonEventData Source #
Joystick button event information.
Constructors
JoyButtonEventData | |
Fields
|
Instances
data JoyDeviceEventData Source #
Joystick device event information.
Constructors
JoyDeviceEventData | |
Fields
|
Instances
Controller events
data ControllerAxisEventData Source #
Game controller axis motion event information.
Constructors
ControllerAxisEventData | |
Fields
|
Instances
data ControllerButtonEventData Source #
Game controller button event information
Constructors
ControllerButtonEventData | |
Fields
|
Instances
data ControllerDeviceEventData Source #
Controller device event information
Constructors
ControllerDeviceEventData | |
Fields
|
Instances
Audio events
data AudioDeviceEventData Source #
Constructors
AudioDeviceEventData | |
Fields
|
Instances
User events
data UserEventData Source #
Event data for application-defined events.
Constructors
UserEventData | |
Fields
|
Instances
Touch events
data TouchFingerEventData Source #
Finger touch event information.
Constructors
TouchFingerEventData | |
Fields
|
Instances
data TouchFingerMotionEventData Source #
Finger motion event information.
Constructors
TouchFingerMotionEventData | |
Fields
|
Instances
Gesture events
data MultiGestureEventData Source #
Multiple finger gesture event information
Constructors
MultiGestureEventData | |
Fields
|
Instances
data DollarGestureEventData Source #
Complex gesture event information.
Constructors
DollarGestureEventData | |
Fields
|
Instances
Drag and drop events
newtype DropEventData Source #
An event used to request a file open by the system
Constructors
DropEventData | |
Fields
|
Instances
Unknown events
newtype UnknownEventData Source #
SDL reported an unknown event type.
Constructors
UnknownEventData | |
Fields
|
Instances
Auxiliary event data
data InputMotion Source #
Instances
data MouseButton Source #
Constructors
ButtonLeft | |
ButtonMiddle | |
ButtonRight | |
ButtonX1 | |
ButtonX2 | |
ButtonExtra !Int | An unknown mouse button. |