[longomatch] Improve preformance with timeline redraws



commit ae113966531b28280327643f57ec8188f2fc4b25
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Fri Oct 24 15:56:13 2014 +0200

    Improve preformance with timeline redraws
    
    Reduce drasctically CPU usage by only redrawing the timing line
    area that changed after updating the current time.

 LongoMatch.Drawing/CanvasObjects/NeedleObject.cs |   18 ++++++++++++------
 LongoMatch.Drawing/Widgets/PlaysTimeline.cs      |   16 +++++++++++++++-
 LongoMatch.Drawing/Widgets/Timerule.cs           |   21 ++++++++++++++++++---
 LongoMatch.GUI/Gui/Component/Timeline.cs         |    1 -
 LongoMatch.GUI/gtk-gui/objects.xml               |    1 +
 5 files changed, 46 insertions(+), 11 deletions(-)
---
diff --git a/LongoMatch.Drawing/CanvasObjects/NeedleObject.cs 
b/LongoMatch.Drawing/CanvasObjects/NeedleObject.cs
index 5b9b022..f8074d6 100644
--- a/LongoMatch.Drawing/CanvasObjects/NeedleObject.cs
+++ b/LongoMatch.Drawing/CanvasObjects/NeedleObject.cs
@@ -34,7 +34,7 @@ namespace LongoMatch.Drawing.CanvasObjects
                                Image img = Image.LoadFromFile (path);
                                needle = Config.DrawingToolkit.CreateSurface (img.Width, img.Height, img, 
false);
                        }
-                       Size = needle.Width;
+                       Width = needle.Width;
                }
 
                protected override void Dispose (bool disposing)
@@ -56,20 +56,26 @@ namespace LongoMatch.Drawing.CanvasObjects
                        set;
                }
 
