ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/kgsueme/bin/kgsueme
(Generate patch)

Comparing kgsueme/bin/kgsueme (file contents):
Revision 1.15 by pcg, Fri May 30 04:17:25 2003 UTC vs.
Revision 1.16 by pcg, Fri May 30 07:19:16 2003 UTC

1#!/usr/bin/perl -I../lib/ 1#!/usr/bin/perl -I../lib/
2
3#use PApp::Util qw(dumpval); # debug only
4 2
5use Gtk; 3use Gtk;
6use Gtk::Gdk; 4use Gtk::Gdk;
7use Gtk::Gdk::Pixbuf; 5use Gtk::Gdk::Pixbuf;
8#use Gtk::Gdk::ImlibImage; 6#use Gtk::Gdk::ImlibImage;
9 7
10use KGS::Protocol; 8use KGS::Protocol;
11use KGS::Listener::Debug; 9use KGS::Listener::Debug;
12 10
11use Audio::Data;
12use Audio::Play;
13
13use IO::Socket::INET; 14use IO::Socket::INET;
14 15
15use Errno; 16use Errno;
16 17
17init Gtk; 18init Gtk;
18 19
19$HACK = 1; # do NEVER enable. ;) 20$HACK = 1; # do NEVER enable. ;)
20 21
21our $config; 22our $config;
23our $LIBDIR = ".";
22our $IMGDIR = "images"; 24our $IMGDIR = "$LIBDIR/images";
25our $SNDDIR = "$LIBDIR/sounds";
23 26
24sub load_img { 27sub load_img {
25 new_from_file Gtk::Gdk::Pixbuf "$IMGDIR/$_[0]" 28 new_from_file Gtk::Gdk::Pixbuf "$IMGDIR/$_[0]"
26# load_image Gtk::Gdk::ImlibImage "$IMGDIR/$_[0]" 29# load_image Gtk::Gdk::ImlibImage "$IMGDIR/$_[0]"
27 or die "$IMGDIR/$_[0]: $!"; 30 or die "$IMGDIR/$_[0]: $!";
33our @square_img = map +(load_img "square-$_.png"), qw(b w); 36our @square_img = map +(load_img "square-$_.png"), qw(b w);
34our @circle_img = map +(load_img "circle-$_.png"), qw(b w); 37our @circle_img = map +(load_img "circle-$_.png"), qw(b w);
35our $board_img = load_img "woodgrain-01.jpg"; 38our $board_img = load_img "woodgrain-01.jpg";
36 39
37{ 40{
41 #my $audioserver = new Audio::Play(0);
42 my %sound;
43 $SIG{CHLD} = 'IGNORE';
44
45 for (qw(alarm warning move)) {
46 local $/;
47 open my $snd, "<", "$SNDDIR/$_"
48 or die "$SNDDIR: $!";
49 binmode $snd;
50
51 $sound{$_} = new Audio::Data;
52 $sound{$_}->Load($snd);
53 }
54
55 sub play_sound {
56 if (fork == 0) {
57 my $audioserver = new Audio::Play(1);
58 $audioserver->play ($sound{$_[0]});
59 Gtk->_exit(0);
60 }
61 }
62}
63
64{
38 use Storable (); 65 use Storable ();
39 use Scalar::Util (); 66 use Scalar::Util ();
40 67
41 my $staterc = "$ENV{HOME}/.kgsueme"; 68 my $staterc = "$ENV{HOME}/.kgsueme";
42 69
48 # grr... more gtk+ brokenness 75 # grr... more gtk+ brokenness
49 my %get = ( 76 my %get = (
50 hpane_position => sub { ($_[0]->children)[0]->allocation->[2] }, 77 hpane_position => sub { ($_[0]->children)[0]->allocation->[2] },
51 vpane_position => sub { ($_[0]->children)[0]->allocation->[3] }, 78 vpane_position => sub { ($_[0]->children)[0]->allocation->[3] },
52 window_size => sub { [ @{$_[0]->allocation}[2,3] ] }, 79 window_size => sub { [ @{$_[0]->allocation}[2,3] ] },
53 #window_pos => sub { die PApp::Util::dumpval [ $_[0]->get_root_origin ] }, 80 #window_pos => sub { die KGS::Listener::Debug::dumpval [ $_[0]->get_root_origin ] },
54 clist_column_widths => sub { 81 clist_column_widths => sub {
55 $_[0]{column_widths}; 82 $_[0]{column_widths};
56 }, 83 },
57 ); 84 );
58 85
246 if ($msg->{success}) { 273 if ($msg->{success}) {
247 for (keys %{$::config->{rooms}}) { 274 for (keys %{$::config->{rooms}}) {
248 $self->{roomlist}->join_room($_); 275 $self->{roomlist}->join_room($_);
249 } 276 }
250 } 277 }
251
252 warn PApp::Util::dumpval($::config);
253} 278}
254 279
255sub event_disconnect { } 280sub event_disconnect { }
256 281
257############################################################################# 282#############################################################################
708 733
709sub repaint_board { 734sub repaint_board {
710 my ($self) = @_; 735 my ($self) = @_;
711 my $canvas = $self->{canvas}; 736 my $canvas = $self->{canvas};
712 737
738 return unless $self->{board};
739
713 %cache = (); 740 %cache = ();
714 741
715 my ($w, $h) = @{$canvas->allocation}[2,3]; 742 my ($w, $h) = @{$canvas->allocation}[2,3];
716 743
717 my $s = $w > $h ? $h : $w; 744 my $s = $w > $h ? $h : $w;
751 $pixmap->draw_line ($gc, $k[$i], $k[1], $k[$i], $k[$size]); 778 $pixmap->draw_line ($gc, $k[$i], $k[1], $k[$i], $k[$size]);
752 $pixmap->draw_line ($gc, $k[1], $k[$i], $k[$size], $k[$i]); 779 $pixmap->draw_line ($gc, $k[1], $k[$i], $k[$size], $k[$i]);
753 780
754 center_text $pixmap, $font, $gc, $k[$i], ($ofs +$border) / 2, $a; 781 center_text $pixmap, $font, $gc, $k[$i], ($ofs +$border) / 2, $a;
755 center_text $pixmap, $font, $gc, $k[$i], $s2 + $border + $ofs / 2, $a; 782 center_text $pixmap, $font, $gc, $k[$i], $s2 + $border + $ofs / 2, $a;
756 center_text $pixmap, $font, $gc, ($ofs + $border) / 2, $k[$i], $i; 783 center_text $pixmap, $font, $gc, ($ofs + $border) / 2, $k[$i], $size - $i + 1;
757 center_text $pixmap, $font, $gc, $s2 + $border + $ofs / 2, $k[$i], $i; 784 center_text $pixmap, $font, $gc, $s2 + $border + $ofs / 2, $k[$i], $size - $i + 1;
758 785
759 $a++; 786 $a++;
760 $a++ if $a eq "I"; # not correct, instead of AA AB, we should get HH JJ KK... 787 $a++ if $a eq "I"; # not correct, instead of AA AB, we should get HH JJ KK...
761 } 788 }
762 789
763 # hoshi-points(!)#d# 790 # hoshi-points(!)#d#
764 # caching of empty board gfx(!)#d# 791 # caching of empty board gfx(!)#d#
765 792
766 if ($self->{board}) { 793 for my $x (1 .. $size) {
767 for my $x (1 .. $size) { 794 for my $y (1 .. $size) {
768 for my $y (1 .. $size) {
769 my $yk = $s2 * $x / $size - $ofs + $border; 795 my $yk = $s2 * $x / $size - $ofs + $border;
770 my $mark = $self->{board}{board}[$x-1][$y-1]; 796 my $mark = $self->{board}{board}[$x-1][$y-1];
771 797
772 if ($mark) { 798 if ($mark) {
773 my ($dx, $dy) = ($k[$x] - $ofs, $k[$y] - $ofs); 799 my ($dx, $dy) = ($k[$x] - $ofs, $k[$y] - $ofs);
774 my ($pm, $bm) = $self->create_stack($gc, $mark, $edge, $x * 17 + $y * 11 ); 800 my ($pm, $bm) = $self->create_stack($gc, $mark, $edge, $x * 17 + $y * 11 );
775 801
776 $gc->set_clip_mask ($bm); 802 $gc->set_clip_mask ($bm);
777 $gc->set_clip_origin ($dx, $dy); 803 $gc->set_clip_origin ($dx, $dy);
778 $pixmap->draw_pixmap ($gc, $pm, 0, 0, $dx, $dy, $edge, $edge); 804 $pixmap->draw_pixmap ($gc, $pm, 0, 0, $dx, $dy, $edge, $edge);
779 }
780 } 805 }
781 } 806 }
782 } 807 }
783} 808}
784 809
792 817
793 # force a redraw (not perfect(?)) 818 # force a redraw (not perfect(?))
794 expose_event $self->{canvas}, $self, { area => $self->{canvas}->allocation }; 819 expose_event $self->{canvas}, $self, { area => $self->{canvas}->allocation };
795 820
796 $self->{text}->backward_delete($self->{text}->get_length); 821 $self->{text}->backward_delete($self->{text}->get_length);
797 $self->{text}->insert(undef, undef, undef, $self->{board}{comment}.PApp::Util::dumpval([$self->{board}{time},$self->{board}{captures}])); 822 $self->{text}->insert(undef, undef, undef, KGS::Listener::Debug::dumpval([$self->{board}{time},$self->{board}{captures}]). $self->{board}{comment});
823}
824
825sub event_move {
826 ::play_sound "move";
798} 827}
799 828
8001; 8291;
801 830
802 831

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines