Merge pull request #512 from mono/dev/touch-handler
Changes to SKTouchHandler
This commit is contained in:
Коммит
7576a8714f
|
@ -23,8 +23,8 @@
|
|||
<Member Id="F:SkiaSharp.Views.Tizen.RenderingMode.WhenDirty" />
|
||||
</Type>
|
||||
<Type Name="SkiaSharp.Views.Tizen.ScalingInfo" Id="T:SkiaSharp.Views.Tizen.ScalingInfo">
|
||||
<Member Id="M:SkiaSharp.Views.Tizen.ScalingInfo.FromPixel(System.Single)" />
|
||||
<Member Id="M:SkiaSharp.Views.Tizen.ScalingInfo.ToPixel(System.Single)" />
|
||||
<Member Id="M:SkiaSharp.Views.Tizen.ScalingInfo.FromPixel(System.Double)" />
|
||||
<Member Id="M:SkiaSharp.Views.Tizen.ScalingInfo.ToPixel(System.Double)" />
|
||||
<Member Id="P:SkiaSharp.Views.Tizen.ScalingInfo.Dpi" />
|
||||
<Member Id="P:SkiaSharp.Views.Tizen.ScalingInfo.Profile" />
|
||||
<Member Id="P:SkiaSharp.Views.Tizen.ScalingInfo.ScalingFactor" />
|
||||
|
|
|
@ -41,18 +41,18 @@
|
|||
</Member>
|
||||
<Member MemberName="FromPixel">
|
||||
<MemberSignature Language="C#" Value="public static float FromPixel (float v);" />
|
||||
<MemberSignature Language="ILAsm" Value=".method public static hidebysig float32 FromPixel(float32 v) cil managed" />
|
||||
<MemberSignature Language="DocId" Value="M:SkiaSharp.Views.Tizen.ScalingInfo.FromPixel(System.Single)" />
|
||||
<MemberSignature Language="ILAsm" Value=".method public static hidebysig float64 FromPixel(float64 v) cil managed" />
|
||||
<MemberSignature Language="DocId" Value="M:SkiaSharp.Views.Tizen.ScalingInfo.FromPixel(System.Double)" />
|
||||
<MemberType>Method</MemberType>
|
||||
<AssemblyInfo>
|
||||
<AssemblyName>SkiaSharp.Views.Tizen</AssemblyName>
|
||||
<AssemblyVersion>1.60.0.0</AssemblyVersion>
|
||||
</AssemblyInfo>
|
||||
<ReturnValue>
|
||||
<ReturnType>System.Single</ReturnType>
|
||||
<ReturnType>System.Double</ReturnType>
|
||||
</ReturnValue>
|
||||
<Parameters>
|
||||
<Parameter Name="v" Type="System.Single" />
|
||||
<Parameter Name="v" Type="System.Double" />
|
||||
</Parameters>
|
||||
<Docs>
|
||||
<param name="v">The raw pixel dimension.</param>
|
||||
|
@ -87,7 +87,7 @@
|
|||
</Member>
|
||||
<Member MemberName="ScalingFactor">
|
||||
<MemberSignature Language="C#" Value="public static float ScalingFactor { get; }" />
|
||||
<MemberSignature Language="ILAsm" Value=".property float32 ScalingFactor" />
|
||||
<MemberSignature Language="ILAsm" Value=".property float64 ScalingFactor" />
|
||||
<MemberSignature Language="DocId" Value="P:SkiaSharp.Views.Tizen.ScalingInfo.ScalingFactor" />
|
||||
<MemberType>Property</MemberType>
|
||||
<AssemblyInfo>
|
||||
|
@ -95,7 +95,7 @@
|
|||
<AssemblyVersion>1.60.0.0</AssemblyVersion>
|
||||
</AssemblyInfo>
|
||||
<ReturnValue>
|
||||
<ReturnType>System.Single</ReturnType>
|
||||
<ReturnType>System.Double</ReturnType>
|
||||
</ReturnValue>
|
||||
<Docs>
|
||||
<summary>The scaling factor to convert between raw pixels and device-independent pixels.</summary>
|
||||
|
@ -109,18 +109,18 @@
|
|||
</Member>
|
||||
<Member MemberName="ToPixel">
|
||||
<MemberSignature Language="C#" Value="public static float ToPixel (float v);" />
|
||||
<MemberSignature Language="ILAsm" Value=".method public static hidebysig float32 ToPixel(float32 v) cil managed" />
|
||||
<MemberSignature Language="DocId" Value="M:SkiaSharp.Views.Tizen.ScalingInfo.ToPixel(System.Single)" />
|
||||
<MemberSignature Language="ILAsm" Value=".method public static hidebysig float64 ToPixel(float64 v) cil managed" />
|
||||
<MemberSignature Language="DocId" Value="M:SkiaSharp.Views.Tizen.ScalingInfo.ToPixel(System.Double)" />
|
||||
<MemberType>Method</MemberType>
|
||||
<AssemblyInfo>
|
||||
<AssemblyName>SkiaSharp.Views.Tizen</AssemblyName>
|
||||
<AssemblyVersion>1.60.0.0</AssemblyVersion>
|
||||
</AssemblyInfo>
|
||||
<ReturnValue>
|
||||
<ReturnType>System.Single</ReturnType>
|
||||
<ReturnType>System.Double</ReturnType>
|
||||
</ReturnValue>
|
||||
<Parameters>
|
||||
<Parameter Name="v" Type="System.Single" />
|
||||
<Parameter Name="v" Type="System.Double" />
|
||||
</Parameters>
|
||||
<Docs>
|
||||
<param name="v">The device-independent pixel dimension.</param>
|
||||
|
|
|
@ -6,9 +6,9 @@ namespace SkiaSharp.Views.Forms
|
|||
internal class SKTouchHandler
|
||||
{
|
||||
private Action<SKTouchEventArgs> onTouchAction;
|
||||
private Func<float, float> scalePixels;
|
||||
private Func<double, double, SKPoint> scalePixels;
|
||||
|
||||
public SKTouchHandler(Action<SKTouchEventArgs> onTouchAction, Func<float, float> scalePixels)
|
||||
public SKTouchHandler(Action<SKTouchEventArgs> onTouchAction, Func<double, double, SKPoint> scalePixels)
|
||||
{
|
||||
this.onTouchAction = onTouchAction;
|
||||
this.scalePixels = scalePixels;
|
||||
|
@ -45,7 +45,7 @@ namespace SkiaSharp.Views.Forms
|
|||
var pointer = evt.ActionIndex;
|
||||
|
||||
var id = evt.GetPointerId(pointer);
|
||||
var coords = new SKPoint(scalePixels(evt.GetX(pointer)), scalePixels(evt.GetY(pointer)));
|
||||
var coords = scalePixels(evt.GetX(pointer), evt.GetY(pointer));
|
||||
|
||||
switch (evt.ActionMasked)
|
||||
{
|
||||
|
@ -64,7 +64,7 @@ namespace SkiaSharp.Views.Forms
|
|||
for (pointer = 0; pointer < count; pointer++)
|
||||
{
|
||||
id = evt.GetPointerId(pointer);
|
||||
coords = new SKPoint(scalePixels(evt.GetX(pointer)), scalePixels(evt.GetY(pointer)));
|
||||
coords = scalePixels(evt.GetX(pointer), evt.GetY(pointer));
|
||||
|
||||
var args = new SKTouchEventArgs(id, SKTouchAction.Moved, coords, true);
|
||||
onTouchAction(args);
|
||||
|
|
|
@ -8,9 +8,9 @@ namespace SkiaSharp.Views.Forms
|
|||
internal class SKTouchHandler : NSGestureRecognizer
|
||||
{
|
||||
private Action<SKTouchEventArgs> onTouchAction;
|
||||
private Func<nfloat, nfloat> scalePixels;
|
||||
private Func<double, double, SKPoint> scalePixels;
|
||||
|
||||
public SKTouchHandler(Action<SKTouchEventArgs> onTouchAction, Func<nfloat, nfloat> scalePixels)
|
||||
public SKTouchHandler(Action<SKTouchEventArgs> onTouchAction, Func<double, double, SKPoint> scalePixels)
|
||||
{
|
||||
this.onTouchAction = onTouchAction;
|
||||
this.scalePixels = scalePixels;
|
||||
|
@ -115,7 +115,7 @@ namespace SkiaSharp.Views.Forms
|
|||
// flip the Y coordinate for macOS
|
||||
cgPoint.Y = View.Bounds.Height - cgPoint.Y;
|
||||
|
||||
var point = new SKPoint((float)scalePixels(cgPoint.X), (float)scalePixels(cgPoint.Y));
|
||||
var point = scalePixels(cgPoint.X, cgPoint.Y);
|
||||
|
||||
var args = new SKTouchEventArgs(id, actionType, mouse, device, point, inContact);
|
||||
onTouchAction(args);
|
||||
|
|
|
@ -54,27 +54,9 @@ namespace SkiaSharp.Views.Forms
|
|||
|
||||
private void Initialize()
|
||||
{
|
||||
#if __ANDROID__
|
||||
touchHandler = new SKTouchHandler(
|
||||
args => ((ISKCanvasViewController)Element).OnTouch(args),
|
||||
coord => Element.IgnorePixelScaling ? (float)Context.FromPixels(coord) : coord);
|
||||
#elif __IOS__
|
||||
touchHandler = new SKTouchHandler(
|
||||
args => ((ISKCanvasViewController)Element).OnTouch(args),
|
||||
coord => Element.IgnorePixelScaling ? coord : coord * Control.ContentScaleFactor);
|
||||
#elif __MACOS__
|
||||
touchHandler = new SKTouchHandler(
|
||||
args => ((ISKCanvasViewController)Element).OnTouch(args),
|
||||
coord => Element.IgnorePixelScaling ? coord : coord * Control.Window.BackingScaleFactor);
|
||||
#elif WINDOWS_UWP
|
||||
touchHandler = new SKTouchHandler(
|
||||
args => ((ISKCanvasViewController)Element).OnTouch(args),
|
||||
coord => Element.IgnorePixelScaling ? coord : (float)(coord * Control.Dpi));
|
||||
#elif TIZEN4_0
|
||||
touchHandler = new SKTouchHandler(
|
||||
args => ((ISKCanvasViewController)Element).OnTouch(args),
|
||||
coord => Element.IgnorePixelScaling ? Tizen.ScalingInfo.FromPixel(coord) : coord);
|
||||
#endif
|
||||
(x, y) => GetScaledCoord(x, y));
|
||||
}
|
||||
|
||||
#if __IOS__
|
||||
|
@ -176,6 +158,43 @@ namespace SkiaSharp.Views.Forms
|
|||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
private SKPoint GetScaledCoord(double x, double y)
|
||||
{
|
||||
if (Element.IgnorePixelScaling)
|
||||
{
|
||||
#if __ANDROID__
|
||||
x = Context.FromPixels(x);
|
||||
x = Context.FromPixels(y);
|
||||
#elif TIZEN4_0
|
||||
x = Tizen.ScalingInfo.FromPixel(x);
|
||||
x = Tizen.ScalingInfo.FromPixel(y);
|
||||
#elif __IOS__ || __MACOS__ || WINDOWS_UWP
|
||||
// Tizen and Android are the reverse of the other platforms
|
||||
#else
|
||||
#error Missing platform logic
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
#if __ANDROID__ || TIZEN4_0
|
||||
// Tizen and Android are the reverse of the other platforms
|
||||
#elif __IOS__
|
||||
x = x * Control.ContentScaleFactor;
|
||||
y = y * Control.ContentScaleFactor;
|
||||
#elif __MACOS__
|
||||
x = x * Control.Window.BackingScaleFactor;
|
||||
y = y * Control.Window.BackingScaleFactor;
|
||||
#elif WINDOWS_UWP
|
||||
x = x * Control.Dpi;
|
||||
y = y * Control.Dpi;
|
||||
#else
|
||||
#error Missing platform logic
|
||||
#endif
|
||||
}
|
||||
|
||||
return new SKPoint((float)x, (float)y);
|
||||
}
|
||||
|
||||
private void OnPaintSurface(object sender, SKNativePaintSurfaceEventArgs e)
|
||||
{
|
||||
var controller = Element as ISKCanvasViewController;
|
||||
|
|
|
@ -54,27 +54,9 @@ namespace SkiaSharp.Views.Forms
|
|||
|
||||
private void Initialize()
|
||||
{
|
||||
#if __ANDROID__
|
||||
touchHandler = new SKTouchHandler(
|
||||
args => ((ISKGLViewController)Element).OnTouch(args),
|
||||
coord => coord);
|
||||
#elif __IOS__
|
||||
touchHandler = new SKTouchHandler(
|
||||
args => ((ISKGLViewController)Element).OnTouch(args),
|
||||
coord => coord * Control.ContentScaleFactor);
|
||||
#elif __MACOS__
|
||||
touchHandler = new SKTouchHandler(
|
||||
args => ((ISKGLViewController)Element).OnTouch(args),
|
||||
coord => coord * Control.Window.BackingScaleFactor);
|
||||
#elif WINDOWS_UWP
|
||||
touchHandler = new SKTouchHandler(
|
||||
args => ((ISKGLViewController)Element).OnTouch(args),
|
||||
coord => (float)(coord * Control.ContentsScale));
|
||||
#elif TIZEN4_0
|
||||
touchHandler = new SKTouchHandler(
|
||||
args => ((ISKGLViewController)Element).OnTouch(args),
|
||||
coord => coord);
|
||||
#endif
|
||||
(x, y) => GetScaledCoord(x, y));
|
||||
}
|
||||
|
||||
public GRContext GRContext => Control.GRContext;
|
||||
|
@ -188,6 +170,27 @@ namespace SkiaSharp.Views.Forms
|
|||
|
||||
protected abstract void SetupRenderLoop(bool oneShot);
|
||||
|
||||
private SKPoint GetScaledCoord(double x, double y)
|
||||
{
|
||||
#if __ANDROID__ || TIZEN4_0
|
||||
// Android and Tizen are the reverse of the other platforms
|
||||
#elif __IOS__
|
||||
x = x * Control.ContentScaleFactor;
|
||||
y = y * Control.ContentScaleFactor;
|
||||
#elif __MACOS__
|
||||
x = x * Control.Window.BackingScaleFactor;
|
||||
y = y * Control.Window.BackingScaleFactor;
|
||||
#elif WINDOWS_UWP
|
||||
x = x * Control.ContentsScale;
|
||||
y = y * Control.ContentsScale;
|
||||
#else
|
||||
#error Missing platform logic
|
||||
#endif
|
||||
|
||||
return new SKPoint((float)x, (float)y);
|
||||
}
|
||||
|
||||
|
||||
// the user asked to repaint
|
||||
private void OnSurfaceInvalidated(object sender, EventArgs eventArgs)
|
||||
{
|
||||
|
|
|
@ -7,10 +7,10 @@ namespace SkiaSharp.Views.Forms
|
|||
{
|
||||
private readonly MomentumHandler momentumHandler;
|
||||
private Action<SKTouchEventArgs> onTouchAction;
|
||||
private Func<float, float> scalePixels;
|
||||
private Func<double, double, SKPoint> scalePixels;
|
||||
private GestureLayer gestureLayer;
|
||||
|
||||
public SKTouchHandler(Action<SKTouchEventArgs> onTouchAction, Func<float, float> scalePixels)
|
||||
public SKTouchHandler(Action<SKTouchEventArgs> onTouchAction, Func<double, double, SKPoint> scalePixels)
|
||||
{
|
||||
this.onTouchAction = onTouchAction;
|
||||
this.scalePixels = scalePixels;
|
||||
|
@ -111,7 +111,7 @@ namespace SkiaSharp.Views.Forms
|
|||
return;
|
||||
|
||||
var p = handler.gestureLayer.EvasCanvas.Pointer;
|
||||
var coords = new SKPoint(handler.scalePixels(p.X), handler.scalePixels(p.Y));
|
||||
var coords = handler.scalePixels(p.X, p.Y);
|
||||
var inContact = (action == SKTouchAction.Pressed || action == SKTouchAction.Moved) ? true : false;
|
||||
|
||||
handler.onTouchAction(new SKTouchEventArgs(currentId, action, coords, inContact));
|
||||
|
|
|
@ -9,9 +9,9 @@ namespace SkiaSharp.Views.Forms
|
|||
internal class SKTouchHandler
|
||||
{
|
||||
private Action<SKTouchEventArgs> onTouchAction;
|
||||
private Func<float, float> scalePixels;
|
||||
private Func<double, double, SKPoint> scalePixels;
|
||||
|
||||
public SKTouchHandler(Action<SKTouchEventArgs> onTouchAction, Func<float, float> scalePixels)
|
||||
public SKTouchHandler(Action<SKTouchEventArgs> onTouchAction, Func<double, double, SKPoint> scalePixels)
|
||||
{
|
||||
this.onTouchAction = onTouchAction;
|
||||
this.scalePixels = scalePixels;
|
||||
|
@ -100,7 +100,7 @@ namespace SkiaSharp.Views.Forms
|
|||
|
||||
var pointerPoint = evt.GetCurrentPoint(view);
|
||||
var windowsPoint = pointerPoint.Position;
|
||||
var skPoint = new SKPoint(scalePixels((float)windowsPoint.X), scalePixels((float)windowsPoint.Y));
|
||||
var skPoint = scalePixels(windowsPoint.X, windowsPoint.Y);
|
||||
|
||||
var mouse = GetMouseButton(pointerPoint);
|
||||
var device = GetTouchDevice(evt);
|
||||
|
|
|
@ -8,9 +8,9 @@ namespace SkiaSharp.Views.Forms
|
|||
internal class SKTouchHandler : UIGestureRecognizer
|
||||
{
|
||||
private Action<SKTouchEventArgs> onTouchAction;
|
||||
private Func<nfloat, nfloat> scalePixels;
|
||||
private Func<double, double, SKPoint> scalePixels;
|
||||
|
||||
public SKTouchHandler(Action<SKTouchEventArgs> onTouchAction, Func<nfloat, nfloat> scalePixels)
|
||||
public SKTouchHandler(Action<SKTouchEventArgs> onTouchAction, Func<double, double, SKPoint> scalePixels)
|
||||
{
|
||||
this.onTouchAction = onTouchAction;
|
||||
this.scalePixels = scalePixels;
|
||||
|
@ -100,7 +100,7 @@ namespace SkiaSharp.Views.Forms
|
|||
var id = touch.Handle.ToInt64();
|
||||
|
||||
var cgPoint = touch.LocationInView(View);
|
||||
var point = new SKPoint((float)scalePixels(cgPoint.X), (float)scalePixels(cgPoint.Y));
|
||||
var point = scalePixels(cgPoint.X, cgPoint.Y);
|
||||
|
||||
var args = new SKTouchEventArgs(id, actionType, point, inContact);
|
||||
onTouchAction(args);
|
||||
|
|
|
@ -19,16 +19,16 @@ namespace SkiaSharp.Views.Tizen
|
|||
});
|
||||
|
||||
// allows to convert pixels to Android-style device-independent pixels
|
||||
private static readonly Lazy<float> scalingFactor = new Lazy<float>(() => dpi.Value / 160.0f);
|
||||
private static readonly Lazy<double> scalingFactor = new Lazy<double>(() => dpi.Value / 160.0);
|
||||
|
||||
public static string Profile => profile.Value;
|
||||
|
||||
public static int Dpi => dpi.Value;
|
||||
|
||||
public static float ScalingFactor => scalingFactor.Value;
|
||||
public static double ScalingFactor => scalingFactor.Value;
|
||||
|
||||
public static float FromPixel(float v) => v / ScalingFactor;
|
||||
public static double FromPixel(double v) => v / ScalingFactor;
|
||||
|
||||
public static float ToPixel(float v) => v * ScalingFactor;
|
||||
public static double ToPixel(double v) => v * ScalingFactor;
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче