Show: Delphi C++
Display Preferences

Gestures in FireMonkey

From RAD Studio
Jump to: navigation, search

Go Up to FireMonkey Applications Guide


Gestures in FireMonkey desktop applications are very similar to gestures in VCL. 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).

Contents

There are two types of gestures:

  • Standard Gestures:
    • The standard gestures (sgUp, sgDown, sgTriangle, 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 (igZoom, igRotate, and so on) that are equivalent to System Gestures on Windows, and to Gestures on Mac OS X and iOS. 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, and Windows 8).

Platforms for Gestures

This topic describes gestures for both desktop and mobile applications:

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.
  2. In the Object Inspector, assign a name to the TGestureManager in the Touch | GestureManager field of the control. You can use the default name, such as GestureManager1.
  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:

FMX.Touch2.png

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:

Note: If you are working with an iOS application, start at step 3 (assigning a GestureManager is not part of enabling interactive gestures for iOS).
  1. In the Form Designer, add a TGestureManager to the control you want to enable for gestures.
  2. In the Object Inspector, assign a name to the TGestureManager in the Touch | GestureManager field of the control. You can use the default name, such as "GestureManager1".
  3. In the Object Inspector, select the specific interactive gesture(s) from the Touch | InteractiveGestures field of the control.
  4. Implement an OnGesture event procedure for that control, and handle the appropriate EventInfo.GestureId.

IGFMX.png

Differences between Gestures in FMX and in VCL

  • 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. (VCL does not support TouchTargetExpansion.)
  • Supported interactive gestures are described in FMX.Types.TInteractiveGestures and in Vcl.Controls.TInteractiveGestures.
    • On Windows platforms:
      • FireMonkey supports the following interactive gestures: Zoom, Pan, Rotate, TwoFingerTap, and PressAndTap. (This is the same as VCL.)
    • On Mac OS X:
      • FireMonkey supports only the Zoom, Pan, and Rotate interactive gestures. (VCL does not support development on the Mac.)
    • On iOS:
      • FireMonkey supports Zoom, Pan, Rotate, TwoFingerTap, and PressAndTap and two additional interactive gestures: LongTap and DoubleTap (VCL does not support development on iOS.)
  • FireMonkey does not support custom gestures. (VCL supports custom gestures.)
  • 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.

See Also

Personal tools
In other languages