Boolean handleGesture(Gesture gesture, String modeButtonName, Boolean buttonOn) { if (gesture.gestureStart()) { buttonOn = !buttonOn; turnOffOtherButtons(modeButtonName, buttonOn); } return buttonOn; }
// This method gets called every time the Kinect returns a new frame private void Render() { if (skeleton != null) { EllipseCanvas.Children.Clear(); // Allow user to resize window EllipseCanvas.Height = Canvas.ActualHeight; EllipseCanvas.Width = Canvas.ActualWidth; if (this.pliesGesture == null) { this.pliesGesture = new Gesture(EllipseCanvas, skeleton, (Rectangle)Canvas.FindName("pliesButton"), (TextBlock)Canvas.FindName("pliesTitle"), this.pliesMode); } if (this.firstPositionGesture == null) { this.firstPositionGesture = new Gesture(EllipseCanvas, skeleton, (Rectangle)Canvas.FindName("firstPositionButton"), (TextBlock)Canvas.FindName("firstPositionTitle"), this.firstPositionMode); } this.pliesMode = handleGesture(this.pliesGesture, "pliesButton", this.pliesMode); this.firstPositionMode = handleGesture(this.firstPositionGesture, "firstPositionButton", this.firstPositionMode); DrawSkeleton(skeleton, FRONT_VIEW); DrawSkeleton(skeleton, SIDE_VIEW); if (pliesMode) { // Show title TextBlock title = (TextBlock)Canvas.FindName("pliesTitle"); title.Visibility = Visibility.Visible; if (this.plie == null) { this.plie = new Plie(EllipseCanvas, skeleton); } // If the user successfully completes a plie or breaks out of the plie movement sequence, // set our Plie object to null so we know to start over with a new Plie object when render gets // called again. if (this.plie.gestureComplete && this.plie.position.showSuccessBanner("plieCompletedImage") || !this.plie.gestureComplete && !this.plie.trackPlie()) { this.plie = null; } } if (firstPositionMode) { // Show title TextBlock title = (TextBlock)Canvas.FindName("firstPositionTitle"); title.Visibility = Visibility.Visible; if (this.position == null) { this.position = new Position(EllipseCanvas, skeleton); } // If the user successfully completes a first position or breaks out of the first position // movement sequence, set our Position to null so we know to start over with a new Postition // when render gets called again. if (this.position.gestureComplete && this.position.showSuccessBanner("firstPositionCompletedImage") || !this.position.firstPosition()) { this.position = null; } } } else { System.Console.WriteLine("skeleton is null"); } }