10 var zoomy = new ZoomyWindow()
16 class ZoomyWindow : Gtk.Window
19 prop scaled_pixbuf : Pixbuf
21 //prop pixbuf_width_over_height : double
27 window_position = WindowPosition.CENTER
29 destroy += Gtk.main_quit
31 var vbox = new VBox( false, 0 )
33 //var lbl = new Label( "Press ESC to exit" )
35 //vbox.set_child_packing( lbl, false, false, 0, PackType.START )
37 pixbuf = new Pixbuf.from_file( "/home/andy/Desktop/Carys-Fish.jpg" )
38 //pixbuf_width_over_height = (double)pixbuf.width / (double)pixbuf.height
40 scaled_pixbuf = new Pixbuf( Colorspace.RGB, false, 8, pixbuf.width, pixbuf.height )
42 img = new Gtk.Image.from_pixbuf( pixbuf )
45 vbox.set_child_packing( img, true, true, 0, PackType.START )
49 events |= EventMask.POINTER_MOTION_MASK
51 motion_notify_event += mouse_move
52 configure_event += config_evt
54 key_press_event += def( obj, key )
55 if key.keyval == 65307
60 def mouse_move( obj : ZoomyWindow, evt : Gdk.Event ) : bool
61 var height = (int)( evt.motion.y * 4 )
67 var scale = (double)height / (double)obj.scaled_pixbuf.height
69 var dest_width = obj.scaled_pixbuf.width
70 var dest_height = obj.scaled_pixbuf.height
72 //var shift_x = ( obj.scaled_pixbuf.width - dest_width ) / 2
73 //var shift_y = ( obj.scaled_pixbuf.height - dest_height ) / 2
76 dest_width = (int)( obj.scaled_pixbuf.width * scale )
77 dest_height = (int)( obj.scaled_pixbuf.height * scale )
79 obj.pixbuf.scale( obj.scaled_pixbuf, 0, 0, dest_width, dest_height, 0, 0, scale, scale, InterpType.NEAREST )
81 //print "%d, %d", dest_width, dest_height
83 var clipped_pixbuf = new Pixbuf.subpixbuf( obj.scaled_pixbuf, 0, 0, dest_width, dest_height )
85 obj.img.set_from_pixbuf( clipped_pixbuf )
90 def config_evt( obj : ZoomyWindow, evt : Gdk.Event ) : bool
91 obj.scaled_pixbuf = new Pixbuf( Colorspace.RGB, false, 8, evt.configure.width, evt.configure.height )