[longomatch] Refactor TimeNodeObject to simplify selection and move modes.



commit 41fd28bfc5dba5645499e47b3537652fef5a79a3
Author: Julien Moutte <julien fluendo com>
Date:   Tue Mar 10 17:08:54 2015 +0100

    Refactor TimeNodeObject to simplify selection and move modes.
    
    Remove SelectWhole and MoveWhole properties and use an enumeration defining how the node can be selected 
(none, borders, segment, all)

 LongoMatch.Core/Common/Enums.cs                    |   22 ++++++
 LongoMatch.Drawing/CanvasObjects/PlayObject.cs     |    2 +-
 LongoMatch.Drawing/CanvasObjects/TimeNodeObject.cs |   73 ++++++++++---------
 LongoMatch.Drawing/CanvasObjects/TimelineObject.cs |    8 +-
 LongoMatch.Drawing/Widgets/PlaysTimeline.cs        |    4 +-
 LongoMatch.Drawing/Widgets/TimersTimeline.cs       |   19 +++++-
 6 files changed, 85 insertions(+), 43 deletions(-)
---
diff --git a/LongoMatch.Core/Common/Enums.cs b/LongoMatch.Core/Common/Enums.cs
index 88e8d86..49b0840 100644
--- a/LongoMatch.Core/Common/Enums.cs
+++ b/LongoMatch.Core/Common/Enums.cs
@@ -156,6 +156,28 @@ namespace LongoMatch.Core.Common
                Timeline,
                GameUnits,
        }
+
+       /// <summary>
+       /// Node selection mode.
+       /// </summary>
+       public enum NodeSelectionMode {
+               /// <summary>
+               /// The node is not selectable at all.
+               /// </summary>
+               None,
+               /// <summary>
+               /// Only borders of the node can be selected.
+               /// </summary>
+               Borders,
+               /// <summary>
+               /// Only the inner segment of the node can be selected.
+               /// </summary>
+               Segment,
+               /// <summary>
+               /// Both borders and inner segment can be selected.
+               /// </summary>
+               All,
+       }
        
        public enum SelectionPosition {
                TopLeft,
diff --git a/LongoMatch.Drawing/CanvasObjects/PlayObject.cs b/LongoMatch.Drawing/CanvasObjects/PlayObject.cs
index 8fddc3b..6ec244f 100644
--- a/LongoMatch.Drawing/CanvasObjects/PlayObject.cs
+++ b/LongoMatch.Drawing/CanvasObjects/PlayObject.cs
@@ -27,7 +27,7 @@ namespace LongoMatch.Drawing.CanvasObjects
                public PlayObject (TimelineEvent play, Project project):base (play)
                {
                        Project = project;
-                       MoveWhole = false;
+                       SelectionMode = NodeSelectionMode.All;
                }
 
                public ISurface SelectionLeft {
diff --git a/LongoMatch.Drawing/CanvasObjects/TimeNodeObject.cs 
b/LongoMatch.Drawing/CanvasObjects/TimeNodeObject.cs
index c3f4da4..13c8aea 100644
--- a/LongoMatch.Drawing/CanvasObjects/TimeNodeObject.cs
+++ b/LongoMatch.Drawing/CanvasObjects/TimeNodeObject.cs
@@ -34,8 +34,7 @@ namespace LongoMatch.Drawing.CanvasObjects
                public TimeNodeObject (TimeNode node)
                {
                        TimeNode = node;
-                       SelectWhole = true;
-                       MoveWhole = true;
+                       SelectionMode = NodeSelectionMode.All;
                        LineColor = Config.Style.PaletteBackgroundLight;
                }
 
@@ -53,12 +52,11 @@ namespace LongoMatch.Drawing.CanvasObjects
                        set;
                }
 
-               public bool SelectWhole {
-                       get;
-                       set;
-               }
-
-               public bool MoveWhole {
+               /// <summary>
+               /// Gets or sets the selection mode.
+               /// </summary>
+               /// <value>The selection mode.</value>
+               public NodeSelectionMode SelectionMode {
                        get;
                        set;
                }
@@ -123,15 +121,22 @@ namespace LongoMatch.Drawing.CanvasObjects
 
                public Selection GetSelection (Point point, double precision, bool inMotion=false)
                {
-                       double accuracy;
-                       if (point.Y >= OffsetY && point.Y < OffsetY + 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 (SelectWhole && point.X > StartX && point.X < StopX) {
-                                       return new Selection (this, SelectionPosition.All,
-                                                             Math.Abs (CenterX - point.X));
+                       if (SelectionMode == NodeSelectionMode.Borders || SelectionMode == 
NodeSelectionMode.All) {
+                               double accuracy;
+                               if (point.Y >= OffsetY && point.Y < OffsetY + 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);
+                                       }
+                               }
+                       }
+
+                       if (SelectionMode == NodeSelectionMode.Segment || SelectionMode == 
NodeSelectionMode.All) {
+                               if (point.Y >= OffsetY && point.Y < OffsetY + Height) {
+                                       if (point.X > StartX && point.X < StopX) {
+                                               return new Selection (this, SelectionPosition.All, Math.Abs 
(CenterX - point.X));
+                                       }
                                }
                        }
                        return null;
@@ -154,27 +159,25 @@ namespace LongoMatch.Drawing.CanvasObjects
                        }
 
                        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;
-                       case SelectionPosition.All:
-                               if (MoveWhole) {
+                               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;
+                               case SelectionPosition.All:
                                        Time diff = Utils.PosToTime (new Point (p.X - start.X, p.Y), 
SecondsPerPixel);
                                        TimeNode.Start += diff;
                                        TimeNode.Stop += diff;
-                               }
-                               break;
+                                       break;
                        }
                        movingPos = sel.Position;
                }
