예제 #1
0
        private void OnTouch(SKTouchEventArgs args, CameraComponent camera)
        {
            var argsActionType = args.ActionType;
            var argsLocation   = args.Location;
            var argsId         = args.Id;
            var argsInContact  = args.InContact;

            _scene.RunDuringUpdate(
                () =>
            {
                var worldPoint = camera.PixelToWorldMatrix.MapPoint(argsLocation);

                switch (argsActionType)
                {
                case SKTouchAction.Pressed:
                    {
                        // start of a stroke
                        var p = new SKPath();
                        p.MoveTo(worldPoint);

                        _temporaryPaths[argsId] = p;

                        break;
                    }

                case SKTouchAction.Moved:
                    {
                        // the stroke, while pressed
                        if (argsInContact && _temporaryPaths.TryGetValue(argsId, out var foundPath))
                        {
                            foundPath.LineTo(worldPoint);
                        }
                        break;
                    }

                case SKTouchAction.Released:
                    {
                        // end of a stroke
                        if (_temporaryPaths.TryGetValue(argsId, out var foundPath))
                        {
                            _paths.Add(foundPath);
                            _temporaryPaths.Remove(argsId);

                            _camera1.ZoomTo(_paths.SelectMany(path => path.Points));
                            _camera2.ZoomTo(_paths.SelectMany(path => path.Points));
                        }

                        break;
                    }

                case SKTouchAction.Cancelled:
                    {
                        // we don't want that stroke
                        _temporaryPaths.Remove(argsId);
                        break;
                    }
                }
            }
                );

            // we have handled these events
            args.Handled = true;
        }