Пример #1
0
        // processing

        private bool CommonHandler(object sender, SKTouchAction touchActionType, InputEventArgs evt)
        {
            if (onTouchAction == null || scalePixels == null)
            {
                return(false);
            }

            var view = sender as FrameworkElement;

            // bail out if this view is not part the view hierarchy anymore
            if (PresentationSource.FromVisual(view) == null)
            {
                return(false);
            }

            var id           = GetId(evt);
            var action       = GetTouchAction(touchActionType, view, evt);
            var mouse        = GetMouseButton(evt);
            var device       = GetTouchDevice(evt);
            var windowsPoint = GetPosition(evt, view);
            var skPoint      = scalePixels(windowsPoint.X, windowsPoint.Y);
            var inContact    = GetContact(evt);
            var wheelDelta   = evt is MouseWheelEventArgs wheelEvt ? wheelEvt.Delta : 0;

            var args = new SKTouchEventArgs(id, action, mouse, device, skPoint, inContact, wheelDelta);

            onTouchAction(args);
            return(args.Handled);
        }
Пример #2
0
        private bool CommonHandler(object sender, SKTouchAction touchActionType, PointerRoutedEventArgs evt)
        {
            if (onTouchAction == null || scalePixels == null)
            {
                return(false);
            }

            var view = sender as FrameworkElement;

            var id = evt.Pointer.PointerId;

            var pointerPoint = evt.GetCurrentPoint(view);
            var windowsPoint = pointerPoint.Position;
            var skPoint      = scalePixels(windowsPoint.X, windowsPoint.Y);

            var mouse  = GetMouseButton(pointerPoint);
            var device = GetTouchDevice(evt);

            var wheelDelta = pointerPoint?.Properties?.MouseWheelDelta ?? 0;

            var args = new SKTouchEventArgs(id, touchActionType, mouse, device, skPoint, evt.Pointer.IsInContact, wheelDelta);

            onTouchAction(args);
            return(args.Handled);
        }
Пример #3
0
        private void OnTouch(object sender, View.TouchEventArgs e)
        {
            if (onTouchAction == null || scalePixels == null)
            {
                return;
            }

            var evt     = e.Event;
            var pointer = evt.ActionIndex;

            var id     = evt.GetPointerId(pointer);
            var coords = scalePixels(evt.GetX(pointer), evt.GetY(pointer));

            switch (evt.ActionMasked)
            {
            case MotionEventActions.Down:
            case MotionEventActions.PointerDown:
            {
                var args = new SKTouchEventArgs(id, SKTouchAction.Pressed, coords, true);
                onTouchAction(args);
                e.Handled = args.Handled;
                break;
            }

            case MotionEventActions.Move:
            {
                var count = evt.PointerCount;
                for (pointer = 0; pointer < count; pointer++)
                {
                    id     = evt.GetPointerId(pointer);
                    coords = scalePixels(evt.GetX(pointer), evt.GetY(pointer));

                    var args = new SKTouchEventArgs(id, SKTouchAction.Moved, coords, true);
                    onTouchAction(args);
                    e.Handled = e.Handled || args.Handled;
                }
                break;
            }

            case MotionEventActions.Up:
            case MotionEventActions.PointerUp:
            {
                var args = new SKTouchEventArgs(id, SKTouchAction.Released, coords, false);
                onTouchAction(args);
                e.Handled = args.Handled;
                break;
            }

            case MotionEventActions.Cancel:
            {
                var args = new SKTouchEventArgs(id, SKTouchAction.Cancelled, coords, false);
                onTouchAction(args);
                e.Handled = args.Handled;
                break;
            }
            }
        }
        private void SkCanvasView_Touch(object sender, SkiaSharp.Views.Forms.SKTouchEventArgs e)
        {
            if (e.ActionType == SkiaSharp.Views.Forms.SKTouchAction.Pressed)
            {
                _lastTouchPoint = e.Location;
                e.Handled       = true;
            }

            _lastTouchPoint = e.Location;

            SkCanvasView.InvalidateSurface();
        }
