NAME

Gtk2::GoBoard - high quality goban widget with sound

SYNOPSIS

use Games::Go::SimpleBoard;

my $goboard = newe Games::Go::SimpleBoard;

use Gtk2::GoBoard;

my $gtkboard = new Gtk2::GoBoard size => 19;

# update board, makes a copy
$gtkboard->set_board ($goboard);

# advanced: enable stone curser for black player, showing
# only valid moves
$gtkboard->set (cursor => sub {
   my ($mark, $x, $y) = @_;

   $mark |= MARK_GRAYED | MARK_B
      if $goboard->is_valid_move (COLOUR_WHITE,
                                  $x, $y,
                                  $ruleset == RULESET_NEW_ZEALAND);

   $mark
});

# button-release and -press events pass board coordinates
$gtkboard->signal_connect (button_release => sub {
   my ($button, $x, $y) = @_;

   ...
});

DESCRIPTION

This is the very first "true" Gtk2 widget written in Perl.

The Gtk2::GoBoard class works like any other widget, see the SYNOPSIS for short examples of the available methods, and the App::IGS and KGS modules for usage examples.

Please supply a more descriptive description :)

SOUND SUPPORT

In addition to a graphical board widget, this module has some rudimentary support for sounds.

Playing sounds required the Audio::Play module. If it isn't installed, sounds will silently not being played. The module intentionally doesn't depend on Audio::Play as it isn't actively maintained anymore and fails to install cleanly.

Note that Audio::Play is broken on 64-bit platforms, which the author knows about for half a decade now, but apparently can't be bothered to fix. The symptoms are that it cannot load the soundfile and will silently result in - silence.

$board->set_board ($games_go_simpleboard)

Sets the new board position to display from the current position stored in the Games::Go::SimpleBoard object.

Gtk2::GoBoard::play_sound "name"

Play the sound with the give name. Currently supported names are:

alarm connect gamestart info move outoftime pass resign ring warning

If the Audio::Play module cannot be loaded, the function will silently fail. If an unsupported sound name is used, the function might croak or might silently fail.

This function forks a sound-server to play the sound(s) on first use.

EXAMPLE PROGRAM

This program should get you started. It creates a board with some markings, enables a cursor callback that shows a transparent black stone, and after a click, marks the position with a circle and disables the cursor.

use Gtk2 -init;
use Games::Go::SimpleBoard;
use Gtk2::GoBoard;

my $game = new Games::Go::SimpleBoard 9;

# show off some markings
$game->{board}[0][0] = MARK_B;
$game->{board}[1][1] = MARK_GRAY_B | MARK_SMALL_W;
$game->{board}[2][2] = MARK_W | MARK_TRIANGLE;
$game->{board}[1][2] = MARK_B | MARK_LABEL;
$game->{label}[1][2] = "198";
$game->{board}[0][2] = MARK_W | MARK_LABEL;
$game->{label}[0][2] = "AWA";

# create a spot where black cannot put a stone
$game->{board}[17][0] = MARK_W;
$game->{board}[17][1] = MARK_W;
$game->{board}[18][1] = MARK_W;

my $board = new Gtk2::GoBoard;
$board->set_board ($game);

Gtk2::GoBoard::play_sound "gamestart"; # ping

# enable cursor for black, till click
$board->set (cursor => sub {
   my ($mark, $x, $y) = @_;

   $mark |= MARK_GRAYED | MARK_B
      if $game->is_valid_move (COLOUR_BLACK, $x, $y);

   $mark
});

# on press, set a mark and disable cursor
$board->signal_connect (button_release => sub {
   my ($board, $button, $x, $y) = @_;

   $game->{board}[$x][$y] |= MARK_CIRCLE;
   $board->set_board ($game); # force update

   Gtk2::GoBoard::play_sound "move"; # play click sound

   $board->set (cursor => undef); # disable cursor
});

my $w = new Gtk2::Window "toplevel";
$w->set_default_size (450, 450);
$w->add ($board);
$w->show_all;

main Gtk2;

AUTHOR

Marc Lehmann <schmorp@schmorp.de>

SEE ALSO

App::IGS, Games::Go::SimpleBoard, AnyEvent::IGS, KGS.