[longomatch] Add new timeline widgets for timers



commit 114cf233a190efa888caf167f72e975e8e5d233b
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Tue Jun 3 19:09:14 2014 +0200

    Add new timeline widgets for timers

 .../CanvasObject/BaseCanvasObject.cs               |   45 ++++++
 LongoMatch.Drawing/CanvasObject/CategoryLabel.cs   |    2 +
 LongoMatch.Drawing/CanvasObject/CategoryTagger.cs  |   29 ++++
 LongoMatch.Drawing/CanvasObject/PlayObject.cs      |   87 +-----------
 LongoMatch.Drawing/CanvasObject/TimeNodeObject.cs  |  152 ++++++++++++++++++++
 .../{CategoryTimeline.cs => TimelineObject.cs}     |   76 +++++++---
 LongoMatch.Drawing/Common.cs                       |    5 +
 LongoMatch.Drawing/LongoMatch.Drawing.mdp          |    4 +-
 LongoMatch.Drawing/Widgets/PlaysTimeline.cs        |   15 +--
 LongoMatch.Drawing/Widgets/TimersTimeline.cs       |  108 ++++++++++++++
 LongoMatch.Drawing/Widgets/Timerule.cs             |    6 +
 11 files changed, 410 insertions(+), 119 deletions(-)
---
diff --git a/LongoMatch.Drawing/CanvasObject/BaseCanvasObject.cs 
b/LongoMatch.Drawing/CanvasObject/BaseCanvasObject.cs
new file mode 100644
index 0000000..958a473
--- /dev/null
+++ b/LongoMatch.Drawing/CanvasObject/BaseCanvasObject.cs
@@ -0,0 +1,45 @@
+//
+//  Copyright (C) 2014 Andoni Morales Alastruey
+//
+//  This program is free software; you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation; either version 2 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+using System;
+using LongoMatch.Interfaces.Drawing;
+using LongoMatch.Interfaces;
+using LongoMatch.Common;
+
+namespace LongoMatch.Drawing.CanvasObject
+{
+       public abstract class BaseCanvasObject: ICanvasObject
+       {
+               public BaseCanvasObject ()
+               {
+                       Visible = true;
+               }
+               
+               public bool Visible {
+                       get;
+                       set;
+               }
+               
+               public bool Selected {
+                       set;
+                       get;
+               }
+               
+               public abstract void Draw (IDrawingToolkit tk, Area area);
+       }
+}
+
diff --git a/LongoMatch.Drawing/CanvasObject/CategoryLabel.cs 
b/LongoMatch.Drawing/CanvasObject/CategoryLabel.cs
index 07ebbd4..3981009 100644
--- a/LongoMatch.Drawing/CanvasObject/CategoryLabel.cs
+++ b/LongoMatch.Drawing/CanvasObject/CategoryLabel.cs
@@ -54,6 +54,8 @@ namespace LongoMatch.Drawing.CanvasObject
                        tk.Begin();
                        tk.FillColor = category.Color;
                        tk.StrokeColor = category.Color;
+                       tk.FontSlant = FontSlant.Normal;
+                       tk.FontSize = 12;
                        tk.DrawRoundedRectangle (new Point(0, y + 1), width, height - 1, 3);  
                        tk.FillColor = Common.TEXT_COLOR;
                        tk.StrokeColor = Common.TEXT_COLOR;
