[longomatch] Update timers timeline when a new node is added



commit eb9ee94600a5277e88f94e79484a1606a15fa272
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Wed Oct 22 02:38:39 2014 +0200

    Update timers timeline when a new node is added

 LongoMatch.Core/Common/EventsBroker.cs             |    8 ++++++++
 LongoMatch.Core/Handlers/Handlers.cs               |    1 +
 LongoMatch.Drawing/CanvasObjects/TimelineObject.cs |   18 ++++++++++++++++--
 LongoMatch.Drawing/CanvasObjects/TimerObject.cs    |    3 ++-
 LongoMatch.Drawing/Widgets/PlaysTimeline.cs        |    9 +++++++++
 LongoMatch.GUI/Gui/Component/CodingWidget.cs       |    7 +++++++
 LongoMatch.GUI/Gui/Component/Timeline.cs           |   10 +++++++---
 7 files changed, 50 insertions(+), 6 deletions(-)
---
diff --git a/LongoMatch.Core/Common/EventsBroker.cs b/LongoMatch.Core/Common/EventsBroker.cs
index 82074f5..14a4f19 100644
--- a/LongoMatch.Core/Common/EventsBroker.cs
+++ b/LongoMatch.Core/Common/EventsBroker.cs
@@ -34,6 +34,7 @@ namespace LongoMatch.Core.Common
                public event DeleteEventsHandler EventsDeletedEvent;
                public event LoadEventHandler LoadEventEvent;
                public event EventLoadedHandler EventLoadedEvent;
+               public event TimerNodeAddedHandler TimerNodeAddedEvent;
                public event MoveEventHandler MoveToEventTypeEvent;
                public event TimeNodeChangedHandler TimeNodeChanged;
                public event SnapshotSeriesHandler SnapshotSeries;
@@ -405,6 +406,13 @@ namespace LongoMatch.Core.Common
                                MigrateDB ();
                        }
                }
+               
+               public void EmitTimerNodeAddedEvent (Timer timer, TimeNode node)
+               {
+                       if (TimerNodeAddedEvent != null) {
+                               TimerNodeAddedEvent (timer, node);
+                       }
+               }
        }
 }
 
diff --git a/LongoMatch.Core/Handlers/Handlers.cs b/LongoMatch.Core/Handlers/Handlers.cs
index e1e994d..d313306 100644
--- a/LongoMatch.Core/Handlers/Handlers.cs
+++ b/LongoMatch.Core/Handlers/Handlers.cs
@@ -41,6 +41,7 @@ namespace LongoMatch.Core.Handlers
        public delegate void NewTimelineEventHandler (TimelineEvent evt);
        /* An event was edited */
        public delegate void TimeNodeChangedHandler (TimeNode tNode,object val);
+       public delegate void TimerNodeAddedHandler (Timer timer, TimeNode tn);
        /* Edit EventType properties */
        public delegate void EditEventTypeHandler (EventType cat);
        /* A list of plays needs to be deleted */
diff --git a/LongoMatch.Drawing/CanvasObjects/TimelineObject.cs 
b/LongoMatch.Drawing/CanvasObjects/TimelineObject.cs
index 90f3927..03248fc 100644
--- a/LongoMatch.Drawing/CanvasObjects/TimelineObject.cs
+++ b/LongoMatch.Drawing/CanvasObjects/TimelineObject.cs
@@ -260,10 +260,13 @@ namespace LongoMatch.Drawing.CanvasObjects
        public class TimerTimeline: TimelineObject
        {
 
+               List<Timer> timers;
+
                public TimerTimeline (List<Timer> timers, bool showName, bool selectWhole, bool showLine,
                                      Time maxTime, double offsetY, Color background, Color lineColor):
                        base (maxTime, offsetY, background)
                {
+                       this.timers = timers;
                        ShowName = showName;
                        SelectWhole = selectWhole;
                        ShowLine = showLine;
@@ -297,11 +300,19 @@ namespace LongoMatch.Drawing.CanvasObjects
                        return nodes.FirstOrDefault (n => n.TimeNode == tn) != null;
                }
 
-               public void AddTimer (Timer timer)
+               public bool HasTimer (Timer timer)
+               {
+                       return timers.Contains (timer);
+               }
+               
+               public void AddTimer (Timer timer, bool newtimer=true)
                {
                        foreach (TimeNode tn in timer.Nodes) {
                                AddTimeNode (timer, tn);
                        }
+                       if (newtimer) {
+                               timers.Add (timer);
+                       }
                        ReDraw ();
                }
 
@@ -311,6 +322,9 @@ namespace LongoMatch.Drawing.CanvasObjects
                        if (to != null) {
                                RemoveObject (to, true);
                        }
+                       if (timers.Contains (timer)) {
+                               timers.Remove (timer);
+                       }
                        ReDraw ();
                }
 
@@ -330,7 +344,7 @@ namespace LongoMatch.Drawing.CanvasObjects
                {
                        ClearObjects ();
                        foreach (Timer t in timers) {
-                               AddTimer (t);
+                               AddTimer (t, false);
                        }
                }
 
diff --git a/LongoMatch.Drawing/CanvasObjects/TimerObject.cs b/LongoMatch.Drawing/CanvasObjects/TimerObject.cs
index 374d8c1..4faf150 100644
--- a/LongoMatch.Drawing/CanvasObjects/TimerObject.cs
+++ b/LongoMatch.Drawing/CanvasObjects/TimerObject.cs
@@ -103,8 +103,9 @@ namespace LongoMatch.Drawing.CanvasObjects
                        } else {
                                Log.Debug ("Stop timer at " + CurrentTime.ToMSecondsString ());
                                if (StartTime.MSeconds != CurrentTime.MSeconds) {
-                                       Button.Timer.StartTimer (StartTime);
+                                       var tn = Button.Timer.StartTimer (StartTime);
                                        Button.Timer.StopTimer (CurrentTime);
+                                       Config.EventsBroker.EmitTimerNodeAddedEvent (Button.Timer, tn);
                                }
                                StartTime = null;
                        }
diff --git a/LongoMatch.Drawing/Widgets/PlaysTimeline.cs b/LongoMatch.Drawing/Widgets/PlaysTimeline.cs
index 4336b5e..b97caf7 100644
--- a/LongoMatch.Drawing/Widgets/PlaysTimeline.cs
+++ b/LongoMatch.Drawing/Widgets/PlaysTimeline.cs
@@ -129,6 +129,15 @@ namespace LongoMatch.Drawing.Widgets
                        widget.ReDraw ();
                }
 
+               public void AddTimerNode (Timer timer, TimeNode tn)
+               {
+                       TimerTimeline tl = Objects.OfType<TimerTimeline> ().FirstOrDefault (t => t.HasTimer 
(timer));
+                       if (tl != null) {
+                               tl.AddTimeNode (timer, tn);
+                               widget.ReDraw ();
+                       }
+               }
+
                public void RemovePlays (List<TimelineEvent> plays)
                {
                        foreach (TimelineEvent p in plays) {
diff --git a/LongoMatch.GUI/Gui/Component/CodingWidget.cs b/LongoMatch.GUI/Gui/Component/CodingWidget.cs
index eb51c37..b6705ef 100644
--- a/LongoMatch.GUI/Gui/Component/CodingWidget.cs
+++ b/LongoMatch.GUI/Gui/Component/CodingWidget.cs
@@ -76,6 +76,7 @@ namespace LongoMatch.Gui.Component
                        Config.EventsBroker.PlayerTick += HandleTick;
                        Config.EventsBroker.CapturerTick += HandleCapturerTick;
                        Config.EventsBroker.EventLoadedEvent += HandlePlayLoaded;
+                       Config.EventsBroker.TimerNodeAddedEvent += HandleTimerNodeAddedEvent;
                        LongoMatch.Gui.Helpers.Misc.SetFocus (this, false);
                        
                        buttonswidget.Mode = TagMode.Free;
@@ -100,6 +101,7 @@ namespace LongoMatch.Gui.Component
                        Config.EventsBroker.PlayerTick -= HandleTick;
                        Config.EventsBroker.CapturerTick -= HandleCapturerTick;
                        Config.EventsBroker.EventLoadedEvent -= HandlePlayLoaded;
+                       Config.EventsBroker.TimerNodeAddedEvent -= HandleTimerNodeAddedEvent;
                        buttonswidget.Destroy ();
                        timeline.Destroy ();
                        playspositionviewer1.Destroy ();
@@ -282,6 +284,11 @@ namespace LongoMatch.Gui.Component
                        
                }
 
+               void HandleTimerNodeAddedEvent (Timer timer, TimeNode tn)
+               {
+                       timeline.AddTimerNode (timer, tn);
+               }
+
        }
 }
 
diff --git a/LongoMatch.GUI/Gui/Component/Timeline.cs b/LongoMatch.GUI/Gui/Component/Timeline.cs
index bd1c1ae..50c8c9b 100644
--- a/LongoMatch.GUI/Gui/Component/Timeline.cs
+++ b/LongoMatch.GUI/Gui/Component/Timeline.cs
@@ -72,7 +72,7 @@ namespace LongoMatch.Gui.Component
 
                        // Synchronize the zoom widget height with scrolledwindow's scrollbar's.
                        scrolledwindow1.HScrollbar.SizeAllocated += (object o, SizeAllocatedArgs args) => {
-                               int spacing = (int) scrolledwindow1.StyleGetProperty ("scrollbar-spacing");
+                               int spacing = (int)scrolledwindow1.StyleGetProperty ("scrollbar-spacing");
                                zoomhbox.HeightRequest = args.Allocation.Height + spacing;
                        };
 
@@ -144,6 +144,11 @@ namespace LongoMatch.Gui.Component
                        QueueDraw ();
                }
 
+               public void AddTimerNode (Timer timer, TimeNode tn)
+               {
+                       timeline.AddTimerNode (timer, tn);
+               }
+
                bool UpdateTime ()
                {
                        if (nextCurrentTime != currentTime) {
@@ -211,12 +216,11 @@ namespace LongoMatch.Gui.Component
                        m.ShowAll ();
                        m.Popup ();
                }
-               
+
                void HandleShowTimerMenuEvent (Timer timer, Time time)
                {
                        periodsmenu.ShowMenu (project, timer, time, timeline.PeriodsTimeline);
                }
-
        }
 }
 


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