[longomatch] Add a new widget for tagging plays



commit e67fc67ba3fc6ffb30802c1ff462b5b195841246
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Tue Jun 17 18:54:37 2014 +0200

    Add a new widget for tagging plays

 LongoMatch.Drawing/CanvasObject/PositionObject.cs |  123 +++++++++++++++++++++
 LongoMatch.Drawing/Common.cs                      |    6 +-
 LongoMatch.Drawing/LongoMatch.Drawing.mdp         |    2 +
 LongoMatch.Drawing/Widgets/PositionTagger.cs      |   96 ++++++++++++++++
 4 files changed, 226 insertions(+), 1 deletions(-)
---
diff --git a/LongoMatch.Drawing/CanvasObject/PositionObject.cs 
b/LongoMatch.Drawing/CanvasObject/PositionObject.cs
new file mode 100644
index 0000000..d068325
--- /dev/null
+++ b/LongoMatch.Drawing/CanvasObject/PositionObject.cs
@@ -0,0 +1,123 @@
+//
+//  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.Store.Drawables;
+using LongoMatch.Common;
+using LongoMatch.Store;
+using LongoMatch.Interfaces;
+using System.Collections.Generic;
+
+namespace LongoMatch.Drawing.CanvasObject
+{
+
+       public class PositionObject:  BaseCanvasObject, ICanvasSelectableObject
+       {
+
+               public PositionObject (List<Point> points, int width, int height)
+               {
+                       Points = points;
+                       Width = width;
+                       Height = height;
+               }
+               
+               public int Width {
+                       get;
+                       set;
+               }
+               
+               public int Height {
+                       get;
+                       set;
+               }
+               
+               public Play Play {
+                       get;
+                       set;
+               }
+               
+               public List<Point> Points {
+                       get;
+                       set;
+               }
+               
+               Point Start {
+                       get {
+                               return Points[0].Denormalize (Width, Height);
+                       }
+                       set{
+                               Points[0] = value.Normalize (Width, Height);
+                       }
+               }
+               
+               Point Stop {
+                       get {
+                               return Points[1].Denormalize (Width, Height);
+                       }
+                       set {
+                               Points[1] = value.Normalize (Width, Height);
+                       }
+               }
+               
+               
+               public Selection GetSelection (Point point, double precision)
+               {
+                       if (point.Distance (Start) < precision) {
+                               return new Selection (this, SelectionPosition.LineStart);
+                       } else if (Points.Count == 2 && point.Distance (Stop) < precision) {
+                               return new Selection (this, SelectionPosition.LineStop);
+                       }
+                       return null;
+               }
+               
+               public void Move (Selection sel, Point p, Point start)
+               {
+                       switch (sel.Position) {
+                       case SelectionPosition.LineStart:
+                               Start = p;
+                               break;
+                       case SelectionPosition.LineStop:
+                               Stop = p;
+                               break;
+                       default:
+                               throw new Exception ("Unsupported move for circle:  " + sel.Position);
+                       }
+               }
+               
+               public override void Draw (IDrawingToolkit tk, Area area) {
+                       Color color;
+                       
+                       tk.Begin ();
+                       if (Play != null) {
+                               color = Play.Category.Color;
+                       } else {
+                               color = Common.TAGGER_POINT_COLOR;
+                       }
+                       tk.FillColor = color;
+                       tk.StrokeColor = color;
+                       tk.LineWidth = 2;
+                       
+                       tk.DrawCircle (Start, Common.TAGGER_POINT_SIZE);
+                       if (Points.Count == 2) {
+                               tk.DrawLine (Start, Stop);
+                       }
+                       tk.End ();
+               }
+       }
+}
+
diff --git a/LongoMatch.Drawing/Common.cs b/LongoMatch.Drawing/Common.cs
index 3e967c9..e54956a 100644
--- a/LongoMatch.Drawing/Common.cs
+++ b/LongoMatch.Drawing/Common.cs
@@ -27,7 +27,11 @@ namespace LongoMatch.Drawing
                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 int TIMERULE_HEIGHT = 30;
+
+               public const int TAGGER_POINT_SIZE = 5;
+               public const int TAGGER_LINE_WIDTH = 3;
+               public static Color TAGGER_POINT_COLOR = Color.Blue1;
 
                public const double TIMELINE_ACCURACY = 5;
                public static Color TEXT_COLOR = Color.Black;
diff --git a/LongoMatch.Drawing/LongoMatch.Drawing.mdp b/LongoMatch.Drawing/LongoMatch.Drawing.mdp
index 201d25c..9e7fa2c 100644
--- a/LongoMatch.Drawing/LongoMatch.Drawing.mdp
+++ b/LongoMatch.Drawing/LongoMatch.Drawing.mdp
@@ -31,6 +31,8 @@
     <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" />
+    <File subtype="Code" buildaction="Compile" name="Widgets/PositionTagger.cs" />
+    <File subtype="Code" buildaction="Compile" name="CanvasObject/PositionObject.cs" />
     <File subtype="Code" buildaction="Compile" name="CanvasObject/CircleObject.cs" />
     <File subtype="Code" buildaction="Compile" name="CanvasObject/LineObject.cs" />
     <File subtype="Directory" buildaction="Compile" name="CanvasObject" />
diff --git a/LongoMatch.Drawing/Widgets/PositionTagger.cs b/LongoMatch.Drawing/Widgets/PositionTagger.cs
new file mode 100644
index 0000000..175f6f8
--- /dev/null
+++ b/LongoMatch.Drawing/Widgets/PositionTagger.cs
@@ -0,0 +1,96 @@
+//
+//  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 System.Linq;
+using LongoMatch.Common;
+using System.Collections.Generic;
+using LongoMatch.Store;
+using LongoMatch.Drawing.CanvasObject;
+using LongoMatch.Interfaces.Drawing;
+using LongoMatch.Store.Drawables;
+using LongoMatch.Handlers;
+
+namespace LongoMatch.Drawing.Widgets
+{
+       public class PositionTagger: BackgroundCanvas
+       {
+       
+               public event ShowTaggerMenuHandler ShowMenuEvent;
+               List<Play> plays;
+
+               public PositionTagger (IWidget widget): base (widget)
+               {
+                       Accuracy = Common.TAGGER_POINT_SIZE + 3;
+               }
+               
+               public PositionTagger (IWidget widget, List<Play> plays, Image background, FieldPositionType 
position): base (widget)
+               {
+                       Background = background;
+                       Plays = plays;
+                       FieldPosition = position;
+               }
+               
+               FieldPositionType FieldPosition {
+                       get;
+                       set;
+               }
+               
+               public void SelectPlay (Play play) {
+               }
+               
+               public List<Point> Points {
+                       set {
+                               Objects.Clear ();
+                               Objects.Add (new PositionObject (value, Background.Width, Background.Height));
+                       }
+               }
+               
+               public List<Play> Plays {
+                       set {
+                               plays = value;
+                               foreach (Play p in value) {
+                                       Coordinates coords = p.CoordinatesInFieldPosition (FieldPosition);
+                                       
+                                       Objects.Clear ();
+                                       if (coords == null)
+                                               continue;
+                                       
+                                       PositionObject po = new PositionObject (coords.Points,
+                                                                               Background.Width, 
Background.Height);
+                                       po.Play = p;
+                                       Objects.Add (po);
+                               }
+                       }
+               }
+
+               protected override void SelectionChanged (List<Selection> selections) {
+                       if (selections.Count > 0) {
+                               Play p = (selections.Last().Drawable as PositionObject).Play;
+                               Config.EventsBroker.EmitPlaySelected (p);
+                       }
+               }
+               
+               protected override void ShowMenu (Point coords) {
+                       if (ShowMenuEvent != null) {
+                               List<Play> plays = Selections.Select (p => (p.Drawable as 
PositionObject).Play).ToList();
+                               ShowMenuEvent (plays);
+                       }
+               }
+       }
+}
+


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