public MainWindow() { InitializeComponent(); this._Puzzle = new DotPuzzle(); this._Puzzle.Dots.Add(new Point(200, 300)); this._Puzzle.Dots.Add(new Point(1600, 300)); this._Puzzle.Dots.Add(new Point(1650, 400)); this._Puzzle.Dots.Add(new Point(1600, 500)); this._Puzzle.Dots.Add(new Point(1000, 500)); this._Puzzle.Dots.Add(new Point(1000, 600)); this._Puzzle.Dots.Add(new Point(1200, 700)); this._Puzzle.Dots.Add(new Point(1150, 800)); this._Puzzle.Dots.Add(new Point(750, 800)); this._Puzzle.Dots.Add(new Point(700, 700)); this._Puzzle.Dots.Add(new Point(900, 600)); this._Puzzle.Dots.Add(new Point(900, 500)); this._Puzzle.Dots.Add(new Point(200, 500)); this._Puzzle.Dots.Add(new Point(150, 400)); this._PuzzleDotIndex = -1; this.Loaded += (s, e) => { KinectSensor.KinectSensors.StatusChanged += KinectSensors_StatusChanged; this.KinectDevice = KinectSensor.KinectSensors.FirstOrDefault(x => x.Status == KinectStatus.Connected); DrawPuzzle(this._Puzzle); }; }
// Listing 4-10 private void DrawPuzzle(DotPuzzle puzzle) { PuzzleBoardElement.Children.Clear(); if (puzzle != null) { for (int i = 0; i < puzzle.Dots.Count; i++) { Grid dotContainer = new Grid(); dotContainer.Width = 50; dotContainer.Height = 50; dotContainer.Children.Add(new Ellipse { Fill = Brushes.Gray }); TextBlock dotLabel = new TextBlock(); dotLabel.Text = (i + 1).ToString(); dotLabel.Foreground = Brushes.White; dotLabel.FontSize = 24; dotLabel.HorizontalAlignment = HorizontalAlignment.Center; dotLabel.VerticalAlignment = VerticalAlignment.Center; dotContainer.Children.Add(dotLabel); //Position the UI element centered on the dot point Canvas.SetTop(dotContainer, puzzle.Dots[i].Y - (dotContainer.Height / 2)); Canvas.SetLeft(dotContainer, puzzle.Dots[i].X - (dotContainer.Width / 2)); PuzzleBoardElement.Children.Add(dotContainer); } } }
public void DrawPuzzle(DotPuzzle puzzle) { PuzzleBoardElement.Children.Clear(); if (puzzle != null) { for (int i = 0; i < puzzle.Dots.Count; i++) { Grid dotContainer = new Grid(); dotContainer.Width = 70; dotContainer.Height = 70; dotContainer.Children.Add(new Ellipse { Fill = Brushes.Gray }); TextBlock dotLabel = new TextBlock(); dotLabel.Text = (i + 1).ToString(); dotLabel.Foreground = Brushes.White; dotLabel.FontSize = 36; dotLabel.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; dotLabel.VerticalAlignment = System.Windows.VerticalAlignment.Center; dotContainer.Children.Add(dotLabel); //draw dots in UI Canvas.SetTop(dotContainer, puzzle.Dots[i].Y - (dotContainer.Height / 2) - 10); Canvas.SetLeft(dotContainer, puzzle.Dots[i].X - (dotContainer.Width / 2) - 30); PuzzleBoardElement.Children.Add(dotContainer); } } }
public MainWindow() { InitializeComponent(); puzzle = new DotPuzzle(); epuzzle = new eDotPuzzle(); puzzleDotsAdd(); this.puzzleDotIndex = -1; KinectSensor.KinectSensors.StatusChanged += KinectSensors_StatusChanged; this.KinectDevice = KinectSensor.KinectSensors.FirstOrDefault(x => x.Status == KinectStatus.Connected); DrawPuzzle(MainWindow.puzzle); }