-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(PinchGestureRecognizer): Report Pinch angle in degrees #13244
Changes from 1 commit
bcb24df
f7bdd65
f39c585
38d84f0
98bfceb
e92bd22
3dbaf93
7f3e8ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ protected override void PointerMoved(PointerEventArgs e) | |
{ | ||
if (Target != null && Target is Visual visual) | ||
{ | ||
if(_firstContact == e.Pointer) | ||
if (_firstContact == e.Pointer) | ||
{ | ||
_firstPoint = e.GetPosition(visual); | ||
} | ||
|
@@ -50,7 +50,19 @@ protected override void PointerMoved(PointerEventArgs e) | |
|
||
var scale = distance / _initialDistance; | ||
|
||
var pinchEventArgs = new PinchEventArgs(scale, _origin); | ||
var point = _firstPoint; | ||
if (point.X > _origin.X) | ||
{ | ||
point = _secondPoint; | ||
} | ||
|
||
// https://stackoverflow.com/a/15994225/20894223 | ||
var deltaX = point.X - _origin.X; | ||
var deltaY = -(point.Y - _origin.Y); // I reverse the sign, because on the screen the Y axes are reversed with respect to the Cartesian plane. | ||
var rad = System.Math.Atan2(deltaX, deltaY); // radiant | ||
var degree = rad * (180 / System.Math.PI); | ||
degree += 90; // Shift angle of 90° | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Also, I'm assuming WPF's coordinates system for measure degrees: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 90° is wrog, the corrent 180. Atan2 returns a radian value between -π to +π, in degrees -180 to +180. To get the angle between 0 and 360 degrees you need to add 180 degrees. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Do you suggest adding a Sing or AngleDelta property? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let me think about this some more and compare to other platforms:
Actually, yes, I think is probably a good idea. + is clockwise. - is counterclockwise.
Yea... that might be useful. I also wonder if we should track (or if it is even possible to track) rotations past 360 degrees. If a user wants to just keep rotating something during a pin/zoom/rotate operation triggered by this gesture it might be useful. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've been thinking about this more. I realize it is a larger topic. We really are starting to add features that should be in a generic ManipulationStarted/Completed event as in WinUI. Specifically for the angle delta, ManipulationDelta in WinUI is a generic representation of everything you would want to know about the gesture. We probably should be using that. I still think Pinch is a useful special-case of the fully generic Manipulation gesture (which doesn't exist yet). But I guess we either 1) should exclude delta in pinch for now or 2) design the manipulation gesture as well so event args and data types can be shared with the pinch gesture. The most future-proof is to implement Looking at other platforms, https://developer.apple.com/documentation/uikit/uirotationgesturerecognizer, I notice the name |
||
var pinchEventArgs = new PinchEventArgs(scale, _origin, degree); | ||
Target?.RaiseEvent(pinchEventArgs); | ||
|
||
e.Handled = pinchEventArgs.Handled; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,20 +4,32 @@ namespace Avalonia.Input | |
{ | ||
public class PinchEventArgs : RoutedEventArgs | ||
{ | ||
public PinchEventArgs(double scale, Point scaleOrigin) : base(Gestures.PinchEvent) | ||
public PinchEventArgs(double scale, Point scaleOrigin) : base(Gestures.PinchEvent) | ||
{ | ||
Scale = scale; | ||
ScaleOrigin = scaleOrigin; | ||
} | ||
|
||
public PinchEventArgs(double scale, Point scaleOrigin, double degree) : base(Gestures.PinchEvent) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
{ | ||
Scale = scale; | ||
ScaleOrigin = scaleOrigin; | ||
Angle = degree; | ||
} | ||
|
||
public double Scale { get; } = 1; | ||
|
||
public Point ScaleOrigin { get; } | ||
|
||
/// <summary> | ||
/// Pinch angle in degrees | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be a lot more descriptive. Also needs to start with "Gets" and have a "." at the end to avoid analyzer warnings and follow conventions.
|
||
/// </summary> | ||
public double Angle { get; } | ||
} | ||
|
||
public class PinchEndedEventArgs : RoutedEventArgs | ||
{ | ||
public PinchEndedEventArgs() : base(Gestures.PinchEndedEvent) | ||
public PinchEndedEventArgs() : base(Gestures.PinchEndedEvent) | ||
{ | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"radiant" is "radians" in English