Renamed TouchAction to Touch because reasons

This commit is contained in:
Matthew Leibowitz 2017-06-01 20:02:19 -05:00
Родитель 060ae87389
Коммит 2670f6728b
10 изменённых файлов: 64 добавлений и 64 удалений

Просмотреть файл

@ -5,10 +5,10 @@ namespace SkiaSharp.Views.Forms
{
internal class SKTouchHandler
{
private Action<SKTouchActionEventArgs> onTouchAction;
private Action<SKTouchEventArgs> onTouchAction;
private Func<float, float> scalePixels;
public SKTouchHandler(Action<SKTouchActionEventArgs> onTouchAction, Func<float, float> scalePixels)
public SKTouchHandler(Action<SKTouchEventArgs> onTouchAction, Func<float, float> scalePixels)
{
this.onTouchAction = onTouchAction;
this.scalePixels = scalePixels;
@ -48,7 +48,7 @@ namespace SkiaSharp.Views.Forms
case MotionEventActions.Down:
case MotionEventActions.PointerDown:
{
var args = new SKTouchActionEventArgs(id, SKTouchActionType.Pressed, coords, true);
var args = new SKTouchEventArgs(id, SKTouchAction.Pressed, coords, true);
onTouchAction(args);
e.Handled = args.Handled;
break;
@ -62,7 +62,7 @@ namespace SkiaSharp.Views.Forms
id = evt.GetPointerId(pointer);
coords = new SKPoint(scalePixels(evt.GetX(pointer)), scalePixels(evt.GetY(pointer)));
var args = new SKTouchActionEventArgs(id, SKTouchActionType.Moved, coords, true);
var args = new SKTouchEventArgs(id, SKTouchAction.Moved, coords, true);
onTouchAction(args);
e.Handled = e.Handled || args.Handled;
}
@ -72,7 +72,7 @@ namespace SkiaSharp.Views.Forms
case MotionEventActions.Up:
case MotionEventActions.PointerUp:
{
var args = new SKTouchActionEventArgs(id, SKTouchActionType.Released, coords, false);
var args = new SKTouchEventArgs(id, SKTouchAction.Released, coords, false);
onTouchAction(args);
e.Handled = args.Handled;
break;
@ -80,7 +80,7 @@ namespace SkiaSharp.Views.Forms
case MotionEventActions.Cancel:
{
var args = new SKTouchActionEventArgs(id, SKTouchActionType.Cancelled, coords, false);
var args = new SKTouchEventArgs(id, SKTouchAction.Cancelled, coords, false);
onTouchAction(args);
e.Handled = args.Handled;
break;

Просмотреть файл

@ -7,10 +7,10 @@ namespace SkiaSharp.Views.Forms
{
internal class SKTouchHandler : NSGestureRecognizer
{
private Action<SKTouchActionEventArgs> onTouchAction;
private Action<SKTouchEventArgs> onTouchAction;
private Func<nfloat, nfloat> scalePixels;
public SKTouchHandler(Action<SKTouchActionEventArgs> onTouchAction, Func<nfloat, nfloat> scalePixels)
public SKTouchHandler(Action<SKTouchEventArgs> onTouchAction, Func<nfloat, nfloat> scalePixels)
{
this.onTouchAction = onTouchAction;
this.scalePixels = scalePixels;
@ -38,66 +38,66 @@ namespace SkiaSharp.Views.Forms
{
base.MouseDown(mouseEvent);
FireEvent(SKTouchActionType.Pressed, SKMouseButton.Left, SKTouchDeviceType.Mouse, mouseEvent, true);
FireEvent(SKTouchAction.Pressed, SKMouseButton.Left, SKTouchDeviceType.Mouse, mouseEvent, true);
}
public override void MouseUp(NSEvent mouseEvent)
{
base.MouseUp(mouseEvent);
FireEvent(SKTouchActionType.Released, SKMouseButton.Left, SKTouchDeviceType.Mouse, mouseEvent, false);
FireEvent(SKTouchAction.Released, SKMouseButton.Left, SKTouchDeviceType.Mouse, mouseEvent, false);
}
public override void MouseDragged(NSEvent mouseEvent)
{
base.MouseDragged(mouseEvent);
FireEvent(SKTouchActionType.Moved, SKMouseButton.Left, SKTouchDeviceType.Mouse, mouseEvent, true);
FireEvent(SKTouchAction.Moved, SKMouseButton.Left, SKTouchDeviceType.Mouse, mouseEvent, true);
}
public override void OtherMouseDown(NSEvent mouseEvent)
{
base.OtherMouseDown(mouseEvent);
FireEvent(SKTouchActionType.Pressed, SKMouseButton.Middle, SKTouchDeviceType.Mouse, mouseEvent, true);
FireEvent(SKTouchAction.Pressed, SKMouseButton.Middle, SKTouchDeviceType.Mouse, mouseEvent, true);
}
public override void OtherMouseUp(NSEvent mouseEvent)
{
base.OtherMouseUp(mouseEvent);
FireEvent(SKTouchActionType.Released, SKMouseButton.Middle, SKTouchDeviceType.Mouse, mouseEvent, false);
FireEvent(SKTouchAction.Released, SKMouseButton.Middle, SKTouchDeviceType.Mouse, mouseEvent, false);
}
public override void OtherMouseDragged(NSEvent mouseEvent)
{
base.OtherMouseDragged(mouseEvent);
FireEvent(SKTouchActionType.Moved, SKMouseButton.Middle, SKTouchDeviceType.Mouse, mouseEvent, true);
FireEvent(SKTouchAction.Moved, SKMouseButton.Middle, SKTouchDeviceType.Mouse, mouseEvent, true);
}
public override void RightMouseDown(NSEvent mouseEvent)
{
base.RightMouseDown(mouseEvent);
FireEvent(SKTouchActionType.Pressed, SKMouseButton.Right, SKTouchDeviceType.Mouse, mouseEvent, true);
FireEvent(SKTouchAction.Pressed, SKMouseButton.Right, SKTouchDeviceType.Mouse, mouseEvent, true);
}
public override void RightMouseUp(NSEvent mouseEvent)
{
base.RightMouseUp(mouseEvent);
FireEvent(SKTouchActionType.Released, SKMouseButton.Right, SKTouchDeviceType.Mouse, mouseEvent, false);
FireEvent(SKTouchAction.Released, SKMouseButton.Right, SKTouchDeviceType.Mouse, mouseEvent, false);
}
public override void RightMouseDragged(NSEvent mouseEvent)
{
base.RightMouseDragged(mouseEvent);
FireEvent(SKTouchActionType.Moved, SKMouseButton.Right, SKTouchDeviceType.Mouse, mouseEvent, true);
FireEvent(SKTouchAction.Moved, SKMouseButton.Right, SKTouchDeviceType.Mouse, mouseEvent, true);
}
private bool FireEvent(SKTouchActionType actionType, SKMouseButton mouse, SKTouchDeviceType device, NSEvent mouseEvent, bool inContact)
private bool FireEvent(SKTouchAction actionType, SKMouseButton mouse, SKTouchDeviceType device, NSEvent mouseEvent, bool inContact)
{
if (onTouchAction == null || scalePixels == null)
return false;
@ -110,7 +110,7 @@ namespace SkiaSharp.Views.Forms
var point = new SKPoint((float)scalePixels(cgPoint.X), (float)scalePixels(cgPoint.Y));
var args = new SKTouchActionEventArgs(id, actionType, mouse, device, point, inContact);
var args = new SKTouchEventArgs(id, actionType, mouse, device, point, inContact);
onTouchAction(args);
return args.Handled;
}

Просмотреть файл

@ -34,19 +34,19 @@ namespace SkiaSharp.Views.Forms
{
#if __ANDROID__
touchHandler = new SKTouchHandler(
args => ((ISKCanvasViewController)Element).OnTouchAction(args),
args => ((ISKCanvasViewController)Element).OnTouch(args),
coord => Element.IgnorePixelScaling ? (float)Context.FromPixels(coord) : coord);
#elif __IOS__
touchHandler = new SKTouchHandler(
args => ((ISKCanvasViewController)Element).OnTouchAction(args),
args => ((ISKCanvasViewController)Element).OnTouch(args),
coord => Element.IgnorePixelScaling ? coord : coord * Control.ContentScaleFactor);
#elif __MACOS__
touchHandler = new SKTouchHandler(
args => ((ISKCanvasViewController)Element).OnTouchAction(args),
args => ((ISKCanvasViewController)Element).OnTouch(args),
coord => Element.IgnorePixelScaling ? coord : coord * Control.Window.BackingScaleFactor);
#elif WINDOWS_UWP
touchHandler = new SKTouchHandler(
args => ((ISKCanvasViewController)Element).OnTouchAction(args),
args => ((ISKCanvasViewController)Element).OnTouch(args),
coord => Element.IgnorePixelScaling ? coord : (float)(coord * Control.Dpi));
#endif
}

Просмотреть файл

@ -34,19 +34,19 @@ namespace SkiaSharp.Views.Forms
{
#if __ANDROID__
touchHandler = new SKTouchHandler(
args => ((ISKGLViewController)Element).OnTouchAction(args),
args => ((ISKGLViewController)Element).OnTouch(args),
coord => coord);
#elif __IOS__
touchHandler = new SKTouchHandler(
args => ((ISKGLViewController)Element).OnTouchAction(args),
args => ((ISKGLViewController)Element).OnTouch(args),
coord => coord * Control.ContentScaleFactor);
#elif __MACOS__
touchHandler = new SKTouchHandler(
args => ((ISKGLViewController)Element).OnTouchAction(args),
args => ((ISKGLViewController)Element).OnTouch(args),
coord => coord * Control.Window.BackingScaleFactor);
#elif WINDOWS_UWP
touchHandler = new SKTouchHandler(
args => ((ISKGLViewController)Element).OnTouchAction(args),
args => ((ISKGLViewController)Element).OnTouch(args),
coord => (float)(coord * Control.ContentsScale));
#endif
}

Просмотреть файл

@ -6,14 +6,14 @@ namespace SkiaSharp.Views.Forms
[RenderWith(typeof(SKCanvasViewRenderer))]
public class SKCanvasView : View, ISKCanvasViewController
{
public static readonly BindableProperty IgnorePixelScalingProperty =
public static readonly BindableProperty IgnorePixelScalingProperty =
BindableProperty.Create(nameof(IgnorePixelScaling), typeof(bool), typeof(SKCanvasView), default(bool));
// the user can subscribe to repaint
public event EventHandler<SKPaintSurfaceEventArgs> PaintSurface;
// the user can subscribe to touch events
public event EventHandler<SKTouchActionEventArgs> TouchAction;
public event EventHandler<SKTouchEventArgs> Touch;
// the native listens to this event
private event EventHandler SurfaceInvalidated;
@ -51,9 +51,9 @@ namespace SkiaSharp.Views.Forms
}
// the native view responds to a touch
protected virtual void OnTouchAction(SKTouchActionEventArgs e)
protected virtual void OnTouch(SKTouchEventArgs e)
{
TouchAction?.Invoke(this, e);
Touch?.Invoke(this, e);
}
// ISKViewController implementation
@ -75,9 +75,9 @@ namespace SkiaSharp.Views.Forms
OnPaintSurface(e);
}
void ISKCanvasViewController.OnTouchAction(SKTouchActionEventArgs e)
void ISKCanvasViewController.OnTouch(SKTouchEventArgs e)
{
OnTouchAction(e);
OnTouch(e);
}
protected override SizeRequest OnMeasure(double widthConstraint, double heightConstraint)
@ -96,6 +96,6 @@ namespace SkiaSharp.Views.Forms
void OnPaintSurface(SKPaintSurfaceEventArgs e);
// the native view responds to a touch
void OnTouchAction(SKTouchActionEventArgs e);
void OnTouch(SKTouchEventArgs e);
}
}

Просмотреть файл

@ -19,7 +19,7 @@ namespace SkiaSharp.Views.Forms
public event EventHandler<SKPaintGLSurfaceEventArgs> PaintSurface;
// the user can subscribe to touch events
public event EventHandler<SKTouchActionEventArgs> TouchAction;
public event EventHandler<SKTouchEventArgs> Touch;
// the native listens to this event
private event EventHandler SurfaceInvalidated;
@ -51,9 +51,9 @@ namespace SkiaSharp.Views.Forms
}
// the native view responds to a touch
protected virtual void OnTouchAction(SKTouchActionEventArgs e)
protected virtual void OnTouch(SKTouchEventArgs e)
{
TouchAction?.Invoke(this, e);
Touch?.Invoke(this, e);
}
// ISKViewController implementation
@ -75,9 +75,9 @@ namespace SkiaSharp.Views.Forms
OnPaintSurface(e);
}
void ISKGLViewController.OnTouchAction(SKTouchActionEventArgs e)
void ISKGLViewController.OnTouch(SKTouchEventArgs e)
{
OnTouchAction(e);
OnTouch(e);
}
protected override SizeRequest OnMeasure(double widthConstraint, double heightConstraint)
@ -96,6 +96,6 @@ namespace SkiaSharp.Views.Forms
void OnPaintSurface(SKPaintGLSurfaceEventArgs e);
// the native view responds to a touch
void OnTouchAction(SKTouchActionEventArgs e);
void OnTouch(SKTouchEventArgs e);
}
}

Просмотреть файл

@ -3,14 +3,14 @@ using System.Linq;
namespace SkiaSharp.Views.Forms
{
public class SKTouchActionEventArgs : EventArgs
public class SKTouchEventArgs : EventArgs
{
public SKTouchActionEventArgs(long id, SKTouchActionType type, SKPoint location, bool inContact)
public SKTouchEventArgs(long id, SKTouchAction type, SKPoint location, bool inContact)
: this(id, type, SKMouseButton.Left, SKTouchDeviceType.Touch, location, inContact)
{
}
public SKTouchActionEventArgs(long id, SKTouchActionType type, SKMouseButton mouseButton, SKTouchDeviceType deviceType, SKPoint location, bool inContact)
public SKTouchEventArgs(long id, SKTouchAction type, SKMouseButton mouseButton, SKTouchDeviceType deviceType, SKPoint location, bool inContact)
{
Id = id;
ActionType = type;
@ -26,7 +26,7 @@ namespace SkiaSharp.Views.Forms
public long Id { get; private set; }
public SKTouchActionType ActionType { get; private set; }
public SKTouchAction ActionType { get; private set; }
public SKTouchDeviceType DeviceType { get; private set; }
@ -42,7 +42,7 @@ namespace SkiaSharp.Views.Forms
}
}
public enum SKTouchActionType
public enum SKTouchAction
{
Entered,
Pressed,

Просмотреть файл

@ -17,6 +17,6 @@
<Compile Include="$(MSBuildThisFileDirectory)SKCanvasView.cs" />
<Compile Include="$(MSBuildThisFileDirectory)RendererTypes.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SKImageSource.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SKTouchActionEventArgs.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SKTouchEventArgs.cs" />
</ItemGroup>
</Project>

Просмотреть файл

@ -8,10 +8,10 @@ namespace SkiaSharp.Views.Forms
{
internal class SKTouchHandler
{
private Action<SKTouchActionEventArgs> onTouchAction;
private Action<SKTouchEventArgs> onTouchAction;
private Func<float, float> scalePixels;
public SKTouchHandler(Action<SKTouchActionEventArgs> onTouchAction, Func<float, float> scalePixels)
public SKTouchHandler(Action<SKTouchEventArgs> onTouchAction, Func<float, float> scalePixels)
{
this.onTouchAction = onTouchAction;
this.scalePixels = scalePixels;
@ -47,17 +47,17 @@ namespace SkiaSharp.Views.Forms
private void OnPointerEntered(object sender, PointerRoutedEventArgs args)
{
CommonHandler(sender, SKTouchActionType.Entered, args);
CommonHandler(sender, SKTouchAction.Entered, args);
}
private void OnPointerExited(object sender, PointerRoutedEventArgs args)
{
CommonHandler(sender, SKTouchActionType.Exited, args);
CommonHandler(sender, SKTouchAction.Exited, args);
}
private void OnPointerPressed(object sender, PointerRoutedEventArgs args)
{
CommonHandler(sender, SKTouchActionType.Pressed, args);
CommonHandler(sender, SKTouchAction.Pressed, args);
var view = sender as FrameworkElement;
view.CapturePointer(args.Pointer);
@ -65,20 +65,20 @@ namespace SkiaSharp.Views.Forms
private void OnPointerMoved(object sender, PointerRoutedEventArgs args)
{
CommonHandler(sender, SKTouchActionType.Moved, args);
CommonHandler(sender, SKTouchAction.Moved, args);
}
private void OnPointerReleased(object sender, PointerRoutedEventArgs args)
{
CommonHandler(sender, SKTouchActionType.Released, args);
CommonHandler(sender, SKTouchAction.Released, args);
}
private void OnPointerCancelled(object sender, PointerRoutedEventArgs args)
{
CommonHandler(sender, SKTouchActionType.Cancelled, args);
CommonHandler(sender, SKTouchAction.Cancelled, args);
}
private bool CommonHandler(object sender, SKTouchActionType touchActionType, PointerRoutedEventArgs evt)
private bool CommonHandler(object sender, SKTouchAction touchActionType, PointerRoutedEventArgs evt)
{
if (onTouchAction == null || scalePixels == null)
return false;
@ -94,7 +94,7 @@ namespace SkiaSharp.Views.Forms
var mouse = GetMouseButton(pointerPoint);
var device = GetTouchDevice(evt);
var args = new SKTouchActionEventArgs(id, touchActionType, mouse, device, skPoint, evt.Pointer.IsInContact);
var args = new SKTouchEventArgs(id, touchActionType, mouse, device, skPoint, evt.Pointer.IsInContact);
onTouchAction(args);
return args.Handled;
}

Просмотреть файл

@ -7,10 +7,10 @@ namespace SkiaSharp.Views.Forms
{
internal class SKTouchHandler : UIGestureRecognizer
{
private Action<SKTouchActionEventArgs> onTouchAction;
private Action<SKTouchEventArgs> onTouchAction;
private Func<nfloat, nfloat> scalePixels;
public SKTouchHandler(Action<SKTouchActionEventArgs> onTouchAction, Func<nfloat, nfloat> scalePixels)
public SKTouchHandler(Action<SKTouchEventArgs> onTouchAction, Func<nfloat, nfloat> scalePixels)
{
this.onTouchAction = onTouchAction;
this.scalePixels = scalePixels;
@ -40,7 +40,7 @@ namespace SkiaSharp.Views.Forms
foreach (UITouch touch in touches.Cast<UITouch>())
{
FireEvent(SKTouchActionType.Pressed, touch, true);
FireEvent(SKTouchAction.Pressed, touch, true);
}
}
@ -50,7 +50,7 @@ namespace SkiaSharp.Views.Forms
foreach (UITouch touch in touches.Cast<UITouch>())
{
FireEvent(SKTouchActionType.Moved, touch, true);
FireEvent(SKTouchAction.Moved, touch, true);
}
}
@ -60,7 +60,7 @@ namespace SkiaSharp.Views.Forms
foreach (UITouch touch in touches.Cast<UITouch>())
{
FireEvent(SKTouchActionType.Released, touch, false);
FireEvent(SKTouchAction.Released, touch, false);
}
}
@ -70,11 +70,11 @@ namespace SkiaSharp.Views.Forms
foreach (UITouch touch in touches.Cast<UITouch>())
{
FireEvent(SKTouchActionType.Cancelled, touch, false);
FireEvent(SKTouchAction.Cancelled, touch, false);
}
}
private bool FireEvent(SKTouchActionType actionType, UITouch touch, bool inContact)
private bool FireEvent(SKTouchAction actionType, UITouch touch, bool inContact)
{
if (onTouchAction == null || scalePixels == null)
return false;
@ -84,7 +84,7 @@ namespace SkiaSharp.Views.Forms
var cgPoint = touch.LocationInView(View);
var point = new SKPoint((float)scalePixels(cgPoint.X), (float)scalePixels(cgPoint.Y));
var args = new SKTouchActionEventArgs(id, actionType, point, inContact);
var args = new SKTouchEventArgs(id, actionType, point, inContact);
onTouchAction(args);
return args.Handled;
}