[longomatch] Fix bench size in the teams tagger
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch] Fix bench size in the teams tagger
- Date: Wed, 24 Sep 2014 20:17:28 +0000 (UTC)
commit 1390dc01fb151c39f5b1dd6aa10796a3368610db
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date: Wed Aug 27 19:45:57 2014 +0200
Fix bench size in the teams tagger
Bench is dynamically adjusted to fit all the players
instead of using a fixed width of 2 columns
.../CanvasObjects/PlayersTaggerObject.cs | 48 +++++++++++++++++---
LongoMatch.Drawing/Widgets/TeamTagger.cs | 6 +++
LongoMatch.GUI/Gui/Component/CodingWidget.cs | 1 +
3 files changed, 48 insertions(+), 7 deletions(-)
---
diff --git a/LongoMatch.Drawing/CanvasObjects/PlayersTaggerObject.cs
b/LongoMatch.Drawing/CanvasObjects/PlayersTaggerObject.cs
index b11437b..95e2a10 100644
--- a/LongoMatch.Drawing/CanvasObjects/PlayersTaggerObject.cs
+++ b/LongoMatch.Drawing/CanvasObjects/PlayersTaggerObject.cs
@@ -96,6 +96,11 @@ namespace LongoMatch.Drawing.CanvasObjects
set;
}
+ public bool Compact {
+ get;
+ set;
+ }
+
public bool SubstitutionMode {
get {
return substitutionMode;
@@ -169,7 +174,7 @@ namespace LongoMatch.Drawing.CanvasObjects
public void LoadTeams (TeamTemplate homeTeam, TeamTemplate awayTeam, Image background)
{
int[] homeF = null, awayF = null;
- int playerSize, colSize, border;
+ int playerSize, benchPlayerSize, colSize, border, benchWidth, playersPerRow;
this.homeTeam = homeTeam;
this.awayTeam = awayTeam;
@@ -208,15 +213,13 @@ namespace LongoMatch.Drawing.CanvasObjects
}
colSize = ColumnSize;
- playerSize = colSize * 80 / 100;
+ playerSize = colSize * 90 / 100;
+ BenchWidth (colSize, field.Height, playerSize);
field.LoadTeams (background, homeF, awayF, homePlayingPlayers,
awayPlayingPlayers, playerSize, NTeams);
homeBench.BenchPlayers = homeBenchPlayers;
awayBench.BenchPlayers = awayBenchPlayers;
- homeBench.PlayersSize = awayBench.PlayersSize = playerSize;
- homeBench.PlayersPerRow = awayBench.PlayersPerRow = 2;
- homeBench.Width = awayBench.Width = colSize * 2;
homeBench.Height = awayBench.Height = field.Height;
border = Config.Style.TeamTaggerBenchBorder;
@@ -227,6 +230,36 @@ namespace LongoMatch.Drawing.CanvasObjects
Update ();
}
+ void BenchWidth (int colSize, int height, int playerSize)
+ {
+ int maxPlayers, playersPerColumn, playersPerRow;
+ double ncolSize;
+
+ ncolSize = colSize;
+
+ maxPlayers = Math.Max (
+ homeBenchPlayers != null ? homeBenchPlayers.Count : 0,
+ awayBenchPlayers != null ? awayBenchPlayers.Count : 0);
+ playersPerColumn = height / colSize;
+ if (Compact) {
+ /* Try with 4/4, 3/4 and 2/4 of the original column size
+ * to fit all players in a single column */
+ for (int i=4; i>1; i--) {
+ ncolSize = (double)colSize * i / 4;
+ playersPerColumn = (int)(height / ncolSize);
+ playersPerRow = (int)Math.Ceiling ((double)maxPlayers /
playersPerColumn);
+ if (playersPerRow == 1) {
+ break;
+ }
+ }
+ }
+
+ homeBench.PlayersSize = awayBench.PlayersSize = (int)(ncolSize * 90 / 100);
+ homeBench.PlayersPerRow = awayBench.PlayersPerRow =
+ (int)Math.Ceiling ((double)maxPlayers / playersPerColumn);
+ homeBench.Width = awayBench.Width = (int)ncolSize * homeBench.PlayersPerRow;
+ }
+
void ClearPlayers ()
{
if (homePlayers != null) {
@@ -242,7 +275,7 @@ namespace LongoMatch.Drawing.CanvasObjects
}
}
}
-
+
ISurface CreateSurface (string name)
{
@@ -344,7 +377,8 @@ namespace LongoMatch.Drawing.CanvasObjects
Team = team, Background = backgroundSurface,
Number = number, In = sin, Out = sout,
SubstitutionMode = SubstitutionMode,
- Photo = photoSurface };
+ Photo = photoSurface
+ };
po.ClickedEvent += HandleClickedEvent;
playerObjects.Add (po);
}
diff --git a/LongoMatch.Drawing/Widgets/TeamTagger.cs b/LongoMatch.Drawing/Widgets/TeamTagger.cs
index e42479e..3e59460 100644
--- a/LongoMatch.Drawing/Widgets/TeamTagger.cs
+++ b/LongoMatch.Drawing/Widgets/TeamTagger.cs
@@ -66,6 +66,12 @@ namespace LongoMatch.Drawing.Widgets
{
tagger.Reload ();
}
+
+ public bool Compact {
+ set {
+ tagger.Compact = value;
+ }
+ }
public bool SubstitutionMode {
set {
diff --git a/LongoMatch.GUI/Gui/Component/CodingWidget.cs b/LongoMatch.GUI/Gui/Component/CodingWidget.cs
index 7039012..bf3f769 100644
--- a/LongoMatch.GUI/Gui/Component/CodingWidget.cs
+++ b/LongoMatch.GUI/Gui/Component/CodingWidget.cs
@@ -61,6 +61,7 @@ namespace LongoMatch.Gui.Component
teamtagger = new TeamTagger (new WidgetWrapper (teamsdrawingarea));
teamtagger.SelectionMode = MultiSelectionMode.Multiple;
teamtagger.PlayersSelectionChangedEvent += HandlePlayersSelectionChangedEvent;
+ teamtagger.Compact = true;
teamsdrawingarea.HeightRequest = 200;
teamsdrawingarea.WidthRequest = 300;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]