Class: Sprite::Frame

Inherits:
Object
  • Object
show all
Defined in:
lib/rmagick-sprite/frame.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Frame

Returns a new instance of Frame.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rmagick-sprite/frame.rb', line 6

def initialize(options)
  raise 'options must be a Hash' unless options.respond_to?(:to_hash) || options.respond_to?(:to_h)
  options = options.to_hash rescue options.to_h
  
  raise 'options[:action] must be given' if options[:action].nil?
  raise 'options[:action] must be an Action' unless options[:action].instance_of?(Action)
  raise 'options[:x] must be given' if options[:x].nil?
  raise 'options[:x] must be a Integer-like object' unless options[:x].respond_to?(:to_i)
  raise 'options[:y] must be given' if options[:y].nil?
  raise 'options[:y] must be a Integer-like object' unless options[:y].respond_to?(:to_i)
  raise 'options[:width] must be given' if options[:width].nil?
  raise 'options[:width] must be a Integer-like object' unless options[:width].respond_to?(:to_i)
  raise 'options[:height] must be given' if options[:height].nil?
  raise 'options[:height] must be a Integer-like object' unless options[:height].respond_to?(:to_i)
  
  @action = options[:action]
  @x, @y, @width, @height = options.values_at(:x, :y, :width, :height).collect(&:to_i)
  @sprite = @action.sprite
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



4
5
6
# File 'lib/rmagick-sprite/frame.rb', line 4

def action
  @action
end

#heightObject (readonly)

Returns the value of attribute height.



4
5
6
# File 'lib/rmagick-sprite/frame.rb', line 4

def height
  @height
end

#spriteObject (readonly)

Returns the value of attribute sprite.



4
5
6
# File 'lib/rmagick-sprite/frame.rb', line 4

def sprite
  @sprite
end

#widthObject (readonly)

Returns the value of attribute width.



4
5
6
# File 'lib/rmagick-sprite/frame.rb', line 4

def width
  @width
end

#xObject (readonly)

Returns the value of attribute x.



4
5
6
# File 'lib/rmagick-sprite/frame.rb', line 4

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



4
5
6
# File 'lib/rmagick-sprite/frame.rb', line 4

def y
  @y
end

Instance Method Details

#imageObject



26
27
28
29
30
# File 'lib/rmagick-sprite/frame.rb', line 26

def image
  reload if @image.nil?
  
  @image
end

#reloadObject



32
33
34
# File 'lib/rmagick-sprite/frame.rb', line 32

def reload
  @image = @sprite.image.excerpt(@x, @y, @width, @height)
end