[longomatch] Fix score and card buttons in manual mode



commit c3feebf074477113c933314ed9dadd733edb7b9d
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Mon Dec 22 14:28:24 2014 +0100

    Fix score and card buttons in manual mode

 LongoMatch.Drawing/CanvasObjects/CardObject.cs     |   30 ++++++---
 LongoMatch.Drawing/CanvasObjects/CategoryObject.cs |   48 +++----------
 LongoMatch.Drawing/CanvasObjects/ScoreObject.cs    |   10 ++-
 LongoMatch.Drawing/CanvasObjects/TaggerObject.cs   |   74 +++++++++++++++++++-
 LongoMatch.Drawing/Widgets/DashboardCanvas.cs      |    6 +-
 5 files changed, 111 insertions(+), 57 deletions(-)
---
diff --git a/LongoMatch.Drawing/CanvasObjects/CardObject.cs b/LongoMatch.Drawing/CanvasObjects/CardObject.cs
index b2bbb9b..8b88be2 100644
--- a/LongoMatch.Drawing/CanvasObjects/CardObject.cs
+++ b/LongoMatch.Drawing/CanvasObjects/CardObject.cs
@@ -22,7 +22,7 @@ using LongoMatch.Core.Store;
 
 namespace LongoMatch.Drawing.CanvasObjects
 {
-       public class CardObject: TaggerObject
+       public class CardObject: TimedTaggerObject
        {
                public CardObject (PenaltyCardButton card): base (card)
                {
@@ -33,18 +33,28 @@ namespace LongoMatch.Drawing.CanvasObjects
                        get;
                        set;
                }
-
+               
                public override void Draw (IDrawingToolkit tk, Area area)
                {
+                       Color front, back;
+                       int width;
+
                        if (!UpdateDrawArea (tk, area, Area)) {
                                return;
                        }
                        tk.Begin ();
 
-                       /* Draw Rectangle */
-                       tk.FillColor = CurrentBackgroundColor;
-                       tk.StrokeColor = CurrentBackgroundColor;
-                       tk.LineWidth = 0;
+                       if (Active) {
+                               tk.LineWidth = StyleConf.ButtonLineWidth;
+                               tk.StrokeColor = BackgroundColor;
+                               tk.FillColor = TextColor;
+                       } else {
+                               tk.LineWidth = 0;
+                               tk.StrokeColor = TextColor;
+                               tk.FillColor =  BackgroundColor;
+                       }
+
+                       /* Draw Shape */
                        switch (Button.PenaltyCard.Shape) {
                        case CardShape.Rectangle:
                                tk.DrawRoundedRectangle (Button.Position, Button.Width, Button.Height, 3);
@@ -62,9 +72,11 @@ namespace LongoMatch.Drawing.CanvasObjects
 
                        /* Draw header */
                        tk.LineWidth = 2;
-                       tk.StrokeColor = Button.TextColor;
-                       tk.FillColor = Button.TextColor;
-                       tk.DrawText (Position, Button.Width, Button.Height, Button.PenaltyCard.Name);
+                       if (Recording) {
+                               tk.DrawText (Position, Button.Width, Button.Height, (CurrentTime - 
Start).ToSecondsString());
+                       } else {
+                               tk.DrawText (Position, Button.Width, Button.Height, Button.PenaltyCard.Name);
+                       }
                        DrawSelectionArea (tk);
                        tk.End ();
                }
diff --git a/LongoMatch.Drawing/CanvasObjects/CategoryObject.cs 
b/LongoMatch.Drawing/CanvasObjects/CategoryObject.cs
index 429c580..5170f20 100644
--- a/LongoMatch.Drawing/CanvasObjects/CategoryObject.cs
+++ b/LongoMatch.Drawing/CanvasObjects/CategoryObject.cs
@@ -26,7 +26,7 @@ using LongoMatch.Core.Store.Drawables;
 
 namespace LongoMatch.Drawing.CanvasObjects
 {
-       public class CategoryObject: TaggerObject
+       public class CategoryObject: TimedTaggerObject
        {
                public event ButtonSelectedHandler EditButtonTagsEvent;
 
@@ -37,11 +37,10 @@ namespace LongoMatch.Drawing.CanvasObjects
                static Image applyImage;
                Dictionary <Rectangle, object> rects, buttonsRects;
                Dictionary <string, List<Tag>> tagsByGroup;
-               bool recording, emitEvent, delayEvent, editClicked;
+               bool emitEvent, delayEvent, editClicked;
                bool cancelClicked, applyClicked, moved;
                int nrows;
                const int TIMEOUT_MS = 800;
-               Time currentTime;
                System.Threading.Timer timer;
                object cancelButton = new object ();
                object editbutton = new object ();
@@ -55,7 +54,6 @@ namespace LongoMatch.Drawing.CanvasObjects
                        rects = new Dictionary <Rectangle, object> ();
                        buttonsRects = new Dictionary <Rectangle, object> ();
                        SelectedTags = new List<Tag> ();
-                       currentTime = new Time (0);
                        cancelRect = new Rectangle (new Point (0, 0), 0, 0);
                        editRect = new Rectangle (new Point (0, 0), 0, 0);
                        applyRect = new Rectangle (new Point (0, 0), 0, 0);
@@ -103,23 +101,6 @@ namespace LongoMatch.Drawing.CanvasObjects
                        }
                }
 
-               public Time CurrentTime {
-                       get {
-                               return currentTime;
-                       }
-                       set {
-                               bool secsChanged = currentTime.TotalSeconds != value.TotalSeconds;
-                               currentTime = value;
-                               if (Start != null) {
-                                       if (currentTime < Start) {
-                                               Clear ();
-                                       } else if (secsChanged) {
-                                               ReDraw ();
-                                       }
-                               }
-                       }
-               }
-
                public override Color BackgroundColor {
                        get {
                                return Tagger.BackgroundColor;
@@ -186,14 +167,12 @@ namespace LongoMatch.Drawing.CanvasObjects
                        ReDraw ();
                }
 
-               void Clear ()
+               override protected void Clear ()
                {
-                       recording = false;
+                       base.Clear();
                        emitEvent = false;
                        cancelClicked = false;
-                       Start = null;
                        SelectedTags.Clear ();
-                       Active = false;
                }
 
                void EmitCreateEvent ()
@@ -202,15 +181,6 @@ namespace LongoMatch.Drawing.CanvasObjects
                        Clear ();
                }
 
-               void StartRecording ()
-               {
-                       recording = true;
-                       if (Start == null) {
-                               Start = CurrentTime;
-                       }
-                       Active = true;
-               }
-
                void TimerCallback (Object state)
                {
                        Config.DrawingToolkit.Invoke (delegate {
@@ -237,7 +207,7 @@ namespace LongoMatch.Drawing.CanvasObjects
                                emitEvent = true;
                                Active = true;
                        } else if (Button.TagMode == TagMode.Free) {
-                               if (!recording) {
+                               if (!Recording) {
                                        StartRecording ();
                                } else {
                                        emitEvent = true;
@@ -415,12 +385,12 @@ namespace LongoMatch.Drawing.CanvasObjects
 
                        if (ShowTags) {
                                rects.Add (new Rectangle (Position, Width, HeaderHeight), Button);
-                               if (recording) {
+                               if (Recording) {
                                        /* Draw Timer instead */
                                        return;
                                }
                        } else {
-                               if (!recording) {
+                               if (!Recording) {
                                        width = Width;
                                        height = Height - HeaderHeight;
                                        pos = new Point (Position.X, Position.Y + HeaderHeight);
@@ -486,7 +456,7 @@ namespace LongoMatch.Drawing.CanvasObjects
 
                void DrawRecordTime (IDrawingToolkit tk)
                {
-                       if (recording && Mode != TagMode.Edit) {
+                       if (Recording && Mode != TagMode.Edit) {
                                if (ShowTags) {
                                        tk.FontSize = 12;
                                        tk.FontWeight = FontWeight.Normal;
@@ -547,7 +517,7 @@ namespace LongoMatch.Drawing.CanvasObjects
                        width = StyleConf.ButtonRecWidth;
                        height = HeaderHeight;
                        tk.FontSize = StyleConf.ButtonButtonsFontSize;
-                       if (!recording) {
+                       if (!Recording) {
                                tk.FillColor = Config.Style.PaletteBackgroundDark;
                                tk.StrokeColor = BackgroundColor;
                                tk.LineWidth = StyleConf.ButtonLineWidth;
diff --git a/LongoMatch.Drawing/CanvasObjects/ScoreObject.cs b/LongoMatch.Drawing/CanvasObjects/ScoreObject.cs
index 05f4812..2224fdb 100644
--- a/LongoMatch.Drawing/CanvasObjects/ScoreObject.cs
+++ b/LongoMatch.Drawing/CanvasObjects/ScoreObject.cs
@@ -16,14 +16,12 @@
 //  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 //
 using System;
-using LongoMatch.Core.Interfaces.Drawing;
 using LongoMatch.Core.Common;
-using LongoMatch.Core.Interfaces;
 using LongoMatch.Core.Store;
 
 namespace LongoMatch.Drawing.CanvasObjects
 {
-       public class ScoreObject: TaggerObject
+       public class ScoreObject: TimedTaggerObject
        {
                static Image iconImage;
 
@@ -49,7 +47,11 @@ namespace LongoMatch.Drawing.CanvasObjects
 
                public override string Text {
                        get {
-                               return Button.Name;
+                               if (Recording) {
+                                       return (CurrentTime - Start).ToSecondsString ();
+                               } else {
+                                       return Button.Name;
+                               }
                        }
                }
        }
diff --git a/LongoMatch.Drawing/CanvasObjects/TaggerObject.cs 
b/LongoMatch.Drawing/CanvasObjects/TaggerObject.cs
index 2790bcd..8b51064 100644
--- a/LongoMatch.Drawing/CanvasObjects/TaggerObject.cs
+++ b/LongoMatch.Drawing/CanvasObjects/TaggerObject.cs
@@ -65,12 +65,17 @@ namespace LongoMatch.Drawing.CanvasObjects
                        }
                }
 
+               public Time Start {
+                       get;
+                       set;
+               }
+
                public override Color BackgroundColor {
                        get {
                                return Tagger.BackgroundColor;
                        }
                }
-               
+
                public override Color BackgroundColorActive {
                        get {
                                return Tagger.DarkColor;
@@ -117,11 +122,76 @@ namespace LongoMatch.Drawing.CanvasObjects
                                return 1;
                        }
                }
+       }
 
-               public Time Start {
+       public class TimedTaggerObject: TaggerObject
+       {
+               Time currentTime;
+
+               public TimedTaggerObject (TimedDashboardButton button): base (button)
+               {
+                       TimedButton = button;
+                       currentTime = new Time (0);
+                       Start = null;
+               }
+
+               public TimedDashboardButton TimedButton {
                        get;
                        set;
                }
+
+               public Time CurrentTime {
+                       get {
+                               return currentTime;
+                       }
+                       set {
+                               Time prevCurrentTime = currentTime;
+                               currentTime = value;
+                               if (Start != null) {
+                                       bool secsChanged = (prevCurrentTime - Start).TotalSeconds != (value - 
Start).TotalSeconds;
+                                       if (currentTime < Start) {
+                                               Clear ();
+                                       } else if (secsChanged) {
+                                               ReDraw ();
+                                       }
+                               }
+                       }
+               }
+
+               protected bool Recording {
+                       get;
+                       set;
+               }
+
+               public override void ClickReleased ()
+               {
+                       if (TimedButton.TagMode == TagMode.Predefined) {
+                               Active = !Active;
+                               EmitClickEvent ();
+                       } else if (!Recording) {
+                               StartRecording ();
+                       } else {
+                               EmitClickEvent ();
+                               Clear ();
+                       }
+               }
+
+               protected void StartRecording ()
+               {
+                       Recording = true;
+                       if (Start == null) {
+                               Start = CurrentTime;
+                       }
+                       Active = true;
+                       ReDraw ();
+               }
+
+               protected virtual void Clear ()
+               {
+                       Recording = false;
+                       Start = null;
+                       Active = false;
+               }
        }
 }
 
diff --git a/LongoMatch.Drawing/Widgets/DashboardCanvas.cs b/LongoMatch.Drawing/Widgets/DashboardCanvas.cs
index f71a323..2da58d6 100644
--- a/LongoMatch.Drawing/Widgets/DashboardCanvas.cs
+++ b/LongoMatch.Drawing/Widgets/DashboardCanvas.cs
@@ -85,9 +85,9 @@ namespace LongoMatch.Drawing.Widgets
                                foreach (TimerObject to in Objects.OfType<TimerObject>()) {
                                        to.CurrentTime = value;
                                }
-                               foreach (CategoryObject co in Objects.OfType<CategoryObject>()) {
-                                       if (co.Button.TagMode == TagMode.Free) {
-                                               co.CurrentTime = value;
+                               foreach (TimedTaggerObject to in Objects.OfType<TimedTaggerObject>()) {
+                                       if (to.TimedButton.TagMode == TagMode.Free) {
+                                               to.CurrentTime = value;
                                        }
                                }
                        }


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