[gbrainy] Cache icons locally to prevent loading them multiple times
- From: Jordi Mas <jmas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gbrainy] Cache icons locally to prevent loading them multiple times
- Date: Mon, 13 Jun 2011 08:12:54 +0000 (UTC)
commit 9a1e5b55c97ad28c3a24f5fb313a6de6214b7d2c
Author: Jordi Mas <jmas softcatala org>
Date: Mon Jun 13 10:12:21 2011 +0200
Cache icons locally to prevent loading them multiple times
src/Clients/Classical/Widgets/GameDrawingArea.cs | 12 +++++++++++-
src/Core/Libraries/CairoContext.cs | 2 +-
2 files changed, 12 insertions(+), 2 deletions(-)
---
diff --git a/src/Clients/Classical/Widgets/GameDrawingArea.cs b/src/Clients/Classical/Widgets/GameDrawingArea.cs
index 31eb4fd..5ef140c 100644
--- a/src/Clients/Classical/Widgets/GameDrawingArea.cs
+++ b/src/Clients/Classical/Widgets/GameDrawingArea.cs
@@ -21,6 +21,7 @@ using System;
using Gtk;
using Cairo;
using Mono.Unix;
+using gbrainy.Core.Libraries;
using gbrainy.Core.Main;
@@ -64,10 +65,13 @@ namespace gbrainy.Clients.Classical.Widgets
const double icon_size = 0.08;
const double icon_margin = 0.01;
+ SVGImage [] images;
+
public GameDrawingArea ()
{
UseSolutionArea = true;
SolutionIcon = SolutionType.None;
+ images = new SVGImage [Enum.GetValues (typeof (SolutionType)).Length];
}
public void ReloadBackground ()
@@ -224,6 +228,7 @@ namespace gbrainy.Clients.Classical.Widgets
void DrawSolutionIcon (CairoContextEx cr, double x, double y, double width, double height)
{
string image;
+ int img_index = (int) SolutionIcon;
switch (SolutionIcon) {
case SolutionType.CorrectAnswer:
@@ -239,7 +244,12 @@ namespace gbrainy.Clients.Classical.Widgets
return;
}
- cr.DrawImageFromAssembly (image, x + icon_margin, y, width, height);
+ // In memory games, the image gets painted several dozen times
+ if (images [img_index] == null) {
+ images [img_index] = new SVGImage (System.Reflection.Assembly.GetExecutingAssembly (), image);
+ }
+
+ cr.DrawImage (images [img_index], x + icon_margin, y, width, height);
}
}
}
diff --git a/src/Core/Libraries/CairoContext.cs b/src/Core/Libraries/CairoContext.cs
index b465a55..13a1497 100644
--- a/src/Core/Libraries/CairoContext.cs
+++ b/src/Core/Libraries/CairoContext.cs
@@ -295,7 +295,7 @@ namespace gbrainy.Core.Libraries
}
}
- void DrawImage (SVGImage image, double x, double y, double width, double height)
+ public void DrawImage (SVGImage image, double x, double y, double width, double height)
{
Save ();
Translate (x, y);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]