Exemplo n.º 1
0
        private protected override void OnTouchesMovedUI(List <CCTouch> touches, CCEvent touchEvent)
        {
            switch (touches.Count)
            {
            case 1:
            {
                var touch = touches[0];
                if (Rows == 1)
                {
                    var rect = BoundingBoxTransformedToWorld;
                    rect = new CCRect(rect.MinX, rect.MinY + rect.Size.Height / 4, rect.Size.Width, rect.Size.Height / 2);
                    if (!rect.ContainsPoint(touch.Location))
                    {
                        var boxSize = BoxSize * GetTotalScale();
                        foreach (var node in Collection)
                        {
                            var    ccNode  = (CCNode)node;
                            CCRect boxRect = new CCRect(ccNode.PositionWorldspace.X - boxSize.Width / 2, ccNode.PositionWorldspace.Y - boxSize.Height / 2, boxSize.Width, boxSize.Height);
                            if (boxRect.ContainsPoint(new CCPoint(touch.Location.X, touch.StartLocation.Y)))
                            {
                                RemoveFromCollection(node, touch);
                                Pressed = false;
                                return;
                            }
                        }
                    }
                }
                else if (Columns == 1)
                {
                    var rect = BoundingBoxTransformedToWorld;
                    rect = new CCRect(rect.MinX + rect.Size.Width / 4, rect.MinY, rect.Size.Width / 2, rect.Size.Height);
                    if (!rect.ContainsPoint(touch.Location))
                    {
                        var boxSize = BoxSize * GetTotalScale();
                        foreach (var node in Collection)
                        {
                            var    ccNode  = (CCNode)node;
                            CCRect boxRect = new CCRect(ccNode.PositionWorldspace.X - boxSize.Width / 2, ccNode.PositionWorldspace.Y - boxSize.Height / 2, boxSize.Width, boxSize.Height);
                            if (boxRect.ContainsPoint(new CCPoint(touch.StartLocation.X, touch.Location.Y)))
                            {
                                RemoveFromCollection(node, touch);
                                Pressed = false;
                                return;
                            }
                        }
                    }
                }
                // move the collectionNode via scroller
                Scroller.OnTouchesMoved(touches, touchEvent);
            }
            break;

            default:
                break;
            }
        }
Exemplo n.º 2
0
        private protected override void OnTouchesMovedUI(List <CCTouch> touches, CCEvent touchEvent)
        {
            switch (touches.Count)
            {
            case 1:
            {
                // move the collectionNode via scroller
                Scroller.OnTouchesMoved(touches, touchEvent);
            }
            break;

            default:
                break;
            }
        }
Exemplo n.º 3
0
        private protected void OnTouchesMovedMoveAndZoom(List <CCTouch> touches, CCEvent touchEvent)
        {
            if (!Pressed)
            {
                return;
            }
            //Console.WriteLine("touches.Count: " + touches.Count);
            //Console.WriteLine("TouchCount: " + TouchCount);
            switch (touches.Count)
            {
            case 1:
            {
                if (TouchCount == 2)
                {
                    goto zoom;
                }
                // move the camera
                if (Scroller != null)
                {
                    Scroller.OnTouchesMoved(touches, touchEvent);
                }
            }
            break;

            case 2:
zoom:
                {
                    // check for zoom
                    float   zoomFactor = 1f;
                    CCTouch touch1     = touches[0];
                    CCTouch touch2     = null;
                    CCPoint touch1Loc  = touch1.Location;
                    CCPoint touch2Loc  = CCPoint.Zero;
                    if (touches.Count == 2)
                    {
                        touch2     = touches[1];
                        touch2Loc  = touch2.Location;
                        zoomFactor = MyTouchExtensions.GetZoom(touch1, touch2);
                    }
                    else
                    {
                        foreach (var touch in ActiveTouches.Keys)
                        {
                            if (touch != touch1)
                            {
                                touch2Loc = ActiveTouches[touch];
                            }
                        }
                        zoomFactor = MyTouchExtensions.GetZoomOneTouchMoving(touch1, touch2Loc);
                    }
                    if (!float.IsNaN(zoomFactor))
                    {
                        var oldCameraSize = new CCSize(CameraSize.Width, CameraSize.Height);
                        CameraSize = new CCSize(oldCameraSize.Width * zoomFactor, oldCameraSize.Height * zoomFactor);
                        float   dw          = CameraSize.Width - oldCameraSize.Width;
                        float   dh          = CameraSize.Height - oldCameraSize.Height;
                        CCPoint touchCenter = new CCPoint((touch1Loc.X + touch2Loc.X) / 2, (touch1Loc.Y + touch2Loc.Y) / 2);
                        float   relativeX   = (touchCenter.X - CameraPosition.X) / oldCameraSize.Width;
                        float   relativeY   = (touchCenter.Y - CameraPosition.Y) / oldCameraSize.Height;
                        CameraPosition = new CCPoint(CameraPosition.X - dw * relativeX, CameraPosition.Y - dh * relativeY);
                        UpdateCamera();
                    }
                }
                break;

            default:
                break;
            }
        }