private bool TouchedTouchPoint(Point location, GestureTouchPoint touchPoint) { if (location.X >= touchPoint.X && location.X <= (touchPoint.X + touchPoint.Width) && location.Y >= touchPoint.Y && location.Y <= (touchPoint.Y + touchPoint.Height)) { return(true); } return(false); }
public void CreateTouchInterface() { this.Content = null; _touchPoints.Clear(); if (this.VerticalTouchPoints <= 0 || this.HorizontalTouchPoints <= 0) { return; } var grid = new Grid { RowDefinitions = new RowDefinitionCollection(), ColumnDefinitions = new ColumnDefinitionCollection(), HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand }; for (int vIndex = 0; vIndex < this.VerticalTouchPoints; vIndex++) { grid.RowDefinitions.Add(new RowDefinition()); if (vIndex < (this.VerticalTouchPoints - 1)) { grid.RowDefinitions.Add(new RowDefinition() { Height = 20 }); } } for (int hIndex = 0; hIndex < this.HorizontalTouchPoints; hIndex++) { grid.ColumnDefinitions.Add(new ColumnDefinition()); if (hIndex < (this.HorizontalTouchPoints - 1)) { grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = 20 }); } } for (int vIndex = 0; vIndex < grid.RowDefinitions.Count; vIndex += 2) { for (int hIndex = 0; hIndex < grid.ColumnDefinitions.Count; hIndex += 2) { var touchPoint = new GestureTouchPoint() { Text = this.TouchPointText, HighlightText = this.TouchPointHighlightText, FontSize = 30, FontFamily = string.IsNullOrEmpty(this.TouchPointFontFamily) ? "FontAwesome" : this.TouchPointFontFamily, InputTransparent = true, TextColor = this.TouchPointTextColor, HighlightTextColor = this.TouchPointHighlightTextColor, HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Center, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand }; var tpValue = _touchPoints.Count + 1; touchPoint.Value = tpValue.ToString(); touchPoint.SetValue(Grid.RowProperty, vIndex); touchPoint.SetValue(Grid.ColumnProperty, hIndex); grid.Children.Add(touchPoint); _touchPoints.Add(touchPoint); } } this.Content = grid; }