#!/usr/bin/perl -w use Gtk; use strict; set_locale Gtk; init Gtk; my $false = 0; my $true = 1; my $xsize = 600; my $ysize = 400; my $window; my $table; my $area; my $hrule; my $vrule; $window = new Gtk::Window( "toplevel" ); $window->signal_connect( "delete_event", sub { Gtk->exit( 0 ); } ); $window->border_width( 10 ); # Create a table for placing the ruler and the drawing area $table = new Gtk::Table( 3, 2, $false ); $window->add( $table ); $area = new Gtk::DrawingArea(); $area->size( $xsize, $ysize ); $table->attach( $area, 1, 2, 1, 2, [ 'expand', 'fill' ], 'fill', 0, 0 ); $area->set_events( [ 'pointer_motion_mask', 'pointer_motion_hint_mask' ] ); # The horizontal ruler goes on top. As the mouse moves across the # drawing area, a motion_notify_event is passed to the # appropriate event handler for the ruler. $hrule = new Gtk::HRuler(); $hrule->set_metric( 'pixels' ); $hrule->set_range( 7, 13, 0, 20 ); $area->signal_connect( "motion_notify_event", sub { $hrule->motion_notify_event( $_[1] ); } ); $table->attach( $hrule, 1, 2, 0, 1, [ 'expand', 'shrink', 'fill' ], 'fill', 0, 0 ); # The vertical ruler goes on the left. As the mouse moves across # the drawing area, a motion_notify_event is passed to the # appropriate event handler for the ruler. $vrule = new Gtk::VRuler(); $vrule->set_metric( 'pixels' ); $vrule->set_range( 0, $ysize, 10, $ysize ); $area->signal_connect( "motion_notify_event", sub { $vrule->motion_notify_event( $_[1] ); } ); $table->attach( $vrule, 0, 1, 1, 2, [ 'fill', 'expand', 'shrink' ], 'fill', 0, 0 ); # Now show everything $area->show(); $hrule->show(); $vrule->show(); $table->show(); $window->show(); main Gtk; exit( 0 ); # END EXAMPLE PROGRAM