Пример #5
0
        private bool FireEvent(SKTouchAction actionType, UITouch touch, bool inContact)
        {
            if (onTouchAction == null || scalePixels == null)
            {
                return(false);
            }

            var id = touch.Handle.ToInt64();

            var cgPoint = touch.LocationInView(View);
            var point   = new SKPoint((float)scalePixels(cgPoint.X), (float)scalePixels(cgPoint.Y));

            var args = new SKTouchEventArgs(id, actionType, point, inContact);

            onTouchAction(args);
            return(args.Handled);
        }
Пример #6
0
    private void Chart_Touched(object sender, SkiaSharp.Views.Forms.SKTouchEventArgs e)
    {
        var chart = (CartesianChart)FindByName("chart");

        var viewModel = (ViewModel)BindingContext;

        // scales the UI coordintaes to the corresponging data in the chart.
        // ScaleUIPoint retuns an array of double
        var scaledPoint = chart.ScaleUIPoint(new LvcPoint(e.Location.X, e.Location.Y));

        // where the X coordinate is in the first position
        var x = scaledPoint[0];

        // and the Y coordinate in the second position
        var y = scaledPoint[1];

        // finally add the new point to the data in our chart.
        viewModel.Data.Add(new ObservablePoint(x, y));
    }
Пример #7
0
        void OnTouchEffectAction(System.Object sender, SkiaSharp.Views.Forms.SKTouchEventArgs e)
        {
            switch (e.ActionType)
            {
            case SKTouchAction.Pressed:
                if (!inProgressPaths.ContainsKey(e.Id))
                {
                    SKPath path = new SKPath();
                    path.MoveTo(e.Location);
                    inProgressPaths.Add(e.Id, path);
                    canvasView.InvalidateSurface();
                }
                break;

            case SKTouchAction.Moved:
                if (inProgressPaths.ContainsKey(e.Id))
                {
                    SKPath path = inProgressPaths[e.Id];
                    path.LineTo(e.Location);
                    canvasView.InvalidateSurface();
                }
                break;

            case SKTouchAction.Released:
                if (inProgressPaths.ContainsKey(e.Id))
                {
                    completedPaths.Add(new DrawItem()
                    {
                        Path  = inProgressPaths[e.Id],
                        Paint = DrawHelper.GetCurrentPaintObject(false, brushColourToBeUsed, brushThickness),
                        Area  = areaUsed,
                        Name  = brushName
                    });

                    inProgressPaths.Remove(e.Id);
                    canvasView.InvalidateSurface();
                }
                break;
            }

            e.Handled = true;
        }
Пример #8
0
        async void Handle_Touch(object sender, SkiaSharp.Views.Forms.SKTouchEventArgs e)
        {
            SKPoint touchLocation = e.Location;

            float popOverWidth = (float)Math.Sqrt(2 * Math.Pow(Cake.PopOver.Radius, 2));

            float minX = Cake.Center.X - 0.5f * popOverWidth;
            float maxX = Cake.Center.X + 0.5f * popOverWidth;
            float minY = Cake.Center.Y - 0.5f * popOverWidth;
            float maxY = Cake.Center.X + 0.5f * popOverWidth;

            minX *= Cake.Scale;
            maxX *= Cake.Scale;
            minY *= Cake.Scale;
            maxY *= Cake.Scale;

            bool insideX = touchLocation.X > minX && touchLocation.X < maxX;
            bool insideY = touchLocation.Y > minY && touchLocation.Y < maxY;

            if (insideX && insideY && Cake.CurrentlySelected != null)
            {
                await Navigation.PushAsync(new EmissionDetailsPage(Cake.CurrentlySelected.Emission));
            }
            else
            {
                PieceOfCake Slice = Cake.SelectPieceOfCake(e);
                if (Slice != null)
                {
                    //MainGrid.Children.RemoveAt(1);
                    //MainGrid.Children.Add(new EmissionHighlightView(Slice.Emission), 0, 0);
                    await Cake.AnimateSelection(Slice.Emission, 500);

                    Cake.CurrentlySelected = Slice;
                }
                else
                {
                    Cake.CurrentlySelected = null;
                }
                Cake.CanvasView.InvalidateSurface();
            }
        }
