public void OnXamlRendered(FrameworkElement control) { GazeInput.IsDeviceAvailableChanged += GazeInput_IsDeviceAvailableChanged; WarnUserToPlugInDevice(); var buttonControl = control.FindChild("TargetButton") as Button; if (buttonControl != null) { buttonControl.Click += TargetButton_Click; gazeButtonControl = GazeInput.GetGazeElement(buttonControl); if (gazeButtonControl == null) { gazeButtonControl = new GazeElement(); GazeInput.SetGazeElement(buttonControl, gazeButtonControl); } if (gazeButtonControl != null) { gazeButtonControl.DwellProgressFeedback += OnProgressFeedback; gazeButtonControl.Invoked += OnGazeInvoked; gazeButtonControl.StateChanged += GazeButtonControl_StateChanged; } } gazePointer = GazeInput.GetGazePointer(null); CoreWindow.GetForCurrentThread().KeyDown += (CoreWindow sender, KeyEventArgs args) => gazePointer.Click(); }
public void OnXamlRendered(FrameworkElement control) { GazeInput.IsDeviceAvailableChanged += GazeInput_IsDeviceAvailableChanged; WarnUserToPlugInDevice(); var buttonControl = control.FindChildByName("TargetButton") as Button; if (buttonControl != null) { gazeButtonControl = GazeInput.GetGazeElement(buttonControl); if (gazeButtonControl == null) { gazeButtonControl = new GazeElement(); GazeInput.SetGazeElement(buttonControl, gazeButtonControl); } if (gazeButtonControl != null) { gazeButtonControl.DwellProgressFeedback += OnProgressFeedback; gazeButtonControl.Invoked += OnGazeInvoked; gazeButtonControl.StateChanged += GazeButtonControl_StateChanged; } } }
public BlankPage1() { this.InitializeComponent(); gazePointer = GazeInput.GetGazePointer(null); gazeButtonControl = GazeInput.GetGazeElement(GazeBlock); gazeButtonControl = new GazeElement(); GazeInput.SetGazeElement(GazeBlock, gazeButtonControl); gazeButtonControl.StateChanged += GazeButtonControl_StateChanged; // Add the object to our dictionary along with a new stopwatch stopwatchesByObject.Add(gazeButtonControl, new Stopwatch());
private GazeElement GetGazeButtonControl(Control c) { GazeElement gazeButtonControl; // First try to get the control gazeButtonControl = GazeInput.GetGazeElement(c); if (gazeButtonControl != null) { return(gazeButtonControl); } // If it doesn't exist - make it gazeButtonControl = new GazeElement(); GazeInput.SetGazeElement(c, gazeButtonControl); return(gazeButtonControl); }
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); }); }
public ChaosControl(int largeSize, int tinySize, SolidColorBrush foregroundColor, SolidColorBrush backgroundColor, string title = "", string xLabel = "", string yLabel = "") { // -------- Parameters -------- InstanceNumber = NumberOfControls; NumberOfControls++; // -------- UI Elements -------- ChaosForegroundColor = foregroundColor; ChaosBackgroundColor = backgroundColor; ChaosCanvas = new Canvas(); ChaosCanvas.Width = largeSize; ChaosCanvas.Height = largeSize; ChaosCanvas.Visibility = Visibility.Collapsed; ChaosBorder = new Border(); ChaosBorder.Width = largeSize; ChaosBorder.Height = largeSize; ChaosBorder.Background = backgroundColor; ChaosBorder.CornerRadius = new CornerRadius(15); ChaosShadow = new DropShadowPanel(); ChaosShadow.Color = Windows.UI.Colors.Black; ChaosShadow.BlurRadius = 7; ChaosShadow.ShadowOpacity = 1; ChaosShadow.OffsetX = 0; ChaosShadow.OffsetY = 0; ChaosEllipse = new Ellipse(); ChaosEllipse.Fill = foregroundColor; ChaosEllipse.Height = 30; ChaosEllipse.Width = 30; ChaosEllipse.Stroke = new SolidColorBrush((Color)Application.Current.Resources["SystemAltHighColor"]); ChaosEllipse.StrokeThickness = 4; TargetEllipse = new Ellipse(); TargetEllipse.Fill = new SolidColorBrush(Colors.Transparent); TargetEllipse.Height = 30; TargetEllipse.Width = 30; TargetEllipse.Stroke = new SolidColorBrush((Color)Application.Current.Resources["SystemAltHighColor"]); TargetEllipse.StrokeThickness = 4; TargetEllipse.Opacity = 0; InnerNotifier = new TextBlock(); InnerNotifier.Margin = new Thickness(0, TargetEllipse.Height, 0, 0); InnerNotifier.Text = "recording"; InnerNotifier.Foreground = new SolidColorBrush((Color)Application.Current.Resources["SystemAltHighColor"]); InnerNotifier.Style = (Style)Application.Current.Resources["SubtitleTextBlockStyle"]; InnerNotifier.Opacity = 0; ChaosButton = new Button(); ChaosButton.Width = largeSize; ChaosButton.Height = largeSize; ChaosButton.Background = new SolidColorBrush(Windows.UI.Colors.Transparent); XLabel = new TextBlock(); Canvas.SetTop(XLabel, ChaosCanvas.Height); XLabel.Text = xLabel; XLabel.Style = (Style)Application.Current.Resources["SubheaderTextBlockStyle"]; YLabel = new TextBlock(); Canvas.SetTop(YLabel, ChaosCanvas.Height); YLabel.Text = yLabel; YLabel.Style = (Style)Application.Current.Resources["SubheaderTextBlockStyle"]; Canvas.SetLeft(YLabel, -50); YLabel.Rotate(-90, 0, 0, 0).Start(); ChaosCanvas.Children.Add(ChaosBorder); ChaosCanvas.Children.Add(XLabel); ChaosCanvas.Children.Add(YLabel); ChaosCanvas.Children.Add(TargetEllipse); ChaosCanvas.Children.Add(InnerNotifier); ChaosCanvas.Children.Add(ChaosShadow); ChaosShadow.Content = ChaosEllipse; ChaosCanvas.Children.Add(ChaosButton); // -------- The Ghosts -------- GhostCanvas = new Canvas(); GhostCanvas.Width = ChaosCanvas.Width; GhostCanvas.Height = ChaosCanvas.Height; GhostCanvas.Background = new SolidColorBrush(Windows.UI.Colors.Transparent); GhostCanvas.Visibility = Visibility.Visible; GhostShadow = new DropShadowPanel(); GhostShadow.Color = foregroundColor.Color; GhostShadow.BlurRadius = ChaosShadow.BlurRadius; GhostShadow.ShadowOpacity = ChaosShadow.ShadowOpacity; GhostShadow.OffsetX = ChaosShadow.OffsetX; GhostShadow.OffsetY = ChaosShadow.OffsetY; GhostEllipse = new Ellipse(); GhostEllipse.Fill = ChaosEllipse.Fill; GhostEllipse.Height = ChaosEllipse.Height; GhostEllipse.Width = ChaosEllipse.Width; GhostEllipse.Stroke = ChaosEllipse.Stroke; GhostEllipse.StrokeThickness = ChaosEllipse.StrokeThickness; GhostEllipse.Fade((float)0.6, 0).Start(); GhostShadow.Content = GhostEllipse; GhostCanvas.Children.Add(GhostShadow); // -------- Now the Tiny stuff -------- ChaosButtonsNoLabel = new StackPanel(); ChaosButtonsNoLabel.Orientation = Orientation.Horizontal; ChaosButtons = new StackPanel(); ChaosButtons.Margin = new Thickness(10); ChaosTitle = new TextBlock(); ChaosTitle.Style = (Style)Application.Current.Resources["SubtitleTextBlockStyle"]; ChaosTitle.Margin = new Thickness(10, 0, 10, 0); ChaosTitle.Text = title; TinyCanvas = new Canvas(); TinyCanvas.Width = tinySize; TinyCanvas.Height = tinySize; TinyCanvas.Margin = new Thickness(10); TinyBorder = new Border(); TinyBorder.Width = tinySize; TinyBorder.Height = tinySize; TinyBorder.Background = backgroundColor; TinyBorder.CornerRadius = new CornerRadius(10); TinyEllipse = new Ellipse(); TinyEllipse.Fill = foregroundColor; TinyEllipse.Height = 15; TinyEllipse.Width = 15; TinyEllipse.Stroke = new SolidColorBrush((Color)Application.Current.Resources["SystemAltHighColor"]); TinyEllipse.StrokeThickness = 2; TinyButton = new Button(); TinyButton.Width = tinySize; TinyButton.Height = tinySize; TinyButton.Background = new SolidColorBrush(Windows.UI.Colors.Transparent); TinyCanvas.Children.Add(TinyBorder); TinyCanvas.Children.Add(TinyEllipse); TinyCanvas.Children.Add(TinyButton); SnapshotButton = new ToggleButton(); SnapshotButton.Width = tinySize; SnapshotButton.Height = tinySize; SnapshotButton.Margin = new Thickness(10); SnapshotButton.FontFamily = new FontFamily("Segoe MDL2 Assets"); SnapshotButton.Content = "\uEA3A"; SnapshotButton.FontWeight = FontWeights.Medium; ChaosNotifier = new InAppNotification(); ChaosNotifier.Background = foregroundColor; ChaosNotifier.Foreground = new SolidColorBrush((Color)Application.Current.Resources["SystemAltHighColor"]); ChaosNotifier.ShowDismissButton = false; ChaosNotifier.HorizontalAlignment = HorizontalAlignment.Left; ChaosNotifier.VerticalOffset = 0; ChaosNotifier.HorizontalOffset = -200; ChaosNotifier.FontFamily = new FontFamily("Segoe MDL2 Assets"); ChaosNotifier.HorizontalContentAlignment = HorizontalAlignment.Center; ChaosNotifier.FontSize = 32; ChaosNotifier.Margin = new Thickness(0, 0, 25, 25); ChaosButtonsNoLabel.Children.Add(SnapshotButton); ChaosButtonsNoLabel.Children.Add(TinyCanvas); ChaosButtons.Children.Add(ChaosButtonsNoLabel); ChaosButtons.Children.Add(ChaosTitle); TinyCanvas.Children.Add(ChaosNotifier); // -------- Now the events -------- TinyButton.Click += TinyButton_Click; GazeElement chaosButtonControl = new GazeElement(); GazeInput.SetGazeElement(ChaosButton, chaosButtonControl); chaosButtonControl.DwellProgressFeedback += GazeElement_DwellProgressFeedback; chaosButtonControl.StateChanged += ChaosButtonControl_StateChanged; GazeElement snapshotButtonControl = new GazeElement(); GazeInput.SetGazeElement(SnapshotButton, snapshotButtonControl); snapshotButtonControl.StateChanged += SnapshotButtonControl_StateChanged; SnapshotButton.Click += SnapshotButton_Click; // All automation is hardcoded at one second now // Faster times make it harder to move off the grid and accidentally trigger the ellipse // However, possibly in the future we will want to change this timing and/or sync it to the beat SnapshotPlayer = new DispatcherTimer(); SnapshotPlayer.Tick += MoveEllipse; SnapshotPlayer.Interval = new TimeSpan(0, 0, 1); // -------- Finally add to our list -------- AllControls.Add(this); }