-               public double Size {
+               public double Width {
                        get;
                        set;
                }
 
-               Point TopLeft {
+               public double Height {
                        get {
-                               return new Point (X - Size / 2, TimelineHeight - needle.Height);
+                               return needle.Height;
+                       }
+               }
+               
+               public Point TopLeft {
+                       get {
+                               return new Point (X - Width / 2, TimelineHeight - needle.Height);
                        }
                }
                
                Area Area {
                        get {
-                               return new Area (TopLeft, Size, Size);
+                               return new Area (TopLeft, Width, Width);
                        }
                }
                
@@ -86,7 +92,7 @@ namespace LongoMatch.Drawing.CanvasObjects
                
                public Selection GetSelection (Point point, double precision, bool inMotion=false)
                {
-                       if ((Math.Abs (point.X - X) < Size / 2 + precision)) {
+                       if ((Math.Abs (point.X - X) < Width / 2 + precision)) {
                                return new Selection (this, SelectionPosition.All, 0);
                        } else {
                                return null;
diff --git a/LongoMatch.Drawing/Widgets/PlaysTimeline.cs b/LongoMatch.Drawing/Widgets/PlaysTimeline.cs
index f9daee5..f8e55b1 100644
--- a/LongoMatch.Drawing/Widgets/PlaysTimeline.cs
+++ b/LongoMatch.Drawing/Widgets/PlaysTimeline.cs
@@ -37,7 +37,7 @@ namespace LongoMatch.Drawing.Widgets
                Project project;
                EventsFilter playsFilter;
                double secondsPerPixel;
-               Time duration;
+               Time duration, currentTime;
                TimelineEvent loadedEvent;
                bool movingTimeNode;
                Dictionary<TimelineObject, object> timelineToFilter;
@@ -51,6 +51,7 @@ namespace LongoMatch.Drawing.Widgets
                        Accuracy = Constants.TIMELINE_ACCURACY;
                        SelectionMode = MultiSelectionMode.MultipleWithModifier;
                        SingleSelectionObjects.Add (typeof(TimerTimeNodeObject));
+                       currentTime = new Time (0);
                }
 
                protected override void Dispose (bool disposing)
@@ -78,9 +79,22 @@ namespace LongoMatch.Drawing.Widgets
 
                public Time CurrentTime {
                        set {
+                               Area area;
+                               double start, stop;
+
                                foreach (TimelineObject tl in Objects) {
                                        tl.CurrentTime = value;
                                }
+                               if (currentTime < value) {
+                                       start = Utils.TimeToPos (currentTime,SecondsPerPixel);
+                                       stop = Utils.TimeToPos (value, SecondsPerPixel);
+                               } else {
+                                       start = Utils.TimeToPos (value, SecondsPerPixel);
+                                       stop = Utils.TimeToPos (currentTime, SecondsPerPixel);
+                               }
+                               area = new Area (new Point (start - 1, 0), stop - start + 2, widget.Height);
+                               currentTime = value;
+                               widget.ReDraw (area);
                        }
                }
 
diff --git a/LongoMatch.Drawing/Widgets/Timerule.cs b/LongoMatch.Drawing/Widgets/Timerule.cs
index 70e942f..421a480 100644
--- a/LongoMatch.Drawing/Widgets/Timerule.cs
+++ b/LongoMatch.Drawing/Widgets/Timerule.cs
@@ -42,7 +42,7 @@ namespace LongoMatch.Drawing.Widgets
                        needle = new NeedleObject();
                        AddObject (needle);
                        SecondsPerPixel = 0.1;
-                       CurrentTime = new Time (0);
+                       currentTime = new Time (0);
                }
 
                public double Scroll {
@@ -65,8 +65,23 @@ namespace LongoMatch.Drawing.Widgets
                                return currentTime;
                        }
                        set {
+                               Area area;
+                               double start, stop, timeX;
+
+                               timeX = Utils.TimeToPos (value, SecondsPerPixel) - Scroll;
+                               if (needle.X < timeX) {
+                                       start = needle.X;
+                                       stop = timeX;
+                               } else {
+                                       start = timeX;
+                                       stop = needle.X;
+                               }
+                               start -= needle.Width / 2;
+                               stop += needle.Width / 2;
+                               area = new Area (new Point (start - 1, needle.TopLeft.Y), stop - start + 2, 
needle.Height);
                                currentTime = value;
                                needle.ResetDrawArea ();
+                               widget.ReDraw (area);
                        }
                }
 
@@ -121,8 +136,8 @@ namespace LongoMatch.Drawing.Widgets
                                     new Point (area.Start.X + area.Width, height));
 
                        startX = (int)(area.Start.X + Scroll);
-                       start = (startX - (startX % TIME_SPACING)) + TIME_SPACING;
-                       stop = (int)(startX + area.Width);
+                       start = (startX - (startX % TIME_SPACING));
+                       stop = (int)(startX + area.Width + TIME_SPACING);
 
                        /* Draw big lines each 10 * secondsPerPixel */
                        for (int i=start; i <= stop; i += TIME_SPACING) {
diff --git a/LongoMatch.GUI/Gui/Component/Timeline.cs b/LongoMatch.GUI/Gui/Component/Timeline.cs
index a3c7619..258d3f5 100644
--- a/LongoMatch.GUI/Gui/Component/Timeline.cs
+++ b/LongoMatch.GUI/Gui/Component/Timeline.cs
@@ -167,7 +167,6 @@ namespace LongoMatch.Gui.Component
                                currentTime = nextCurrentTime;
                                timeline.CurrentTime = currentTime;
                                timerule.CurrentTime = currentTime;
-                               QueueDraw ();
                        }
                        return true;
                }
diff --git a/LongoMatch.GUI/gtk-gui/objects.xml b/LongoMatch.GUI/gtk-gui/objects.xml
index d594818..0de5976 100644
--- a/LongoMatch.GUI/gtk-gui/objects.xml
+++ b/LongoMatch.GUI/gtk-gui/objects.xml
@@ -351,6 +351,7 @@
     <itemgroups>
       <itemgroup label="VideoWindow Properties">
         <property name="Ready" />
+        <property name="Visible" />
       </itemgroup>
     </itemgroups>
     <signals>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]