Пример #9
0
        private bool FireEvent(SKTouchAction actionType, SKMouseButton mouse, SKTouchDeviceType device, NSEvent mouseEvent, bool inContact)
        {
            if (onTouchAction == null || scalePixels == null)
            {
                return(false);
            }

            var id = mouseEvent.ButtonNumber;

            var cgPoint = LocationInView(View);

            // 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 args = new SKTouchEventArgs(id, actionType, mouse, device, point, inContact);

            onTouchAction(args);
            return(args.Handled);
        }
Пример #10
0
        private bool CommonHandler(object sender, SKTouchAction touchActionType, MouseEventArgs evt)
        {
            if (onTouchAction == null || scalePixels == null)
            {
                return(false);
            }

            var view = sender as Control;

            var id = 0L;            // evt.Pointer.PointerId;

            var windowsPoint = evt.Location;
            var skPoint      = new SKPoint((float)windowsPoint.X, (float)windowsPoint.Y);

            var mouse  = GetMouseButton(evt.Button);
            var device = SKTouchDeviceType.Mouse;            // GetTouchDevice(evt);

            var args = new SKTouchEventArgs(id, touchActionType, mouse, device, skPoint, false /*evt.Pointer.IsInContact*/);

            onTouchAction(args);
            return(args.Handled);
        }
Пример #11
0
        // processing

        private bool CommonHandler(object sender, SKTouchAction touchActionType, MouseEventArgs evt)
        {
            if (onTouchAction == null || scalePixels == null)
            {
                return(false);
            }

            var view = sender as Control;

            var id           = 1;
            var action       = touchActionType;
            var mouse        = GetMouseButton(evt);
            var device       = SKTouchDeviceType.Mouse;
            var windowsPoint = evt.Location;
            var skPoint      = scalePixels(windowsPoint.X, windowsPoint.Y);
            var inContact    = GetContact(evt);

            var args = new SKTouchEventArgs(id, action, mouse, device, skPoint, inContact);

            onTouchAction(args);
            return(args.Handled);
        }
        // processing

        private bool CommonHandler(object sender, SKTouchAction touchActionType, InputEventArgs evt)
        {
            if (onTouchAction == null || scalePixels == null)
            {
                return(false);
            }

            var view = sender as FrameworkElement;

            var id           = GetId(evt);
            var action       = GetTouchAction(touchActionType, view, evt);
            var mouse        = GetMouseButton(evt);
            var device       = GetTouchDevice(evt);
            var windowsPoint = GetPosition(evt, view);
            var skPoint      = scalePixels(windowsPoint.X, windowsPoint.Y);
            var inContact    = GetContact(evt);

            var args = new SKTouchEventArgs(id, action, mouse, device, skPoint, inContact);

            onTouchAction(args);
            return(args.Handled);
        }
Пример #13
0
        // processing

        private bool CommonHandler(object sender, SKTouchAction touchActionType, Event evt)
        {
            if (onTouchAction == null || scalePixels == null)
            {
                return(false);
            }

            var view = sender as Widget;

            var id           = GetId(evt);
            var action       = touchActionType;
            var mouse        = GetMouseButton(evt);
            var device       = GetTouchDevice(evt);
            var windowsPoint = GetPosition(evt);
            var skPoint      = scalePixels(windowsPoint.X, windowsPoint.Y);
            var inContact    = GetContact(evt);
            var wheelDelta   = GetWheelDelta(evt);

            var args = new SKTouchEventArgs(id, action, mouse, device, skPoint, inContact, wheelDelta);

            onTouchAction(args);
            return(args.Handled);
        }