diff --git a/LongoMatch.Drawing/CanvasObject/CategoryTagger.cs 
b/LongoMatch.Drawing/CanvasObject/CategoryTagger.cs
new file mode 100644
index 0000000..5577de2
--- /dev/null
+++ b/LongoMatch.Drawing/CanvasObject/CategoryTagger.cs
@@ -0,0 +1,29 @@
+//
+//  Copyright (C) 2014 Andoni Morales Alastruey
+//
+//  This program is free software; you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation; either version 2 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+using System;
+
+namespace LongoMatch.Drawing.CanvasObject
+{
+               public class CategoryTagger
+               {
+                               public CategoryTagger ()
+                               {
+                               }
+               }
+}
+
diff --git a/LongoMatch.Drawing/CanvasObject/PlayObject.cs b/LongoMatch.Drawing/CanvasObject/PlayObject.cs
index 0ff7d00..c57154c 100644
--- a/LongoMatch.Drawing/CanvasObject/PlayObject.cs
+++ b/LongoMatch.Drawing/CanvasObject/PlayObject.cs
@@ -24,51 +24,15 @@ using LongoMatch.Store.Drawables;
 
 namespace LongoMatch.Drawing.CanvasObject
 {
-       public class PlayObject: BaseCanvasObject, ICanvasSelectableObject
+       public class PlayObject: TimeNodeObject
        {
-               const int MAX_TIME_SPAN=1000;
-               
-               public PlayObject (Play play)
+               public PlayObject (Play play):base (play)
                {
-                       Play = play;
                }
                
                public Play Play {
-                       get;
-                       set;
-               }
-               
-               public Time MaxTime {
-                       set;
-                       protected get;
-               }
-               
-               public double OffsetY {
-                       get;
-                       set;
-               }
-               
-               public double SecondsPerPixel {
-                       set;
-                       protected get;
-               }
-               
-               double StartX {
-                       get {
-                               return Common.TimeToPos (Play.Start, SecondsPerPixel);
-                       }
-               }
-               
-               double StopX {
-                       get {
-                               return Common.TimeToPos (Play.Stop, SecondsPerPixel);
-                       }
-               }
-               
-               double CenterX {
                        get {
-                               return Common.TimeToPos (Play.Start + Play.Duration / 2,
-                                                        SecondsPerPixel);
+                               return TimeNode as Play;
                        }
                }
                
@@ -87,51 +51,6 @@ namespace LongoMatch.Drawing.CanvasObject
                                          Common.CATEGORY_HEIGHT, 2);
                        tk.End ();
                }
-               
-               public Selection GetSelection (Point point, double precision) {
-                       double accuracy;
-                       if (point.Y >= OffsetY && point.Y < OffsetY + Common.CATEGORY_HEIGHT) {
-                               if (Drawable.MatchAxis (point.X, StartX, precision, out accuracy)) {
-                                       return new Selection (this, SelectionPosition.Left, accuracy);
-                               } else if (Drawable.MatchAxis (point.X, StopX, precision, out accuracy)) {
-                                       return new Selection (this, SelectionPosition.Right, accuracy);
-                               } else if (point.X > StartX && point.X < StopX) {
-                                       return new Selection (this, SelectionPosition.All,
-                                                             Math.Abs (CenterX - point.X));
-                               }
-                       }
-                       return null;
-               }
-               
-               public void Move (Selection sel, Point p, Point start) {
-                       Time newTime = Common.PosToTime (p, SecondsPerPixel);
-
-                       if (p.X < 0) {
-                               p.X = 0;
-                       } else if (newTime > MaxTime) {
-                               p.X = Common.TimeToPos (MaxTime, SecondsPerPixel);
-                       }
-                       newTime = Common.PosToTime (p, SecondsPerPixel);
-
-                       switch (sel.Position) {
-                       case SelectionPosition.Left: {
-                               if (newTime.MSeconds + MAX_TIME_SPAN > Play.Stop.MSeconds) {
-                                       Play.Start.MSeconds = Play.Stop.MSeconds - MAX_TIME_SPAN;
-                               } else {
-                                       Play.Start = newTime;
-                               }
-                               break;
-                       }
-                       case SelectionPosition.Right: {
-                               if (newTime.MSeconds - MAX_TIME_SPAN < Play.Start.MSeconds) {
-                                       Play.Stop.MSeconds = Play.Start.MSeconds + MAX_TIME_SPAN;
-                               } else {
-                                       Play.Stop = newTime;
-                               }
-                               break;
-                       }
-                       }
-               }
        }
 }
 
diff --git a/LongoMatch.Drawing/CanvasObject/TimeNodeObject.cs 
b/LongoMatch.Drawing/CanvasObject/TimeNodeObject.cs
new file mode 100644
index 0000000..052beb9
--- /dev/null
+++ b/LongoMatch.Drawing/CanvasObject/TimeNodeObject.cs
@@ -0,0 +1,152 @@
+//
+//  Copyright (C) 2014 Andoni Morales Alastruey
+//
+//  This program is free software; you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation; either version 2 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+using System;
+using LongoMatch.Store;
+using LongoMatch.Interfaces.Drawing;
+using LongoMatch.Interfaces;
+using LongoMatch.Common;
+using LongoMatch.Store.Drawables;
+
+namespace LongoMatch.Drawing.CanvasObject
+{
+       public class TimeNodeObject: BaseCanvasObject, ICanvasSelectableObject
+       {
+               const int MAX_TIME_SPAN=1000;
+               
+               public TimeNodeObject (TimeNode node)
+               {
+                       TimeNode = node;
+               }
+               
+               public TimeNode TimeNode {
+                       get;
+                       set;
+               }
+               
+               public Time MaxTime {
+                       set;
+                       protected get;
+               }
+               
+               public double OffsetY {
+                       get;
+                       set;
+               }
+               
+               public double SecondsPerPixel {
+                       set;
+                       protected get;
+               }
+               
+               protected double StartX {
+                       get {
+                               return Common.TimeToPos (TimeNode.Start, SecondsPerPixel);
+                       }
+               }
+               
+               protected double StopX {
+                       get {
+                               return Common.TimeToPos (TimeNode.Stop, SecondsPerPixel);
+                       }
+               }
+               
+               protected double CenterX {
+                       get {
+                               return Common.TimeToPos (TimeNode.Start + TimeNode.Duration / 2,
+                                                        SecondsPerPixel);
+                       }
+               }
+               
+               public Selection GetSelection (Point point, double precision) {
+                       double accuracy;
+                       if (point.Y >= OffsetY && point.Y < OffsetY + Common.CATEGORY_HEIGHT) {
+                               if (Drawable.MatchAxis (point.X, StartX, precision, out accuracy)) {
+                                       return new Selection (this, SelectionPosition.Left, accuracy);
+                               } else if (Drawable.MatchAxis (point.X, StopX, precision, out accuracy)) {
+                                       return new Selection (this, SelectionPosition.Right, accuracy);
+                               } else if (point.X > StartX && point.X < StopX) {
+                                       return new Selection (this, SelectionPosition.All,
+                                                             Math.Abs (CenterX - point.X));
+                               }
+                       }
+                       return null;
+               }
+               
+               public void Move (Selection sel, Point p, Point start) {
+                       Time newTime = Common.PosToTime (p, SecondsPerPixel);
+
+                       if (p.X < 0) {
+                               p.X = 0;
+                       } else if (newTime > MaxTime) {
+                               p.X = Common.TimeToPos (MaxTime, SecondsPerPixel);
+                       }
+                       newTime = Common.PosToTime (p, SecondsPerPixel);
+
+                       switch (sel.Position) {
+                       case SelectionPosition.Left: {
+                               if (newTime.MSeconds + MAX_TIME_SPAN > TimeNode.Stop.MSeconds) {
+                                       TimeNode.Start.MSeconds = TimeNode.Stop.MSeconds - MAX_TIME_SPAN;
+                               } else {
+                                       TimeNode.Start = newTime;
+                               }
+                               break;
+                       }
+                       case SelectionPosition.Right: {
+                               if (newTime.MSeconds - MAX_TIME_SPAN < TimeNode.Start.MSeconds) {
+                                       TimeNode.Stop.MSeconds = TimeNode.Start.MSeconds + MAX_TIME_SPAN;
+                               } else {
+                                       TimeNode.Stop = newTime;
+                               }
+                               break;
+                       }
+                       }
+               }
+               
+               public override void Draw (IDrawingToolkit tk, Area area) {
+                       double mid, bottom, stop;
+                       Color c;
+
+                       tk.Begin ();
+                       if (Selected) {
+                               c = Common.TIMER_SELECTED_COLOR;
+                       } else {
+                               c = Common.TIMER_UNSELECTED_COLOR;
+                       }
+                       tk.FillColor = c;
+                       tk.StrokeColor = c;
+                       tk.LineWidth = 4;
+                       
+                       mid = OffsetY + Common.CATEGORY_HEIGHT / 2;
+                       bottom = OffsetY + Common.CATEGORY_HEIGHT / 2;
+                       stop = Common.TimeToPos (TimeNode.Stop, SecondsPerPixel);
+                       
+                       tk.DrawLine (new Point (StartX, OffsetY),
+                                    new Point (StartX, bottom));
+                       tk.DrawLine (new Point (StartX, bottom),
+                                    new Point (stop, bottom));
+                       tk.DrawLine (new Point (stop, OffsetY),
+                                    new Point (stop, bottom));
+                       tk.FontSize = 20;
+                       tk.DrawText (new Point (StartX, OffsetY), stop - StartX,
+                                    Common.CATEGORY_HEIGHT - 4, TimeNode.Name);
+                                    
+                       tk.End ();
+               }
+               
+       }
+}
diff --git a/LongoMatch.Drawing/CanvasObject/CategoryTimeline.cs 
b/LongoMatch.Drawing/CanvasObject/TimelineObject.cs
similarity index 71%
rename from LongoMatch.Drawing/CanvasObject/CategoryTimeline.cs
rename to LongoMatch.Drawing/CanvasObject/TimelineObject.cs
index 3e74f9d..f3a358f 100644
--- a/LongoMatch.Drawing/CanvasObject/CategoryTimeline.cs
+++ b/LongoMatch.Drawing/CanvasObject/TimelineObject.cs
@@ -25,32 +25,29 @@ using LongoMatch.Store.Drawables;
 
 namespace LongoMatch.Drawing.CanvasObject
 {
-       public class CategoryTimeline: BaseCanvasObject, ICanvasSelectableObject
+       public abstract class TimelineObject: BaseCanvasObject, ICanvasSelectableObject
        {
                Color background;
-               List<PlayObject> plays;
+               List<TimeNodeObject> nodes;
                double secondsPerPixel;
-               Time maxTime;
+               protected Time maxTime;
                
-               public CategoryTimeline (List<Play> plays, Time maxTime, double offsetY, Color background)
+               public TimelineObject (Time maxTime, double offsetY, Color background)
                {
                        this.background = background;
-                       this.plays = new List<PlayObject> ();
+                       this.nodes = new List<TimeNodeObject> ();
                        this.maxTime = maxTime;
                        Visible = true;
                        CurrentTime = new Time (0);
                        OffsetY  = offsetY;
-                       foreach (Play p in plays) {
-                               AddPlay (p);
-                       }
                        SecondsPerPixel = 0.1;
                }
                
                public double SecondsPerPixel {
                        set {
                                secondsPerPixel = value;
-                               foreach (PlayObject po in plays) {
-                                       po.SecondsPerPixel = secondsPerPixel;
+                               foreach (TimeNodeObject to in nodes) {
+                                       to.SecondsPerPixel = secondsPerPixel;
                                }
                        }
                        protected get {
@@ -73,23 +70,19 @@ namespace LongoMatch.Drawing.CanvasObject
                        get;
                }
                
-               public void AddPlay (Play play) {
-                       PlayObject po = new PlayObject (play);
-                       po.OffsetY = OffsetY;
-                       po.SecondsPerPixel = SecondsPerPixel;
-                       po.MaxTime = maxTime;
-                       plays.Add (po);
+               public void AddNode (TimeNodeObject o) {
+                       nodes.Add (o);
                }
                
-               public void RemovePlay (Play play) {
-                       plays.RemoveAll (po => po.Play == play);
+               public void RemoveNode (TimeNode node) {
+                       nodes.RemoveAll (po => po.TimeNode == node);
                }
 
                public override void Draw (IDrawingToolkit tk, Area area) {
                        double position;
-                       List<PlayObject> selected;
+                       List<TimeNodeObject> selected;
                        
-                       selected = new List<PlayObject>();
+                       selected = new List<TimeNodeObject>();
 
                        tk.Begin ();
                        tk.FillColor = background;
@@ -97,14 +90,14 @@ namespace LongoMatch.Drawing.CanvasObject
                        tk.LineWidth = 1;
                        tk.DrawRectangle (new Point (0, OffsetY), Width,
                                          Common.CATEGORY_HEIGHT);
-                       foreach (PlayObject p in plays) {
+                       foreach (TimeNodeObject p in nodes) {
                                if (p.Selected) {
                                        selected.Add (p);
                                        continue;
                                }
                                p.Draw (tk, area);
                        }
-                       foreach (PlayObject p in selected) {
+                       foreach (TimeNodeObject p in selected) {
                                p.Draw (tk, area);
                        }
                        
@@ -122,7 +115,7 @@ namespace LongoMatch.Drawing.CanvasObject
                        Selection selection = null;
 
                        if (point.Y >= OffsetY && point.Y < OffsetY + Common.CATEGORY_HEIGHT) {
-                               foreach (PlayObject po in plays) {
+                               foreach (TimeNodeObject po in nodes) {
                                        Selection tmp;
                                        tmp = po.GetSelection (point, precision);
                                        if (tmp == null) {
@@ -149,5 +142,42 @@ namespace LongoMatch.Drawing.CanvasObject
                        s.Drawable.Move (s, p, start);
                }
        }
+       
+       public class CategoryTimeline: TimelineObject {
+
+               public CategoryTimeline (List<Play> plays, Time maxTime, double offsetY, Color background):
+                       base (maxTime, offsetY, background)
+               {
+                       foreach (Play p in plays) {
+                               AddPlay (p);
+                       }
+               }
+               
+               public void AddPlay (Play play){
+                       PlayObject po = new PlayObject (play);
+                       po.OffsetY = OffsetY;
+                       po.SecondsPerPixel = SecondsPerPixel;
+                       po.MaxTime = maxTime;
+                       AddNode (po);
+               }
+
+       }
+       
+       public class TimerTimeline: TimelineObject {
+
+               public TimerTimeline (List<Timer> timers, Time maxTime, double offsetY, Color background):
+                       base (maxTime, offsetY, background)
+               {
+                       foreach (Timer t in timers) {
+                               foreach (TimeNode tn in t.Nodes) {
+                                       TimeNodeObject to = new TimeNodeObject (tn);
+                                       to.OffsetY = OffsetY;
+                                       to.SecondsPerPixel = SecondsPerPixel;
+                                       to.MaxTime = maxTime;
+                                       AddNode (to);
+                               }
+                       }
+               }
+       }
 }
 
diff --git a/LongoMatch.Drawing/Common.cs b/LongoMatch.Drawing/Common.cs
index 46b0a56..3e967c9 100644
--- a/LongoMatch.Drawing/Common.cs
+++ b/LongoMatch.Drawing/Common.cs
@@ -26,6 +26,9 @@ namespace LongoMatch.Drawing
                public const int CATEGORY_HEIGHT = 20;
                public const int CATEGORY_WIDTH = 150;
                public const int CATEGORY_H_SPACE = 5;
+               public const int TIMER_HEIGHT = 20;
+               public static int TIMERULE_HEIGHT = 30;
+
                public const double TIMELINE_ACCURACY = 5;
                public static Color TEXT_COLOR = Color.Black;
                public static Color TIMELINE_LINE_COLOR = Color.Black;
@@ -36,6 +39,8 @@ namespace LongoMatch.Drawing
                public static Color PLAYER_UNSELECTED_COLOR = Color.Grey2;
                public static Color PLAYER_PLAYING_COLOR = Color.Green;
                public static Color PLAYER_NOT_PLAYING_COLOR = Color.Red;
+               public static Color TIMER_UNSELECTED_COLOR = Color.Blue1;
+               public static Color TIMER_SELECTED_COLOR = Color.Red1;
 
                public const int TIMELINE_LINE_WIDTH = 1;
                
diff --git a/LongoMatch.Drawing/LongoMatch.Drawing.mdp b/LongoMatch.Drawing/LongoMatch.Drawing.mdp
index d67c7b3..774f834 100644
--- a/LongoMatch.Drawing/LongoMatch.Drawing.mdp
+++ b/LongoMatch.Drawing/LongoMatch.Drawing.mdp
@@ -25,10 +25,12 @@
     <File subtype="Code" buildaction="Compile" name="CanvasObject/PlayObject.cs" />
     <File subtype="Code" buildaction="Compile" name="Common.cs" />
     <File subtype="Code" buildaction="Compile" name="Widgets/PlaysTimeline.cs" />
-    <File subtype="Code" buildaction="Compile" name="CanvasObject/CategoryTimeline.cs" />
+    <File subtype="Code" buildaction="Compile" name="CanvasObject/TimelineObject.cs" />
     <File subtype="Code" buildaction="Compile" name="CanvasObject/BaseCanvasObject.cs" />
     <File subtype="Code" buildaction="Compile" name="CanvasObject/PlayerObject.cs" />
     <File subtype="Code" buildaction="Compile" name="Widgets/TeamTagger.cs" />
+    <File subtype="Code" buildaction="Compile" name="CanvasObject/TimeNodeObject.cs" />
+    <File subtype="Code" buildaction="Compile" name="Widgets/TimersTimeline.cs" />
   </Contents>
   <References>
     <ProjectReference type="Package" localcopy="True" refto="System, Version=4.0.0.0, Culture=neutral, 
PublicKeyToken=b77a5c561934e089" />
diff --git a/LongoMatch.Drawing/Widgets/PlaysTimeline.cs b/LongoMatch.Drawing/Widgets/PlaysTimeline.cs
index cc4fcd8..56a94af 100644
--- a/LongoMatch.Drawing/Widgets/PlaysTimeline.cs
+++ b/LongoMatch.Drawing/Widgets/PlaysTimeline.cs
@@ -27,13 +27,6 @@ using LongoMatch.Store.Drawables;
 
 namespace LongoMatch.Drawing.Widgets
 {
-       /*      Widget schematic
-        *
-        *  time |___|___|___|___|__|
-        *  cat1    ---     -- -
-        *  cat2 --  -------  --
-        *  cat3    ----    ----
-        */
         
        public class PlaysTimeline: SelectionCanvas
        {
@@ -91,7 +84,7 @@ namespace LongoMatch.Drawing.Widgets
 
                public void RemovePlays(List<Play> plays) {
                        foreach (Play p in plays) {
-                               categories[p.Category].RemovePlay (p);
+                               categories[p.Category].RemoveNode (p);
                                Selections.RemoveAll (s => (s.Drawable as PlayObject).Play == p);
                        }
                }
@@ -99,7 +92,7 @@ namespace LongoMatch.Drawing.Widgets
                void Update () {
                        double width = duration.Seconds / SecondsPerPixel;
                        widget.Width = width;
-                       foreach (CategoryTimeline tl in categories.Values) {
+                       foreach (TimelineObject tl in categories.Values) {
                                tl.Width = width;
                                tl.SecondsPerPixel = SecondsPerPixel;
                        }
@@ -130,7 +123,7 @@ namespace LongoMatch.Drawing.Widgets
                void UpdateVisibleCategories () {
                        int i=0;
                        foreach (Category cat in categories.Keys) {
-                               CategoryTimeline timeline = categories[cat];
+                               TimelineObject timeline = categories[cat];
                                if (playsFilter.VisibleCategories.Contains (cat)) {
                                        timeline.OffsetY = i * Common.CATEGORY_HEIGHT;
                                        timeline.Visible = true;
@@ -172,7 +165,7 @@ namespace LongoMatch.Drawing.Widgets
                        List<Play> plays = Selections.Select (p => (p.Drawable as PlayObject).Play).ToList();
                        
                        foreach (Category c in categories.Keys) {
-                               CategoryTimeline tl = categories[c];
+                               TimelineObject tl = categories[c];
                                if (!tl.Visible)
                                        continue;
                                if (coords.Y >= tl.OffsetY && coords.Y < tl.OffsetY + Common.CATEGORY_HEIGHT) 
{
diff --git a/LongoMatch.Drawing/Widgets/TimersTimeline.cs b/LongoMatch.Drawing/Widgets/TimersTimeline.cs
new file mode 100644
index 0000000..14122bd
--- /dev/null
+++ b/LongoMatch.Drawing/Widgets/TimersTimeline.cs
@@ -0,0 +1,108 @@
+using System.Linq;
+using LongoMatch.Store;
+using LongoMatch.Drawing.CanvasObject;
+using LongoMatch.Common;
+using LongoMatch.Handlers;
+using LongoMatch.Interfaces.Drawing;
+using LongoMatch.Store.Drawables;
+using System.Collections.Generic;
+
+namespace LongoMatch.Drawing.Widgets
+{
+       public class TimersTimeline: SelectionCanvas
+       {
+       
+               public event TimeNodeChangedHandler TimeNodeChanged;
+               public event PlaySelectedHandler TimeNodeSelected;
+               public event ShowTimelineMenuHandler ShowMenuEvent;
+
+               double secondsPerPixel;
+               Time duration;
+               Dictionary <Timer, TimerTimeline> timers;
+               
+               public TimersTimeline (IWidget widget): base(widget)
+               {
+                       secondsPerPixel = 0.1;
+                       Accuracy = Common.TIMELINE_ACCURACY;
+                       SelectionMode = MultiSelectionMode.MultipleWithModifier;
+               }
+
+               public void LoadTimers (List<Timer> timers, Time duration, bool splitTimers) {
+                       Objects.Clear();
+                       this.timers = new Dictionary<Timer, TimerTimeline>();
+                       this.duration = duration;
+                       FillCanvas (timers, splitTimers);
+               }
+               
+               public Time CurrentTime {
+                       set {
+                               foreach (TimerTimeline tl in timers.Values) {
+                                       tl.CurrentTime = value;
+                               }
+                       }
+               }
+               
+               public double SecondsPerPixel {
+                       set {
+                               secondsPerPixel = value;
+                               Update ();
+                       }
+                       get {
+                               return secondsPerPixel;
+                       }
+               }
+               
+               void Update () {
+                       double width = duration.Seconds / SecondsPerPixel;
+                       widget.Width = width;
+                       foreach (TimelineObject tl in timers.Values) {
+                               tl.Width = width;
+                               tl.SecondsPerPixel = SecondsPerPixel;
+                       }
+               }
+               
+               void FillCanvas (List<Timer> timers, bool splitTimers) {
+                       if (!splitTimers) {
+                               widget.Height = Common.TIMER_HEIGHT;
+                               TimerTimeline tl = new TimerTimeline (timers, duration, 0, Color.White);
+                               foreach (Timer t in timers) {
+                                       this.timers[t] = tl;
+                               }
+                               Objects.Add (tl);
+                       } else {
+                               widget.Height = timers.Count * Common.TIMER_HEIGHT;
+                       }
+                       Update ();
+               }
+               
+               protected override void SelectionChanged (List<Selection> selections) {
+               }
+               
+               protected override void StartMove (Selection sel) {
+                       if (sel.Position != SelectionPosition.All) {
+                               widget.SetCursor (CursorType.DoubleArrow);
+                       }
+               }
+               
+               protected override void StopMove () {
+                       widget.SetCursor (CursorType.Arrow);
+               }
+
+               protected override void ShowMenu (Point coords) {
+               }
+               
+               protected override void SelectionMoved (Selection sel) {
+                       if (TimeNodeChanged != null) {
+                               Time moveTime;
+                               TimeNode tn = (sel.Drawable as TimeNodeObject).TimeNode;
+
+                               if (sel.Position == SelectionPosition.Right) {
+                                       moveTime = tn.Stop;
+                               } else {
+                                       moveTime = tn.Start;
+                               }
+                               TimeNodeChanged (tn, moveTime);
+                       }
+               }
+       }
+}
diff --git a/LongoMatch.Drawing/Widgets/Timerule.cs b/LongoMatch.Drawing/Widgets/Timerule.cs
index aa3c8ae..b5ed3d3 100644
--- a/LongoMatch.Drawing/Widgets/Timerule.cs
+++ b/LongoMatch.Drawing/Widgets/Timerule.cs
@@ -60,6 +60,10 @@ namespace LongoMatch.Drawing.Widgets
                        double height = widget.Height;
                        double width = widget.Width;
                        double tpos;
+                       
+                       if (Duration == null) {
+                               return;
+                       }
 
                        tk.Context = context;
                        tk.Begin ();
@@ -69,6 +73,8 @@ namespace LongoMatch.Drawing.Widgets
                        
                        tk.StrokeColor = Common.TIMELINE_LINE_COLOR;
                        tk.LineWidth = Common.TIMELINE_LINE_WIDTH;
+                       tk.FontSlant = FontSlant.Normal;
+                       tk.FontSize = 12;
                        tk.DrawLine (new Point (0, height), new Point (width, height));
                
                        /* Draw big lines each 10 * secondsPerPixel */


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