[longomatch] Load surfaces in the Player and scale using the correct width
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch] Load surfaces in the Player and scale using the correct width
- Date: Wed, 24 Sep 2014 20:33:29 +0000 (UTC)
commit 26b8925a56a384a8d1a64231b942a3dd419321dd
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date: Tue Sep 23 20:29:07 2014 +0200
Load surfaces in the Player and scale using the correct width
LongoMatch.Drawing/CanvasObjects/PlayerObject.cs | 106 ++++++++++++--------
.../CanvasObjects/PlayersTaggerObject.cs | 44 +--------
2 files changed, 67 insertions(+), 83 deletions(-)
---
diff --git a/LongoMatch.Drawing/CanvasObjects/PlayerObject.cs
b/LongoMatch.Drawing/CanvasObjects/PlayerObject.cs
index 6ca37f0..051792d 100644
--- a/LongoMatch.Drawing/CanvasObjects/PlayerObject.cs
+++ b/LongoMatch.Drawing/CanvasObjects/PlayerObject.cs
@@ -22,11 +22,22 @@ using LongoMatch.Core.Interfaces;
using LongoMatch.Core.Common;
using LongoMatch.Core.Store.Drawables;
using LongoMatch.Drawing.Widgets;
+using System.IO;
namespace LongoMatch.Drawing.CanvasObjects
{
public class PlayerObject: CanvasButtonObject, ICanvasSelectableObject
{
+ static ISurface Photo;
+ static ISurface Background;
+ static ISurface HomeNumber;
+ static ISurface AwayNumber;
+ static ISurface HomeOut;
+ static ISurface AwayOut;
+ static ISurface HomeIn;
+ static ISurface AwayIn;
+ static bool surfacesCached = false;
+
public PlayerObject ()
{
Init ();
@@ -38,42 +49,6 @@ namespace LongoMatch.Drawing.CanvasObjects
Init (position);
}
- void Init (Point pos = null) {
- if (pos == null) {
- pos = new Point (0, 0);
- }
- Position = pos;
- DrawPhoto = true;
- Color = Constants.PLAYER_SELECTED_COLOR;
- Size = (int)PlayersIconSize.Medium;
- Toggle = true;
- }
-
- public ISurface Photo {
- set;
- protected get;
- }
-
- public ISurface Background {
- set;
- protected get;
- }
-
- public ISurface Number {
- set;
- protected get;
- }
-
- public ISurface Out {
- set;
- protected get;
- }
-
- public ISurface In {
- set;
- protected get;
- }
-
public bool SubstitutionMode {
get;
set;
@@ -147,11 +122,25 @@ namespace LongoMatch.Drawing.CanvasObjects
Point zero, p;
double numberWidth, numberHeight;
double size, scale;
+ ISurface number, sin, sout;
+
+ if (Player == null)
+ return;
zero = new Point (0, 0);
size = Background.Height - StyleConf.PlayerLineWidth;
- scale = Width / size;
+ scale = (double) Width / Background.Height;
+ if (Team == Team.LOCAL) {
+ number = HomeNumber;
+ sin = HomeIn;
+ sout = HomeOut;
+ } else {
+ number = AwayNumber;
+ sin = AwayIn;
+ sout = AwayOut;
+ }
+
tk.Begin ();
tk.TranslateAndScale (Position - new Point (Size / 2, Size / 2),
new Point (scale, scale));
@@ -170,19 +159,19 @@ namespace LongoMatch.Drawing.CanvasObjects
p = new Point (StyleConf.PlayerNumberOffset, size - numberHeight);
/* Draw background */
- tk.DrawSurface (Number, zero);
+ tk.DrawSurface (number, zero);
/* Draw Arrow */
if (SubstitutionMode && (Highlighted || Active)) {
ISurface arrow;
if (Playing) {
- arrow = Out;
+ arrow = sout;
} else {
- arrow = In;
+ arrow = sin;
}
- tk.DrawSurface (arrow, new Point (Background.Width / 2 - In.Width / 2,
- Background.Height / 2 - In.Height / 2));
+ tk.DrawSurface (arrow, new Point (Background.Width / 2 - arrow.Width / 2,
+ Background.Height / 2 - arrow.Height / 2));
}
/* Draw number */
@@ -207,6 +196,39 @@ namespace LongoMatch.Drawing.CanvasObjects
tk.End ();
}
+
+ void Init (Point pos = null) {
+ if (pos == null) {
+ pos = new Point (0, 0);
+ }
+ Position = pos;
+ DrawPhoto = true;
+ Color = Constants.PLAYER_SELECTED_COLOR;
+ Size = (int)PlayersIconSize.Medium;
+ Toggle = true;
+ LoadSurfaces ();
+ }
+
+ void LoadSurfaces ()
+ {
+ if (!surfacesCached) {
+ Photo = CreateSurface (StyleConf.PlayerPhoto);
+ Background = CreateSurface (StyleConf.PlayerBackground);
+ HomeNumber = CreateSurface (StyleConf.PlayerHomeNumber);
+ AwayNumber = CreateSurface (StyleConf.PlayerAwayNumber);
+ HomeOut = CreateSurface (StyleConf.PlayerHomeOut);
+ AwayOut = CreateSurface (StyleConf.PlayerAwayOut);
+ HomeIn = CreateSurface (StyleConf.PlayerHomeIn);
+ AwayIn = CreateSurface (StyleConf.PlayerAwayIn);
+ surfacesCached = true;
+ }
+ }
+
+ ISurface CreateSurface (string name)
+ {
+ return Config.DrawingToolkit.CreateSurface (Path.Combine (Config.ImagesDir, name));
+ }
+
}
}
diff --git a/LongoMatch.Drawing/CanvasObjects/PlayersTaggerObject.cs
b/LongoMatch.Drawing/CanvasObjects/PlayersTaggerObject.cs
index 26e5acf..f5ebea0 100644
--- a/LongoMatch.Drawing/CanvasObjects/PlayersTaggerObject.cs
+++ b/LongoMatch.Drawing/CanvasObjects/PlayersTaggerObject.cs
@@ -41,9 +41,6 @@ namespace LongoMatch.Drawing.CanvasObjects
const int SUBSTITUTION_BUTTONS_HEIGHT = 40;
const int SUBSTITUTION_BUTTONS_WIDTH = 60;
ButtonObject subPlayers, subInjury;
- /* Cached surfaces reused by player objects */
- ISurface backgroundSurface, homeNumberSurface, awayNumberSurface, photoSurface;
- ISurface homeInSurface, homeOutSurface, awayInSurface, awayOutSurface;
TeamTemplate homeTeam, awayTeam;
Image background;
Dictionary<Player, PlayerObject> playerToPlayerObject;
@@ -69,7 +66,6 @@ namespace LongoMatch.Drawing.CanvasObjects
field = new FieldObject ();
SelectedPlayers = new List<Player> ();
lastTime = null;
- LoadSurfaces ();
LoadSubsButtons ();
}
@@ -79,14 +75,6 @@ namespace LongoMatch.Drawing.CanvasObjects
homeBench.Dispose ();
awayBench.Dispose ();
field.Dispose ();
- photoSurface.Dispose ();
- backgroundSurface.Dispose ();
- homeNumberSurface.Dispose ();
- awayNumberSurface.Dispose ();
- homeOutSurface.Dispose ();
- awayOutSurface.Dispose ();
- homeInSurface.Dispose ();
- awayInSurface.Dispose ();
subPlayers.Dispose ();
subInjury.Dispose ();
base.Dispose (disposing);
@@ -367,23 +355,6 @@ namespace LongoMatch.Drawing.CanvasObjects
playerToPlayerObject.Clear ();
}
- ISurface CreateSurface (string name)
- {
- return Config.DrawingToolkit.CreateSurface (Path.Combine (Config.ImagesDir, name));
- }
-
- void LoadSurfaces ()
- {
- photoSurface = CreateSurface (StyleConf.PlayerPhoto);
- backgroundSurface = CreateSurface (StyleConf.PlayerBackground);
- homeNumberSurface = CreateSurface (StyleConf.PlayerHomeNumber);
- awayNumberSurface = CreateSurface (StyleConf.PlayerAwayNumber);
- homeOutSurface = CreateSurface (StyleConf.PlayerHomeOut);
- awayOutSurface = CreateSurface (StyleConf.PlayerAwayOut);
- homeInSurface = CreateSurface (StyleConf.PlayerHomeIn);
- awayInSurface = CreateSurface (StyleConf.PlayerAwayIn);
- }
-
void LoadSubsButtons () {
subPlayers = new ButtonObject ();
string path = Path.Combine (Config.IconsDir, StyleConf.SubsUnlock);
@@ -461,27 +432,18 @@ namespace LongoMatch.Drawing.CanvasObjects
{
List<PlayerObject> playerObjects;
Color color = null;
- ISurface number, sin, sout;
if (team == Team.LOCAL) {
color = Config.Style.HomeTeamColor;
- number = homeNumberSurface;
- sin = homeInSurface;
- sout = homeOutSurface;
} else {
color = Config.Style.AwayTeamColor;
- number = awayNumberSurface;
- sin = awayInSurface;
- sout = awayOutSurface;
}
playerObjects = new List<PlayerObject> ();
foreach (Player p in players) {
- PlayerObject po = new PlayerObject { Player = p, Color = color,
- Team = team, Background = backgroundSurface,
- Number = number, In = sin, Out = sout,
- SubstitutionMode = SubstitutionMode,
- Photo = photoSurface
+ PlayerObject po = new PlayerObject { Player = p,
+ Color = color,
+ Team = team,
};
po.ClickedEvent += HandlePlayerClickedEvent;
playerObjects.Add (po);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]