Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using TUIO;
- namespace TuioProcessing
- {
- class MultiGestureManager : GestureListener
- {
- private Dictionary<long, AutoResetEvent> events;
- private MultiGesture mg = null;
- public MultiGestureManager()
- {
- events = new Dictionary<long, AutoResetEvent>();
- }
- public AutoResetEvent getResetEvent(long id)
- {
- return events[id];
- }
- #region GestureListener Member
- public void gestureChainCode(Gesture g)
- {
- if(g.getCursorID() > 0)
- {
- mg.addGesture(g);
- foreach (AutoResetEvent are in events.Values)
- {
- are.Set();
- }
- } else
- {
- if (mg != null)
- {
- if (events.ContainsKey(mg.getID()))
- {
- events.Remove(mg.getID());
- }
- Console.WriteLine("MultiGesture: " + mg.getID() + " #Fingers: " + mg.getFingers());
- }
- mg = new MultiGesture();
- mg.addGesture(g);
- events.Add(mg.getID(), new AutoResetEvent(false));
- ThreadPool.QueueUserWorkItem(mg.threadStart, this);
- }
- }
- #endregion
- class MultiGesture
- {
- private List<Gesture> gestures;
- private MultiGestureManager mgm;
- private bool wait;
- private static long id = 0;
- public MultiGesture()
- {
- gestures = new List<Gesture>();
- wait = true;
- id++;
- }
- public long getID()
- {
- return id;
- }
- public int getFingers()
- {
- return gestures.Count;
- }
- public void addGesture(Gesture g)
- {
- gestures.Add(g);
- }
- public void threadStart(Object threadContext)
- {
- mgm = (MultiGestureManager)threadContext;
- mgm.getResetEvent(id).WaitOne(100, false);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment