public GestureArg(UIElement sender, GestureResult result, TouchDevice device) : base() { this.Result = result; this.Device = device; this.Sender = sender; }
public override GestureResult CheckGesture(Body body) { GestureResult gestureResult = ANDGestures(LeftPosition(body), RightPosition(body)); //logger.Debug($"Compared Result : {gestureResult}"); return(gestureResult); }
public override void onUpdate(float delta) { if (isCollecting()) { if (inputSource.onUpdate(delta)) { onNewPoint(inputSource.LastAddedPoint); } if (endRecording()) { endCollectingInput(); lastGesture = recognizeGesture(); if (newGestureDetected != null) { newGestureDetected(lastGesture); } inputSource.resetRecording(); } } else { if (startRecording()) { startCollectingInput(); } } }
private void GestureEnd(TouchDevice device) { if (this.GestureStatus.Count <= 0 || this.AssociatedObject.TouchesOver.Count() <= 1 || this.isGestureBehavior) { Console.WriteLine("Tap time is " + (DateTime.Now - this.gestTimeRecord).TotalMilliseconds); if (this.isGestureBehavior == false && (DateTime.Now - this.gestTimeRecord).TotalMilliseconds < 350) { this.isGestureBehavior = true;; this.currentGesture = GestureResult.Tap; GestureArg arg = new GestureArg(this.AssociatedObject, this.currentGesture, device); this.FireEvent(arg); this.GestureEnd(device); } else { this.isGestureBehavior = false; this.currentGesture = GestureResult.End; if (this.GestureStatus.Count > 0) { this.GestureStatus.Clear(); } this.gestureCount = 0; GestureArg arg = new GestureArg(this.AssociatedObject, this.currentGesture, device); this.FireEvent(arg); } } }
private bool CheckIsSimpleZoom(ManipulationDeltaEventArgs e) { if ((DateTime.Now - this.gestureTime).TotalMilliseconds > 150) { bool isInTime = this.IsFingersTouchInTime(); if (this.IsZoom(e.CumulativeManipulation.Scale) && isInTime) { double distance = this.GetMinFingerDistance(e); if (distance > GestureConsts.Current.OneFingerSize && e.CumulativeManipulation.Translation.Length < GestureConsts.Current.MultiFingerZoomLimitDrag * 2) { if (this.OnGestureDetector != null) { this.currentResult = GestureResult.Zoom; GestureArg arg = new GestureArg(this.AssociatedObject, this.currentResult, (TouchDevice)e.Manipulators.First()); arg.Tag = e.DeltaManipulation.Scale; this.OnGestureDetector(this.AssociatedObject, arg); } this.isGestureBehavior = true; } return(true); } } return(false); }
public void UpdateGesture(Body data) { ulong id = data.TrackingId; if (!currentGesturePart.ContainsKey(data.TrackingId)) { currentGesturePart.Add(data.TrackingId, 0); } if (!frameCount.ContainsKey(id)) { frameCount.Add(data.TrackingId, 0); } if (!framePauseCount.ContainsKey(id)) { framePauseCount.Add(data.TrackingId, 10); } if (!paused.ContainsKey(id)) { paused.Add(data.TrackingId, false); } if (this.paused[id]) { if (this.frameCount[id] >= this.framePauseCount[id]) { this.paused[id] = false; } this.frameCount[id]++; } GestureResult result = this.gestureParts[this.currentGesturePart[data.TrackingId]].CheckGesture(data); if (result == GestureResult.Suceed) { if (this.currentGesturePart[data.TrackingId] + 1 < this.gestureParts.Length) { this.currentGesturePart[data.TrackingId]++; this.ResetPause(id); } else { if (this.GestureRecognised != null) { this.GestureRecognised(this, new GestureEventArgs(this.gestureParts[this.currentGesturePart[data.TrackingId]].GetGestureType(), data.TrackingId)); this.Reset(id); } } } else if (result == GestureResult.Fail || this.frameCount[id] == 80) { this.Reset(id); } else { this.frameCount[id] = 0; this.framePauseCount[id] = 5; this.paused[id] = true; } }
/// <summary> /// Checks that non-dominant hand is in the IDLE state then calls PerformDominantCheck /// </summary> public override GestureResult CheckGesture(Body body) { GestureResult offHandResult = OffHandCheck(body); if (offHandResult == GestureResult.SUCEEDED) { return(PerformDominantCheck(body)); } return(offHandResult); // Can be PAUSED }
private void PerformCheck(Body body) { //if (relativeGestureSegment is TwoHandGestureSegment && currentGestureSegment != 0) logger.Trace("Resuming"); RelativeGestureSegment relativeGestureSegment = gestureSegments[currentGestureSegment]; GestureResult result = relativeGestureSegment.CheckGesture(body); //if ((Type == GestureType.RIGHT_SWIPE_DOWN_LEFT_HAND_RAISED) && (currentGestureSegment != 0 || result == GestureResult.SUCEEDED)) //{ // logger.Debug($"{Type} : {currentGestureSegment} : {result}"); //} if (result == GestureResult.PAUSED && relativeGestureSegment is TwoHandGestureSegment && currentGestureSegment != 0) { logger.Debug($"{Type} : {currentGestureSegment} : {result}"); } if (result == GestureResult.SUCEEDED) { //if (relativeGestureSegment is TwoHandGestureSegment) logger.Debug($"{Type} Succeeded at Step {currentGestureSegment + 1}"); if (currentGestureSegment + 1 < gestureSegments.Length) { //if (relativeGestureSegment is TwoHandGestureSegment) logger.Trace("PAUSING"); currentGestureSegment++; frameCount = 0; pausedFrameCount = SuccessfulPausedFrameCount(); paused = true; } else { RaiseGestureRecognised(); Reset(); } } else if (result == GestureResult.FAILED || frameCount == MAX_FRAME_COUNT) { //if (currentGestureSegment > 0) //{ // if (result == GestureResult.FAILED) // { // logger.Debug($"{Type} Failed at Step {currentGestureSegment + 1} : FAILED"); // } // else // { // logger.Debug($"{Type} Failed at Step {currentGestureSegment + 1} : MAX_FRAME_COUNT hit"); // } //} Reset(); } else { frameCount++; pausedFrameCount = FailedPausedFrameCount(); paused = true; } }
private void FireHoldEvent(TouchDevice device, Point newCenter) { this.currentGesture = GestureResult.Hold; GestureArg arg = new GestureArg(this.AssociatedObject, this.currentGesture, device); Vector vector = this.GetCumulativeTransitionResultParamater(newCenter); arg.Tag = vector; arg.Info = this.GestureStatus; this.FireEvent(arg); this.isGestureBehavior = true;; }
/// <summary> /// Used by <see cref="GesturesContentView"/>. /// </summary> /// <param name="gesture">The resulting gesture<see cref="GestureResult"/></param> /// <returns>True if the gesture was handled,false otherwise</returns> internal bool ProcessGesture(GestureResult gesture) { //Check the view stack first if (ExcludeChildren && gesture.ViewStack != null && gesture.ViewStack.Count != 0 && _viewInterests.All(x => x.View != gesture.ViewStack[0])) { return(false); //The innermost (source) is not an actual interested view } var interestedview = InterestedView(gesture.Origin); if (interestedview == null) { return(false); } gesture.StartView = interestedview.View; //Check for perfect matches first var interest = interestedview.Interests.Where(x => x.GestureType == gesture.GestureType && ( (x.Direction & Directionality.HorizontalMask) == (gesture.Direction & Directionality.HorizontalMask) && (x.Direction & Directionality.VerticalMask) == (gesture.Direction & Directionality.VerticalMask)) ).ToList(); if (!interest.Any()) { //Check for match on the dominant axis var horizontaldirection = gesture.HorizontalDistance < gesture.VerticalDistance ? Directionality.None : gesture.Direction & Directionality.HorizontalMask; var verticaldirection = gesture.HorizontalDistance < gesture.VerticalDistance ? gesture.Direction & Directionality.VerticalMask : Directionality.None; //Swap in the new direction so the user knows what the final match was gesture.Direction = horizontaldirection | verticaldirection; interest = interestedview.Interests.Where(x => x.GestureType == gesture.GestureType && (x.Direction & Directionality.HorizontalMask) == horizontaldirection && (x.Direction & Directionality.VerticalMask) == verticaldirection).ToList(); } //Winnow out the swipe gestures to match on either a perfect direction match (ie Up,Left) or based on the dominant axis //Is there one or more interest int this gesture? if (!interest.Any()) { return(false); } var final = interest.First(); //Finish setting up our gestureresult gesture.Origin = new Point(Math.Max(gesture.Origin.X - interestedview.View.X, 0), Math.Max(gesture.Origin.Y - interestedview.View.Y, 0)); SatisfyInterest(final, gesture); return(true); }
private bool CheckIsDoubleTap(TouchDevice device) { if (this.AssociatedObject.TouchesOver.Count() == 1) { if (this.preTouchUpInfo != null && this.lastTouchUpInfo == null) { bool isVaild = this.preTouchUpInfo.IsVaild(DateTime.Now); if (isVaild == false) { this.preTouchUpInfo = null; return(false); } } else if (this.lastTouchUpInfo != null) { bool isVaild = this.lastTouchUpInfo.IsVaild(DateTime.Now); if (isVaild == false) { this.preTouchUpInfo = null; this.lastTouchUpInfo = null; return(false); } else { double diffTime = (this.lastTouchUpInfo.TouchTime - this.preTouchUpInfo.TouchTime).TotalMilliseconds; if (diffTime < GestureConsts.Current.VaildDoubleTapTimeDiff) { double diff = this.GetPowDis(this.lastTouchUpInfo.TouchPoint, this.preTouchUpInfo.TouchPoint); if (diff < GestureConsts.Current.DoubleTapDistance) { this.currentResult = GestureResult.DoubleTap; GestureArg arg = new GestureArg(this.AssociatedObject, this.currentResult, device); List <Point> posInfo = new List <Point>(); posInfo.Add(this.preTouchUpInfo.TouchPoint); posInfo.Add(this.lastTouchUpInfo.TouchPoint); arg.Tag = posInfo; if (this.OnGestureDetector != null) { this.OnGestureDetector(this.AssociatedObject, arg); } this.isGestureBehavior = true; this.preTouchUpInfo = null; this.lastTouchUpInfo = null; return(true); } } this.preTouchUpInfo = this.lastTouchUpInfo; this.lastTouchUpInfo = null; } } } return(false); }
protected GestureResult ORGestures(GestureResult one, GestureResult two) { if (one == GestureResult.SUCEEDED || two == GestureResult.SUCEEDED) { return(GestureResult.SUCEEDED); } if (one == GestureResult.PAUSED || two == GestureResult.PAUSED) { return(GestureResult.PAUSED); } return(GestureResult.FAILED); }
private void OnMaidGesture(GestureResult gr, object obj) { switch (gr.GestureType) { case GestureType.SingleTap: SingleTap(); break; case GestureType.LongPress: LongPress(); break; } }
private void SatisfyInterest(GestureInterest gi, GestureResult args) { var commandparam = gi.GestureParameter ?? args.StartView.BindingContext ?? BindingContext; if (gi.GestureCommand != null && gi.GestureCommand.CanExecuteGesture(args, gi.GestureParameter)) { gi.GestureCommand.ExecuteGesture(args, commandparam); } var handler = GestureRecognized; if (handler != null) { handler(args.StartView, args); } }
public void TouchEvent(object sender, EventArgs e) { Gesture gesture = (Gesture)sender; GestureResult res = new GestureResult(); res.gesture = gesture; Ray ray = Camera.main.ScreenPointToRay(new Vector3(gesture.ScreenPosition.x, gesture.ScreenPosition.y, 0)); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { res.hit = hit.collider.gameObject; } this.GestureChanged(res); }
private void OnGesture(GestureResult gr, object obj) { GestureCount++; switch (gr.GestureType) { case GestureType.SingleTap: Gestures.Insert(0, string.Format("Gesture:{0} param is {1}", gr.GestureType, obj)); break; case GestureType.DoubleTap: Gestures.Insert(0, string.Format("Gesture:{0} param is {1}", gr.GestureType, obj)); break; case GestureType.LongPress: Gestures.Insert(0, string.Format("Gesture:{0} param is {1}", gr.GestureType, obj)); break; case GestureType.Swipe: Gestures.Insert(0,string.Format("Gesture:{0} Direction: {1} param is {2}",gr.GestureType,gr.Direction,obj)); break; } }
protected void GesturesContentView_GestureRecognized(object sender, GestureResult e) { switch (e.GestureType) { case GestureType.LongPress: //Add code here break; case GestureType.SingleTap: // Add code here break; case GestureType.DoubleTap: // Add code here break; default: break; } }
/// <summary> /// Fire the Hold event /// </summary> void Tmer_Hold(object sender, EventArgs e) { timer.Stop(); if (this.AssociatedObject.TouchesOver.Count() > 0) { TouchDevice device = this.AssociatedObject.TouchesOver.First(); TouchPoint point = device.GetTouchPoint(Application.Current.MainWindow); Point startPos = (Point)timer.Tag; if (point.Position.Sub(startPos).Length() < GestureConsts.Current.ShakedThreshold) { if (this.isHold && this.OnGestureDetector != null) { this.currentResult = GestureResult.Hold; GestureArg arg = new GestureArg(this.AssociatedObject, this.currentResult, null); arg.Tag = this.timer.Tag; this.OnGestureDetector(this.AssociatedObject, arg); this.isGestureBehavior = true; this.isHold = false; } } } }
private bool CheckIsSimpleDrag(ManipulationDeltaEventArgs e) { if ((DateTime.Now - this.gestureTime).TotalMilliseconds > 150) { bool isSimpleDrag = this.IsSimpleDrag(e, this.sensitiveFactor.DragFactor); bool isInTime = this.IsFingersTouchInTime(); if (e.Manipulators.Count() == 2 && isSimpleDrag && isInTime) { if (this.OnGestureDetector != null) { this.currentResult = GestureResult.Drag; GestureArg arg = new GestureArg(this.AssociatedObject, this.currentResult, (TouchDevice)e.Manipulators.First()); arg.Tag = e.DeltaManipulation.Translation; this.OnGestureDetector(this.AssociatedObject, arg); } this.isGestureBehavior = true; return(true); } } return(false); }
private void OnGesture(GestureResult gr, object obj) { GestureCount++; switch (gr.GestureType) { case GestureType.SingleTap: Gestures.Insert(0, string.Format("Gesture:{0} param is {1}", gr.GestureType, obj)); break; case GestureType.DoubleTap: Gestures.Insert(0, string.Format("Gesture:{0} param is {1}", gr.GestureType, obj)); break; case GestureType.LongPress: Gestures.Insert(0, string.Format("Gesture:{0} param is {1}", gr.GestureType, obj)); break; case GestureType.Swipe: Gestures.Insert(0, string.Format("Gesture:{0} Direction: {1} param is {2}", gr.GestureType, gr.Direction, obj)); break; } }
private bool CheckFiveFingersScrath(ManipulationDeltaEventArgs e) { if (IsScrachTrend(e)) { Size area = this.FingersTouchArea(e); double ratio = area.Height / area.Width; TraceLog("Five Ratio is " + ratio); if (ratio < 2 && ratio > 0.5) { bool isOnTime = IsFingersTouchInTime(); double maxFingerDistance = this.GetMaxFingerDistance(e); bool isInArea = maxFingerDistance < GestureConsts.Current.FiveFingerAreaDistance; if (this.OnGestureDetector != null && isOnTime && isInArea) { this.currentResult = GestureResult.FiveFingersScratch; this.OnGestureDetector(this.AssociatedObject, new GestureArg(this.AssociatedObject, this.currentResult, (TouchDevice)e.Manipulators.First())); this.isGestureBehavior = true; return(true); } } } return(false); }
private bool CheckZoomOrDragGesture(ManipulationDeltaEventArgs e) { double costTime = (DateTime.Now - this.gestureTime).TotalMilliseconds; TraceLog("Cost time:" + costTime); if (costTime > 60) { GestureResult result = this.GetDragOrZoomGestureResult(e); if (result == GestureResult.Drag) { if (this.OnGestureDetector != null) { this.currentResult = GestureResult.Drag; GestureArg arg = new GestureArg(this.AssociatedObject, this.currentResult, (TouchDevice)e.Manipulators.First()); arg.Tag = e.CumulativeManipulation.Translation; this.OnGestureDetector(this.AssociatedObject, arg); } this.isGestureBehavior = true; return(true); } else if (result == GestureResult.Zoom) { if (this.OnGestureDetector != null) { this.currentResult = GestureResult.Zoom; GestureArg arg = new GestureArg(this.AssociatedObject, this.currentResult, (TouchDevice)e.Manipulators.First()); arg.Tag = e.DeltaManipulation.Scale; this.OnGestureDetector(this.AssociatedObject, arg); } this.isGestureBehavior = true; return(true); } } return(false); }
/// <summary> /// Composes two Gesture Results. /// </summary> /// <param name="one"></param> /// <param name="two"></param> /// <returns></returns> protected GestureResult ANDGestures(GestureResult one, GestureResult two) { if (one == two) { return(one); } if (one == GestureResult.FAILED || two == GestureResult.FAILED) { return(GestureResult.FAILED); } if (one == GestureResult.PAUSED || two == GestureResult.PAUSED) { return(GestureResult.PAUSED); } if (one == GestureResult.LOST_TRACK || two == GestureResult.LOST_TRACK) { return(GestureResult.LOST_TRACK); } throw new ArgumentException($"Unknown Composition of GestureResults {one} and {two}"); }
/// <summary> /// Returns true if the result is either SUCEEDED or PAUSED /// </summary> /// <param name="result"></param> /// <returns></returns> public static bool IsSuceeding(this GestureResult result) { return(result == GestureResult.SUCEEDED || result == GestureResult.PAUSED ? true : false); }
public void GestureChanged(GestureResult gesture) { ss1.update(gesture); }
private void GestureRender(TouchDevice device) { this.RefreashTouchDeviceStatus(device); IEnumerable <Point> points = this.GestureStatus.Select(item => item.Value.Position); TraceLog("Check Gesture Count is" + points.Count()); Point newCenter = this.GetCenterPoint(points); double newRadius = this.GetRadius(points); double transition = this.GetDis(newCenter, gestureInitCenterPoint); double changeRadius = Math.Abs(this.initGestureRadius - newRadius); TraceLog(string.Format("newRadius is {0} initGestureRadius is {1} newCenter is {2} gestureInitCenterPoint is {3} transition is {4} changeRadius is {5}", newRadius, initGestureRadius, newCenter, gestureInitCenterPoint, transition, changeRadius)); if (this.isGestureBehavior) { if (this.currentGesture == GestureResult.Drag || this.currentGesture == GestureResult.Zoom || this.currentGesture == GestureResult.OneFinger) { this.TheProcessAfterGestureDetermined(device, newCenter, newRadius); } } else { if (points.Count() > 1) { double time = (DateTime.Now - logTime).TotalMilliseconds; TraceLog("Cost time is " + time); if (time < 50) { return; } bool isInTime = this.IsFingersTouchInTime(); if (isInTime) { bool isTwoHandFarZoom = false; double dis = this.GetMaxFingerDistance(); isTwoHandFarZoom = dis > GestureConsts.Current.TwoHandsDistance; if (isTwoHandFarZoom || transition < changeRadius * 2) { if ((changeRadius / this.currentGestureRadius) > GestureConsts.Current.MultiFingerZoomThreshold * this.sensitiveFactor.ZoomFactor) { Vector zoomArg = this.GetCumulativeZoomResultParamater(newRadius); if (points.Count() >= 4 && zoomArg.Length < 1.414 && isTwoHandFarZoom == false) { this.currentGesture = GestureResult.FiveFingersScratch; } else { this.currentGesture = GestureResult.Zoom; } this.FireZoomOrScrachEvnet(device, zoomArg); } } else { if (transition > GestureConsts.Current.MultiFingerDragThreshold * this.sensitiveFactor.DragFactor) { this.FireDragEvent(device, newCenter); } } } } else { if (gestureCount == 1) { if (transition > GestureConsts.Current.ShakedThreshold) { this.timer.Stop(); } if (transition > GestureConsts.Current.MultiFingerDragThreshold) { this.FireDrawingEvent(device, newCenter); TraceLog(string.Format("Gesture cost time is {0}", (DateTime.Now - logTime).TotalMilliseconds)); } } } } this.currentGestureRadius = newRadius; this.currentCenterPoint = newCenter; }
private bool CheckIsAreaGesture(ManipulationDeltaEventArgs e) { int fingerCount = this.AssociatedObject.TouchesOver.Count(); if (fingerCount > this.gestureFingerCount) { this.gestureFingerCount = fingerCount; } TouchDevice device = (TouchDevice)e.Manipulators.First(); TouchPoint point = device.GetTouchPoint(Application.Current.MainWindow); double mendedHeight = GestureDetector.GetMendedHeight(point.Size.Width, point.Size.Height); if (GestureDetector.IsErase(point.Size.Width, mendedHeight)) { if (this.OnGestureDetector != null) { this.currentResult = GestureResult.Brush; GestureArg arg = new GestureArg(this.AssociatedObject, this.currentResult, device); arg.Tag = new Rect(point.Position.X, point.Position.Y, point.Size.Width, mendedHeight); this.OnGestureDetector(this.AssociatedObject, arg); } this.isGestureBehavior = true; return(true); } else { if (this.gestureFingerCount == 1) { double checkWidht = point.Size.Width; double checkHeight = mendedHeight; double checkRadio = checkHeight / checkWidht; bool isZoom = this.IsZoom(e.CumulativeManipulation.Scale); if ( (checkRadio > GestureConsts.Current.FingerHeightWidhtRatio || checkWidht < (1 / GestureConsts.Current.FingerHeightWidhtRatio)) && (Math.Min(checkWidht, checkHeight) > GestureConsts.Current.OneFingerSize) ) { if (this.gestureStatusBehavior != null) { this.gestureStatusBehavior(new GestureArg(this.AssociatedObject, GestureResult.MultipleFingers, device)); } if (e.CumulativeManipulation.Translation.Length > GestureConsts.Current.MultiFingerDragThreshold && isZoom == false) { if (this.OnGestureDetector != null) { this.currentResult = GestureResult.Drag; GestureArg arg = new GestureArg(this.AssociatedObject, this.currentResult, device); arg.Tag = e.CumulativeManipulation.Translation; this.OnGestureDetector(this.AssociatedObject, arg); } this.isGestureBehavior = true; return(true); } } else if (e.CumulativeManipulation.Translation.Length > GestureConsts.Current.MultiFingerDragThreshold && isZoom == false) { if (this.OnGestureDetector != null) { this.currentResult = GestureResult.OneFinger; this.OnGestureDetector(this.AssociatedObject, new GestureArg(this.AssociatedObject, this.currentResult, device)); } this.isGestureBehavior = true; return(true); } } } return(false); }