void CheckCollision(UITouch touch, IStorage contactBase, TouchActionEventArgs.TouchActionType type) { long id = touch.Handle.ToInt64(); List <int> contactIndexes = new List <int>(); List <Xamarin.Forms.View> contactViews = new List <Xamarin.Forms.View>(); isInContact = false; if (contactBase != null) { var coordinate = touch.LocationInView(null); foreach (var cell in contactBase.GetGridCells()) { var child = cell.GetButton(); var contactRect = new CGRect(child.GetAbsolutePosition().X, child.GetAbsolutePosition().Y, child.Width, child.Height); if (contactRect.Contains(coordinate)) { isInContact = true; contactIndexes.Add(cell.Index); contactViews.Add(child); } } } if (isInContact) { FireEvent(idToTouchDictionary[id], id, type, touch, true, contactIndexes, contactViews); } else { FireEvent(idToTouchDictionary[id], id, type, touch, false, null, null); } }
void CheckCollision(IStorage contactBase, Point coordinate, TouchActionEventArgs.TouchActionType type) { List <int> contactIndexes = new List <int>(); List <Xamarin.Forms.View> contactViews = new List <Xamarin.Forms.View>(); if (contactBase != null) { var controlRect = new Rectangle(fromPixels(GetAbsolutePositionAndroid(Control).X + (Control.Width / 2)) - 10, fromPixels(GetAbsolutePositionAndroid(Control).Y - GetStatusBarHeight() + (Control.Height / 2)) - 10, 20, 20); foreach (var cell in contactBase.GetGridCells()) { var child = cell.GetButton(); var contactRect = new Rectangle(child.GetAbsolutePosition().X, child.GetAbsolutePosition().Y, child.Width, child.Height); if (contactRect.IntersectsWith(controlRect)) { isInContact = true; contactIndexes.Add(cell.Index); contactViews.Add(child); } } } if (isInContact) { FireEvent(this, type, coordinate, contactIndexes, contactViews); } else { FireEvent(this, type, coordinate, null, null); } }
void FireEvent(TouchRecognizer recognizer, long id, TouchActionEventArgs.TouchActionType actionType, UITouch touch, bool isInContact, List <int> contactIndexes, List <Xamarin.Forms.View> contactView) { Console.WriteLine("contact " + isInContact); // Get the method to call for firing events Action <Element, TouchActionEventArgs> onTouchAction = recognizer.touchEffect.OnTouchAction; // Get the location within the view var cgPoint = touch.LocationInView(view); Point point = new Point(cgPoint.X - view.Bounds.Width / 2, cgPoint.Y - view.Bounds.Height / 2); // Call the method onTouchAction(touchEffect.Element, new TouchActionEventArgs(actionType, point, isInContact, contactIndexes, contactView)); isInContact = false; }
void FireEvent(TouchEffect touchEffect, TouchActionEventArgs.TouchActionType actionType, Point pointerLocation, List <int> contactIndexes, List <Xamarin.Forms.View> contactView) { Console.WriteLine("contact " + isInContact); // Get the method to call for firing events Action <Element, TouchActionEventArgs> onTouchAction = touchEffect.touchEffect.OnTouchAction; // Get the location of the pointer within the view touchEffect.Control.GetLocationOnScreen(location); var x = fromPixels(pointerLocation.X - touchEffect.Control.Width / 2); var y = fromPixels(pointerLocation.Y - touchEffect.Control.Height / 2); Point point = new Point(fromPixels(x), fromPixels(y)); // Call the method onTouchAction(touchEffect.Element, new TouchActionEventArgs(actionType, point, isInContact, contactIndexes, contactView)); isInContact = false; }