Пример #14
0
        private void canvasView_Touch(object sender, SkiaSharp.Views.Forms.SKTouchEventArgs e)
        {
            if (e.ActionType == SKTouchAction.Pressed || e.ActionType == SKTouchAction.Moved)
            {
                if (e.Location.X >= width / 2)
                {
                    right = true;
                    left  = false;
                }
                else
                {
                    right = false;
                    left  = true;
                }
            }

            else if (e.ActionType == SkiaSharp.Views.Forms.SKTouchAction.Released)
            {
                right = false;
                left  = false;
            }

            e.Handled = true;
        }
Пример #15
0
        private void SkCanvasView_Touch(object sender, SkiaSharp.Views.Forms.SKTouchEventArgs e)
        {
            try
            {
                var x = (int)(e.Location.X / scale.Width);
                var y = (int)(e.Location.Y / scale.Height);

                Console.WriteLine(Extensions.ToJSON(e, Formatting.None));

                if (e.ActionType == SKTouchAction.Moved)
                {
                    if (e.InContact)
                    {
                        XplatUI.driver.SendMessage(IntPtr.Zero, Msg.WM_MOUSEMOVE, new IntPtr((int)MsgButtons.MK_LBUTTON),
                                                   (IntPtr)((y) << 16 | (x)));
                    }
                    else
                    {
                        XplatUI.driver.SendMessage(IntPtr.Zero, Msg.WM_MOUSEMOVE, new IntPtr(),
                                                   (IntPtr)((y) << 16 | (x)));
                    }
                }

                if (e.ActionType == SKTouchAction.Pressed && e.MouseButton == SKMouseButton.Left)
                {
                    XplatUI.driver.SendMessage(IntPtr.Zero, Msg.WM_MOUSEMOVE, new IntPtr(), (IntPtr)((y) << 16 | (x)));

                    if (LastPressed.AddMilliseconds(500) > DateTime.Now && Math.Abs(LastPressedX - x) < 10 &&
                        Math.Abs(LastPressedY - y) < 10)
                    {
                        XplatUI.driver.SendMessage(IntPtr.Zero, Msg.WM_LBUTTONDBLCLK, new IntPtr((int)MsgButtons.MK_LBUTTON),
                                                   (IntPtr)((y) << 16 | (x)));
                        LastPressed = DateTime.MinValue;
                    }
                    else
                    {
                        XplatUI.driver.SendMessage(IntPtr.Zero, Msg.WM_LBUTTONDOWN,
                                                   new IntPtr((int)MsgButtons.MK_LBUTTON), (IntPtr)((y) << 16 | (x)));
                    }
                }

                if (e.ActionType == SKTouchAction.Released && e.MouseButton == SKMouseButton.Left)
                {
                    //XplatUI.driver.SendMessage(IntPtr.Zero, Msg.WM_MOUSEMOVE, new IntPtr((int) MsgButtons.MK_LBUTTON), (IntPtr)((y) << 16 | (x)));

                    XplatUI.driver.SendMessage(IntPtr.Zero, Msg.WM_LBUTTONUP, new IntPtr((int)MsgButtons.MK_LBUTTON), (IntPtr)((y) << 16 | (x)));
                    LastPressed  = DateTime.Now;
                    LastPressedX = x;
                    LastPressedY = y;
                }

                if (e.ActionType == SKTouchAction.Entered)
                {
                    XplatUI.driver.SendMessage(IntPtr.Zero, Msg.WM_MOUSEMOVE, new IntPtr(), (IntPtr)((y) << 16 | (x)));
                }

                if (e.ActionType == SKTouchAction.Exited)
                {
                    XplatUI.driver.SendMessage(IntPtr.Zero, Msg.WM_MOUSEMOVE, new IntPtr(), (IntPtr)((y) << 16 | (x)));
                }

                e.Handled = true;
            } catch {}
        }
