/// <summary> /// Adds the gesture event request to the end of the existing requests collection /// </summary> /// <param name="uiElement"></param> /// <param name="gestureName"></param> /// <param name="handler"></param> public static void Add(UIElement uiElement, Gesture gesture, GestureEventHandler handler, int stepNo) { if (uiElement == null) throw new FrameworkException("UIElement can not be null!"); // Add new record in the list eventRequests.Add(new EventRequest() { UIElement = uiElement, Gesture = gesture, EventHandler = handler, StepNo = stepNo }); }
private void AddEvent(UIElement uiElement, Gesture gesture, GestureEventHandler handler, int stepNo) { if (GestureFramework.IsInitialized) { EventRequestDirectory.Add(uiElement, gesture, handler, stepNo); } else { throw new FrameworkException("You need to initialize the framework first!. Call GestureEventManager.Initialize(...) at application startup."); } }
private ValidSetOfPointsCollection ValidateGesture(Gesture gesture, ValidSetOfPointsCollection validResultSets, int blockNo) { var validateBlock = gesture.ValidationBlocks[blockNo]; var validPoints = from a in validResultSets from b in a.ToList() where b.Source != null select b; if (validPoints.Count() == 0) return validResultSets; // Validate the specified block validResultSets.ExpectedGestureName = gesture.Name; // Console.WriteLine("Name:" + validResultSets.ExpectedGestureName); validResultSets = validateBlock.PrimitiveConditions.Validate(validResultSets); if (validResultSets.Count > 0) // current dataset satisfies the validation block { List<UIElement> alreadyNotifiedUIelements = new List<UIElement>(); // Building return objects for each valid sets foreach (var validSetOfPoint in validResultSets) { List<EventRequest> eventReqs = EventRequestDirectory.GetRequests(gesture.Name, validSetOfPoint.GetUIElements(), blockNo); if (eventReqs.Count > 0) { //PartiallyEvaluatedGestures.clearCache(); // Build return objects List<IReturnType> returnObjs = gesture.ReturnTypes.Calculate(validSetOfPoint); // Execute gesture effects, if any if (GestureFramework.GestureFeedbacks.ContainsKey(gesture.Name)) { var gestureFeeds = GestureFramework.GestureFeedbacks[gesture.Name]; foreach (Type gestureFeedbackTyoe in gestureFeeds) { ExecuteFeedback(gestureFeedbackTyoe, returnObjs); } } // Invoke the callback to notify the subscriber(s) foreach (var eventRequest in eventReqs) { if (!alreadyNotifiedUIelements.Contains(eventRequest.UIElement)) // Prevent same element from receiving multiple notifications (e.g. 1..3 finger drag) { GestureEventArgs e = new GestureEventArgs() { Values = returnObjs }; eventRequest.EventHandler(eventRequest.UIElement, e); alreadyNotifiedUIelements.Add(eventRequest.UIElement); } } } } // Its one of the validate blocks of a multi-step gesture (and it is not the last block) if (!string.IsNullOrEmpty(validateBlock.Name) && gesture.ValidationBlocks.Count != blockNo + 1) { PartiallyEvaluatedGestures.Add(gesture.Name, blockNo, validResultSets, validateBlock.Name); // Save the partial result in cache } } return validResultSets; }
public static List<IPrimitiveConditionData> GetAllPrimitives() { List<IPrimitiveConditionData> primitives = new List<IPrimitiveConditionData>() ; // Find all classes in "Gestures" assembly that implements IRuleValidator interface Gesture g = new Gesture(); var types = g.GetType().Assembly.GetTypes(); IPrimitiveConditionData primitiveData; foreach (Type t in types) { if (t.IsTypeOf(typeof(IPrimitiveConditionData))) { primitiveData = GetPrimitiveByTypeName(t.Name); primitives.Add(primitiveData); } } return primitives; }
private static Type GetType(string className) { Type type = null; // Check in TouchToolkit assembly (GestureProcessor) Gesture g = new Gesture(); var types = g.GetType().Assembly.GetTypes(); type = GetType(className, type, types); // If not found, check in application assembly if (type == null) { types = GestureFramework.HostAssembly.GetTypes(); type = GetType(className, type, types); } return type; }
private static IPrimitiveConditionValidator GetPreCondition(IPrimitiveConditionData ruleData, Gesture gesture) { IPrimitiveConditionValidator preCondition = null; IPrimitiveConditionValidator newPreCondition = GetPrimitiveConditionValidator(ruleData); // Check if same preCondition already exists foreach (var rule in _preCons) { if (newPreCondition.Equals(rule)) { preCondition = rule; break; } } // Update preCondition to gesture mapping if (preCondition == null) preCondition = newPreCondition; var map = Tuple.Create<IPrimitiveConditionValidator, Gesture>(preCondition, gesture); _preConGestureMap.Add(map); return preCondition; }
internal static void LoadGestureDefinitions() { // Loading both pre-defined gestures from framework assembly and user defined gestures (if any) List<GestureToken> gestureTokens = GetGestureTokens(); // Load Gestures foreach (var gToken in gestureTokens) { // Name Gesture g = new Gesture() { Name = gToken.Name }; // Validate blocks foreach (var validateToken in gToken.ValidateTokens) { ValidationBlock vb = new ValidationBlock() { Name = validateToken.Name }; // Primitive conditions foreach (var priConData in validateToken.PrimitiveConditions) { IPrimitiveConditionValidator primitiveCondition = GetPrimitiveConditionValidator(priConData); vb.PrimitiveConditions.Add(primitiveCondition); } g.ValidationBlocks.Add(vb); } // Returns foreach (var retToken in gToken.Returns) { ReturnTypeInfo info = GetReturnTypeInfo(retToken); g.ReturnTypes.Add(info); } // If a gesture definition with same name already exists (probably from the pre-defined list) // then override that with the latest one (defined by the user) var existingGesture = _gestures.Get(gToken.Name); if (existingGesture != null) { _gestures.Remove(existingGesture); } _gestures.Add(g); } }
/// <summary> /// Returns all unique rules defined in the "Gestures" assembly /// </summary> /// <returns></returns> public static List<Type> GetAllRules() { if (_allRules.Count == 0) { // Find all classes in "Gestures" assembly that implements IRuleValidator interface Gesture g = new Gesture(); var types = g.GetType().Assembly.GetTypes(); foreach (Type t in types) { if (t.IsTypeOf(typeof(IPrimitiveConditionValidator))) _allRules.Add(t); } } return _allRules; }