Browse Source

-fixed timer clear
-added active block in toucheventvisualizer

Alexander Hendrich 10 years ago
parent
commit
4294bfad93

+ 4 - 0
bbiwarg/Graphics/OutputImage.cs

@@ -56,6 +56,10 @@ namespace bbiwarg.Graphics
             Image.Draw(new CircleF(new PointF(x, y), radius), new Rgb(color), 0);
         }
 
+        public void fillRectangle(int x, int y, int width, int height, Color color) {
+            Image.Draw(new Rectangle(x, y, width, height), new Rgb(color),-1);
+        }
+
         public void drawRectangle(int x, int y, int width, int height, Color color, int thichness = 0)
         {
             Image.Draw(new Rectangle(x, y, width, height), new Rgb(color), thichness);

+ 22 - 1
bbiwarg/Graphics/TouchEventVisualizer.cs

@@ -21,7 +21,8 @@ namespace bbiwarg.Graphics
         private Dictionary<int, List<Vector2D>> positions;
         private Dictionary<int, long> lastUpdates;
         private int nextFreeID;
-
+        private int lastUpdated;
+        private bool active;
 
         public TouchEventVisualizer(int width, int height)
         {
@@ -37,6 +38,8 @@ namespace bbiwarg.Graphics
             timer.Start();
 
             nextFreeID = 1;
+            lastUpdated = 0;
+            active = false;
             idTranslations = new Dictionary<int, int>();
             positions = new Dictionary<int, List<Vector2D>>();
             lastUpdates = new Dictionary<int, long>();
@@ -52,6 +55,8 @@ namespace bbiwarg.Graphics
             positions.Add(id, new List<Vector2D>());
             positions[id].Add(tea.RelativePosition);
             lastUpdates.Add(id, timer.ElapsedMilliseconds);
+            lastUpdated = id;
+            active = true;
         }
 
 
@@ -60,6 +65,7 @@ namespace bbiwarg.Graphics
             int id = idTranslations[tea.TrackID];
             positions[id].Add(tea.RelativePosition);
             lastUpdates[id] = timer.ElapsedMilliseconds;
+            lastUpdated = id;
         }
 
         public void touchUp(object sender, TouchEventArgs tea)
@@ -67,6 +73,7 @@ namespace bbiwarg.Graphics
             int id = idTranslations[tea.TrackID];
             positions[id].Add(tea.RelativePosition);
             lastUpdates[id] = timer.ElapsedMilliseconds;
+            lastUpdated = id;
 
             idTranslations.Remove(tea.TrackID);
         }
@@ -82,6 +89,8 @@ namespace bbiwarg.Graphics
                 if (currentTime - lastUpdates[id] > Parameters.TouchEventVisualizerFadeOutTime) {
                     positions.Remove(id);
                     lastUpdates.Remove(id);
+                    if (id == lastUpdated)
+                        active = false;
                 }
             }
 
@@ -96,6 +105,15 @@ namespace bbiwarg.Graphics
             int widthPerColumn = width / numColumns;
             int heightPerRow = height / numRows;
 
+            int activeRow = -1;
+            int activeCol = -1;
+            if (active && numRows*numColumns > 1) {
+                Vector2D position = positions[lastUpdated][positions[lastUpdated].Count-1];
+                activeRow = (int)Math.Floor(position.Y * Parameters.PalmGridNumRows);
+                activeCol = (int)Math.Floor(position.X * Parameters.PalmGridNumColumns);
+            }
+
+
             for (int i = 0; i <= numColumns; i++)
             {
                 OutputImage.drawLineSegment(new LineSegment2D(new Vector2D(i * widthPerColumn, 0), new Vector2D(i * widthPerColumn, height - 1)), Parameters.TouchEventVisualizerGridColor);
@@ -108,6 +126,9 @@ namespace bbiwarg.Graphics
                         
             for (int row = 0; row < numRows; row++) {
                 for (int col = 0; col < numColumns; col++) {
+                    if(row == activeRow && col == activeCol) 
+                        OutputImage.fillRectangle(col*widthPerColumn, row*heightPerRow, widthPerColumn, heightPerRow, Parameters.TouchEventVisualizerActiveBlockColor);
+                    
                     int x = (int)((col+0.5f)*widthPerColumn)-5;
                     int y = (int)((row+0.5f)*heightPerRow)+5;
                     OutputImage.drawText(x,y,(1+row*numColumns+col).ToString(),Parameters.TouchEventVisualizerTextColor);

+ 1 - 0
bbiwarg/Parameters.cs

@@ -172,6 +172,7 @@ namespace bbiwarg
         public static readonly Color TouchEventVisualizerPointColor = Color.Red;
         public static readonly Color TouchEventVisualizerGridColor = Color.White;
         public static readonly Color TouchEventVisualizerTextColor = Color.White;
+        public static readonly Color TouchEventVisualizerActiveBlockColor = Color.DarkSlateGray;
 
         public static readonly Color PalmQuadColor = Color.Blue;
         public static readonly Color PalmGridColor = Color.CornflowerBlue;

+ 1 - 0
bbiwarg/Utility/Timer.cs

@@ -49,6 +49,7 @@ namespace bbiwarg.Utility
 
         public static void outputAll()
         {
+            Logger.clear(LogSubject.Timer);
             Logger.log("---TIMERS-START---", LogSubject.Timer);
             foreach (String name in stopwatches.Keys)
             {