Unit CastleInputs
Description
Key and mouse shortcuts (TInputShortcut) and global management of them.
TInputShortcut instance represents a key/mouse shortcut. Instances of this class are spread throughout the engine. We have two different ways of using TInputShortcut instance:
Global
TInputShortcut instance with TInputShortcut.Group <> igLocal is called "global". Such instance is automatically (at construction) added to InputsAll and InputsGroup[Group] lists.
The purpose of such global input map is to be able to detect key conflicts, be able to restore whole input map to default, load/save them to the user config file, and so on. All shortcuts used in a typical 3D game, with normal CastleLevels and CastlePlayer usage, are global.
Global shortcuts are owned (they will be freed by) this unit (more specifically, they will be freed by InputsAll). When creating them, pass Nil to the Owner parameter of constructor TInputShortcut.Create. This implies that InputsAll and InputsGroup[Group] lists will never shrink, which is useful — once added, shortcuts will not disappear. Global TInputShortcut instances are always in practice also global variables.
For example CastleSceneManager unit contains Input_Interact. For example CastlePlayer contains many inputs.
Local
TInputShortcut instance with TInputShortcut.Group = igLocal is called "local". Basically, it means it's a normal component, it's not magically present on any global list, it's not magically managed by any list.
For example TWalkCamera contains a number of them like TWalkCamera.Input_Forward.
Although it seems like "global" inputs are such a good idea, there are some reasons for having some inputs "local":
You can set them locally, obviously, not program-wide.
You can set them from Lazarus object inspector e.g. for cameras.
We cannot add shortcuts of both TExamineCamera and TWalkCamera to global, as they would conflict (e.g. "up arrow key" is used by both by default). The InputsAll doesn't have (for now) any mechanism to indicate that only one of the cameras will be in practice used for a given TCastleSceneManager.
We cannot add shortcuts of TCamera descendants also because CastlePlayer has shortcuts that override camera shortcuts. One day this problem may disappear, when TPlayer and TCamera will become integrated more.
You create new inputs by simply constructing new TInputShortcut instances. Make sure you add all global inputs before calling Config.Load , as some functionality assumes that all shortcuts are already added at the time Config.Load is called. The engine units themselves never call Config.Load , it is left to the final application.
This unit also defines new CastleScript function: shortcut , see [http://castle-engine.sourceforge.net/castle_script.php#function_shortcut].
Uses
Overview
Classes, Interfaces, Objects and Records
Class TInputShortcut |
A keyboard and/or mouse shortcut for activating some action. |
Class TInputShortcutList |
TODO: Maybe introduce a way to limit (TKey, or all shortcuts?) to activate only when specific modifier is pressed. |
Types
Variables
Description
Types
TInputGroup = (...); |
Values
-
igLocal:
-
igBasic:
-
igItems:
-
igOther:
|
Variables
InputsAll: TInputShortcutList; |
List of all global inputs. Will be created in initialization and freed in finalization of this unit. All TInputShortcut instances will automatically add to this.
|
Generated by PasDoc 0.13.0 on 2013-08-17 21:27:13
|