Sha256: b5e0113539ffa0aa46da6d00985a4a74715f66eae63dd7a5305e84066a957f34

Contents?: true

Size: 827 Bytes

Versions: 11

Compression:

Stored size: 827 Bytes

Contents

# encoding: utf-8

module Fidgit
  # Wrapper for Gosu::Image that always pads the image out to being square.
  class Thumbnail
    DEFAULT_COLOR = Gosu::Color.rgb(255, 255, 255)

    attr_reader :image, :height, :width

    def image=(value)
      @image = value
      @height = [@image.width, @image.height].max
      @width = [@image.width, @image.height].max

      value
    end

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

    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
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
fidgit-0.1.5 lib/fidgit/thumbnail.rb
fidgit-0.1.4 lib/fidgit/thumbnail.rb
fidgit-0.1.3 lib/fidgit/thumbnail.rb
fidgit-0.1.2 lib/fidgit/thumbnail.rb
fidgit-0.1.1 lib/fidgit/thumbnail.rb
fidgit-0.1.0 lib/fidgit/thumbnail.rb
fidgit-0.0.6alpha lib/fidgit/thumbnail.rb
fidgit-0.0.5alpha lib/fidgit/thumbnail.rb
fidgit-0.0.4alpha lib/fidgit/thumbnail.rb
fidgit-0.0.3alpha lib/fidgit/thumbnail.rb
fidgit-0.0.2alpha lib/fidgit/thumbnail.rb