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.



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

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.



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

def draw_image
  @draw_image
end

#fpathObject

Returns the value of attribute fpath.



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

def fpath
  @fpath
end

#oldimgObject

Returns the value of attribute oldimg.



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

def oldimg
  @oldimg
end

#pixbufObject

Returns the value of attribute pixbuf.



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

def pixbuf
  @pixbuf
end

#viewObject

Returns the value of attribute view.



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

def view
  @view
end

Instance Method Details

#do_draw(da, cr) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/vimamsa/gui_image.rb', line 42

def do_draw(da, cr)
  # puts @fpath
  # Ripl.start :binding => binding

  cr.set_source_pixbuf(@draw_image, @view.gutter_width, 0)
  cr.paint
end

#scale_imageObject

Scale to fit window width



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

def scale_image()
  pb = @pixbuf
  view = @view
  if view.visible_rect.width > 0
    imglimit = view.visible_rect.width - 50
  else
    imglimit = 500
  end

  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
    # Ripl.start :binding => binding

    pb = pb.scale_simple(nwidth, nheight, GdkPixbuf::InterpType::HYPER)
  else
    pb = @oldimg
  end
  @draw_image = pb
  @oldimg = pb
  #TODO: Should be better way to compensate for the gutter
  self.set_size_request(pb.width+@view.gutter_width, pb.height)
end