Difference between revisions of "macOS Gestures"

From Lazarus wiki
Jump to navigationJump to search
(New Mac content)
 
(→‎See also: New section)
 
(2 intermediate revisions by the same user not shown)
Line 3: Line 3:
 
== Overview ==
 
== Overview ==
  
The Gestures unit is provides convenient Free Pascal classes for handling macOS gestures.
+
The Gestures unit provides convenient Free Pascal classes for handling macOS gestures.
  
 
Currently only the magnification gesture is implemented, but others can be implemented easily in a similar way.
 
Currently only the magnification gesture is implemented, but others can be implemented easily in a similar way.
Line 35: Line 35:
 
     gsBegan:
 
     gsBegan:
 
       InitialScale := MyScalableControl.Scale;
 
       InitialScale := MyScalableControl.Scale;
 +
 
     gsChanged:
 
     gsChanged:
       MyScalableControl.Scale := InitialScale * (1 + Magnification);
+
       if Magnification > 0 then
 +
        MyScalableControl.Scale := InitialScale * (1 + Magnification)
 +
      else
 +
        MyScalableControl.Scale := InitialScale / (1 - Magnification);
 
   end;
 
   end;
 
end;
 
end;
Line 52: Line 56:
  
 
The Gestures unit may be downloaded from [https://github.com/plashenkov/macOS-gestures-FPC GitHub].
 
The Gestures unit may be downloaded from [https://github.com/plashenkov/macOS-gestures-FPC GitHub].
 +
 +
== External links ==
 +
 +
* [https://support.apple.com/en-au/HT204895 Apple: Trackpad gestures]
 +
* [https://developer.apple.com/documentation/appkit/gestures Apple: Gestures]
  
 
[[Category:macOS]]
 
[[Category:macOS]]
 
[[Category:Code Snippets]]
 
[[Category:Code Snippets]]
 
[[Category:Platform-sensitive development]]
 
[[Category:Platform-sensitive development]]

Latest revision as of 00:05, 30 November 2020

macOSlogo.png

This article applies to macOS only.

See also: Multiplatform Programming Guide

Overview

The Gestures unit provides convenient Free Pascal classes for handling macOS gestures.

Currently only the magnification gesture is implemented, but others can be implemented easily in a similar way.

Usage Example

Let's assume your scalable control has a Scale property and you want to allow an end user to scale it by using the typical trackpad gesture. Here is the code:

uses
  Gestures;

type
  TForm_Main = class(TForm)
  private
    Gesture: TMagnificationGesture;
    InitialScale: Double;
  end;

procedure TForm_Main.FormCreate(Sender: TObject);
begin
  Gesture := TMagnificationGesture.Create(Self);
  Gesture.Control := MyScalableControl;
  Gesture.OnGesture := @MagnificationGestureGesture;
end;

procedure TForm_Main.MagnificationGestureGesture(Sender: TMagnificationGesture;
  State: TGestureState; Magnification: Double);
begin
  case State of
    gsBegan:
      InitialScale := MyScalableControl.Scale;

    gsChanged:
      if Magnification > 0 then
        MyScalableControl.Scale := InitialScale * (1 + Magnification)
      else
        MyScalableControl.Scale := InitialScale / (1 - Magnification);
  end;
end;

Author

Yuri Plashenkov

License

This package is licensed under the MIT license.

Download

The Gestures unit may be downloaded from GitHub.

External links