[longomatch] Notify buttons click to subclasses



commit d36c2e77e2de257ef3967f0fdb98407d947f054a
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Mon Aug 4 12:49:56 2014 +0200

    Notify buttons click to subclasses

 LongoMatch.Core/Interfaces/Drawing/ICanvas.cs   |    2 +
 LongoMatch.Drawing/Canvas.cs                    |   12 ++++++
 LongoMatch.Drawing/CanvasObject/CanvasObject.cs |   44 +++++++++++++---------
 3 files changed, 40 insertions(+), 18 deletions(-)
---
diff --git a/LongoMatch.Core/Interfaces/Drawing/ICanvas.cs b/LongoMatch.Core/Interfaces/Drawing/ICanvas.cs
index 5aa621c..a3431e6 100644
--- a/LongoMatch.Core/Interfaces/Drawing/ICanvas.cs
+++ b/LongoMatch.Core/Interfaces/Drawing/ICanvas.cs
@@ -34,6 +34,8 @@ namespace LongoMatch.Interfaces.Drawing
                void Draw (IDrawingToolkit tk, Area area);
                bool Visible {set; get;}
                string Description {set; get;}
+               void ClickPressed (Point p);
+               void ClickReleased ();
        }
        
        public interface ICanvasSelectableObject: ICanvasObject, IMovableObject
diff --git a/LongoMatch.Drawing/Canvas.cs b/LongoMatch.Drawing/Canvas.cs
index d69bda2..75bdab4 100644
--- a/LongoMatch.Drawing/Canvas.cs
+++ b/LongoMatch.Drawing/Canvas.cs
@@ -75,6 +75,7 @@ namespace LongoMatch.Drawing
                protected bool moving;
                protected Point start; 
                uint lastTime;
+               Selection clickedSel;
                
                public SelectionCanvas (IWidget widget): base (widget) {
                        Selections = new List<Selection>();
@@ -201,6 +202,11 @@ namespace LongoMatch.Drawing
                        Selection sel;
                        
                        sel = GetSelection (coords);
+                       
+                       clickedSel = sel;
+                       if (sel != null) {
+                               (sel.Drawable as ICanvasSelectableObject).ClickPressed (coords);
+                       }
 
                        if ((SelectionMode == MultiSelectionMode.Multiple) ||
                            (SelectionMode == MultiSelectionMode.MultipleWithModifier &&
@@ -244,6 +250,12 @@ namespace LongoMatch.Drawing
                void HandleButtonReleasedEvent (Point coords, ButtonType type, ButtonModifier modifier)
                {
                        moving = false;
+                       
+                       if (clickedSel != null) {
+                               (clickedSel.Drawable as ICanvasSelectableObject).ClickReleased ();
+                               clickedSel = null;
+                               widget.ReDraw ();
+                       }
                        StopMove ();
                }
 
diff --git a/LongoMatch.Drawing/CanvasObject/CanvasObject.cs b/LongoMatch.Drawing/CanvasObject/CanvasObject.cs
index ed67d7c..a1b1b4b 100644
--- a/LongoMatch.Drawing/CanvasObject/CanvasObject.cs
+++ b/LongoMatch.Drawing/CanvasObject/CanvasObject.cs
@@ -15,9 +15,7 @@
 //  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;
 using LongoMatch.Store.Drawables;
 
@@ -25,29 +23,37 @@ namespace LongoMatch.Drawing.CanvasObject
 {
        public abstract class CanvasObject: ICanvasObject
        {
-               public CanvasObject ()
+               protected CanvasObject ()
                {
                        Visible = true;
                }
-               
+
                public virtual string Description {
                        get;
                        set;
                }
-               
+
                public bool Visible {
                        get;
                        set;
                }
-               
+
                public virtual bool Selected {
                        set;
                        get;
                }
-               
+
+               public virtual void ClickPressed (Point p)
+               {
+               }
+
+               public virtual void ClickReleased ()
+               {
+               }
+
                public abstract void Draw (IDrawingToolkit tk, Area area);
        }
-       
+
        public abstract class CanvasDrawableObject<T>: CanvasObject, ICanvasDrawableObject where T: 
IBlackboardObject
        {
                
@@ -56,15 +62,15 @@ namespace LongoMatch.Drawing.CanvasObject
                                return Drawable;
                        }
                        set {
-                               Drawable = (T) value;
+                               Drawable = (T)value;
                        }
                }
-               
+
                public T Drawable {
                        get;
                        set;
                }
-               
+
                public override bool Selected {
                        get {
                                return Drawable.Selected;
@@ -73,16 +79,18 @@ namespace LongoMatch.Drawing.CanvasObject
                                Drawable.Selected = value;
                        }
                }
-               
-               public Selection GetSelection (Point point, double precision) {
+
+               public Selection GetSelection (Point point, double precision)
+               {
                        Selection sel = Drawable.GetSelection (point, precision);
                        if (sel != null) {
                                sel.Drawable = this;
                        }
                        return sel;
                }
-               
-               public void Move (Selection s, Point p, Point start) {
+
+               public void Move (Selection s, Point p, Point start)
+               {
                        s.Drawable = Drawable;
                        Drawable.Move (s, p, start);
                        s.Drawable = this;
@@ -101,8 +109,9 @@ namespace LongoMatch.Drawing.CanvasObject
                        tk.LineStyle = LineStyle.Normal;
                        tk.DrawCircle (p, 3);
                }
-               
-               protected void DrawSelectionArea (IDrawingToolkit tk) {
+
+               protected void DrawSelectionArea (IDrawingToolkit tk)
+               {
                        Area area;
                        
                        area = Drawable.Area;
@@ -122,6 +131,5 @@ namespace LongoMatch.Drawing.CanvasObject
                                DrawCenterSelection (tk, p);
                        }
                }
-
        }
 }
\ No newline at end of file


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