Added a (currently infinite) cache of loaded pngs

dev
Andy Meneely 2014-08-01 15:44:23 -04:00
parent 9cde048c00
commit 3e92bf0fc6
1 changed files with 12 additions and 1 deletions

View File

@ -1,4 +1,15 @@
module Squib 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 class Card
# :nodoc: # :nodoc:
@ -6,7 +17,7 @@ module Squib
def png(file, x, y, alpha) def png(file, x, y, alpha)
return if file.nil? or file.eql? '' return if file.nil? or file.eql? ''
cc = cairo_context cc = cairo_context
png = Cairo::ImageSurface.from_png(file) png = Squib.cache_load_image(file)
cc.set_source(png, x, y) cc.set_source(png, x, y)
cc.paint(alpha) cc.paint(alpha)
end end