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.
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_image ⇒ Object
Returns the value of attribute draw_image.
5 6 7 |
# File 'lib/vimamsa/gui_image.rb', line 5 def draw_image @draw_image end |
#fpath ⇒ Object
Returns the value of attribute fpath.
5 6 7 |
# File 'lib/vimamsa/gui_image.rb', line 5 def fpath @fpath end |
#oldimg ⇒ Object
Returns the value of attribute oldimg.
5 6 7 |
# File 'lib/vimamsa/gui_image.rb', line 5 def oldimg @oldimg end |
#pixbuf ⇒ Object
Returns the value of attribute pixbuf.
5 6 7 |
# File 'lib/vimamsa/gui_image.rb', line 5 def pixbuf @pixbuf end |
#view ⇒ Object
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_image ⇒ Object
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 |