Created
May 23, 2018 15:50
-
-
Save felipebaltazar/47d7aa1befb62bc52e1201317f5054f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void PinchGesturePinchUpdated(object sender, PinchGestureUpdatedEventArgs e) | |
{ | |
if(e.Status == GestureStatus.Started) | |
{ | |
AmbientControl = AmbientControl.Zoom; | |
StartCanvasScale = CanvasScale; | |
} | |
else if(e.Status == GestureStatus.Running) | |
{ | |
var factor = (e.Scale - 1); | |
var delta = factor < 0 ? -1 : 1; | |
factor = (factor * delta).Clamp(0, MaximumZoomStep) * delta; | |
CanvasScale += ((factor * StartCanvasScale)).ToSingle(); | |
CanvasScale = CanvasScale.Clamp(0.01f, 2); | |
if(delta > 0) | |
{ | |
var touchX = (WidthScreen * e.ScaleOrigin.X).ToSingle(); | |
var touchY = (HeightScreen * e.ScaleOrigin.Y).ToSingle(); | |
var centerXScreen = WidthScreen / 2; | |
var centerYScreen = HeightScreen / 2; | |
CanvasPosition.X += (centerXScreen - touchX) * CanvasScale; | |
CanvasPosition.Y += (centerYScreen - touchY) * CanvasScale; | |
} | |
else | |
{ | |
var centerXScreen = (WidthScreen / 2); | |
var centerYScreen = (HeightScreen / 2); | |
var newCenterXScreen = (WidthScreen * ((factor * StartCanvasScale))) / 2; | |
var newCenterYScreen = (HeightScreen * ((factor * StartCanvasScale))) / 2; | |
CanvasPosition.X += (newCenterXScreen - centerXScreen).ToSingle(); | |
CanvasPosition.Y += (newCenterYScreen - centerYScreen).ToSingle(); | |
} | |
CanvasView.InvalidateSurface(); | |
StartCanvasScale = CanvasScale; | |
} | |
else | |
{ | |
AmbientControl = AmbientControl.Stoped; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment