How to determine the direction of increase (in / out) using gestures and apply the zoom effect?

Using Delphi XE 2 I am trying to determine the zoom direction for applying the zoom effect to the image (TImage), but I did not find a function for this, and the EventInfo property in the OnGesture event of the image did not have this information.

I have seen many samples using Direct2d to zoom in and out, but it uses direct wp_touch messages to do this, and the scaling effects are performed using the matrix matrix scaling functions from direct 2d, but I don't want to use direct2d for this project, since it will only have a zoom effect based on touch, other things are simple clicks.

It would be possible to identify the input / output, keeping the first direction and comparing with the current one, since the EventInfo parameter has the Direction property, but I don’t think this is a good way to do this, or am I mistaken?

So, after that, are there any recommendations or examples on how to perform the scaling effect in TImage? I already did this, but when scaling it does not pan to give a pinch effect that every application does.

+4
source share
2 answers

After reading a large number of documents, I found out that the correct way:

Intercept EventInfo.GestureID to determine the desired command in my case with the scaling command, after which you should read EventInfo.Flags and determine if it is gfBegin so that you can cache the first location point (x, y) and the first distance and when the flag is different , then gfBegin you do your calculations using the first and current points (EventInfo.Location)

The main command should be like this:

case EventInfo.GestureID of igiZoom: begin if (EventInfo.Flags = [gfBegin]) then begin FLastDistance := EventInfo.Distance; FFirstPoint.X := EventInfo.Location.X; FFirstPoint.Y := EventInfo.Location.Y; FFirstPoint := ScreenToClient(FFirstPoint); if (FSecondPoint.X = 0) and (FSecondPoint.Y = 0) then begin FSecondPoint.X := EventInfo.Location.X + 10; FSecondPoint.Y := EventInfo.Location.Y + 10; FSecondPoint := ScreenToClient(FSecondPoint); end; //ZoomCenter is a local TPoint var ZoomCenter.Create(((FFirstPoint.X + FSecondPoint.X) div 2), ((FFirstPoint.Y + FSecondPoint.Y) div 2)); //Apply the zoom to the object FDrawingObject.Zoom(EventInfo.Distance / FLastDistance, ZoomCenter.X, ZoomCenter.Y); Invalidate; end else begin FSecondPoint.X := EventInfo.Location.X; FSecondPoint.Y := EventInfo.Location.Y; FSecondPoint := ScreenToClient(FSecondPoint); ZoomCenter.Create(((FFirstPoint.X + FSecondPoint.X) div 2), ((FFirstPoint.Y + FSecondPoint.Y) div 2)); FDrawingObject.Zoom(EventInfo.Distance / FLastDistance, ZoomCenter.X, ZoomCenter.Y); Invalidate; //Update with the new values for next interaction FFirstPoint := FSecondPoint; FLastDistance := EventInfo.Distance; end; 

There is sample code written in C #, available in the Windows v7.0 SDK, which can be used as a link and helps me lote.

+1
source

In the latest release of Delphi, EventInfo has the Distance property. We do not need to calculate it.

For interactive gestures such as scaling, see the sample code in docwiki: http://docwiki.embarcadero.com/CodeExamples/Tokyo/en/FMXInteractiveGestures_(Delphi)

  procedure TForm36.handleZoom(EventInfo: TGestureEventInfo); var LObj: IControl; image: TImage; begin LObj := Self.ObjectAtPoint(ClientToScreen(EventInfo.Location)); if LObj is TImage then begin if not(TInteractiveGestureFlag.gfBegin in EventInfo.Flags) then begin image := TImage(LObj.GetObject); image.Width := image.Width + (EventInfo.Distance - FLastDIstance)/2; image.Height := image.Height + (EventInfo.Distance - FLastDIstance)/2; image.Position.X := image.Position.X - (EventInfo.Distance - FLastDIstance)/2; image.Position.Y := image.Position.Y - (EventInfo.Distance - FLastDIstance)/2; end; end; FLastDIstance := EventInfo.Distance; end; 
0
source

All Articles