Beispiel #1
0
            public void Update(out bool cancelRing)
            {
                sliceActivated = false;
                cancelRing     = false;
                Vector2 hitUV    = Vector2.Zero;
                Matrix  invWorld = Matrix.Invert(worldMatrix);
                // user clicked on me?

                GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice;
                // Center on screen and just high enough to clear bottom help overlay text.
                Vector2 screenSize = new Vector2(device.Viewport.Width, device.Viewport.Height);

                int sliceIndex = -1;

                for (int i = 0; i < TouchInput.TouchCount; i++)
                {
                    TouchContact touch    = TouchInput.GetTouchContactByIndex(i);
                    Vector2      touchPos = touch.position;

                    touchPos = touch.position - ScreenOffset;
                    hitUV    = TouchInput.GetHitOrtho(touchPos, camera, ref invWorld, useRtCoords: false);

                    if (gotTouchBegan)
                    {
                        if (touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Stationary)
                        {
                            if (WithinPieRing(hitUV))
                            {
                                sliceIndex = GetSliceAtAngle(hitUV);
                                SetFocus(sliceIndex);
                                indexLastHoverItem = indexCurrentHoverItem;
                            }
                        }
                        else if (TouchGestureManager.Get().TapGesture.WasTapped())  //cancel?
                        {
                            float len = hitUV.Length();
                            if (len > outerRadius)
                            {
                                cancelRing     = true;
                                sliceActivated = false;
                            }
                        }

                        // is this a group slice? open its pie!
                        if (!cancelRing && (touch.phase == TouchPhase.Ended))
                        {
                            if (WithinPieRing(hitUV))
                            {
                                sliceIndex = GetSliceAtAngle(hitUV);
                                if (sliceIndex > -1)
                                {
                                    PieDisk nextDisk = slices[sliceIndex].subDisk;
                                    if (nextDisk != null &&
                                        nextDisk.SliceCount() > 0)
                                    {
                                        Object rootParent = Parent;
                                        while ((rootParent as PieMenu) == null)
                                        {
                                            rootParent = (rootParent as PieDisk).Parent;
                                        }
                                        (rootParent as PieMenu).activeDisk = nextDisk;
                                        (rootParent as PieMenu).focusedDiskNo++;

                                        nextDisk.Visible        = true;
                                        nextDisk.ScreenPosition = touch.position;
                                        nextDisk.BuildSlices();
                                    }
                                    else
                                    {
                                        indexPickedItem = sliceIndex;
                                        sliceActivated  = true;
                                    }
                                }
                                else
                                {
                                    Debug.Assert(false);// && "something unexpected failed here.");
                                }
                            }
                        }
                        else
                        {
                            sliceActivated = false;
                        }
                    }

                    if (touch.phase == TouchPhase.Began)
                    {
                        gotTouchBegan = true;
                    }
                    else if (touch.phase == TouchPhase.Ended)
                    {
                        gotTouchBegan = false;
                    }
                }
                if (TouchInput.TouchCount == 0)
                {
                    indexCurrentHoverItem = -1;
                    SetFocus(sliceIndex);
                }
                if ((sliceIndex == -1))
                {
                    indexCurrentHoverItem = -1;
                    SetFocus(sliceIndex);
                    indexLastHoverItem = -1;
                }
            }