Пример #16
0
        private void SkCanvasView_Touch(object sender, SkiaSharp.Views.Forms.SKTouchEventArgs e)
        {
            try
            {
                var x = (int)(e.Location.X / scale.Width);
                var y = (int)(e.Location.Y / scale.Height);

                Console.WriteLine(Extensions.ToJSON(e, Formatting.None));
                XplatUIMine.PaintPending = true;

                if (e.ActionType == SKTouchAction.Moved)
                {
                    if (touchDictionary.ContainsKey(e.Id))
                    {
                        if (Math.Abs(touchDictionary[e.Id].atdown.Location.X / scale.Width - x) > 5 &&
                            Math.Abs(touchDictionary[e.Id].atdown.Location.Y / scale.Height - y) > 5)
                        {
                            //Console.WriteLine("Mouse has moved");
                            touchDictionary[e.Id].hasmoved = true;
                        }

                        touchDictionary[e.Id].prev = touchDictionary[e.Id].now;
                        touchDictionary[e.Id].now  = e;
                    }

                    if (touchDictionary.Count >= 2)
                    {
                        // Copy two dictionary keys into array
                        long[] keys = new long[touchDictionary.Count];
                        touchDictionary.Keys.CopyTo(keys, 0);

                        // Find index non-moving (pivot) finger
                        int pivotIndex = (keys[0] == e.Id) ? 1 : 0;

                        // Get the three points in the transform
                        SKPoint pivotPoint = touchDictionary[keys[pivotIndex]].atdown.Location;
                        SKPoint prevPoint  = touchDictionary[e.Id].atdown.Location;
                        SKPoint newPoint   = e.Location;

                        // Calculate two vectors
                        SKPoint oldVector = prevPoint - pivotPoint;
                        SKPoint newVector = newPoint - pivotPoint;

                        SKPoint center = (pivotPoint + prevPoint);
                        center.X /= 2;
                        center.Y /= 2;

                        // Find angles from pivot point to touch points
                        float oldAngle = (float)Math.Atan2(oldVector.Y, oldVector.X);
                        float newAngle = (float)Math.Atan2(newVector.Y, newVector.X);

                        float scale1 = Magnitude(newVector) / Magnitude(oldVector);

                        if (!float.IsNaN(scale1) && !float.IsInfinity(scale1))
                        {
                            //var centre = pivotPoint;
                            x = (int)(center.X / scale.Width);
                            y = (int)(center.Y / scale.Height);

                            Console.WriteLine("scale: {0} {1} {2}", scale, newVector.Length, oldVector.Length);
                            if (scale1 >= 2)
                            {
                                XplatUI.driver.SendMessage(IntPtr.Zero, Msg.WM_MOUSEWHEEL,
                                                           new IntPtr((int)(1) << 16),
                                                           (IntPtr)((y) << 16 | (x)));
                                touchDictionary[e.Id].atdown = e;
                            }

                            if (scale1 <= 0.5)
                            {
                                XplatUI.driver.SendMessage(IntPtr.Zero, Msg.WM_MOUSEWHEEL,
                                                           new IntPtr((int)(-1) << 16),
                                                           (IntPtr)((y) << 16 | (x)));
                                touchDictionary[e.Id].atdown = e;
                            }
                        }

                        e.Handled = true;
                        return;
                    }

                    if (e.InContact)
                    {
                        XplatUI.driver.SendMessage(IntPtr.Zero, Msg.WM_MOUSEMOVE,
                                                   new IntPtr((int)MsgButtons.MK_LBUTTON),
                                                   (IntPtr)((y) << 16 | (x)));
                    }
                    else
                    {
                        XplatUI.driver.SendMessage(IntPtr.Zero, Msg.WM_MOUSEMOVE, new IntPtr(),
                                                   (IntPtr)((y) << 16 | (x)));
                    }
                }

                if (e.ActionType == SKTouchAction.Pressed && e.MouseButton == SKMouseButton.Left)
                {
                    var now = DateTime.Now;
                    touchDictionary.Add(e.Id, new TouchInfo()
                    {
                        now = e, prev = e, DownTime = now, atdown = e
                    });

                    // right click handler
                    Device.StartTimer(TimeSpan.FromMilliseconds(1000), () =>
                    {
                        /*
                         * Console.WriteLine("Mouse rightclick check true={0} 1={1} {2} {3} {4}",
                         *  touchDictionary.ContainsKey(e.Id),
                         *  touchDictionary.Count,
                         *  touchDictionary.ContainsKey(e.Id) ? touchDictionary[e.Id] : null, now, DateTime.Now);
                         */
                        if (touchDictionary.ContainsKey(e.Id) && touchDictionary.Count == 1)
                        {
                            if (!touchDictionary[e.Id].hasmoved && touchDictionary[e.Id].DownTime == now)
                            {
                                touchDictionary[e.Id].wasright = true;
                                XplatUI.driver.SendMessage(IntPtr.Zero, Msg.WM_RBUTTONDOWN,
                                                           new IntPtr((int)MsgButtons.MK_RBUTTON), (IntPtr)((y) << 16 | (x)));
                                XplatUI.driver.SendMessage(IntPtr.Zero, Msg.WM_RBUTTONUP,
                                                           new IntPtr((int)MsgButtons.MK_RBUTTON), (IntPtr)((y) << 16 | (x)));
                                touchDictionary.Remove(e.Id);
                                return(false);
                            }
                        }
                        return(false);
                    });

                    XplatUI.driver.SendMessage(IntPtr.Zero, Msg.WM_MOUSEMOVE, new IntPtr(), (IntPtr)((y) << 16 | (x)));

                    if (LastPressed.AddMilliseconds(500) > DateTime.Now && Math.Abs(LastPressedX - x) < 20 &&
                        Math.Abs(LastPressedY - y) < 20)
                    {
                        XplatUI.driver.SendMessage(IntPtr.Zero, Msg.WM_LBUTTONDBLCLK, new IntPtr((int)MsgButtons.MK_LBUTTON),
                                                   (IntPtr)((y) << 16 | (x)));
                        LastPressed = DateTime.MinValue;
                    }
                    else
                    {
                        XplatUI.driver.SendMessage(IntPtr.Zero, Msg.WM_LBUTTONDOWN,
                                                   new IntPtr((int)MsgButtons.MK_LBUTTON), (IntPtr)((y) << 16 | (x)));
                    }
                }

                if (e.ActionType == SKTouchAction.Released && e.MouseButton == SKMouseButton.Left)
                {
                    if (touchDictionary.ContainsKey(e.Id) && touchDictionary[e.Id].wasright)
                    {
                        // no action here
                    }
                    else
                    {
                        // only up if we have seen the down
                        if (touchDictionary.ContainsKey(e.Id))
                        {
                            XplatUI.driver.SendMessage(IntPtr.Zero, Msg.WM_LBUTTONUP,
                                                       new IntPtr((int)MsgButtons.MK_LBUTTON), (IntPtr)((y) << 16 | (x)));
                        }
                    }

                    LastPressed  = DateTime.Now;
                    LastPressedX = x;
                    LastPressedY = y;
                    touchDictionary.Remove(e.Id);
                }

                if (e.ActionType == SKTouchAction.Entered)
                {
                    XplatUI.driver.SendMessage(IntPtr.Zero, Msg.WM_MOUSEMOVE, new IntPtr(), (IntPtr)((y) << 16 | (x)));
                    touchDictionary.Clear();
                }

                if (e.ActionType == SKTouchAction.Cancelled)
                {
                    touchDictionary.Clear();
                }

                if (e.ActionType == SKTouchAction.Exited)
                {
                    XplatUI.driver.SendMessage(IntPtr.Zero, Msg.WM_MOUSEMOVE, new IntPtr(), (IntPtr)((y) << 16 | (x)));
                    touchDictionary.Clear();
                }

                e.Handled = true;
            } catch {}
        }
Пример #17
0
 void ISKCanvasViewController.OnTouch(SKTouchEventArgs e)
 {
     OnTouch(e);
 }
Пример #18
0
 // the native view responds to a touch
 protected virtual void OnTouch(SKTouchEventArgs e)
 {
     Touch?.Invoke(this, e);
 }
 private void ThisElement_Touch(object sender, SkiaSharp.Views.Forms.SKTouchEventArgs e)
 {
     Element.StartClick(e.Location.X, e.Location.Y);
 }