Browse Source

Cursor sends the number of button which is pressed through TUIO

Jalal Khademi 8 years ago
parent
commit
194c84371a

+ 1 - 1
bbiwarg/Output/DebugOutput/TouchEventVisualizer.cs

@@ -126,8 +126,8 @@ namespace BBIWARG.Output.DebugOutput
                         activeBlocks.ElementAt(sliderPos)[i] = true;
                     }
                 }
-                
 
+                Parameters.ActiveTouches = activeBlocks;
                 // draw blocks
 
                 int index = 1;

+ 7 - 0
bbiwarg/Parameters.cs

@@ -1,5 +1,6 @@
 using BBIWARG.Utility;
 using System;
+using System.Collections.Generic;
 using System.Drawing;
 
 namespace BBIWARG
@@ -663,6 +664,12 @@ namespace BBIWARG
         /// </summary>
         public static readonly Color TouchEventTrackedColor = ColorTracked;
 
+        ///<summary>
+        /// all touched buttons
+        /// </summary>
+        /// 
+        public static List<List<bool>> ActiveTouches;
+
         #endregion touch
 
         #region TouchEventVisualizer

+ 17 - 2
bbiwarg/TUIO/TuioCommunicator.cs

@@ -4,6 +4,7 @@ using BBIWARG.Recognition.TouchRecognition;
 using BBIWARG.Utility;
 using System;
 using System.Collections.Generic;
+using System.Drawing;
 using System.Linq;
 using System.Net;
 using System.Net.Sockets;
@@ -95,15 +96,16 @@ namespace BBIWARG.TUIO
 
                 foreach (TouchEvent te in frameData.TouchEvents)
                 {
+                    Point p = getButton(te.Touch.RelativePosition.X, te.Touch.RelativePosition.Y);
                     switch (te.Type)
                     {
                         case TouchEventType.Down:
-                            TuioCursor tcur = server.addTuioCursor(te.Touch.RelativePosition.X, te.Touch.RelativePosition.Y);
+                            TuioCursor tcur = server.addTuioCursor(p.X, p.Y);
                             tcursors.Add(te.Touch.TrackID, tcur);
                             break;
 
                         case TouchEventType.Move:
-                            server.updateTuioCursor(tcursors[te.Touch.TrackID], te.Touch.RelativePosition.X, te.Touch.RelativePosition.Y);
+                            server.updateTuioCursor(tcursors[te.Touch.TrackID], p.X, p.Y);
                             break;
 
                         case TouchEventType.Up:
@@ -236,6 +238,19 @@ namespace BBIWARG.TUIO
             server.commitFrame();
         }
 
+
+        private Point getButton(float rX , float rY)
+        {
+            int activeRow = (int)Math.Min(rY * Parameters.ActiveTouches.Count,
+                Parameters.PalmGridDefaultNumRows - 1);
+            int activeCol = (int)Math.Min(rX * Parameters.ActiveTouches.ElementAt(activeRow).Count,
+                Parameters.ActiveTouches.ElementAt(activeRow).Count - 1);
+            if (activeRow != Parameters.PalmSliderPos)
+                return new Point(activeRow, activeCol);
+            else
+                return new Point(activeRow, Parameters.PalmSliderCurr);
+        }
+
         /// <summary>
         /// Resets the server by removing all cursors and objects.
         /// </summary>