Class: EZDraw::Image
- Inherits:
-
Object
- Object
- EZDraw::Image
- Defined in:
- lib/ezdraw.rb
Constant Summary collapse
- @@instances =
[]
Instance Attribute Summary collapse
-
#sfc ⇒ Object
readonly
Returns the value of attribute sfc.
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
- #height ⇒ Object
-
#initialize(img_filename) ⇒ Image
constructor
A new instance of Image.
- #width ⇒ Object
Constructor Details
#initialize(img_filename) ⇒ Image
Returns a new instance of Image.
391 392 393 394 395 396 397 398 399 400 401 402 403 |
# 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 |
Instance Attribute Details
#sfc ⇒ Object (readonly)
Returns the value of attribute sfc.
405 406 407 |
# File 'lib/ezdraw.rb', line 405 def sfc @sfc end |
Class Method Details
._destroy(sfc, dflag) ⇒ Object
422 423 424 425 426 427 428 429 430 431 |
# 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 ⇒ Object
415 416 417 418 419 420 |
# File 'lib/ezdraw.rb', line 415 def self.cleanup EZDraw.requires_init @@instances.each {|img| img.close} @@instances = [] SDL2::Image.IMG_Quit end |
.init ⇒ Object
407 408 409 410 411 412 413 |
# 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 |
Instance Method Details
#close ⇒ Object
433 434 435 |
# File 'lib/ezdraw.rb', line 433 def close self.class._destroy(@sfc, @dflag) end |
#height ⇒ Object
441 442 443 |
# File 'lib/ezdraw.rb', line 441 def height @sfc[:h] end |
#width ⇒ Object
437 438 439 |
# File 'lib/ezdraw.rb', line 437 def width @sfc[:w] end |