#!/usr/bin/perl
package main;

use strict;

use Glib qw/TRUE FALSE/;
use Goo::Canvas;
use Gtk2 -init;

# Read in glade file with gui
our $builder = Gtk2::Builder->new;
$builder->add_from_file("GooTest.glade");

# Get main window from widget tree.
my $main_window = $builder->get_object('window1') || die "Can't find window.\n";
my $scrwin = $builder->get_object('scrolledwindow1') || die "Can't
find scrolled window.\n";
my $canvas = Goo::Canvas->new();
$scrwin->add_with_viewport($canvas);
$canvas->show;

&connect_signals;

# Quit when user clicks on the close button/alt-f4 etc.
$main_window->signal_connect (destroy => sub { Gtk2->main_quit; });

# Maximise window
#$main_window->maximize;

# Run main loop.
Gtk2->main;


sub connect_signals
{
    # Respond to mouse button presses
    $scrwin->signal_connect(button_press_event => \&button_press_event);
    $scrwin->signal_connect(button_release_event => \&change_cursor, 'left_ptr');

}

sub button_press_event
{
  my ($widget, $event) = @_;

  if ($event->button == 1)
  {
    print join ' ', $event->coords,"\n";
  }

  &change_cursor($widget, $event, 'hand1');

  return TRUE;
}

sub change_cursor
{

    my ($widget, $event, $ctype) = @_;
    my $cursor = Gtk2::Gdk::Cursor->new ($ctype);

    if ($event->button == 1)
    {
        $widget->window->set_cursor($cursor);
    }

    return TRUE;
}
