private void RenderDisk(PieDisk disk, int depth) { Matrix invWorld = Matrix.Invert(disk.worldMatrix); Vector2 orthoPos = TouchInput.GetHitOrtho(disk.ScreenPosition, camera, ref invWorld, useRtCoords: false); for (int i = 0; i < disk.slices.Count; i++) { PieMenuSlice pieSlice = disk.slices[i]; RenderBastardPieSlice(pieSlice, orthoPos, disk.ScreenOffset, depth); } for (int i = 0; i < disk.slices.Count; i++) { PieMenuSlice pieSlice = disk.slices[i]; if (pieSlice.sliceType == PieSelector.SliceType.group) { PieDisk subDisk = pieSlice.subDisk; if (subDisk.Visible) { RenderDisk(subDisk, depth + 1); } } } }
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; } }