Gestures in FireMonkey
Go Up to FireMonkey Applications Guide
Gestures in FireMonkey are very similar to gestures in VCL. For FireMonkey, gestures are supported on Windows (including Windows 8) as well as Mac OS X.
A gesture is considered to be intended for the control that is under either the finger (for Windows) or mouse cursor (for Mac OS X), or one of the control's parents (the first one in the hierarchy that handles the gesture).
Contents |
There are two types of gestures:
- Standard Gestures:
- These gestures (up, down, rectangle, and so on) are equivalent to Application Gestures on Windows and to Multi-Touch Sequences on Mac OS X. Standard gestures are made with one finger on Windows, and with two fingers on Mac OS X.
- Only when the gesture finishes (the user lifts the finger) the OnGesture event is fired (if a standard gesture was recognized).
- Interactive Gestures:
- These are multi-touch gestures (zoom, rotate, and so on) that are equivalent to System Gestures on Windows and to Gestures on Mac OS X. Every time the fingers move, an OnGesture event is fired.
For Windows touch screens, even if the finger lifts up from the screen outside the boundaries of the intended control, the gesture is still sent to that control.
How to Use Gestures with FireMonkey
For a control to be able to use gestures, the control must have the Touch property (TForm and many of the objects derived from TFmxObject support this property).
Enabling Standard Gestures
To add support for standard gestures for a control, you need to do the following:
- In the Form Designer, add a TGestureManager to the control you want to enable for gestures.
- In the Object Inspecor, assign a name to the TGestureManager in the Touch | GestureManager field of the control.
- In the Object Inspector, select the specific custom gesture(s) from the Touch | Gestures field of the control.
- Implement the OnGesture event procedure for the control and handle the appropriate EventInfo.GestureId.
Selecting a Standard Gesture
Here are the gestures in the TStandardGesture Enum as presented for you to select in the Object Inspector:
Implementing the OnGesture Event Handler
Here is an example of an OnGesture procedure for a TPanel named Panel1 placed on a TForm named Form 28 (there is also a TMemo named TMemo1 on the form):
procedure TForm28.Panel1Gesture(Sender: TObject; const EventInfo: TGestureEventInfo; var Handled: Boolean); var S: string; begin if GestureToIdent(EventInfo.GestureID, S) then begin Memo1.Lines.Add(S); Handled := True; end; end;
The code above writes in the memo the name of the gesture for which the event was fired (sgiUp, sgiZoom, and so on).
Enabling Interactive Gestures
To add support for interactive gestures for a control, you need to do the following:
- In the Object Inspector, select the specific interactive gesture(s) from the Touch | InteractiveGestures field of the control.
- Implement an OnGesture event procedure for that control and handle the appropriate EventInfo.GestureId.
Differences between Gestures in FMX and in VCL
- FireMonkey supports TouchTargetExpansion, which expands the touch target of a control by adding a specified zone around the control that can be touch-activated as part of the control. (VCL does not support TouchTargetExpansion.)
- Supported interactive gestures are described in FMX.Types.TInteractiveGestures.
- On Windows platforms, FireMonkey supports the interactive gestures. (This is the same as VCL.)
- On Mac OS X, FireMonkey supports only the igZoom, igPan and igRotate interactive gestures. (VCL does not support development on the Mac.)
- FireMonkey does not support custom gestures, which are supported by VCL.
- Vcl.Controls.TCustomTouchManager and Vcl.Controls.TCustomTouchManager.TabletOptions are not supported in FireMonkey.
- Mouse gestures work only on Windows 7 and Windows 8.
- On Windows 8, interactive gestures and standard gestures cannot be used at the same time.
- For more information about Windows 8 gesture support, see Gesture Support in Metropolis UI Applications.
See Also
- Gesture Support in Metropolis UI Applications
- Touch Target Support in FireMonkey
- Using Gesturing in Your Applications
- Gesturing Overview
- TStandardGesture Enum
- FMX.Types.TFmxObject.Touch
- FMX.Types.TFmxObject.OnGesture
- FMX.Types.TGestureEventInfo
- FMX.Types.TControl.TouchTargetExpansion
- FMX.Types.TInteractiveGesture
- FMXInteractiveGestures (Delphi) example

