public async Task Cleanup() { await App.Dispatcher.EnqueueAsync(() => { GazeInput.SetInteraction(_grid, Interaction.Disabled); }); }
public async Task Cleanup() { await App.Dispatcher.ExecuteOnUIThreadAsync(() => { GazeInput.SetInteraction(_grid, Interaction.Disabled); }); }
private void OnPause(object sender, RoutedEventArgs e) { Button button = sender as Button; if (_interactionPaused) { PauseButtonText.Text = "\uE769"; PauseButtonBorder.Background = _toolButtonBrush; GazeInput.SetInteraction(MazeGrid, Interaction.Enabled); GazeInput.SetInteraction(SolveButton, Interaction.Enabled); _interactionPaused = false; if (_isMazeSolved) { ResetMaze(); } } else { PauseButtonText.Text = "\uE768"; PauseButtonBorder.Background = _pausedButtonBrush; GazeInput.SetInteraction(MazeGrid, Interaction.Disabled); GazeInput.SetInteraction(SolveButton, Interaction.Disabled); _interactionPaused = true; } }
private void FlipBatchAnimation_Completed(object sender, CompositionBatchCompletedEventArgs args) { _animationActive = false; if (_secondButton == null) { return; } if (_secondButton.Tag.ToString() != _firstButton.Tag.ToString()) { GazeInput.SetInteraction(buttonMatrix, Interaction.Disabled); _flashTimer.Start(); } else { //Do Match confirmation animation PulseButton(_firstButton); PulseButton(_secondButton); _firstButton = null; _secondButton = null; _remaining -= 2; CheckGameCompletion(); } }
private void OnFlashTimerTick(object sender, object e) { _reverseAnimationActive = true; //Flip button visual var btn1Visual = ElementCompositionPreview.GetElementVisual(_firstButton); var btn2Visual = ElementCompositionPreview.GetElementVisual(_secondButton); var compositor = btn1Visual.Compositor; //Get a visual for the content var btn1Content = VisualTreeHelper.GetChild(VisualTreeHelper.GetChild(_firstButton, 0), 0); var btn1ContentVisual = ElementCompositionPreview.GetElementVisual(btn1Content as FrameworkElement); var btn2Content = VisualTreeHelper.GetChild(VisualTreeHelper.GetChild(_secondButton, 0), 0); var btn2ContentVisual = ElementCompositionPreview.GetElementVisual(btn2Content as FrameworkElement); var easing = compositor.CreateLinearEasingFunction(); if (_reverseFlipBatchAnimation != null) { _reverseFlipBatchAnimation.Completed -= ReverseFlipBatchAnimation_Completed; _reverseFlipBatchAnimation.Dispose(); } _reverseFlipBatchAnimation = compositor.CreateScopedBatch(CompositionBatchTypes.Animation); _reverseFlipBatchAnimation.Completed += ReverseFlipBatchAnimation_Completed; ScalarKeyFrameAnimation flipAnimation = compositor.CreateScalarKeyFrameAnimation(); flipAnimation.InsertKeyFrame(0.000001f, 0); flipAnimation.InsertKeyFrame(0.999999f, -180, easing); flipAnimation.InsertKeyFrame(1f, 0); flipAnimation.Duration = TimeSpan.FromMilliseconds(400); flipAnimation.IterationBehavior = AnimationIterationBehavior.Count; flipAnimation.IterationCount = 1; btn1Visual.CenterPoint = new Vector3((float)(0.5 * _firstButton.ActualWidth), (float)(0.5f * _firstButton.ActualHeight), 0f); btn1Visual.RotationAxis = new Vector3(0.0f, 1f, 0f); btn2Visual.CenterPoint = new Vector3((float)(0.5 * _secondButton.ActualWidth), (float)(0.5f * _secondButton.ActualHeight), 0f); btn2Visual.RotationAxis = new Vector3(0.0f, 1f, 0f); ScalarKeyFrameAnimation appearAnimation = compositor.CreateScalarKeyFrameAnimation(); appearAnimation.InsertKeyFrame(0.0f, 1); appearAnimation.InsertKeyFrame(0.399999f, 1); appearAnimation.InsertKeyFrame(0.4f, 0); appearAnimation.InsertKeyFrame(1f, 0); appearAnimation.Duration = TimeSpan.FromMilliseconds(400); appearAnimation.IterationBehavior = AnimationIterationBehavior.Count; appearAnimation.IterationCount = 1; btn1Visual.StartAnimation(nameof(btn1Visual.RotationAngleInDegrees), flipAnimation); btn2Visual.StartAnimation(nameof(btn2Visual.RotationAngleInDegrees), flipAnimation); btn1ContentVisual.StartAnimation(nameof(btn1ContentVisual.Opacity), appearAnimation); btn2ContentVisual.StartAnimation(nameof(btn2ContentVisual.Opacity), appearAnimation); _reverseFlipBatchAnimation.End(); _flashTimer.Stop(); GazeInput.SetInteraction(buttonMatrix, Interaction.Enabled); }
async void ResetBoard() { PlayAgainText.Visibility = Visibility.Collapsed; _gameOver = false; _firstButton = null; _secondButton = null; _numMoves = 0; MoveCountTextBlock.Text = _numMoves.ToString(); _remaining = _boardRows * _boardColumns; var pairs = (_boardRows * _boardColumns) / 2; List <string> listContent; if (_usePictures) { try { listContent = await GetPicturesContent(pairs); } catch { listContent = GetSymbolContent(pairs); _usePictures = false; } } else { listContent = GetSymbolContent(pairs); } List <Button> listButtons = ShuffleList(GetButtonList()); var compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; if (_resetBatchAnimation != null) { _resetBatchAnimation.Completed -= ResetBatchAnimation_Completed; _resetBatchAnimation.Dispose(); } _resetBatchAnimation = compositor.CreateScopedBatch(CompositionBatchTypes.Animation); _resetBatchAnimation.Completed += ResetBatchAnimation_Completed;; foreach (Button button in listButtons) { FlipCardFaceDown(button); GazeInput.SetInteraction(button, Interaction.Inherited); } _resetBatchAnimation.End(); for (int i = 0; i < _boardRows * _boardColumns; i += 2) { listButtons[i].Tag = listContent[i / 2]; listButtons[i + 1].Tag = listContent[i / 2]; } }
private void SlideBatchAnimation_Completed(object sender, CompositionBatchCompletedEventArgs args) { CheckCompletionAsync(); if (!_gameOver) { _animationActive = false; GazeInput.SetInteraction(GameGrid, Interaction.Enabled); GazeInput.DwellFeedbackProgressBrush = new SolidColorBrush(Colors.White); } }
private void PauseButton_Click(object sender, RoutedEventArgs e) { isPaused = !isPaused; if (isPaused) { PauseButton.Content = "\uE768"; BacktoStartButton.IsEnabled = false; ShowSolutionButton.IsEnabled = false; _ConfirmGuessButton.IsEnabled = false; GazeInput.SetInteraction(PaletteGrid, Interaction.Disabled); GazeInput.SetInteraction(CircleGrid, Interaction.Disabled); foreach (var child in CircleGrid.Children) { Button b = child as Button; if (b != null) { b.IsEnabled = false; } } foreach (var child in PaletteGrid.Children) { Button b = child as Button; b.IsEnabled = false; } } else { PauseButton.Content = "\uE769"; BacktoStartButton.IsEnabled = true; ShowSolutionButton.IsEnabled = true; _ConfirmGuessButton.IsEnabled = true; GazeInput.SetInteraction(PaletteGrid, Interaction.Enabled); GazeInput.SetInteraction(CircleGrid, Interaction.Enabled); foreach (var child in CircleGrid.Children) { Button b = child as Button; if (b != null) { b.IsEnabled = true; } } foreach (var child in PaletteGrid.Children) { Button b = child as Button; b.IsEnabled = true; } } }
void ResetBoard() { PlayAgainText.Visibility = Visibility.Collapsed; _gameOver = false; _numMoves = 0; MoveCountTextBlock.Text = _numMoves.ToString(); for (int i = 0; i < _boardSize; i++) { for (int j = 0; j < _boardSize; j++) { _buttons[i, j].Content = ((i * _boardSize) + j + 1).ToString(); } } _buttons[_boardSize - 1, _boardSize - 1].Content = ""; _blankRow = _boardSize - 1; _blankCol = _boardSize - 1; int shuffleCount = 500; Random rnd = new Random(); while (shuffleCount > 0) { bool changeRow = rnd.Next(0, 2) == 0; bool decrement = rnd.Next(0, 2) == 0; int row = _blankRow; int col = _blankCol; if (changeRow) { row = decrement ? row - 1 : row + 1; } else { col = decrement ? col - 1 : col + 1; } if ((row < 0) || (row >= _boardSize) || (col < 0) || (col >= _boardSize)) { continue; } if (SwapBlank(row, col)) { shuffleCount--; } } GazeInput.SetInteraction(GameGrid, Interaction.Enabled); }
private void FlipBatchAnimation_Completed(object sender, CompositionBatchCompletedEventArgs args) { _animationActive = false; if (_secondButton == null) { return; } if (_secondButton.Tag.ToString() != _firstButton.Tag.ToString()) { GazeInput.SetInteraction(buttonMatrix, Interaction.Disabled); _flashTimer.Start(); } else { //Do Match confirmation animation //Flip button visual var btn1Visual = ElementCompositionPreview.GetElementVisual(_firstButton); var btn2Visual = ElementCompositionPreview.GetElementVisual(_secondButton); var compositor = btn1Visual.Compositor; var springSpeed = 50; GazeInput.SetInteraction(_firstButton, Interaction.Disabled); GazeInput.SetInteraction(_secondButton, Interaction.Disabled); btn1Visual.CenterPoint = new System.Numerics.Vector3((float)_firstButton.ActualWidth / 2, (float)_firstButton.ActualHeight / 2, 0f); btn2Visual.CenterPoint = new System.Numerics.Vector3((float)_secondButton.ActualWidth / 2, (float)_secondButton.ActualHeight / 2, 0f); var scaleAnimation = compositor.CreateSpringVector3Animation(); scaleAnimation.InitialValue = new System.Numerics.Vector3(0.9f, 0.9f, 0f); scaleAnimation.FinalValue = new System.Numerics.Vector3(1.0f, 1.0f, 0f); scaleAnimation.DampingRatio = 0.4f; scaleAnimation.Period = TimeSpan.FromMilliseconds(springSpeed); btn1Visual.StartAnimation(nameof(btn1Visual.Scale), scaleAnimation); btn2Visual.StartAnimation(nameof(btn2Visual.Scale), scaleAnimation); _firstButton = null; _secondButton = null; _remaining -= 2; CheckGameCompletion(); } }
void InitializeButtonArray() { GazeInput.SetInteraction(GameGrid, Interaction.Disabled); GameGrid.Children.Clear(); GameGrid.RowDefinitions.Clear(); GameGrid.ColumnDefinitions.Clear(); for (int row = 0; row < _boardSize; row++) { GameGrid.RowDefinitions.Add(new RowDefinition()); GameGrid.ColumnDefinitions.Add(new ColumnDefinition()); } _buttons = new Button[_boardSize, _boardSize]; for (int row = 0; row < _boardSize; row++) { for (int col = 0; col < _boardSize; col++) { var button = new Button(); button.Background = _solidTileBrush; button.Name = "button" + "_" + col + "_" + row; if (!(row == _boardSize - 1 && col == _boardSize - 1)) { button.Content = ((row * _boardSize) + col + 1).ToString(); } else { button.Content = ""; button.Background = _blankTileBrush; } button.Tag = (row * _boardSize) + col; button.Click += OnButtonClick; button.Style = Resources["ButtonStyle"] as Style; _buttons[row, col] = button;; Grid.SetRow(button, row); Grid.SetColumn(button, col); GameGrid.Children.Add(button); } } GameGrid.UpdateLayout(); }
public async Task Init() { await App.Dispatcher.ExecuteOnUIThreadAsync(() => { var xamlItemsPanelTemplate = @"<Grid xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:g='using:Microsoft.Toolkit.Uwp.Input.GazeInteraction'> <Button HorizontalAlignment='Center' BorderBrush='#7FFFFFFF' g:GazeInput.ThresholdDuration='50' g:GazeInput.FixationDuration='350' g:GazeInput.DwellDuration='400' g:GazeInput.RepeatDelayDuration='400' g:GazeInput.DwellRepeatDuration='400' g:GazeInput.MaxDwellRepeatCount='0' Content='Gaze click here' Width='100' Height='100'/> </Grid>"; _grid = XamlReader.Load(xamlItemsPanelTemplate) as Grid; GazeInput.SetInteraction(_grid, Interaction.Enabled); GazeInput.SetIsCursorVisible(_grid, true); GazeInput.SetCursorRadius(_grid, 20); GazeInput.SetIsSwitchEnabled(_grid, false); _button = (Button)_grid.Children.First(); _button.Click += (sender, e) => { _button.Content = "Clicked"; }; var gazeButtonControl = GazeInput.GetGazeElement(_button); if (gazeButtonControl == null) { gazeButtonControl = new GazeElement(); GazeInput.SetGazeElement(_button, gazeButtonControl); } TestsPage.Instance.SetMainTestContent(_grid); }); }
private void OnPause(object sender, RoutedEventArgs e) { Button button = sender as Button; if (_interactionPaused) { PauseButtonText.Text = "\uE769"; PauseButtonBorder.Background = _toolButtonBrush; GazeInput.SetInteraction(buttonMatrix, Interaction.Enabled); _interactionPaused = false; if (_gameOver) { ResetBoard(); } } else { PauseButtonText.Text = "\uE768"; PauseButtonBorder.Background = _pausedButtonBrush; GazeInput.SetInteraction(buttonMatrix, Interaction.Disabled); _interactionPaused = true; } }
private void MoveToNextColumnOfButtons(int col) { foreach (var child in CircleGrid.Children) { Button b = child as Button; if (b != null) { int c = Grid.GetColumn(b); if (c == col) { b.Visibility = Visibility.Visible; } if (c == col - 1) { b.Click -= OnCircleClick; GazeInput.SetInteraction(b, Interaction.Disabled); } } } int confirmGuessButtonColumn = Grid.GetColumn(_ConfirmGuessButton); Grid.SetColumn(_ConfirmGuessButton, confirmGuessButtonColumn + 1); }
private void Pause_Button_Click(object sender, RoutedEventArgs e) { isPaused = !isPaused; if (!isPaused) { GazeInput.SetInteraction(ShipGrid, Interaction.Disabled); Pause_Button.Content = "\uE769"; foreach (var child in ShipGrid.Children) { Button button = child as Button; button.IsEnabled = true; } } if (isPaused) { GazeInput.SetInteraction(ShipGrid, Interaction.Enabled); Pause_Button.Content = "\uE768"; foreach (var child in ShipGrid.Children) { Button button = child as Button; button.IsEnabled = false; } } }
private void ShowSolutionButton_Click(object sender, RoutedEventArgs e) { Ellipse e1 = _ellipses[0, _maxAttempts]; SolidColorBrush CodePeg1 = new SolidColorBrush(_currentCode[0]); e1.Fill = CodePeg1; Ellipse e2 = _ellipses[1, _maxAttempts]; SolidColorBrush CodePeg2 = new SolidColorBrush(_currentCode[1]); e2.Fill = CodePeg2; Ellipse e3 = _ellipses[2, _maxAttempts]; SolidColorBrush CodePeg3 = new SolidColorBrush(_currentCode[2]); e3.Fill = CodePeg3; Ellipse e4 = _ellipses[3, _maxAttempts]; SolidColorBrush CodePeg4 = new SolidColorBrush(_currentCode[3]); e4.Fill = CodePeg4; GazeInput.SetInteraction(CircleGrid, Interaction.Disabled); foreach (var child in CircleGrid.Children) { Button b = child as Button; if (b != null) { b.IsEnabled = false; GazeInput.SetInteraction(b, Interaction.Disabled); } } _isSolutionVisibleOnBoard = true; EndScreen(false); }
bool SwapBlank(int row, int col) { //Prevent tile slides once puzzle is solved if (DialogGrid.Visibility == Visibility.Visible || _gameOver) { return(false); } if (!((((row == _blankRow - 1) || (row == _blankRow + 1)) && (col == _blankCol)) || (((col == _blankCol - 1) || (col == _blankCol + 1)) && (row == _blankRow)))) { return(false); } GazeInput.DwellFeedbackProgressBrush = new SolidColorBrush(Colors.Transparent); _animationActive = true; GazeInput.SetInteraction(GameGrid, Interaction.Disabled); //Slide button visual Button btn = _buttons[row, col]; Button blankBtn = _buttons[_blankRow, _blankCol]; //Get Visuals for the selected button that is going to appear to slide and for the blank button var btnVisual = ElementCompositionPreview.GetElementVisual(btn); var compositor = btnVisual.Compositor; var blankBtnVisual = ElementCompositionPreview.GetElementVisual(blankBtn); var easing = compositor.CreateLinearEasingFunction(); if (_slideBatchAnimation != null) { _slideBatchAnimation.Completed -= SlideBatchAnimation_Completed; _slideBatchAnimation.Dispose(); } _slideBatchAnimation = compositor.CreateScopedBatch(CompositionBatchTypes.Animation); _slideBatchAnimation.Completed += SlideBatchAnimation_Completed; //Create an animation to first move the blank button with its updated contents to //instantly appear in the position position of the selected button //then slide that button back into its original position var slideAnimation = compositor.CreateVector3KeyFrameAnimation(); slideAnimation.InsertKeyFrame(0f, btnVisual.Offset); slideAnimation.InsertKeyFrame(1f, blankBtnVisual.Offset, easing); slideAnimation.Duration = TimeSpan.FromMilliseconds(500); //Apply the slide animation to the blank button blankBtnVisual.StartAnimation(nameof(btnVisual.Offset), slideAnimation); //Pulse after slide if sliding to correct position if (((_blankRow * _boardSize) + _blankCol + 1).ToString() == btn.Content.ToString()) { var springSpeed = 50; blankBtnVisual.CenterPoint = new System.Numerics.Vector3((float)blankBtn.ActualWidth / 2, (float)blankBtn.ActualHeight / 2, 0f); var scaleAnimation = compositor.CreateSpringVector3Animation(); scaleAnimation.InitialValue = new System.Numerics.Vector3(0.9f, 0.9f, 0f); scaleAnimation.FinalValue = new System.Numerics.Vector3(1.0f, 1.0f, 0f); scaleAnimation.DampingRatio = 0.4f; scaleAnimation.Period = TimeSpan.FromMilliseconds(springSpeed); scaleAnimation.DelayTime = TimeSpan.FromMilliseconds(500); blankBtnVisual.StartAnimation(nameof(blankBtnVisual.Scale), scaleAnimation); } _slideBatchAnimation.End(); //Swap content of the selected button with the blank button and clear the selected button _buttons[_blankRow, _blankCol].Content = _buttons[row, col].Content; _buttons[row, col].Content = ""; _blankRow = row; _blankCol = col; //Note there is some redunancy in the following settings that corrects the UI at board load as well as tile slide //Force selected button to the bottom and the blank button to the top Canvas.SetZIndex(btn, -_boardSize); Canvas.SetZIndex(blankBtn, 0); //Update the background colors of the two buttons to reflect their new condition btn.Background = _blankTileBrush; blankBtn.Background = _solidTileBrush; //Update the visibility to collapse the selected button that is now blank btn.Visibility = Visibility.Collapsed; blankBtn.Visibility = Visibility.Visible; //Disable eye control for the new empty button so that there are no inappropriate dwell indicators GazeInput.SetInteraction(blankBtn, Interaction.Inherited); GazeInput.SetInteraction(btn, Interaction.Disabled); return(true); }
bool SwapBlank(int row, int col) { //Prevent tile slides once puzzle is solved if (DialogGrid.Visibility == Visibility.Visible) { return(false); } if (!((((row == _blankRow - 1) || (row == _blankRow + 1)) && (col == _blankCol)) || (((col == _blankCol - 1) || (col == _blankCol + 1)) && (row == _blankRow)))) { return(false); } //Slide button visual Button btn = _buttons[row, col]; Button blankBtn = _buttons[_blankRow, _blankCol]; //Get Visuals for the selected button that is going to appear to slide and for the blank button var btnVisual = ElementCompositionPreview.GetElementVisual(btn); var compositor = btnVisual.Compositor; var blankBtnVisual = ElementCompositionPreview.GetElementVisual(blankBtn); var easing = compositor.CreateLinearEasingFunction(); //Create an animation to first move the blank button with its updated contents to //instantly appear in the position position of the selected button //then slide that button back into its original position var slideAnimation = compositor.CreateVector3KeyFrameAnimation(); slideAnimation.InsertKeyFrame(0f, btnVisual.Offset); slideAnimation.InsertKeyFrame(1f, blankBtnVisual.Offset, easing); slideAnimation.Duration = TimeSpan.FromMilliseconds(500); //Apply the slide anitmation to the blank button blankBtnVisual.StartAnimation(nameof(btnVisual.Offset), slideAnimation); //Swap content of the selected button with the blank button and clear the selected button _buttons[_blankRow, _blankCol].Content = _buttons[row, col].Content; _buttons[row, col].Content = ""; _blankRow = row; _blankCol = col; //Note there is some redunancy in the following settings that corrects the UI at board load as well as tile slide //Force selected button to the bottom and the blank button to the top Canvas.SetZIndex(btn, -_boardSize); Canvas.SetZIndex(blankBtn, 0); //Update the background colors of the two buttons to reflect their new condition btn.Background = _blankTileBrush; blankBtn.Background = _solidTileBrush; //Update the visibility to collapse the selected button that is now blank btn.Visibility = Visibility.Collapsed; blankBtn.Visibility = Visibility.Visible; //Disable eye control for the new empty button so that there are no inappropriate dwell indicators GazeInput.SetInteraction(blankBtn, Interaction.Enabled); GazeInput.SetInteraction(btn, Interaction.Disabled); return(true); }