Class: ResizableImage

Inherits:
Gtk::DrawingArea
  • Object
show all
Defined in:
lib/vimamsa/gui_image.rb

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fpath, view) ⇒ ResizableImage

Returns a new instance of ResizableImage.



7
8
9
10
11
12
13
14
15
# File 'lib/vimamsa/gui_image.rb', line 7

def initialize(fpath, view)
  @fpath = fpath
  @pixbuf = GdkPixbuf::Pixbuf.new(:file => fpath)
  @oldimg = @pixbuf
  @draw_image = @pixbuf
  @view = view

  super()
end

Instance Attribute Details

#draw_imageObject

Returns the value of attribute draw_image.



5
6
7
# File 'lib/vimamsa/gui_image.rb', line 5

def draw_image
  @draw_image
end

#fpathObject

Returns the value of attribute fpath.



5
6
7
# File 'lib/vimamsa/gui_image.rb', line 5

def fpath
  @fpath
end

#oldimgObject

Returns the value of attribute oldimg.



5
6
7
# File 'lib/vimamsa/gui_image.rb', line 5

def oldimg
  @oldimg
end

#pixbufObject

Returns the value of attribute pixbuf.



5
6
7
# File 'lib/vimamsa/gui_image.rb', line 5

def pixbuf
  @pixbuf
end

#viewObject

Returns the value of attribute view.



5
6
7
# File 'lib/vimamsa/gui_image.rb', line 5

def view
  @view
end

Instance Method Details

#do_draw(da, cr) ⇒ Object



37
38
39
40
41
# File 'lib/vimamsa/gui_image.rb', line 37

def do_draw(da, cr)
  # puts @fpath
  cr.set_source_pixbuf(@draw_image, 0, 0)
  cr.paint
end

#scale_imageObject

Scale to fit window width



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/vimamsa/gui_image.rb', line 18

def scale_image()
  pb = @pixbuf
  view = @view
  imglimit = view.visible_rect.width - 10

  if @oldimg.width > imglimit or @oldimg.width < imglimit - 10
    nwidth = imglimit
    nwidth = pb.width if pb.width < imglimit
    nheight = (pb.height * (nwidth.to_f / pb.width)).to_i
    pb = pb.scale_simple(nwidth, nheight, GdkPixbuf::InterpType::HYPER)
  else
    pb = @oldimg
  end
  @draw_image = pb
  @oldimg = pb
  self.set_size_request(pb.width, pb.height)

end