private void MTouch_Release(object sender, TouchActionEventArgs args) { if (State == eControlInputState.ePressed) { OnClicked(this, EventArgs.Empty); } State = eControlInputState.eNone; }
void RemoveCursor(TouchActionEventArgs args) { Cursors.Remove(args.ID); if (Mode == TouchMode.Pinch) { PinchProcessor.Clear(); if (Cursors.Count == 1) { Mode = TouchMode.Pan; } } if (Cursors.Count == 0) { Mode = TouchMode.Normal; } }
public void OnTouchAction(Element e, TouchActionEventArgs a) { var type = a.Location.TouchType; var change = type != PreviousType; switch (type) { case TouchPoint.eTouchType.eMoved: switch (PreviousType) { case TouchPoint.eTouchType.eReleased: SafeHover(e, a); break; case TouchPoint.eTouchType.ePressed: SafePressedMove(e, a); break; default: throw (new Exception("Cannot determine previous state. It must be pressed or released")); } break; case TouchPoint.eTouchType.ePressed: if (change) { SafePressed(e, a); } break; case TouchPoint.eTouchType.eReleased: SafeReleased(e, a); break; default: throw (new Exception("Do not issue commands other than pressed, released and move from a device.")); } //Moved is not a state change if (type != TouchPoint.eTouchType.eMoved) { PreviousType = type; } }
//Common handlers public void RaiseAction(TouchActionEventArgs Action) { OnTouchAction(Element, Action); }
private void SafeReleased(Element element, TouchActionEventArgs args) { //Stop the tap timer RemoveCursor(args); PlainEvent(Released, element, args); }
private void SafePressedMove(Element element, TouchActionEventArgs args) { ProcessCursor(args); SafeEvent(PressedMoved, element, args); }
//Calls the safe event function for the event private void SafeHover(Element element, TouchActionEventArgs args) { PlainEvent(Hover, element, args); }
private void SafePressed(Element element, TouchActionEventArgs args) { //Start the tap timer TapProcess(); PlainEvent(Pressed, element, args); }
//Triggers a threadsafe event private void SafeEvent(TouchActionEventHandler EventFunction, Element element, TouchActionEventArgs args) { if (EventFunction != null) { Device.BeginInvokeOnMainThread(() => { EventFunction?.Invoke(element, args); }); } }
private void PlainEvent(TouchActionEventHandler EventFunction, Element element, TouchActionEventArgs args) { if (Mode == TouchMode.Normal) { SafeEvent(EventFunction, element, args); } }
void ProcessCursor(TouchActionEventArgs args) { if (!Cursors.ContainsKey(args.ID)) { Cursors.Add(args.ID, new TouchCursor(args.Location)); if (Cursors.Count >= 2) { Mode = TouchMode.Pinch; } } else { var item1 = Cursors[args.ID]; TouchCursor item2 = item1; foreach (var cursor in Cursors) { if (cursor.Key != args.ID) { item2 = cursor.Value; } } var dx = args.Location.Position.X - item1.Position.X; var dy = args.Location.Position.Y - item1.Position.Y; item1.Position = args.Location.Position; switch (Cursors.Count) { case 0: Mode = TouchMode.Normal; break; case 1: { var temp = new TouchPanActionEventArgs(dx, dy); var dist = temp.Distance; if (dist > 0) { if (Mode == TouchMode.Pan || temp.Distance > GestureThreshold) { TapCancel(); Debug.WriteLine("Pan Enabled"); Mode = TouchMode.Pan; Pan?.Invoke(this, temp); } } } break; case 2: { var temp = new TouchPinchActionEventArgs(PinchProcessor); if (temp.Pinch.DistanceDelta >= 0) { Mode = TouchMode.Pinch; if (PinchProcessor.Set(item1.Position, item2.Position)) { TapCancel(); Pinch?.Invoke(this, temp); } } } break; default: Debug.WriteLine("To many cursors."); break; } } }
private void MTouch_Press(object sender, TouchActionEventArgs args) { }
private void MTouch_Release(object sender, TouchActionEventArgs args) => State = eControlInputState.eNone;
private void MTouch_Hover(object sender, TouchActionEventArgs args) => State = eControlInputState.eHover;
private void MTouch_Pressed(object sender, TouchActionEventArgs args) => State = eControlInputState.ePressed;
private void MTouch_Release(object sender, TouchActionEventArgs args) { }
private void MTouch_Hover(object sender, TouchActionEventArgs args) { }