Next: , Up: Direct Layer


2.1 Input handling and screen management

Once SLAYER is up and running, it has one window where everything is displayed, and which gathers all the input. If you want to use procedures described here, you need to (use-modules (slayer)).

In order to get something displayed on the screen, you need to set a display procedure of your liking.

— Procedure: set-display-procedure! thunk

Sets thunk to be called after each series of events is handled and the screen is wiped.

— Procedure: screen-size

Return a list containing width and height of the window, in pixels.

— Procedure: set-screen-size! width height

Set the screen size to width times height pixels. It causes a screen resize event, which can be handled using set-resize-procedure!.

— Procedure: set-resize-procedure! proc

Sets the binary procedure proc to be invoked on window resize event. proc takes two arguments, namely – the new width and height of the screen.

— Procedure: set-exit-procedure! proc

Sets the proc procedure to be called on exit. Due to historical reasons, proc currently takes one argument, which should be ignored.

— Procedure: set-window-title! string

Sets the window caption to string. This can only be visible if SLAYER is run in a window manager, in non-fullscreen mode.

— Procedure: keydn key [thunk]

Set thunk to be invoked whenever key is pressed (including mouse buttons) within the current key bindings. key can either be a string or a symbol. If thunk is not given, or is given but is not a procedure, it returns the current procedure set for a given key. Key names table to get the names of specific keys.

— Procedure: keyup key thunk

This function works exactly as keydn, except that the thunk is invoked on key release.

— Procedure: mousemove proc

Set proc to be invoked whenever mouse is moved. proc takes four arguments: (x y dx dy), where (x y) is the current mouse position and (dx dy) is the difference between the previous and the current position. If proc not given, returns the current procedure.

— Procedure: current-key-bindings

Returns an object representing the current key bindings. This is useful for saving the set of current bindings for later use.

— Procedure: fresh-key-bindings

Returns a new object that represents a set of key bindings. Initially, the object has no bindings. It can be bound to current input using the set-key-bindings! procedure.

— Procedure: set-key-bindings! key-bindings

Set the current key bindings to key-bindings.

— Procedure: mouse-position

Returns a list (x y) of current mouse cursor coordinates.

— Procedure: set-mouse-position! x y

Set the current cursor position to (x y).

— Procedure: modifier-pressed? modifier

Checks whether modifier is pressed. modifier is a symbol that can be either shift, rshift, lshift, alt, lalt, ralt, ctrl, lctrl, rctrl, meta, lmeta, rmeta.

— Procedure: input-mode

Return the symbol describing current input mode, which can either be 'typing or 'direct. Direct mode is the default for SLAYER.

— Procedure: set-direct-input-mode!

Sets the input mode to “direct”, which means that events are generated only when keys are actually pressed, which is the desired behaviour for most games, and the default behaviour of SLAYER.

— Procedure: set-typing-input-mode!

Sets the input mode to “typing”, which means that the keyboard input behaves like when typing in an editor – once a key is pressed, after a certain time it gets repeated at a certain frequency. In typing mode, pressing printable characters do not cause the procedures specified with keydn and keyup to be called; instead, it causes the typed character to be written to current output port, or it invokes a procedure specified with set-typing-special-procedure! to be called with the pressed special key name as argument.

— Procedure: set-typing-special-procedure! proc

When in typing mode, proc will be called whenever a special (i.e. non-printable, e.g. return, escape of F1) key is pressed or repeated. proc will receive one argument: the name of the special key that was pressed (as a string).

— Procedure: grab-input! state

If state is given and not #f, the procedure causes the SLAYER window to grab all the keyboard and mouse input. This can be deactivated and brought back to normal by passing #f as state. When state is not given, the procedure only returns the current state.

— Procedure: register-userevent! proc

Register a new user event. The proc procedure will be called with zero, one or two arguments, depending on the way the corresponding generate-userevent! procedure is called. register-userevent! returns an identifier of user event (which happens to be an integer). Up to 255 user events can be registered. Note also, that the procedure add-timer! can be used to generate an user event periodically.

— Procedure: generate-userevent! identifier [data1] [data2]

Generate user event identified with identifier, obtained with a previous call to register-userevent. The data1 and data2 arguments are passed to event handler if provided.

— Procedure: add-timer! ms proc

Generate a new user-event to be called periodically at interval of ms miliseconds, and install proc as a handler for the newly-created event. Returns the id of this new event.

— Procedure: set-timer-period! timer-id ms

Change the period of timer timer-id to ms miliseconds. Returns the new period on success or #f on failure.

— Procedure: remove-timer! id

Remove a timer with the id id obtained by prior call to add-timer!. Returns #t on success and #f on failure.