class EZDraw::Image

Attributes

sfc[R]

Public Class Methods

_destroy(sfc, dflag) click to toggle source
# File lib/ezdraw.rb, line 422
def self._destroy(sfc, dflag)
 if dflag[0]
  #EZDraw.logger.debug "(already destroyed image #{sfc})"
  return
 end
 EZDraw.logger.debug "destroy image #{sfc}"

 SDL2.SDL_FreeSurface(sfc)
 dflag[0] = true
end
cleanup() click to toggle source
# File lib/ezdraw.rb, line 415
def self.cleanup
 EZDraw.requires_init
 @@instances.each {|img| img.close}
 @@instances = []
 SDL2::Image.IMG_Quit
end
init() click to toggle source
# File lib/ezdraw.rb, line 407
def self.init
 iflags = SDL2::Image::IMG_INIT_JPG |
          SDL2::Image::IMG_INIT_PNG |
          SDL2::Image::IMG_INIT_TIF
 oflags = SDL2::Image.IMG_Init(iflags)
 raise "IMG_Init: #{SDL2::Image.IMG_GetError}" if (oflags & iflags) != iflags
end
new(img_filename) click to toggle source
# File lib/ezdraw.rb, line 391
def initialize(img_filename)
 EZDraw.requires_init
 
 @sfc = SDL2::Image.IMG_Load(img_filename)
 raise "IMG_Load: #{SDL2::Image.IMG_GetError}" if @sfc.null?

 @dflag = [false] #shared-changable
 ObjectSpace.define_finalizer(self, proc {|id|
  self.class._destroy(@sfc, @dflag)
 })
 
 @@instances << self
end

Public Instance Methods

close() click to toggle source
# File lib/ezdraw.rb, line 433
def close
 self.class._destroy(@sfc, @dflag)
end
height() click to toggle source
# File lib/ezdraw.rb, line 441
def height
 @sfc[:h]
end
width() click to toggle source
# File lib/ezdraw.rb, line 437
def width
 @sfc[:w]
end