using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Net; using System.Net.Sockets; using bbiwarg.Recognition.TouchRecognition; using bbiwarg.Utility; using bbiwarg.Input.InputHandling; using TUIO; namespace bbiwarg.TUIO { class TuioCommunicator { private TuioServer server; private Dictionary cursors; public TuioCommunicator(string host, int port) { server = new TuioServer(host, port); cursors = new Dictionary(); } public void handleNewFrameData(object sender, NewProcessedFrameEventArgs e) { server.initFrame(); FrameData frameData = e.FrameData; lock (frameData) { if (frameData.ResetFlag) reset(); foreach (TouchEvent te in frameData.TouchEvents) { switch (te.Type) { case TouchEventType.Down: TuioCursor cursor = server.addTuioCursor(te.Touch.RelativePosition.X, te.Touch.RelativePosition.Y); cursors.Add(te.Touch.TrackID, cursor); break; case TouchEventType.Move: server.updateTuioCursor(cursors[te.Touch.TrackID], te.Touch.RelativePosition.X, te.Touch.RelativePosition.Y); break; case TouchEventType.Up: server.removeTuioCursor(cursors[te.Touch.TrackID]); cursors.Remove(te.Touch.TrackID); break; } } } server.commitFrame(); } public void close() { server.close(); } public void reset() { foreach (int id in cursors.Keys) { server.removeTuioCursor(cursors[id]); } cursors.Clear(); } public static bool tryParseIPAddress(String ipIn, out String ipOut) { IPAddress ipAddress; bool result = (IPAddress.TryParse(ipIn, out ipAddress) && ipAddress.AddressFamily == AddressFamily.InterNetwork); if (result) ipOut = ipAddress.ToString(); else ipOut = null; return result; } public static bool tryParsePort(String portIn, out Int16 portOut) { return Int16.TryParse(portIn, out portOut); } } }