diff --git a/LongoMatch.Drawing/CanvasObjects/TimelineObject.cs 
b/LongoMatch.Drawing/CanvasObjects/TimelineObject.cs
index 63af0db..b910cfe 100644
--- a/LongoMatch.Drawing/CanvasObjects/TimelineObject.cs
+++ b/LongoMatch.Drawing/CanvasObjects/TimelineObject.cs
@@ -265,13 +265,13 @@ namespace LongoMatch.Drawing.CanvasObjects
 
                List<Timer> timers;
 
-               public TimerTimeline (List<Timer> timers, bool showName, bool selectWhole, bool showLine,
+               public TimerTimeline (List<Timer> timers, bool showName, NodeSelectionMode selectionMode, 
bool showLine,
                                      Time maxTime, double offsetY, Color background, Color lineColor):
                        base (maxTime, offsetY, background)
                {
                        this.timers = timers;
                        ShowName = showName;
-                       SelectWhole = selectWhole;
+                       SelectionMode = selectionMode;
                        ShowLine = showLine;
                        LineColor = lineColor;
        
@@ -293,7 +293,7 @@ namespace LongoMatch.Drawing.CanvasObjects
                        set;
                }
                
-               bool SelectWhole {
+               NodeSelectionMode SelectionMode {
                        get;
                        set;
                }
@@ -337,7 +337,7 @@ namespace LongoMatch.Drawing.CanvasObjects
                        to.OffsetY = OffsetY;
                        to.SecondsPerPixel = SecondsPerPixel;
                        to.MaxTime = maxTime;
-                       to.SelectWhole = SelectWhole;
+                       to.SelectionMode = SelectionMode;
                        to.ShowName = ShowName;
                        to.LineColor = LineColor;
                        AddNode (to);
diff --git a/LongoMatch.Drawing/Widgets/PlaysTimeline.cs b/LongoMatch.Drawing/Widgets/PlaysTimeline.cs
index cfd4b4b..816f439 100644
--- a/LongoMatch.Drawing/Widgets/PlaysTimeline.cs
+++ b/LongoMatch.Drawing/Widgets/PlaysTimeline.cs
@@ -186,7 +186,7 @@ namespace LongoMatch.Drawing.Widgets
                        int i = 0;
 
                        tl = new TimerTimeline (project.Periods.Select (p => p as Timer).ToList (),
-                                               true, true, false, duration,
+                               true, NodeSelectionMode.All, false, duration,
                                                i * StyleConf.TimelineCategoryHeight,
                                                Utils.ColorForRow (i), Config.Style.PaletteBackgroundDark);
                        AddTimeline (tl, null);
@@ -194,7 +194,7 @@ namespace LongoMatch.Drawing.Widgets
                        i++;
 
                        foreach (Timer t in project.Timers) {
-                               tl = new TimerTimeline (new List<Timer> { t }, false, true, false, duration,
+                               tl = new TimerTimeline (new List<Timer> { t }, false, NodeSelectionMode.All, 
false, duration,
                                                        i * StyleConf.TimelineCategoryHeight,
                                                        Utils.ColorForRow (i), 
Config.Style.PaletteBackgroundDark);
                                AddTimeline (tl, t);
diff --git a/LongoMatch.Drawing/Widgets/TimersTimeline.cs b/LongoMatch.Drawing/Widgets/TimersTimeline.cs
index 39ef2b9..86ad978 100644
--- a/LongoMatch.Drawing/Widgets/TimersTimeline.cs
+++ b/LongoMatch.Drawing/Widgets/TimersTimeline.cs
@@ -1,3 +1,20 @@
+//
+//  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.Linq;
 using LongoMatch.Core.Store;
 using LongoMatch.Drawing.CanvasObjects;
@@ -82,7 +99,7 @@ namespace LongoMatch.Drawing.Widgets
                void FillCanvas (List<Timer> timers)
                {
                        widget.Height = Constants.TIMER_HEIGHT;
-                       timertimeline = new TimerTimeline (timers, true, true, true, duration, 0,
+                       timertimeline = new TimerTimeline (timers, true, NodeSelectionMode.All, true, 
duration, 0,
                                                           Config.Style.PaletteBackground,
                                                           Config.Style.PaletteBackgroundLight);
                        foreach (Timer t in timers) {


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