class Mireru::Widget::Image

Public Class Methods

new(file, width, height) click to toggle source
Calls superclass method
# File lib/mireru/widget/image.rb, line 22
def initialize(file, width, height)
  super()
  @pixbuf = Gdk::PixbufAnimation.new(file)
  if @pixbuf.static_image?
    @pixbuf = @pixbuf.static_image
    if @pixbuf.width > width || @pixbuf.height > height
      scale_preserving_aspect_ratio(width, height)
    end
    self.pixbuf = @pixbuf
  else
    self.pixbuf_animation = @pixbuf
  end
end

Public Instance Methods

scale_preserving_aspect_ratio(width, height) click to toggle source
# File lib/mireru/widget/image.rb, line 36
def scale_preserving_aspect_ratio(width, height)
  if @pixbuf.is_a?(Gdk::PixbufAnimation)
    @pixbuf = @pixbuf.static_image
  end
  x_ratio = width.to_f / @pixbuf.width
  y_ratio = height.to_f / @pixbuf.height
  ratio = [x_ratio, y_ratio].min
  self.pixbuf = @pixbuf.scale(@pixbuf.width * ratio,
                              @pixbuf.height * ratio)
end