Beispiel #1
0
 public void SegmentCreationEntryPoint()
 {
     var s1 = TouchControlShapeFactory.GetSegment(5, 0);
     var s2 = TouchControlShapeFactory.GetSegment(5, 1);
     var s3 = TouchControlShapeFactory.GetSegment(5, 2);
     var s4 = TouchControlShapeFactory.GetSegment(5, 3);
     var s5 = TouchControlShapeFactory.GetSegment(5, 4);
 }
Beispiel #2
0
        /// <summary>
        /// Creates a touch control
        /// </summary>
        /// <param name="entryCommand"></param>
        /// <param name="parentWindow"></param>
        public TouchControl(TouchBranchCommand entryCommand, Window parentWindow)
        {
            InitializeComponent();
            initializeBrushes();

            var segmentAmount = entryCommand.Commands.Count();
            int index         = 0;

            foreach (var command in entryCommand.Commands)
            {
                // Slice shape:
                var segment = TouchControlShapeFactory.GetSegment(segmentAmount, index);
                var path    = new Path()
                {
                    Data = segment,
                };
                touchCanvas.Children.Add(path);

                // Invisible border that holds and centers the text label:
                var border = new Border()
                {
                    Width            = TEXT_AVAILABLE_WIDTH,
                    Height           = TEXT_AVAILABLE_HEIGHT,
                    IsHitTestVisible = false,
                };
                var textCenter = TouchControlShapeFactory.GetTextPosition(segmentAmount, index);
                Canvas.SetLeft(border, textCenter.X - TEXT_AVAILABLE_WIDTH / 2);
                Canvas.SetRight(border, textCenter.X + TEXT_AVAILABLE_WIDTH / 2);
                Canvas.SetTop(border, textCenter.Y - TEXT_AVAILABLE_HEIGHT / 2);
                Canvas.SetBottom(border, textCenter.Y + TEXT_AVAILABLE_HEIGHT / 2);

                // The text label, centered inside the invisible border
                var text = new TextBlock()
                {
                    Text = command.DisplayName,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment   = VerticalAlignment.Center,
                };
                border.Child = text;
                touchCanvas.Children.Add(border);

                // Give action to the slice. Looking forward to using extended `is` expression in pattern matching (https://github.com/dotnet/roslyn/issues/206)
                var vsCommand     = command as TouchVSCommand;
                var branchCommand = command as TouchBranchCommand;
                if (vsCommand != null)
                {
                    path.TouchUp += (s, e) =>
                    {
                        e.Handled = true;
                        VisualStudioModule.ExecuteCommand(vsCommand.VsCommandName, vsCommand.VsCommandParams);
                        parentWindow.Hide();
                    };
                }
                else if (branchCommand != null)
                {
                    path.TouchUp += (s, e) =>
                    {
                        e.Handled = true;
                        parentWindow.Hide();
                        Show(branchCommand, e);
                    };
                }

                index++;
            }
        }