public MainPage() { this.InitializeComponent(); // Create a reference to the RadialController. var controller = RadialController.CreateForCurrentView(); // Create the items for the menu var itemResize = RadialControllerMenuItem.CreateFromFontGlyph("Resize", "\xE8B9", "Segoe MDL2 Assets"); var itemRotate = RadialControllerMenuItem.CreateFromFontGlyph("Rotate", "\xE7AD", "Segoe MDL2 Assets"); var itemMoveX = RadialControllerMenuItem.CreateFromFontGlyph("MoveX", "\xE8AB", "Segoe MDL2 Assets"); var itemMoveY = RadialControllerMenuItem.CreateFromFontGlyph("MoveY", "\xE8CB", "Segoe MDL2 Assets"); var itemColor = RadialControllerMenuItem.CreateFromFontGlyph("Color", "\xE7E6", "Segoe MDL2 Assets"); // Add the items to the menu controller.Menu.Items.Add(itemResize); controller.Menu.Items.Add(itemRotate); controller.Menu.Items.Add(itemMoveX); controller.Menu.Items.Add(itemMoveY); controller.Menu.Items.Add(itemColor); // Select the correct tool when the item is selected itemResize.Invoked += (s, e) => _currentTool = CurrentTool.Resize; itemRotate.Invoked += (s, e) => _currentTool = CurrentTool.Rotate; itemMoveX.Invoked += (s, e) => _currentTool = CurrentTool.MoveX; itemMoveY.Invoked += (s, e) => _currentTool = CurrentTool.MoveY; itemColor.Invoked += (s, e) => _currentTool = CurrentTool.Color; // Get all named colors and create brushes from them _namedBrushes = typeof(Colors).GetRuntimeProperties().Select(c => new SolidColorBrush((Color)c.GetValue(null))).ToList(); controller.RotationChanged += ControllerRotationChanged; // Leave only the Volume default item - Zoom and Undo won't be used RadialControllerConfiguration config = RadialControllerConfiguration.GetForCurrentView(); config.SetDefaultMenuItems(new[] { RadialControllerSystemMenuItemKind.Volume }); config.ActiveControllerWhenMenuIsSuppressed = controller; config.IsMenuSuppressed = true; controller.ButtonHolding += (s, e) => _isButtonHolding = true; controller.ButtonReleased += (s, e) => _isButtonHolding = false; controller.UseAutomaticHapticFeedback = false; ToolText.Text = _currentTool.ToString(); }
private void ControllerRotationChanged(RadialController sender, RadialControllerRotationChangedEventArgs args) { if (_isButtonHolding) { _currentTool = args.RotationDeltaInDegrees > 0 ? MoveNext(_currentTool) : MovePrevious(_currentTool); ToolText.Text = _currentTool.ToString(); SendHapticFeedback(args.SimpleHapticsController, 1); return; } switch (_currentTool) { case CurrentTool.Resize: Scale.ScaleX += args.RotationDeltaInDegrees / 10; Scale.ScaleY += args.RotationDeltaInDegrees / 10; break; case CurrentTool.Rotate: Rotate.Angle += args.RotationDeltaInDegrees; break; case CurrentTool.MoveX: if (CanMove(Translate, Scale, args.RotationDeltaInDegrees)) { Translate.X += args.RotationDeltaInDegrees; if (args.IsButtonPressed) { Translate.Y += args.RotationDeltaInDegrees; } } else { SendHapticFeedback(args.SimpleHapticsController, 3); } break; case CurrentTool.MoveY: if (CanMove(Translate, Scale, args.RotationDeltaInDegrees)) { Translate.Y += args.RotationDeltaInDegrees; if (args.IsButtonPressed) { Translate.X += args.RotationDeltaInDegrees; } } else { SendHapticFeedback(args.SimpleHapticsController, 3); } break; case CurrentTool.Color: _selBrush += (int)(args.RotationDeltaInDegrees / 10); if (_selBrush >= _namedBrushes.Count) { _selBrush = 0; } if (_selBrush < 0) { _selBrush = _namedBrushes.Count - 1; } Rectangle.Fill = _namedBrushes[(int)_selBrush]; break; default: break; } }