#!/usr/bin/env perl use strict; use warnings; use utf8; use Data::Dumper; use Glib qw{ TRUE FALSE }; use Gtk2 '-init'; main(); exit(0); # Subroutines/callbacks sub main { my $builder; our $interface; our $image; our $board = Gtk2::Gdk::Pixbuf->new_from_file("./board.png") || die "Reading board.png failed: $@\n"; our $back_width = $board->get_width; our $back_height = $board->get_height; our $background = Gtk2::Gdk::Pixbuf->new_from_file("./board.png") || die "Reading board.png 2nd time failed: $@\n"; our $focus = Gtk2::Gdk::Pixbuf->new_from_file("./Focus.png") || die "Reading Focus.png failed: $@\n"; our $valid = Gtk2::Gdk::Pixbuf->new_from_file("./Valid.png") || die "Reading Valid.png failed: $@\n"; our $invalid = Gtk2::Gdk::Pixbuf->new_from_file("./Invalid.png") || die "Reading Invalid.png failed: $@\n"; our $statusbar; $builder = Gtk2::Builder->new(); # Load my glade XML file which I saved from my glade project # using 'gtkbuilder' format $builder->add_from_file( 'thud.glade' ); # Get my top level object as named in my glade project $interface = $builder->get_object( 'window1' ); $interface->add_events (['pointer-motion-mask', 'pointer-motion-hint-mask']); $image = $builder->get_object( 'image1' ); $image->set_from_pixbuf($background); $statusbar = $builder->get_object( 'statusbar1' ); our $context_id = $statusbar->get_context_id("Location"); # my @objects = $builder->get_objects(); # for (my $i=0; $i <= $#objects; $i++) { # print "Object $i: $objects[$i]\n"; # } $builder->connect_signals (undef); $interface->signal_connect('delete-event' => sub { Gtk2->main_quit }); $interface->show(); Gtk2->main(); } # Defined by Glade sub gtk_main_quit () { # my ($widget, $event) = @_; Gtk2->main_quit(); return FALSE; } sub on_imagemenuitem5_activate () { # my ($widget, $event) = @_; Gtk2->main_quit(); return FALSE; } sub on_window_destroy { my ($widget, $data) = @_; Gtk2->main_quit(); return FALSE; } sub window1_motion_notify_event_cb () { my ($widget, $event) = @_; my ($x, $y) = our $interface->translate_coordinates(our $image, $event->x, $event->y); my $col=int(($x-1)/42) + 1; my $row=int(($y-1)/42) + 1; our $background = our $board->copy; $background->add_alpha(TRUE, "128", "128", "128"); if ($x>0 and $y> 0 and $x < 631 and $y < 631 and $col+$row > 6 and $col+$row < 26 and abs($col-$row) < 10 and !($col == 8 and $row == 8)) { our $focus->composite ($background, 1+42*($col-1), 1+42*($row-1), 42, 42, 0, 0, 1, 1, 'nearest', 127); our $statusbar->pop(our $context_id); $statusbar->push($context_id, sprintf("Cell %s%d\tx: %d\ty: %d", chr($col+64), $row, $x, $y)); } $image->set_from_pixbuf($background); return FALSE; } sub statusbar1_text_popped_cb () { my ($widget, $event) = @_; # print "sub statusbar1_text_popped_cb (", $widget->get_name(), ")\n"; return FALSE; } sub statusbar1_text_pushed_cb () { my ($widget, $event) = @_; # print "sub statusbar1_text_pushed_cb (", $widget->get_name(), ")\n"; return FALSE; }