Class: Fidgit::Thumbnail

Inherits:
Object show all
Defined in:
lib/fidgit/thumbnail.rb

Overview

Wrapper for Gosu::Image that always pads the image out to being square.

Constant Summary collapse

DEFAULT_COLOR =
Gosu::Color.rgb(255, 255, 255)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(image) ⇒ Thumbnail

Returns a new instance of Thumbnail.

Raises:

  • (ArgumentError)


18
19
20
21
# File 'lib/fidgit/thumbnail.rb', line 18

def initialize(image)
  raise ArgumentError, "image must be a Gosu::Image" unless image.is_a? Gosu::Image
  self.image = image
end

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height.



8
9
10
# File 'lib/fidgit/thumbnail.rb', line 8

def height
  @height
end

#imageObject

Returns the value of attribute image.



8
9
10
# File 'lib/fidgit/thumbnail.rb', line 8

def image
  @image
end

#widthObject (readonly)

Returns the value of attribute width.



8
9
10
# File 'lib/fidgit/thumbnail.rb', line 8

def width
  @width
end

Instance Method Details

#draw(x, y, z_order, scale_x = 1, scale_y = 1, color = DEFAULT_COLOR, mode = :default) ⇒ Object



23
24
25
26
27
# File 'lib/fidgit/thumbnail.rb', line 23

def draw(x, y, z_order, scale_x = 1, scale_y = 1, color = DEFAULT_COLOR, mode = :default)
  @image.draw x + (@width - @image.width) * scale_x / 2, y + (@height - @image.height) * scale_y / 2, z_order, scale_x, scale_y, color, mode

  nil
end