[longomatch] Ensure plays are moved within valid bounds



commit 601262073adfb83cd0b63523565188be1b82d88b
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Tue May 20 17:01:29 2014 +0200

    Ensure plays are moved within valid bounds

 LongoMatch.Drawing/CanvasObject/PlayObject.cs |   17 ++++++++++---
 LongoMatch.Drawing/Widgets/PlaysTimeline.cs   |   33 ++++++++++++++++---------
 2 files changed, 34 insertions(+), 16 deletions(-)
---
diff --git a/LongoMatch.Drawing/CanvasObject/PlayObject.cs b/LongoMatch.Drawing/CanvasObject/PlayObject.cs
index 3929cea..874bc62 100644
--- a/LongoMatch.Drawing/CanvasObject/PlayObject.cs
+++ b/LongoMatch.Drawing/CanvasObject/PlayObject.cs
@@ -26,6 +26,7 @@ namespace LongoMatch.Drawing.CanvasObject
 {
        public class PlayObject: ICanvasSelectableObject
        {
+               const int MAX_TIME_SPAN=1000;
                
                public PlayObject (Play play)
                {
@@ -103,15 +104,23 @@ namespace LongoMatch.Drawing.CanvasObject
                }
                
                public void Move (Selection sel, Point p, Point start) {
+                       Time newTime = Common.PosToTime (p, SecondsPerPixel);
+                       
                        switch (sel.Position) {
                        case SelectionPosition.Left: {
-                               if (p.X < StopX)
-                                       Play.Start = Common.PosToTime (p, SecondsPerPixel);
+                               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 (p.X > StartX)
-                                       Play.Stop = Common.PosToTime (p, SecondsPerPixel);
+                               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/Widgets/PlaysTimeline.cs b/LongoMatch.Drawing/Widgets/PlaysTimeline.cs
index 942936b..58ca10a 100644
--- a/LongoMatch.Drawing/Widgets/PlaysTimeline.cs
+++ b/LongoMatch.Drawing/Widgets/PlaysTimeline.cs
@@ -44,7 +44,7 @@ namespace LongoMatch.Drawing.Widgets
 
                Project project;
                double secondsPerPixel;
-               int duration;
+               Time duration;
                uint lastTime;
                bool moving;
                List<Selection> selectionList;
@@ -65,7 +65,7 @@ namespace LongoMatch.Drawing.Widgets
                        this.project = project;
                        Objects.Clear();
                        categories.Clear();
-                       duration = new Time ((int)project.Description.File.Length).Seconds; 
+                       duration= new Time ((int)project.Description.File.Length); 
                        widget.Height = project.Categories.Count * Common.CATEGORY_HEIGHT;
                        FillCanvas ();
                        filter.FilterUpdated += () => {
@@ -104,7 +104,7 @@ namespace LongoMatch.Drawing.Widgets
                }
                
                void Update () {
-                       double width = duration / SecondsPerPixel;
+                       double width = duration.Seconds / SecondsPerPixel;
                        widget.Width = width;
                        foreach (object o in Objects) {
                                CategoryTimeline tl = o as CategoryTimeline;
@@ -206,23 +206,32 @@ namespace LongoMatch.Drawing.Widgets
                void HandleMotionEvent (Point coords)
                {
                        Selection sel;
+                       Play play;
+                       Time newTime, moveTime;
 
                        if (!moving)
                                return;
                        
                        sel = selectionList[0];
+                       play = (sel.Drawable as PlayObject).Play;
+                       newTime = Common.PosToTime (coords, SecondsPerPixel);
+
+                       if (coords.X < 0) {
+                               coords.X = 0;
+                       } else if (newTime > duration) {
+                               coords.X = Common.TimeToPos (duration, SecondsPerPixel);
+                       }
+                       if (sel.Position == SelectionPosition.Right) {
+                               moveTime = play.Stop;
+                       } else {
+                               moveTime = play.Start;
+                       }
+                       
                        sel.Drawable.Move (sel, coords, start);  
                        RedrawSelection (selectionList[0]);
+
                        if (TimeNodeChanged != null) {
-                               Time time;
-                               Play play = (sel.Drawable as PlayObject).Play;
-                               
-                               if (sel.Position == SelectionPosition.Left) {
-                                       time = play.Start;
-                               } else {
-                                       time = play.Stop;
-                               }
-                               TimeNodeChanged (play, time);
+                               TimeNodeChanged (play, moveTime);
                        }
                }
 


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