/// <summary> /// Invokes GetAlternateList in the native dll /// </summary> /// <returns></returns> private GestureRecognitionResult[] InvokeGetAlternateList() { GestureRecognitionResult[] recResults = new GestureRecognitionResult[] { }; int hr = 0; MS.Win32.Recognizer.RECO_RANGE recoRange; recoRange.iwcBegin = 0; recoRange.cCount = 1; uint countOfAlternates = IRAS_DefaultCount; IntPtr[] pRecoAlternates = new IntPtr[IRAS_DefaultCount]; try { hr = MS.Win32.Recognizer.UnsafeNativeMethods.GetAlternateList(_hContext, ref recoRange, ref countOfAlternates, pRecoAlternates, MS.Win32.Recognizer.ALT_BREAKS.ALT_BREAKS_SAME); if (HRESULT.Succeeded(hr) && countOfAlternates != 0) { List <GestureRecognitionResult> resultList = new List <GestureRecognitionResult>(); for (int i = 0; i < countOfAlternates; i++) { uint size = 1; // length of string == 1 since gesture id is a single WCHAR StringBuilder recoString = new StringBuilder(1); RecognitionConfidence confidenceLevel; if (HRESULT.Failed(MS.Win32.Recognizer.UnsafeNativeMethods.GetString(pRecoAlternates[i], out recoRange, ref size, recoString)) || HRESULT.Failed(MS.Win32.Recognizer.UnsafeNativeMethods.GetConfidenceLevel(pRecoAlternates[i], out recoRange, out confidenceLevel))) { // Fail to retrieve the reco result, skip this one continue; } ApplicationGesture gesture = (ApplicationGesture)recoString[0]; Debug.Assert(ApplicationGestureHelper.IsDefined(gesture)); if (ApplicationGestureHelper.IsDefined(gesture)) { resultList.Add(new GestureRecognitionResult(confidenceLevel, gesture)); } } recResults = resultList.ToArray(); } } finally { // Destroy the alternates for (int i = 0; i < countOfAlternates; i++) { if (pRecoAlternates[i] != IntPtr.Zero) { #pragma warning suppress 6031, 56031 // Return value ignored on purpose. MS.Win32.Recognizer.UnsafeNativeMethods.DestroyAlternate(pRecoAlternates[i]); pRecoAlternates[i] = IntPtr.Zero; } } } return(recResults); }
// Helper like Enum.IsDefined, for ApplicationGesture. It is an fxcop violation // to use Enum.IsDefined (for perf reasons) internal static bool IsDefined(ApplicationGesture applicationGesture) { //note that we can't just check the upper and lower bounds since the app gesture //values are not contiguous switch (applicationGesture) { case ApplicationGesture.AllGestures: case ApplicationGesture.ArrowDown: case ApplicationGesture.ArrowLeft: case ApplicationGesture.ArrowRight: case ApplicationGesture.ArrowUp: case ApplicationGesture.Check: case ApplicationGesture.ChevronDown: case ApplicationGesture.ChevronLeft: case ApplicationGesture.ChevronRight: case ApplicationGesture.ChevronUp: case ApplicationGesture.Circle: case ApplicationGesture.Curlicue: case ApplicationGesture.DoubleCircle: case ApplicationGesture.DoubleCurlicue: case ApplicationGesture.DoubleTap: case ApplicationGesture.Down: case ApplicationGesture.DownLeft: case ApplicationGesture.DownLeftLong: case ApplicationGesture.DownRight: case ApplicationGesture.DownRightLong: case ApplicationGesture.DownUp: case ApplicationGesture.Exclamation: case ApplicationGesture.Left: case ApplicationGesture.LeftDown: case ApplicationGesture.LeftRight: case ApplicationGesture.LeftUp: case ApplicationGesture.NoGesture: case ApplicationGesture.Right: case ApplicationGesture.RightDown: case ApplicationGesture.RightLeft: case ApplicationGesture.RightUp: case ApplicationGesture.ScratchOut: case ApplicationGesture.SemicircleLeft: case ApplicationGesture.SemicircleRight: case ApplicationGesture.Square: case ApplicationGesture.Star: case ApplicationGesture.Tap: case ApplicationGesture.Triangle: case ApplicationGesture.Up: case ApplicationGesture.UpDown: case ApplicationGesture.UpLeft: case ApplicationGesture.UpLeftLong: case ApplicationGesture.UpRight: case ApplicationGesture.UpRightLong: { return(true); } default: { return(false); } } }
}// end miniPadForm constructor void mo_Gesture(object sender, InkCollectorGestureEventArgs e) { ApplicationGesture gestureID = e.Gestures[0].Id; string location = e.Gestures[0].HotPoint.ToString(); System.Windows.Forms.MessageBox.Show("Your gesture was: " + gestureID.ToString() + " at " + location); switch (gestureID) { case ApplicationGesture.ArrowDown: pptController.nextSlide(); break; case ApplicationGesture.ArrowUp: pptController.prevSlide(); break; case ApplicationGesture.ChevronDown: pptController.newSlide(); break; default: break; } } // end mo_gesture method
public override GestureRecognizer Create(DeterministicRandom random) { ApplicationGesture[] allAppGestures = (ApplicationGesture[])Enum.GetValues(random.NextEnum <ApplicationGesture>().GetType()); //Get a number of gestures we will enable int gestureCount = random.Next(allAppGestures.Length - 2) + 1; ArrayList enableGesturesArrayList = new ArrayList(); //Fill the arraylist with the number of gestures we want to enable while (gestureCount > 0) { int index = random.Next(allAppGestures.Length); //If adding an AllGestures,reject it and continue to get the next gesture to add if (allAppGestures[index] == ApplicationGesture.AllGestures) { continue; } bool gestureExists = false; //Check if the appgesture is already added. if there are duplicates, API throws exception for (int i = 0; i < enableGesturesArrayList.Count; i++) { ApplicationGesture currentGesture = (ApplicationGesture)enableGesturesArrayList[i]; //Don't add something that already exists in the enableGestures list if (allAppGestures[index] == currentGesture) { gestureExists = true; break; } } //Not added so far, add and continue if (gestureExists == false) { enableGesturesArrayList.Add(allAppGestures[index]); gestureCount--; //One less thing to add } } ApplicationGesture[] applicationGestureArray = (ApplicationGesture[])enableGesturesArrayList.ToArray(random.NextEnum <ApplicationGesture>().GetType()); GestureRecognizer gestureRecognizer; if (random.NextBool()) { gestureRecognizer = new GestureRecognizer(applicationGestureArray); } else { gestureRecognizer = new GestureRecognizer(); gestureRecognizer.SetEnabledGestures(applicationGestureArray); } return(gestureRecognizer); }
}// end method mo_systemgesture private void ClearAppGestures(InkOverlay minioverlay) { ApplicationGesture nogesture = ApplicationGesture.NoGesture; System.Array gestureIDs = System.Enum.GetValues(nogesture.GetType()); foreach (ApplicationGesture gestureID in gestureIDs) { minioverlay.SetGestureStatus(gestureID, false); } }
/// <summary> /// Get the enabled gestures /// </summary> /// <returns></returns> public ReadOnlyCollection <ApplicationGesture> GetEnabledGestures() { VerifyAccess(); VerifyDisposed(); VerifyRecognizerAvailable(); //can be null if the call to SetEnabledGestures failed if (_enabledGestures == null) { _enabledGestures = new ApplicationGesture[] { }; } return(new ReadOnlyCollection <ApplicationGesture>(_enabledGestures)); }
public override void Perform() { ApplicationGesture[] allAppGestures = (ApplicationGesture[])Enum.GetValues(ApplicationGesture.Up.GetType()); //Get a number of gestures we will enable int gestureCount = CountIndex % (allAppGestures.Length - 2) + 1; ArrayList enableGesturesArrayList = new ArrayList(); //Fill the arraylist with the number of gestures we want to enable while (gestureCount > 0) { int index = GestureIndex % allAppGestures.Length; GestureIndex++; //If adding an AllGestures,reject it and continue to get the next gesture to add if (allAppGestures[index] == ApplicationGesture.AllGestures) { continue; } bool gestureExists = false; //Check if the appgesture is already added. if there are duplicates, API throws exception for (int i = 0; i < enableGesturesArrayList.Count; i++) { ApplicationGesture currentGesture = (ApplicationGesture)enableGesturesArrayList[i]; //Don't add something that already exists in the enableGestures list if (allAppGestures[index] == currentGesture) { gestureExists = true; break; } } //Not added so far, add and continue if (gestureExists == false) { enableGesturesArrayList.Add(allAppGestures[index]); gestureCount--; //One less thing to add } } ApplicationGesture[] applicationGestureArray = (ApplicationGesture[])enableGesturesArrayList.ToArray(ApplicationGesture.ArrowDown.GetType()); //Sets the application gestures that the InkCanvas recognizes. InkCanvas.SetEnabledGestures(applicationGestureArray); }
/// <summary> /// This is the InkCanvas gesture event handler. Here certain gestures are received /// and acted upon accordingly. /// </summary> void InkCanvas_Gesture(object sender, InkCanvasGestureEventArgs e) { GestureRecognitionResult topResult = e.GetGestureRecognitionResults()[0]; if (topResult.RecognitionConfidence == RecognitionConfidence.Strong) { ApplicationGesture gesture = topResult.ApplicationGesture; switch (gesture) { case ApplicationGesture.ScratchOut: StrokeCollection strokesToRemove = myInkCanvas.Strokes.HitTest(e.Strokes.GetBounds(), 10); if (strokesToRemove.Count > 0) { myInkCanvas.Strokes.Remove(strokesToRemove); } break; case ApplicationGesture.Right: myScrollViewer.ScrollToHorizontalOffset(myScrollViewer.HorizontalOffset + 30); break; case ApplicationGesture.Left: myScrollViewer.ScrollToHorizontalOffset(myScrollViewer.HorizontalOffset - 30); break; case ApplicationGesture.Up: myScrollViewer.ScrollToVerticalOffset(myScrollViewer.VerticalOffset - 30); break; case ApplicationGesture.Down: myScrollViewer.ScrollToVerticalOffset(myScrollViewer.VerticalOffset + 30); break; } } }
/// <summary>Creates a new <see cref="TouchGestureEventArgs"/> instance.</summary> public TouchGestureEventArgs(RoutedEvent ev, ApplicationGesture gesture, StrokeCollection strokes, Rect bounds) : base(ev) { Gesture = gesture; Strokes = strokes; Bounds = bounds; }
// Helper like Enum.IsDefined, for ApplicationGesture. It is an fxcop violation // to use Enum.IsDefined (for perf reasons) internal static bool IsDefined(ApplicationGesture applicationGesture) { //note that we can't just check the upper and lower bounds since the app gesture //values are not contiguous switch(applicationGesture) { case ApplicationGesture.AllGestures: case ApplicationGesture.ArrowDown: case ApplicationGesture.ArrowLeft: case ApplicationGesture.ArrowRight: case ApplicationGesture.ArrowUp: case ApplicationGesture.Check: case ApplicationGesture.ChevronDown: case ApplicationGesture.ChevronLeft: case ApplicationGesture.ChevronRight: case ApplicationGesture.ChevronUp: case ApplicationGesture.Circle: case ApplicationGesture.Curlicue: case ApplicationGesture.DoubleCircle: case ApplicationGesture.DoubleCurlicue: case ApplicationGesture.DoubleTap: case ApplicationGesture.Down: case ApplicationGesture.DownLeft: case ApplicationGesture.DownLeftLong: case ApplicationGesture.DownRight: case ApplicationGesture.DownRightLong: case ApplicationGesture.DownUp: case ApplicationGesture.Exclamation: case ApplicationGesture.Left: case ApplicationGesture.LeftDown: case ApplicationGesture.LeftRight: case ApplicationGesture.LeftUp: case ApplicationGesture.NoGesture: case ApplicationGesture.Right: case ApplicationGesture.RightDown: case ApplicationGesture.RightLeft: case ApplicationGesture.RightUp: case ApplicationGesture.ScratchOut: case ApplicationGesture.SemicircleLeft: case ApplicationGesture.SemicircleRight: case ApplicationGesture.Square: case ApplicationGesture.Star: case ApplicationGesture.Tap: case ApplicationGesture.Triangle: case ApplicationGesture.Up: case ApplicationGesture.UpDown: case ApplicationGesture.UpLeft: case ApplicationGesture.UpLeftLong: case ApplicationGesture.UpRight: case ApplicationGesture.UpRightLong: { return true; } default: { return false; } } }
/// <summary> /// Invokes GetLatticePtr in the native dll /// </summary> /// <returns></returns> private GestureRecognitionResult[] InvokeGetLatticePtr() { GestureRecognitionResult[] recResults = new GestureRecognitionResult[] { }; // int hr = 0; IntPtr ptr = IntPtr.Zero; // NOTICE-2005/07/11-WAYNEZEN, // There is no need to free the returned the structure. // The memory will be released when ResetContext, which is invoked in the callee - Recognize, is called. if (HRESULT.Succeeded( MS.Win32.Recognizer.UnsafeNativeMethods.GetLatticePtr( _hContext, ref ptr))) { unsafe { MS.Win32.Recognizer.RECO_LATTICE *pRecoLattice = (MS.Win32.Recognizer.RECO_LATTICE *)ptr; uint bestResultColumnCount = pRecoLattice->ulBestResultColumnCount; Debug.Assert(!(bestResultColumnCount != 0 && pRecoLattice->pLatticeColumns == IntPtr.Zero), "Invalid results!"); if (bestResultColumnCount > 0 && pRecoLattice->pLatticeColumns != IntPtr.Zero) { List <GestureRecognitionResult> resultList = new List <GestureRecognitionResult>(); MS.Win32.Recognizer.RECO_LATTICE_COLUMN *pLatticeColumns = (MS.Win32.Recognizer.RECO_LATTICE_COLUMN *)(pRecoLattice->pLatticeColumns); ulong *pulBestResultColumns = (ulong *)(pRecoLattice->pulBestResultColumns); for (uint i = 0; i < bestResultColumnCount; i++) { ulong column = pulBestResultColumns[i]; MS.Win32.Recognizer.RECO_LATTICE_COLUMN recoColumn = pLatticeColumns[column]; Debug.Assert(0 < recoColumn.cLatticeElements, "Invalid results!"); for (int j = 0; j < recoColumn.cLatticeElements; j++) { MS.Win32.Recognizer.RECO_LATTICE_ELEMENT recoElement = ((MS.Win32.Recognizer.RECO_LATTICE_ELEMENT *)(recoColumn.pLatticeElements))[j]; Debug.Assert((RECO_TYPE)(recoElement.type) == RECO_TYPE.RECO_TYPE_WCHAR, "The Application gesture has to be WCHAR type"); if ((RECO_TYPE)(recoElement.type) == RECO_TYPE.RECO_TYPE_WCHAR) { // Retrieve the confidence lever RecognitionConfidence confidenceLevel = RecognitionConfidence.Poor; MS.Win32.Recognizer.RECO_LATTICE_PROPERTIES recoProperties = recoElement.epProp; uint propertyCount = recoProperties.cProperties; MS.Win32.Recognizer.RECO_LATTICE_PROPERTY **apProps = (MS.Win32.Recognizer.RECO_LATTICE_PROPERTY * *)recoProperties.apProps; for (int k = 0; k < propertyCount; k++) { MS.Win32.Recognizer.RECO_LATTICE_PROPERTY *pProps = apProps[k]; if (pProps->guidProperty == GUID_CONFIDENCELEVEL) { Debug.Assert(pProps->cbPropertyValue == sizeof(uint) / sizeof(byte)); RecognitionConfidence level = (RecognitionConfidence)(((uint *)pProps->pPropertyValue))[0]; if (level >= RecognitionConfidence.Strong && level <= RecognitionConfidence.Poor) { confidenceLevel = level; } break; } } ApplicationGesture gesture = (ApplicationGesture)((char)(recoElement.pData)); Debug.Assert(ApplicationGestureHelper.IsDefined(gesture)); if (ApplicationGestureHelper.IsDefined(gesture)) { // Get the gesture result resultList.Add(new GestureRecognitionResult(confidenceLevel, gesture)); } } } } recResults = (GestureRecognitionResult[])(resultList.ToArray()); } } } return(recResults); }
private int SetEnabledGestures(MS.Win32.Recognizer.ContextSafeHandle recContext, ApplicationGesture[] enabledGestures) { Debug.Assert(recContext != null && !recContext.IsInvalid); // NOTICE-2005/01/11-WAYNEZEN, // The following usage was copied from drivers\tablet\recognition\ink\core\twister\src\wispapis.c // SetEnabledUnicodeRanges // Set ranges of gestures enabled in this recognition context // The behavior of this function is the following: // (a) (A part of) One of the requested ranges lies outside // gesture interval---currently [GESTURE_NULL, GESTURE_NULL + 255) // return E_UNEXPECTED and keep the previously set ranges // (b) All requested ranges are within the gesture interval but // some of them are not supported: // return S_TRUNCATED and set those requested gestures that are // supported (possibly an empty set) // (c) All requested gestures are supported // return S_OK and set all requested gestures. // Note: An easy way to set all supported gestures as enabled is to use // SetEnabledUnicodeRanges() with one range=(GESTURE_NULL,255). // Enabel gestures uint cRanges = (uint)( enabledGestures.Length ); MS.Win32.Recognizer.CHARACTER_RANGE[] charRanges = new MS.Win32.Recognizer.CHARACTER_RANGE[cRanges]; if ( cRanges == 1 && enabledGestures[0] == ApplicationGesture.AllGestures ) { charRanges[0].cChars = MAX_GESTURE_COUNT; charRanges[0].wcLow = GESTURE_NULL; } else { for ( int i = 0; i < cRanges; i++ ) { charRanges[i].cChars = 1; charRanges[i].wcLow = (ushort)( enabledGestures[i] ); } } int hr = MS.Win32.Recognizer.UnsafeNativeMethods.SetEnabledUnicodeRanges(recContext, cRanges, charRanges); return hr; }
//------------------------------------------------------------------------------- // // Constructors // //------------------------------------------------------------------------------- #region Constructors internal GestureRecognitionResult(RecognitionConfidence confidence, ApplicationGesture gesture) { _confidence = confidence; _gesture = gesture; }
void DrawingCanvas_Gesture(ApplicationGesture Gestrue) { System.Diagnostics.Debug.WriteLine(Gestrue.ToString()); }
/// <summary> /// Get the enabled gestures /// </summary> /// <returns></returns> public ReadOnlyCollection<ApplicationGesture> GetEnabledGestures() { VerifyAccess(); VerifyDisposed(); VerifyRecognizerAvailable(); //can be null if the call to SetEnabledGestures failed if (_enabledGestures == null) { _enabledGestures = new ApplicationGesture[] { }; } return new ReadOnlyCollection<ApplicationGesture>(_enabledGestures); }