Class EventManager

Manages event polling, event queue and input state.

class EventManager
  : dlib.core.ownership.Owner;

Constructors

NameDescription
this (app) Constructs an EventManager for the given Application.

Fields

NameTypeDescription
application ApplicationApplication object that owns this EventManager.
controllerAxisThreshold intA maximum that controller axis value is clamped to (for normalization in 0..1 range).
controllerButtonDown bool[255][4]Controller button went down this frame (valid only if trackUpDownState is true).
controllerButtonPressed bool[255][4]Controller button is currently pressed/released.
controllerButtonUp bool[255][4]Controller button went up this frame (valid only if trackUpDownState is true).
deltaTime doubleTime in seconds since the last updateTimer call.
deltaTimeMs ulongTime in milliseconds since the last updateTimer call.
displayHeight uintHeight of the screen.
displayWidth uintWidth of the screen.
drawableHeight intApplication's main window drawable height.
drawableWidth intApplication's main window drawable width.
enableKeyRepeat boolSwitch key repeat.
gameInputDevices GameInputDevice[4]Opened controllers/joysticks.
graphicsTablet GraphicsTabletPenMotion events emitter.
inboxEventQueue Event[50]Inbox event queue. All synchronous events from SDL (such as user input) go here. Inbox queue is cleared at the beginning of each event loop iteration, so for emitting custom events, outboxEventQueue should be used.
inputManager InputManagerConfigurable input manager.
joystickButtonDown bool[255][4]Joystick button went down this frame (valid only if trackUpDownState is true).
joystickButtonPressed bool[255][4]Joystick button is currently pressed/released.
joystickButtonUp bool[255][4]Joystick button went up this frame (valid only if trackUpDownState is true).
keyDown bool[512]Keyboard key went down this frame (valid only if trackUpDownState is true).
keyPressed bool[512]Keyboard key is currently pressed/released.
keyUp bool[512]Keyboard key went up this frame (valid only if trackUpDownState is true).
messageBroker MessageBrokerMessage broker for distributing messages and scheduling tasks.
mouseButtonDown bool[255]Mouse button went down this frame (valid only if trackUpDownState is true).
mouseButtonPressed bool[255]Mouse button is currently pressed/released.
mouseButtonUp bool[255]Mouse button went up this frame (valid only if trackUpDownState is true).
mouseRelX intRelative change of the X-coordinate of the mouse pointer's position.
mouseRelY intRelative change of the Y-coordinate of the mouse pointer's position.
mouseX intMouse pointer's X-coordinate relative to the window.
mouseY intMouse pointer's Y-coordinate relative to the window.
numGameInputDevices uintNumber of recognized controllers/joysticks.
numInboxEvents uintNumber of events in the inbox queue.
numOutboxEvents uintNumber of events in the outbox queue.
onProcessEvent void delegate(sdl.events.SDL_Event*)Event dispatching hook. Provide your delegate to receive SDL events directly.
outboxEventQueue Event[50]Outbox event queue. All external events (user events, messages, tasks) should go here.
running boolUsed by Application to indicate activity. Set to false to stop the main loop.
tmpHeap dlib.memory.arena.ArenaTemporary heap allocator to create short-living objects for custom events. tmpHeap is invalidated each step when there are no more pending outbox events. It is mostly used to create payload data which should be immediately byte-copied when event is dispatched.
trackUpDownState boolWhether to update up/down states for keys and buttons.
window sdl.video.SDL_Window*A pointer to main application window.
windowFocused boolApplication's main window focus state.
windowHeight intApplication's main window height.
windowWidth intApplication's main window width.
windowX intApplication's main window's X-coordinate.
windowY intApplication's main window's Y-coordinate.
wmInfo sdl.syswm.SDL_SysWMinfoWindow manager info obtained from SDL.

Methods

NameDescription
addEvent (e) Adds a new event to the inbox queue.
addInputDevice (device) Adds an input device to the event emitters list.
aspectRatio () Returns the current window aspect ratio.
controller (deviceIndex) Get currently opened SDL controller by device index.
controllerHasRumble (deviceIndex) Controller vibration support.
controllerName (deviceIndex) Get controller name.
exit () Signals the Application to stop running.
gameControllerAvailable () Returns true if a game controller is available.
gameControllerAxis (deviceIndex, axis) Gets the normalized value of a game controller axis.
gameControllerRumble (deviceIndex, lowFreq, hiFreg, duration) Triggers controller rumble (vibration) if supported.
gameInputDeviceClose (deviceIndex) Closes the game controller or joystick.
gameInputDeviceOpen (deviceIndex) Opens a game controller or joystick at the specified device index.
joystick (deviceIndex) Get currently opened SDL joystick by device index.
joystickAvailable () Returns true if a joystick is available.
joystickAxis (deviceIndex, axis) Gets the normalized value of a joystick axis.
queueEvent (e) Adds a new event to the outbox queue.
queueFileChangeEvent (filename) Generates a file change event for the given filename.
queueLogEvent (level, message) Prints to the logger asynchronically using the event queue. This method is also useful to log from nothrow functions, because the logger itself is not nothrow.
queueUserEvent (code, payload) Generates a user event with the given code.
resetUpDown () Resets all up and down input event states.
setMouse (x, y) Sets the mouse cursor position.
setMouseToCenter () Centers the mouse cursor in the window.
setRelativeMouseMode (mode) Enables or disables relative mouse mode.
showCursor (mode) Shows or hides the mouse cursor.
update () Polls and processes all pending events.
updateTimer () Updates the internal timer and computes delta time.

Aliases

NameDescription
joystickName Get joystick name.

Description

EventManager polls SDL events and aggregates them in a queue. It also tracks keyboard, mouse, joystick and controller state. Provides methods for generating custom events.