Class: ResizableImage
- Inherits:
-
Gtk::DrawingArea
- Object
- Gtk::DrawingArea
- ResizableImage
- Defined in:
- lib/vimamsa/gui_image.rb
Overview
Following this example: gabmus.org/posts/create_an_auto-resizing_image_widget_with_gtk3_and_python/
Instance Attribute Summary collapse
-
#draw_image ⇒ Object
Returns the value of attribute draw_image.
-
#fpath ⇒ Object
Returns the value of attribute fpath.
-
#oldimg ⇒ Object
Returns the value of attribute oldimg.
-
#pixbuf ⇒ Object
Returns the value of attribute pixbuf.
-
#view ⇒ Object
Returns the value of attribute view.
Instance Method Summary collapse
- #do_draw(da, cr) ⇒ Object
-
#initialize(fpath, view) ⇒ ResizableImage
constructor
A new instance of ResizableImage.
-
#scale_image ⇒ Object
Scale to fit window width.
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_image ⇒ Object
Returns the value of attribute draw_image.
4 5 6 |
# File 'lib/vimamsa/gui_image.rb', line 4 def draw_image @draw_image end |
#fpath ⇒ Object
Returns the value of attribute fpath.
4 5 6 |
# File 'lib/vimamsa/gui_image.rb', line 4 def fpath @fpath end |
#oldimg ⇒ Object
Returns the value of attribute oldimg.
4 5 6 |
# File 'lib/vimamsa/gui_image.rb', line 4 def oldimg @oldimg end |
#pixbuf ⇒ Object
Returns the value of attribute pixbuf.
4 5 6 |
# File 'lib/vimamsa/gui_image.rb', line 4 def pixbuf @pixbuf end |
#view ⇒ Object
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_image ⇒ Object
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 |