void bindTappedHandlers() { // Tapped and point handlers are always managed together // So if one is set the other is also set. if (TappedHandler != null) { return; } // Create the handlers TappedHandler = (s, e) => { TappedFlag = true; e.Handled = false; }; PointHandler = (s, e) => { TappedFlag = true; e.Handled = false; }; // Bind them - this must happen on the UI thread manager.InvokeOnUIThread( () => { manager.DisplayGrid.Tapped += TappedHandler; manager.DisplayGrid.PointerPressed += PointHandler; }); }
public void SetDisplayStringWidth(double width) { manager.InvokeOnUIThread( () => { displayTextBlock.Width = width; }); }
public SnapsCoordinate GetTappedCoordinate() { SnapsCoordinate tappedPositionResult = new SnapsCoordinate(); AutoResetEvent GetTappedCompleteEvent = new AutoResetEvent(false); manager.InvokeOnUIThread( async() => { tappedPositionResult = await GetTappedCoordinateAsync(); GetTappedCompleteEvent.Set(); }); GetTappedCompleteEvent.WaitOne(); return(tappedPositionResult); }
public void SetBackgroundColor(int red, int green, int blue) { manager.InvokeOnUIThread( () => { Color newBackground = Color.FromArgb( 255, SnapsManager.ColorClamp(red), SnapsManager.ColorClamp(green), SnapsManager.ColorClamp(blue)); SolidColorBrush brush = new SolidColorBrush(newBackground); Background = brush; } ); }
public string DoReadMultiLineString(string prompt) { AutoResetEvent gotTextEvent = new AutoResetEvent(false); string result = ""; manager.InvokeOnUIThread( async() => { TextInputTextBox.AcceptsReturn = true; TextInputTextBox.Height = TextBoxMultiLineHeight; result = await ReadStringAsync(prompt); TextInputTextBox.AcceptsReturn = false; TextInputTextBox.Height = TextBoxSingleLineHeight; gotTextEvent.Set(); } ); gotTextEvent.WaitOne(); return(result); }
public string DoSelectFromButtonArray(string[] buttonTexts) { if (buttonTexts.Length > MAX_NO_OF_BUTTONS) { throw new Exception("Too many buttons in call to SelectButton"); } AutoResetEvent gotTextEvent = new AutoResetEvent(false); string result = ""; manager.InvokeOnUIThread( async() => { result = await SelectButtonAsync(buttonTexts); gotTextEvent.Set(); } ); gotTextEvent.WaitOne(); return(result); }
public void SpeakString(string message) { AutoResetEvent speakCompletedEvent = new AutoResetEvent(false); manager.InvokeOnUIThread( async() => { if (soundOutputElement != null) { SpeechSynthesizer synth = new Windows.Media.SpeechSynthesis.SpeechSynthesizer(); // Generate the audio stream from plain text. SpeechSynthesisStream stream = await synth.SynthesizeTextToStreamAsync(message); // Send the stream to the media object. soundOutputElement.SetSource(stream, stream.ContentType); await PlayCompleteSoundAsync(); speakCompletedEvent.Set(); } } ); speakCompletedEvent.WaitOne(); }
public LightPanel(SnapsManager manager, double width, double height, int xCells, int yCells) { this.manager = manager; this.Width = width; this.Height = height; if (xCells > 32 || yCells > 32) { throw new Exception("Maximum panel dimension exceeded. No more than 32 panels in each direction"); } AutoResetEvent lightPanelBuiltEvent = new AutoResetEvent(false); manager.InvokeOnUIThread( async() => { if (this.Opacity != 1) { await FadeElements.FadeElementOpacityAsync(this, 0, 1, new TimeSpan(0, 0, 1)); } clearLightPanel(); lightPanels = new Rectangle[xCells, yCells]; float panelWidth = (float)this.ActualWidth / xCells; float panelHeight = (float)this.ActualHeight / yCells; for (int x = 0; x < xCells; x++) { for (int y = 0; y < yCells; y++) { Rectangle p = new Rectangle(); p.Fill = new SolidColorBrush(Colors.White); p.Stroke = new SolidColorBrush(Colors.Black); p.Width = panelWidth; p.Height = panelHeight; Canvas.SetLeft(p, x * panelWidth); Canvas.SetTop(p, y * panelHeight); lightPanels[x, y] = p; this.Children.Add(p); } } lightPanelBuiltEvent.Set(); }); lightPanelBuiltEvent.WaitOne(); }
public string DoReadPassword(string prompt) { AutoResetEvent gotTextEvent = new AutoResetEvent(false); string result = ""; manager.InvokeOnUIThread( async() => { result = await ReadPasswordAsync(prompt); gotTextEvent.Set(); } ); gotTextEvent.WaitOne(); return(result); }
public void SetPanelCell(int x, int y, int red, int green, int blue) { if (lightPanels == null) { throw new Exception("No LightPanel has been created"); } AutoResetEvent setPanelCompletedEvent = new AutoResetEvent(false); manager.InvokeOnUIThread( () => { if (x < 0) { x = 0; } if (x >= lightPanels.GetLength(0)) { x = lightPanels.GetLength(0) - 1; } if (y < 0) { y = 0; } if (y >= lightPanels.GetLength(1)) { y = lightPanels.GetLength(1) - 1; } Color color = Color.FromArgb( 255, SnapsManager.ColorClamp(red), SnapsManager.ColorClamp(green), SnapsManager.ColorClamp(blue)); Brush b = new SolidColorBrush(color); lightPanels[x, y].Fill = b; //LightPanel[x, y].Stroke = b; setPanelCompletedEvent.Set(); }); setPanelCompletedEvent.WaitOne(); }