[longomatch] Add a new widget for tagging teams
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch] Add a new widget for tagging teams
- Date: Mon, 7 Jul 2014 11:24:31 +0000 (UTC)
commit 216d2ee6b3e232eeacc56b69259b4094633d4a48
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date: Wed May 28 16:55:24 2014 +0200
Add a new widget for tagging teams
LongoMatch.Drawing/CanvasObject/PlayerObject.cs | 129 ++++++++++++++
LongoMatch.Drawing/LongoMatch.Drawing.mdp | 6 +-
LongoMatch.Drawing/Widgets/PlaysTimeline.cs | 2 +-
LongoMatch.Drawing/Widgets/TeamTagger.cs | 216 +++++++++++++++++++++++
4 files changed, 350 insertions(+), 3 deletions(-)
---
diff --git a/LongoMatch.Drawing/CanvasObject/PlayerObject.cs b/LongoMatch.Drawing/CanvasObject/PlayerObject.cs
new file mode 100644
index 0000000..ecd350b
--- /dev/null
+++ b/LongoMatch.Drawing/CanvasObject/PlayerObject.cs
@@ -0,0 +1,129 @@
+//
+// 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;
+using LongoMatch.Interfaces;
+using LongoMatch.Common;
+using LongoMatch.Store.Drawables;
+using LongoMatch.Drawing.Widgets;
+
+namespace LongoMatch.Drawing.CanvasObject
+{
+ public class PlayerObject: BaseCanvasObject, ICanvasSelectableObject
+ {
+ public PlayerObject (Player player, Point position)
+ {
+ Player = player;
+ Position = position;
+ DrawPhoto = true;
+ SelectedColor = Common.PLAYER_SELECTED_COLOR;
+ UnSelectedColor = Common.PLAYER_UNSELECTED_COLOR;
+ }
+
+ public Player Player {
+ get;
+ protected set;
+ }
+
+ public Point Position {
+ get;
+ set;
+ }
+
+ public double Width {
+ get;
+ set;
+ }
+
+ public double Height {
+ get;
+ set;
+ }
+
+ public bool DrawPhoto {
+ get;
+ set;
+ }
+
+ public Color SelectedColor {
+ get;
+ set;
+ }
+
+ public Color UnSelectedColor {
+ get;
+ set;
+ }
+
+ public Selection GetSelection (Point point, double precision) {
+ Point position = new Point (Position.X - Width / 2, Position.Y - Height / 2);
+
+ if (point.X >= position.X && point.X <= position.X + Width) {
+ if (point.Y >= position.Y && point.Y <= position.Y + Height) {
+ return new Selection (this, SelectionPosition.All, 0);
+ }
+ }
+ return null;
+ }
+
+ public void Move (Selection sel, Point p, Point start) {
+ }
+
+ public override void Draw (IDrawingToolkit tk, Area area) {
+ Color background, line;
+ Point position = new Point (Position.X - Width / 2, Position.Y - Height / 2);
+
+ tk.Begin();
+
+ /* Background */
+ if (Selected) {
+ background = SelectedColor;
+ line = SelectedColor;
+ } else {
+ background = UnSelectedColor;
+ line = UnSelectedColor;
+ }
+ tk.StrokeColor = line;
+ tk.FillColor = background;
+ tk.LineWidth = 5;
+ tk.DrawRoundedRectangle (position, Width, Height, 5);
+
+ if (!DrawPhoto || Player.Photo == null) {
+ tk.FillColor = Color.White;
+ tk.StrokeColor = Color.White;
+ tk.FontSize = 30;
+ tk.FontWeight = FontWeight.Bold;
+ tk.DrawText (position, Width, Height - 20, Player.Number.ToString());
+ tk.FontSize = 8;
+ tk.DrawText (new Point (position.X, position.Y + Height - 20), Width, 20,
Player.Name);
+ } else {
+ tk.FillColor = Color.Black;
+ tk.StrokeColor = Color.Black;
+ tk.DrawImage (position, Width, Height, Player.Photo, true);
+ tk.FontSize = 16;
+ tk.FontWeight = FontWeight.Bold;
+ tk.DrawText (new Point (position.X, position.Y + Height - 20), Width, 20,
Player.Number.ToString());
+ }
+
+ tk.End();
+ }
+
+ }
+}
+
diff --git a/LongoMatch.Drawing/LongoMatch.Drawing.mdp b/LongoMatch.Drawing/LongoMatch.Drawing.mdp
index 70fe03c..d67c7b3 100644
--- a/LongoMatch.Drawing/LongoMatch.Drawing.mdp
+++ b/LongoMatch.Drawing/LongoMatch.Drawing.mdp
@@ -27,10 +27,12 @@
<File subtype="Code" buildaction="Compile" name="Widgets/PlaysTimeline.cs" />
<File subtype="Code" buildaction="Compile" name="CanvasObject/CategoryTimeline.cs" />
<File subtype="Code" buildaction="Compile" name="CanvasObject/BaseCanvasObject.cs" />
+ <File subtype="Code" buildaction="Compile" name="CanvasObject/PlayerObject.cs" />
+ <File subtype="Code" buildaction="Compile" name="Widgets/TeamTagger.cs" />
</Contents>
<References>
- <ProjectReference type="Gac" localcopy="True" refto="System, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089" />
+ <ProjectReference type="Package" localcopy="True" refto="System, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089" />
<ProjectReference type="Project" localcopy="True" refto="LongoMatch.Core" />
- <ProjectReference specificVersion="False" type="Gac" localcopy="False" refto="System.Core,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
+ <ProjectReference type="Package" specificVersion="False" localcopy="False" refto="System.Core,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</References>
</Project>
\ No newline at end of file
diff --git a/LongoMatch.Drawing/Widgets/PlaysTimeline.cs b/LongoMatch.Drawing/Widgets/PlaysTimeline.cs
index be3715f..cc4fcd8 100644
--- a/LongoMatch.Drawing/Widgets/PlaysTimeline.cs
+++ b/LongoMatch.Drawing/Widgets/PlaysTimeline.cs
@@ -114,7 +114,7 @@ namespace LongoMatch.Drawing.Widgets
if (i % 2 == 0) {
c = Color.White;
} else {
- c = Color.Grey;
+ c = Color.Grey1;
}
cat = project.Categories[i];
diff --git a/LongoMatch.Drawing/Widgets/TeamTagger.cs b/LongoMatch.Drawing/Widgets/TeamTagger.cs
new file mode 100644
index 0000000..2f9693a
--- /dev/null
+++ b/LongoMatch.Drawing/Widgets/TeamTagger.cs
@@ -0,0 +1,216 @@
+//
+// 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 System.Collections.Generic;
+using LongoMatch.Common;
+using LongoMatch.Interfaces.Drawing;
+using LongoMatch.Store.Drawables;
+using LongoMatch.Store.Templates;
+using LongoMatch.Drawing.CanvasObject;
+using LongoMatch.Store;
+using LongoMatch.Handlers;
+
+namespace LongoMatch.Drawing.Widgets
+{
+ public class TeamTagger: SelectionCanvas
+ {
+
+ public event PlayersPropertiesHandler PlayersSelectionChangedEvent;
+ public event PlayersPropertiesHandler ShowMenuEvent;
+
+ const int PLAYER_WIDTH = 60;
+ const int PLAYER_HEIGHT = 60;
+ const int BENCH_WIDTH = PLAYER_WIDTH * 2;
+ TeamTemplate homeTeam, awayTeam;
+ Image background;
+ double currentWidth, currentHeight, scaleX, scaleY;
+ Point offset;
+ double backgroundWidth;
+
+ public TeamTagger (IWidget widget): base (widget)
+ {
+ Accuracy = 0;
+ SelectionMode = MultiSelectionMode.MultipleWithModifier;
+ HomeColor = Common.PLAYER_UNSELECTED_COLOR;
+ AwayColor = Common.PLAYER_UNSELECTED_COLOR;
+ }
+
+ public Color HomeColor {
+ get;
+ set;
+ }
+
+ public Color AwayColor {
+ get;
+ set;
+ }
+
+ public void LoadTeams (TeamTemplate homeTeam, TeamTemplate awayTeam, Image background) {
+ this.homeTeam = homeTeam;
+ this.awayTeam = awayTeam;
+ this.background = background;
+ Resize ();
+ }
+
+ void LoadTeam (TeamTemplate template, Team team) {
+ int index = 0;
+ double width, colWidth, offsetX;
+ Color color;
+
+ width = backgroundWidth / NTeams;
+ colWidth = width / template.Formation.Length;
+ if (team == Team.LOCAL) {
+ offsetX = BENCH_WIDTH;
+ color = HomeColor;
+ } else {
+ offsetX = currentWidth - BENCH_WIDTH;
+ color = AwayColor;
+ }
+
+ /* Starting players */
+ for (int col=0; col < template.Formation.Length; col ++) {
+ double colX, rowHeight;
+
+ if (template.Count == index)
+ break;
+
+ if (team == Team.LOCAL) {
+ colX = offsetX + colWidth * col + colWidth / 2;
+ } else {
+ colX = offsetX - colWidth * col - colWidth / 2;
+ }
+ rowHeight = currentHeight / template.Formation[col];
+
+ for (int row=0; row < template.Formation[col]; row ++) {
+ Point p = new Point (colX, rowHeight * row + rowHeight / 2);
+ PlayerObject po = new PlayerObject (template [index], p);
+ po.Width = PLAYER_WIDTH;
+ po.Height = PLAYER_HEIGHT;
+ po.UnSelectedColor = color;
+ Objects.Add (po);
+ index ++;
+ if (template.Count == index)
+ break;
+ }
+ }
+
+ for (int i = index; i < template.Count; i++) {
+ PlayerObject po;
+ double x, y;
+ int reli = i - index;
+
+ x = PLAYER_WIDTH * (reli % 2) + PLAYER_WIDTH / 2;
+ y = PLAYER_HEIGHT * (reli / 2) + PLAYER_HEIGHT / 2;
+ if (team == Team.VISITOR) {
+ x += BENCH_WIDTH + backgroundWidth;
+ }
+
+ po = new PlayerObject (template [i], new Point (x, y));
+ po.Width = PLAYER_WIDTH;
+ po.Height = PLAYER_HEIGHT;
+ po.UnSelectedColor = color;
+ Objects.Add (po);
+ }
+ }
+
+ public void Select (Player p) {
+ ClearSelection ();
+ if (p != null) {
+ ICanvasObject co = Objects.LastOrDefault (pl => (pl as PlayerObject).Player
== p);
+ PlayerObject po = co as PlayerObject;
+ if (po != null) {
+ UpdateSelection (new Selection (po, SelectionPosition.All));
+ }
+ }
+ widget.ReDraw ();
+ }
+
+ public void Reload () {
+ Objects.Clear();
+ if (homeTeam != null) {
+ LoadTeam (homeTeam, Team.LOCAL);
+ }
+ if (awayTeam != null) {
+ LoadTeam (awayTeam, Team.VISITOR);
+ }
+ widget.ReDraw ();
+ }
+
+ int NTeams {
+ get {
+ return awayTeam == null ? 1 : 2;
+ }
+ }
+
+ void Resize () {
+ currentWidth = widget.Width;
+ currentHeight = widget.Height;
+ backgroundWidth = currentWidth - BENCH_WIDTH * NTeams;
+
+ if (background != null) {
+ background.ScaleFactor ((int) backgroundWidth, (int) currentHeight,
+ out scaleX, out scaleY, out offset);
+ }
+ Reload ();
+ }
+
+ protected override void SelectionChanged (List<Selection> selections) {
+ if (PlayersSelectionChangedEvent != null) {
+ PlayersSelectionChangedEvent (
+ selections.Select (s => (s.Drawable as
PlayerObject).Player).ToList());
+ }
+ }
+
+ protected override void StartMove (Selection sel) {
+ }
+
+ protected override void StopMove () {
+ }
+
+ protected override void ShowMenu (Point coords) {
+ if (ShowMenuEvent != null && Selections.Count > 0){
+ ShowMenuEvent (
+ Selections.Select (s => (s.Drawable as
PlayerObject).Player).ToList());
+ }
+ }
+
+ protected override void SelectionMoved (Selection sel) {
+ }
+
+ protected override void HandleDraw (object context, Area area)
+ {
+ if (currentWidth != widget.Width || currentHeight != widget.Height) {
+ Resize ();
+ }
+
+ tk.Context = context;
+ tk.Begin ();
+
+ /* Background */
+ if (background != null) {
+ tk.DrawImage (new Point (BENCH_WIDTH, 0), backgroundWidth, currentHeight,
+ background, false);
+ }
+
+ tk.End ();
+ base.HandleDraw (context, area);
+ }
+ }
+}
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]