From 3e92bf0fc62c3728cf1c3ae2ea579596cd363c43 Mon Sep 17 00:00:00 2001 From: Andy Meneely Date: Fri, 1 Aug 2014 15:44:23 -0400 Subject: [PATCH] Added a (currently infinite) cache of loaded pngs --- lib/squib/graphics/image.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/squib/graphics/image.rb b/lib/squib/graphics/image.rb index 5119ce8..505e656 100644 --- a/lib/squib/graphics/image.rb +++ b/lib/squib/graphics/image.rb @@ -1,4 +1,15 @@ module Squib + + # Cache all pngs we've already loaded + # + # :nodoc: + # @api private + def cache_load_image(file) + @img_cache ||= {} + @img_cache[file] || @img_cache[file] = Cairo::ImageSurface.from_png(file) + end + module_function :cache_load_image + class Card # :nodoc: @@ -6,7 +17,7 @@ module Squib def png(file, x, y, alpha) return if file.nil? or file.eql? '' cc = cairo_context - png = Cairo::ImageSurface.from_png(file) + png = Squib.cache_load_image(file) cc.set_source(png, x, y) cc.paint(alpha) end