Gestures in FireMonkey

From Appmethod Topics
Jump to: navigation, search

Go Up to FireMonkey Applications Guide

A gesture is considered to be intended for the control that is under the finger (for Windows and mobile) or under the mouse cursor (for Windows and Mac OS X). Alternatively, the gesture can be handled by one of the control's parents (in the hierarchy, the first one that handles the gesture).

There are two types of gestures:

  • Standard Gestures:
    • The standard gestures (Up, Down, Triangle, and so on) are equivalent to Application Gestures on Windows, and to Multi-Touch Sequences on Mac OS X and iOS. Standard gestures are made with one finger on Windows, and with two fingers on Mac OS X.
    • After the gesture finishes (the user lifts the finger), the OnGesture event is fired (if a standard gesture was recognized).
  • Interactive Gestures:
    • The interactive gestures are multi-touch gestures (Zoom, Rotate, and so on) that are equivalent to System Gestures on Windows, and to Gestures on Mac OS X, iOS, and Android. Every time the fingers move on the touch surface, an OnGesture event is fired.
    • FireMonkey uses the four standard gestures Up, Down, Left, and Right as equivalent to the interactive Swipe gesture (on Mac OS X, iOS, Android, and Windows 8).

Platforms for Gestures

This topic describes gestures for both desktop and mobile platforms:

  • All desktop platforms support gestures.
    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.
  • All mobile platforms support interactive gestures. See Enabling Interactive Gestures.

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:

  1. In the Form Designer, add a TGestureManager to the control you want to enable for gestures. Either give the GestureManager a unique name or just use its assigned name, such as GestureManager1.
  2. In the Object Inspector, assign the TGestureManager in the Touch | GestureManager field of the control.
  3. In the Object Inspector, select the specific custom gesture(s) from the Touch | Gestures field of the control.
  4. 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). The event handler uses FMX.Gestures.GestureToIdent:

In Object Pascal:

procedure TForm28.Panel1Gesture(Sender: TObject;
  const EventInfo: TGestureEventInfo; var Handled: Boolean);
  S: string;
  if GestureToIdent(EventInfo.GestureID, S) then begin
    Handled := True;

In C++:

void __fastcall TForm1::Panel1Gesture(TObject *Sender,
        const TGestureEventInfo &EventInfo, bool &Handled) {
        String s;
        if (GestureToIdent(EventInfo.GestureID, s)) {
                Handled = true;

The code above writes in the memo the name of the gesture for which the event was fired (Up, Down, and so on).

Enabling Interactive Gestures

To add support for interactive gestures for a control:

  1. In the Object Inspector, select the specific interactive gesture(s) from the Touch | InteractiveGestures field of the control.
  2. Implement an OnGesture event handler (procedure) for that control, and handle the appropriate EventInfo.GestureId.

  Initial Gesture Properties for an Android Project   Specific Gestures Enabled

Initial Gesture Properties for an Android Project

Specific Gestures Enabled

Key Gestures Supported in FireMonkey

  • FireMonkey supports TouchTargetExpansion, a property that expands the touch target of a control by adding a specified zone around the control that can be touch-activated as if the specified area were part of the control.
  • Supported interactive gestures are described in FMX.Types.TInteractiveGestures .
    • On Windows platforms:
      • FireMonkey supports the following interactive gestures: Zoom, Pan, Rotate, TwoFingerTap, PressAndTap, DoubleTap, and LongTap.
    • On Mac OS X:
      • FireMonkey supports only the Zoom, Pan, and Rotate interactive gestures.
    • On iOS:
      • FireMonkey supports Zoom, Pan, Rotate, TwoFingerTap, DoubleTap, and LongTap
    • On Android:
      • FireMonkey supports the same gestures on Android as on the iOS platform, that is: Zoom, Pan, Rotate, TwoFingerTap, DoubleTap, and LongTap.
  • FireMonkey does not support custom gestures.

See Also

Code Examples