Class TInputListener
Unit
Declaration
type TInputListener = class(TCastleComponent)
Description
Base class for things that listen to user input.
Hierarchy
- TObject
- TPersistent
- TComponent
- TCastleComponent
- TInputListener
Overview
Methods
![]() |
function ContainerWidth: Cardinal; |
![]() |
function ContainerHeight: Cardinal; |
![]() |
function ContainerRect: TRectangle; |
![]() |
function ContainerSizeKnown: boolean; |
![]() |
procedure SetContainer(const Value: TUIContainer); virtual; |
![]() |
procedure DoCursorChange; virtual; deprecated 'better override VisibleChange and watch for chCursor in Changes'; |
![]() |
constructor Create(AOwner: TComponent); override; |
![]() |
function Press(const Event: TInputPressRelease): boolean; virtual; |
![]() |
function Release(const Event: TInputPressRelease): boolean; virtual; |
![]() |
function PreviewPress(const Event: TInputPressRelease): boolean; virtual; |
![]() |
function PreviewRelease(const Event: TInputPressRelease): boolean; virtual; |
![]() |
function Motion(const Event: TInputMotion): boolean; virtual; |
![]() |
function SensorRotation(const X, Y, Z, Angle: Double; const SecondsPassed: Single): boolean; virtual; |
![]() |
function SensorTranslation(const X, Y, Z, Length: Double; const SecondsPassed: Single): boolean; virtual; |
![]() |
function JoyAxisMove(const JoyID, Axis: Byte): boolean; virtual; |
![]() |
function JoyButtonPress(const JoyID, Button: Byte): boolean; virtual; |
![]() |
procedure Update(const SecondsPassed: Single; var HandleInput: boolean); virtual; |
![]() |
procedure VisibleChange(const Changes: TCastleUserInterfaceChanges; const ChangeInitiatedByChildren: boolean = false); overload; virtual; |
![]() |
procedure VisibleChange(const RectOrCursorChanged: boolean = false); overload; virtual; deprecated 'use VisibleChange overload with (TCastleUserInterfaceChanges,boolean) parameters'; |
![]() |
function AllowSuspendForInput: boolean; virtual; |
![]() |
procedure Resize; virtual; |
![]() |
procedure ContainerResize(const AContainerWidth, AContainerHeight: Cardinal); virtual; deprecated 'use Resize'; |
Properties
![]() |
property OnVisibleChange: TCastleUserInterfaceChangeEvent
read FOnVisibleChange write FOnVisibleChange; |
![]() |
property Container: TUIContainer read FContainer write SetContainer; |
![]() |
property OnCursorChange: TNotifyEvent
read FOnCursorChange write FOnCursorChange; deprecated 'use OnVisibleChange (or override VisibleChange) and watch for Changes that include chCursor'; |
![]() |
property ExclusiveEvents: boolean
read FExclusiveEvents write FExclusiveEvents default true; |
![]() |
property Cursor: TMouseCursor read FCursor write SetCursor default mcDefault; |
![]() |
property OnUpdate: TUiUpdateEvent read FOnUpdate write FOnUpdate; |
![]() |
property OnPress: TUiPressReleaseEvent read FOnPress write FOnPress; |
![]() |
property OnRelease: TUiPressReleaseEvent read FOnRelease write FOnRelease; |
![]() |
property OnMotion: TUiMotionEvent read FOnMotion write FOnMotion; |
Description
Methods
![]() |
function ContainerWidth: Cardinal; |
|
Container sizes. | |
![]() |
function ContainerHeight: Cardinal; |
![]() |
function ContainerRect: TRectangle; |
![]() |
function ContainerSizeKnown: boolean; |
![]() |
procedure SetContainer(const Value: TUIContainer); virtual; |
![]() |
procedure DoCursorChange; virtual; deprecated 'better override VisibleChange and watch for chCursor in Changes'; |
|
Warning: this symbol is deprecated: better override VisibleChange and watch for chCursor in Changes Called when Cursor changed. In TCastleUserInterface class, just calls OnCursorChange. | |
![]() |
constructor Create(AOwner: TComponent); override; |
![]() |
function Press(const Event: TInputPressRelease): boolean; virtual; |
|
Handle press or release of a key, mouse button or mouse wheel. Return When implementing in descendants it is best to override it like this: function TMyControl.Press(const Event: TInputPressRelease): boolean; begin Result := inherited; if Result then Exit; // exit if ancestor already handled event if Event.IsKey(keyEnter) then begin // do something in reaction on Enter Exit(ExclusiveEvents); // ExclusiveEvents is true by default end; if Event.IsMouseButton(buttonLeft) then begin // do something in reaction on Enter Exit(ExclusiveEvents); // ExclusiveEvents is true by default end; end;
Note that releasing of the mouse wheel is not implemented for now, neither by CastleWindow or Lazarus CastleControl. The events PreviewPress and PreviewRelease are passed first to the parent control, before children have a chance to process this event. Overriding them makes sense if you draw something in TCastleUserInterface.RenderOverChildren. The events Press and Release are passed to the parent only after the children had a chance to process this event. Overriding them makes sense if you draw something in TCastleUserInterface.Render. This is usually more natural, and adviced. | |
![]() |
function Release(const Event: TInputPressRelease): boolean; virtual; |
![]() |
function PreviewPress(const Event: TInputPressRelease): boolean; virtual; |
![]() |
function PreviewRelease(const Event: TInputPressRelease): boolean; virtual; |
![]() |
function Motion(const Event: TInputMotion): boolean; virtual; |
|
| |
![]() |
function SensorRotation(const X, Y, Z, Angle: Double; const SecondsPassed: Single): boolean; virtual; |
|
Rotation detected by sensor. Used for example by 3Dconnexion devices or touch controls.
Parameters
| |
![]() |
function SensorTranslation(const X, Y, Z, Length: Double; const SecondsPassed: Single): boolean; virtual; |
|
Translation detected by sensor. Used for example by 3Dconnexion devices or touch controls.
Parameters
| |
![]() |
function JoyAxisMove(const JoyID, Axis: Byte): boolean; virtual; |
|
Axis movement detected by joystick
Parameters
| |
![]() |
function JoyButtonPress(const JoyID, Button: Byte): boolean; virtual; |
|
Joystick button pressed.
Parameters
| |
![]() |
procedure Update(const SecondsPassed: Single; var HandleInput: boolean); virtual; |
|
Control may do here anything that must be continuously repeated. E.g. camera handles here falling down due to gravity, rotating model in Examine mode, and many more.
This method may be used, among many other things, to continuously react to the fact that user pressed some key (or mouse button). For example, if holding some key should move some 3D object, you should do something like: if HandleInput then begin if Container.Pressed[keyArrowRight] then Transform.Position := Transform.Position + Vector3(SecondsPassed * 10, 0, 0); HandleInput := not ExclusiveEvents; end;
Instead of directly using a key code, consider also using TInputShortcut that makes the input key nicely configurable. See engine tutorial about handling inputs. Multiplying movement by SecondsPassed makes your operation frame-rate independent. Object will move by 10 units in a second, regardless of how many FPS your game has. The code related to HandleInput is important if you write a generally-useful control that should nicely cooperate with all other controls, even when placed on top of them or under them. The correct approach is to only look at pressed keys/mouse buttons if HandleInput is Note that to handle a single press / release (like "switch light on when pressing a key") you should rather use Press and Release methods. Use this method only for continuous handling (like "holding this key makes the light brighter and brighter"). To understand why such HandleInput approach is needed, realize that the "Update" events are called differently than simple mouse and key events like "Press" and "Release". "Press" and "Release" events return whether the event was somehow "handled", and the container passes them only to the controls under the mouse (decided by TCastleUserInterface.CapturesEventsAtPosition). And as soon as some control says it "handled" the event, other controls (even if under the mouse) will not receive the event. This approach is not suitable for Update events. Some controls need to do the Update job all the time, regardless of whether the control is under the mouse and regardless of what other controls already did. So all controls (well, all controls that exist, in case of TCastleUserInterface, see TCastleUserInterface.GetExists) receive Update calls. So the "handled" status is passed through HandleInput. If a control is not under the mouse, it will receive HandleInput = Parameters
| |
![]() |
procedure VisibleChange(const Changes: TCastleUserInterfaceChanges; const ChangeInitiatedByChildren: boolean = false); overload; virtual; |
|
Called always when something important inside this control (or it's children) changed. To be more precise, this is called when something mentioned among the TCastleUserInterfaceChange enumerated items changed. This is always called with Changes <> [] (non-empty set). | |
![]() |
function AllowSuspendForInput: boolean; virtual; |
|
Allow window containing this control to suspend waiting for user input. Typically you want to override this to return In this class, this simply returns always See also
| |
![]() |
procedure Resize; virtual; |
|
Event called when the container (component or window with OpenGL context) size changes. You can resize/reposition your component here, for example set TCastleUserInterface.Left or TCastleUserInterface.Bottom, to react to parent size changes. This is called only when the OpenGL context of the container is initialized, so you can be sure that this is called only between GLContextOpen and GLContextClose. We also call this once when inserting into the controls list (like TCastleWindowBase.Controls or TCastleControlBase.Controls or inside parent TCastleUserInterface), if inserting into the container/parent with already initialized OpenGL context. If inserting into the container/parent without OpenGL context initialized, it will be called later, when OpenGL context will get initialized, right after GLContextOpen. In other words, this is always called to let the control know the size of the container, if and only if the OpenGL context is initialized. | |
![]() |
procedure ContainerResize(const AContainerWidth, AContainerHeight: Cardinal); virtual; deprecated 'use Resize'; |
|
Warning: this symbol is deprecated: use Resize | |
Properties
![]() |
property OnVisibleChange: TCastleUserInterfaceChangeEvent
read FOnVisibleChange write FOnVisibleChange; |
|
Called always when something important inside this control (or it's children) changed. See VisibleChange for details about when and how this is called. Be careful when handling this event. Various changes may cause this, so be prepared to handle it at any moment, even in the middle when UI control is changing. It may also occur very often. It's usually safest to only set a boolean flag like "something should be recalculated" when this event happens, and do the actual recalculation later. | |
![]() |
property Container: TUIContainer read FContainer write SetContainer; |
|
Container of this control. When adding control to container's Controls list (like TCastleWindowBase.Controls) container will automatically set itself here, and when removing from container this will be changed back to May be | |
![]() |
property OnCursorChange: TNotifyEvent
read FOnCursorChange write FOnCursorChange; deprecated 'use OnVisibleChange (or override VisibleChange) and watch for Changes that include chCursor'; |
|
Warning: this symbol is deprecated: use OnVisibleChange (or override VisibleChange) and watch for Changes that include chCursor Event called when the Cursor property changes. This event is, in normal circumstances, used by the Container, so you should not use it in your own programs. | |
![]() |
property Cursor: TMouseCursor read FCursor write SetCursor default mcDefault; |
|
Mouse cursor over this control. When user moves mouse over the Container, the currently focused (topmost under the cursor) control determines the mouse cursor look. | |
![]() |
property OnUpdate: TUiUpdateEvent read FOnUpdate write FOnUpdate; |
|
Event that occurs continuously on each control. See Update for details. | |
![]() |
property OnPress: TUiPressReleaseEvent read FOnPress write FOnPress; |
|
An input (key, mouse button, mouse wheel) was pressed. See Press for details. | |
![]() |
property OnRelease: TUiPressReleaseEvent read FOnRelease write FOnRelease; |
|
An input (key, mouse button, mouse wheel) was released. See Release for details. | |
![]() |
property OnMotion: TUiMotionEvent read FOnMotion write FOnMotion; |
|
Pointer (mouse or finger) moved. See Motion for details. | |
Generated by PasDoc 0.16.0.


