[longomatch] Create a new base class for buttons
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch] Create a new base class for buttons
- Date: Wed, 24 Sep 2014 20:30:58 +0000 (UTC)
commit a31cbaea568ea9f729fed4e459f58e1b731b188e
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date: Tue Sep 16 12:46:20 2014 +0200
Create a new base class for buttons
LongoMatch.Drawing/CanvasObjects/ButtonObject.cs | 154 ++++++++++++++++++++
LongoMatch.Drawing/CanvasObjects/CardObject.cs | 6 +-
LongoMatch.Drawing/CanvasObjects/CategoryObject.cs | 8 +-
LongoMatch.Drawing/CanvasObjects/ScoreObject.cs | 2 +-
LongoMatch.Drawing/CanvasObjects/TagObject.cs | 2 +-
LongoMatch.Drawing/CanvasObjects/TaggerObject.cs | 124 ++++------------
LongoMatch.Drawing/CanvasObjects/TimerObject.cs | 4 +-
LongoMatch.Drawing/LongoMatch.Drawing.csproj | 1 +
LongoMatch.Drawing/Makefile.am | 1 +
9 files changed, 200 insertions(+), 102 deletions(-)
---
diff --git a/LongoMatch.Drawing/CanvasObjects/ButtonObject.cs
b/LongoMatch.Drawing/CanvasObjects/ButtonObject.cs
new file mode 100644
index 0000000..bf3251d
--- /dev/null
+++ b/LongoMatch.Drawing/CanvasObjects/ButtonObject.cs
@@ -0,0 +1,154 @@
+//
+// 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.Core.Common;
+using LongoMatch.Core.Store.Drawables;
+using LongoMatch.Core.Interfaces.Drawing;
+
+namespace LongoMatch.Drawing.CanvasObjects
+{
+ public class ButtonObject: CanvasButtonObject, IMovableObject
+ {
+ public virtual Point Position {
+ get;
+ set;
+ }
+
+ public virtual double Width {
+ get;
+ set;
+ }
+
+ public virtual double Height {
+ get;
+ set;
+ }
+
+ public virtual Color BorderColor {
+ get;
+ set;
+ }
+
+ public virtual Color BackgroundColor {
+ get;
+ set;
+ }
+
+ protected Color CurrentBackgroundColor {
+ get {
+ if (!Active) {
+ return BorderColor;
+ } else {
+ return BackgroundColor;
+ }
+ }
+ }
+
+ public TagMode Mode {
+ get;
+ set;
+ }
+
+ protected Point DrawPosition {
+ get {
+ if (!Active) {
+ return Position;
+ } else {
+ return new Point (Position.X + 1, Position.Y + 1);
+ }
+ }
+ }
+
+ public Selection GetSelection (Point p, double precision, bool inMotion=false)
+ {
+ Selection s;
+
+ Rectangle r = new Rectangle (Position, Width, Height);
+ s = r.GetSelection (p, precision);
+ if (s != null) {
+ s.Drawable = this;
+ if (s.Position != SelectionPosition.BottomRight &&
+ s.Position != SelectionPosition.Right &&
+ s.Position != SelectionPosition.Bottom) {
+ s.Position = SelectionPosition.All;
+ }
+ }
+ return s;
+ }
+
+ public void Move (Selection s, Point p, Point start)
+ {
+ switch (s.Position) {
+ case SelectionPosition.Right:
+ Width = (int)(p.X - Position.X);
+ Width = (int)Math.Max (10, Width);
+ break;
+ case SelectionPosition.Bottom:
+ Height = (int)(p.Y - Position.Y);
+ Height = (int)Math.Max (10, Height);
+ break;
+ case SelectionPosition.BottomRight:
+ Width = (int)(p.X - Position.X);
+ Height = (int)(p.Y - Position.Y);
+ Width = Math.Max (10, Width);
+ Height = Math.Max (10, Height);
+ break;
+ case SelectionPosition.All:
+ Position.X += p.X - start.X;
+ Position.Y += p.Y - start.Y;
+ Position.X = Math.Max (Position.X, 0);
+ Position.Y = Math.Max (Position.Y, 0);
+ break;
+ default:
+ throw new Exception ("Unsupported move for tagger object: " + s.Position);
+ }
+ }
+
+ protected void DrawSelectionArea (IDrawingToolkit tk)
+ {
+ if (!Selected || Mode != TagMode.Edit) {
+ return;
+ }
+ tk.StrokeColor = Constants.SELECTION_INDICATOR_COLOR;
+ tk.StrokeColor = Constants.SELECTION_AREA_COLOR;
+ tk.FillColor = null;
+ tk.LineStyle = LineStyle.Dashed;
+ tk.LineWidth = 1;
+ tk.DrawRectangle (DrawPosition, Width, Height);
+
+ tk.StrokeColor = tk.FillColor = Constants.SELECTION_INDICATOR_COLOR;
+ tk.LineStyle = LineStyle.Normal;
+ tk.DrawRectangle (new Point (DrawPosition.X + Width - 3,
+ DrawPosition.Y + Height - 3),
+ 6, 6);
+ }
+
+ protected void DrawButton (IDrawingToolkit tk)
+ {
+ tk.LineWidth = 0;
+ tk.DrawButton (DrawPosition, Width, Height, 3, BorderColor, CurrentBackgroundColor);
+ }
+
+ public override void Draw (IDrawingToolkit tk, Area area)
+ {
+ tk.Begin ();
+ tk.End ();
+ }
+ }
+}
+
diff --git a/LongoMatch.Drawing/CanvasObjects/CardObject.cs b/LongoMatch.Drawing/CanvasObjects/CardObject.cs
index 4c504fa..4b3ee1d 100644
--- a/LongoMatch.Drawing/CanvasObjects/CardObject.cs
+++ b/LongoMatch.Drawing/CanvasObjects/CardObject.cs
@@ -40,8 +40,8 @@ namespace LongoMatch.Drawing.CanvasObjects
tk.Begin ();
/* Draw Rectangle */
- tk.FillColor = Color;
- tk.StrokeColor = Color;
+ tk.FillColor = CurrentBackgroundColor;
+ tk.StrokeColor = CurrentBackgroundColor;
tk.LineWidth = 0;
switch (Button.PenaltyCard.Shape) {
case CardShape.Rectangle:
@@ -62,7 +62,7 @@ namespace LongoMatch.Drawing.CanvasObjects
tk.LineWidth = 2;
tk.StrokeColor = Color.Grey2;
tk.FillColor = Color.Grey2;
- tk.DrawText (Position, Button.Width, Button.Height, Button.PenaltyCard.Name);
+ tk.DrawText (DrawPosition, 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 545573e..f603e51 100644
--- a/LongoMatch.Drawing/CanvasObjects/CategoryObject.cs
+++ b/LongoMatch.Drawing/CanvasObjects/CategoryObject.cs
@@ -47,6 +47,12 @@ namespace LongoMatch.Drawing.CanvasObjects
set;
}
+ public override Color BackgroundColor {
+ get {
+ return Tagger.BackgroundColor;
+ }
+ }
+
public override int NRows {
get {
/* Header */
@@ -141,7 +147,7 @@ namespace LongoMatch.Drawing.CanvasObjects
tk.FontWeight = FontWeight.Bold;
/* Draw Rectangle */
- DrawButton (tk, true);
+ DrawButton (tk);
/* Draw header */
tk.FillColor = LongoMatch.Core.Common.Color.Grey2;
diff --git a/LongoMatch.Drawing/CanvasObjects/ScoreObject.cs b/LongoMatch.Drawing/CanvasObjects/ScoreObject.cs
index 00206dd..e021457 100644
--- a/LongoMatch.Drawing/CanvasObjects/ScoreObject.cs
+++ b/LongoMatch.Drawing/CanvasObjects/ScoreObject.cs
@@ -46,7 +46,7 @@ namespace LongoMatch.Drawing.CanvasObjects
tk.LineWidth = 2;
tk.StrokeColor = Button.TextColor;
tk.FillColor = Button.TextColor;
- tk.DrawText (Position, Button.Width, Button.Height, Button.Score.Name);
+ tk.DrawText (DrawPosition, Button.Width, Button.Height, Button.Score.Name);
DrawSelectionArea (tk);
tk.End ();
}
diff --git a/LongoMatch.Drawing/CanvasObjects/TagObject.cs b/LongoMatch.Drawing/CanvasObjects/TagObject.cs
index 7f189f7..5adeaf7 100644
--- a/LongoMatch.Drawing/CanvasObjects/TagObject.cs
+++ b/LongoMatch.Drawing/CanvasObjects/TagObject.cs
@@ -47,7 +47,7 @@ namespace LongoMatch.Drawing.CanvasObjects
tk.LineWidth = 2;
tk.StrokeColor = TagButton.TextColor;
tk.FillColor = TagButton.TextColor;
- tk.DrawText (Position, TagButton.Width, TagButton.Height, TagButton.Tag.Value);
+ tk.DrawText (DrawPosition, TagButton.Width, TagButton.Height, TagButton.Tag.Value);
DrawSelectionArea (tk);
tk.End ();
}
diff --git a/LongoMatch.Drawing/CanvasObjects/TaggerObject.cs
b/LongoMatch.Drawing/CanvasObjects/TaggerObject.cs
index 0e1a592..3d33d4a 100644
--- a/LongoMatch.Drawing/CanvasObjects/TaggerObject.cs
+++ b/LongoMatch.Drawing/CanvasObjects/TaggerObject.cs
@@ -25,7 +25,7 @@ using LongoMatch.Core.Handlers;
namespace LongoMatch.Drawing.CanvasObjects
{
- public abstract class TaggerObject: CanvasButtonObject, ICanvasSelectableObject
+ public class TaggerObject: ButtonObject, ICanvasSelectableObject
{
public TaggerObject (DashboardButton tagger)
@@ -38,120 +38,56 @@ namespace LongoMatch.Drawing.CanvasObjects
set;
}
- public Point Position {
+ public override Point Position {
get {
- if (!Active) {
- return Tagger.Position;
- } else {
- return new Point (Tagger.Position.X + 1, Tagger.Position.Y + 1);
- }
+ return Tagger.Position;
+ }
+ set {
+ Tagger.Position = value;
}
}
-
- public Color Color {
+
+ public override double Width {
get {
- if (!Active) {
- return Tagger.BackgroundColor;
- } else {
- return Tagger.DarkColor;
- }
+ return Tagger.Width;
+ }
+ set {
+ Tagger.Width = (int) value;
}
}
-
- public TagMode Mode {
- get;
- set;
- }
-
- public virtual int NRows {
+
+ public override double Height {
get {
- return 1;
+ return Tagger.Height;
+ }
+ set {
+ Tagger.Height = (int) value;
}
}
- public Time Start {
- get;
- set;
- }
-
- public Selection GetSelection (Point p, double precision, bool inMotion=false)
- {
- Selection s;
-
- Rectangle r = new Rectangle (Tagger.Position, Tagger.Width,
- Tagger.Height);
- s = r.GetSelection (p, precision);
- if (s != null) {
- s.Drawable = this;
- if (s.Position != SelectionPosition.BottomRight &&
- s.Position != SelectionPosition.Right &&
- s.Position != SelectionPosition.Bottom) {
- s.Position = SelectionPosition.All;
- }
+ public override Color BackgroundColor {
+ get {
+ return Tagger.DarkColor;
}
- return s;
}
- public void Move (Selection s, Point p, Point start)
- {
- switch (s.Position) {
- case SelectionPosition.Right:
- Tagger.Width = (int)(p.X - Tagger.Position.X);
- Tagger.Width = (int)Math.Max (10, Tagger.Width);
- break;
- case SelectionPosition.Bottom:
- Tagger.Height = (int)(p.Y - Tagger.Position.Y);
- Tagger.Height = (int)Math.Max (10, Tagger.Height);
- break;
- case SelectionPosition.BottomRight:
- Tagger.Width = (int)(p.X - Tagger.Position.X);
- Tagger.Height = (int)(p.Y - Tagger.Position.Y);
- Tagger.Width = Math.Max (10, Tagger.Width);
- Tagger.Height = Math.Max (10, Tagger.Height);
- break;
- case SelectionPosition.All:
- {
- Tagger.Position.X += p.X - start.X;
- Tagger.Position.Y += p.Y - start.Y;
- Tagger.Position.X = Math.Max (Tagger.Position.X, 0);
- Tagger.Position.Y = Math.Max (Tagger.Position.Y, 0);
- break;
- }
- default:
- throw new Exception ("Unsupported move for tagger object: " + s.Position);
+ public override Color BorderColor {
+ get {
+ return Tagger.BackgroundColor;
}
}
- protected void DrawSelectionArea (IDrawingToolkit tk)
- {
- if (!Selected || Mode != TagMode.Edit) {
- return;
+ public virtual int NRows {
+ get {
+ return 1;
}
- tk.StrokeColor = Constants.SELECTION_INDICATOR_COLOR;
- tk.StrokeColor = Constants.SELECTION_AREA_COLOR;
- tk.FillColor = null;
- tk.LineStyle = LineStyle.Dashed;
- tk.LineWidth = 1;
- tk.DrawRectangle (Tagger.Position, Tagger.Width, Tagger.Height);
-
- tk.StrokeColor = tk.FillColor = Constants.SELECTION_INDICATOR_COLOR;
- tk.LineStyle = LineStyle.Normal;
- tk.DrawRectangle (new Point (Tagger.Position.X + Tagger.Width - 3,
- Tagger.Position.Y + Tagger.Height - 3),
- 6, 6);
}
- protected void DrawButton (IDrawingToolkit tk, bool ignoreActive=false)
- {
- tk.LineWidth = 0;
- if (Active && !ignoreActive) {
- tk.DrawButton (Tagger.Position, Tagger.Width, Tagger.Height, 3,
Tagger.BackgroundColor, Tagger.DarkColor);
- } else {
- tk.DrawButton (Tagger.Position, Tagger.Width, Tagger.Height, 3,
Tagger.BackgroundColor, Tagger.BackgroundColor);
- }
+ public Time Start {
+ get;
+ set;
}
- public abstract override void Draw (IDrawingToolkit tk, Area area);
}
}
diff --git a/LongoMatch.Drawing/CanvasObjects/TimerObject.cs b/LongoMatch.Drawing/CanvasObjects/TimerObject.cs
index c30c7de..7bbfd74 100644
--- a/LongoMatch.Drawing/CanvasObjects/TimerObject.cs
+++ b/LongoMatch.Drawing/CanvasObjects/TimerObject.cs
@@ -107,9 +107,9 @@ namespace LongoMatch.Drawing.CanvasObjects
tk.StrokeColor = Button.TextColor;
tk.FillColor = Button.TextColor;
tk.FontWeight = FontWeight.Bold;
- tk.DrawText (Position, Button.Width, h, Button.Timer.Name);
+ tk.DrawText (DrawPosition, Button.Width, h, Button.Timer.Name);
if (CurrentTimeNode != null && Mode != TagMode.Edit) {
- tk.DrawText (new Point (Position.X, Position.Y + h), Button.Width, h,
+ tk.DrawText (new Point (DrawPosition.X, Position.Y + h), Button.Width, h,
PartialTime.ToSecondsString ());
}
DrawSelectionArea (tk);
diff --git a/LongoMatch.Drawing/LongoMatch.Drawing.csproj b/LongoMatch.Drawing/LongoMatch.Drawing.csproj
index f69ce7f..d1dd21d 100644
--- a/LongoMatch.Drawing/LongoMatch.Drawing.csproj
+++ b/LongoMatch.Drawing/LongoMatch.Drawing.csproj
@@ -66,6 +66,7 @@
<Compile Include="CanvasObjects\PlayersTaggerObject.cs" />
<Compile Include="PlayslistCellRenderer.cs" />
<Compile Include="Widgets\DashboardCanvas.cs" />
+ <Compile Include="CanvasObjects\ButtonObject.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
diff --git a/LongoMatch.Drawing/Makefile.am b/LongoMatch.Drawing/Makefile.am
index eb73414..e25f19f 100644
--- a/LongoMatch.Drawing/Makefile.am
+++ b/LongoMatch.Drawing/Makefile.am
@@ -6,6 +6,7 @@ LINK = $(REF_DEP_LONGOMATCH_DRAWING)
SOURCES = Canvas.cs \
CanvasObjects/BenchObject.cs \
+ CanvasObjects/ButtonObject.cs \
CanvasObjects/CanvasObject.cs \
CanvasObjects/CardObject.cs \
CanvasObjects/CategoryLabel.cs \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]