| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | #!/usr/bin/perl -w | 
| 2 |  |  |  |  |  |  | ####----------------------------------- | 
| 3 |  |  |  |  |  |  | ### File	: GameClock.pm | 
| 4 |  |  |  |  |  |  | ### Author	: Ch.Minc | 
| 5 |  |  |  |  |  |  | ### Purpose	: Main Package for GameClock | 
| 6 |  |  |  |  |  |  | ### Version	: 1.2 2007/12/23 | 
| 7 |  |  |  |  |  |  | ### copyright GNU license | 
| 8 |  |  |  |  |  |  | ####----------------------------------- | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | package GameClock ; | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | our $VERSION = '1.2' ; | 
| 13 |  |  |  |  |  |  |  | 
| 14 | 1 |  |  | 1 |  | 23739 | use warnings; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 33 |  | 
| 15 | 1 |  |  | 1 |  | 6 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 44 |  | 
| 16 |  |  |  |  |  |  |  | 
| 17 | 1 |  |  | 1 |  | 620 | use Chess::GameClock::GclkData qw(:tout) ; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 38 |  | 
| 18 | 1 |  |  | 1 |  | 663 | use Chess::GameClock::GclkSettings qw(&menu ®lage) ; | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | use Chess::GameClock::GclkCounter ; | 
| 20 |  |  |  |  |  |  | use Chess::GameClock::GclkDisplay qw(display); | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | # Aliases modif 2007/1/8 | 
| 23 |  |  |  |  |  |  | #my %cad=%Chess::GameClock::GclkData::cad ; | 
| 24 |  |  |  |  |  |  | #my %sous_menu=%Chess::GameClock::GclkData::sous_menu ; | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | my %cad=%GclkData::cad ; | 
| 27 |  |  |  |  |  |  | my %sous_menu=%GclkData::sous_menu ; | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | =head1 FUNCTIONS | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | =head2 new | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | Create object of GameClock | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | =cut | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | sub new { | 
| 39 |  |  |  |  |  |  | my ($class,@args)=@_ ; | 
| 40 |  |  |  |  |  |  | my $self={} ;             # a surveiller | 
| 41 |  |  |  |  |  |  | return bless ($self,$class) ; | 
| 42 |  |  |  |  |  |  | } | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | =head2 set | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | Set the parameters of the GclkCounter | 
| 49 |  |  |  |  |  |  | with or without GUI. | 
| 50 |  |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  | =cut | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | sub set { | 
| 54 |  |  |  |  |  |  | my ($self,$cadence)=@_ ; | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  | # build counters | 
| 57 |  |  |  |  |  |  | my $whites=GclkCounter->new ; | 
| 58 |  |  |  |  |  |  | my $blacks=GclkCounter->new ; | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | # build menu | 
| 61 |  |  |  |  |  |  | # if $cadence is a string that defines a cadence: | 
| 62 |  |  |  |  |  |  | # $type in (@menu),$cad in $sous-menus ,Array subscripts ex "Blitz Usuel 0" | 
| 63 |  |  |  |  |  |  | # if cadence is empty call reglage right away | 
| 64 |  |  |  |  |  |  | if(!defined($cadence)) {&GclkSettings::menu($whites,$blacks,"") ; | 
| 65 |  |  |  |  |  |  | &GclkSettings::reglage($whites,$blacks,"") ; | 
| 66 |  |  |  |  |  |  | return($whites,$blacks) ; | 
| 67 |  |  |  |  |  |  | } | 
| 68 |  |  |  |  |  |  | # if cadence is compatible with data array | 
| 69 |  |  |  |  |  |  | elsif ( ref($cadence)  =~ /ARRAY/ ) { | 
| 70 |  |  |  |  |  |  | print "$cadence\n"; | 
| 71 |  |  |  |  |  |  | for my $i (0..$#{$cadence} ){ | 
| 72 |  |  |  |  |  |  | my $cadname="Cadence" . ($i+1) ; | 
| 73 |  |  |  |  |  |  | print " $cadname \n" ; | 
| 74 |  |  |  |  |  |  | for my $k (keys %{$cadence->[$i]}) { | 
| 75 |  |  |  |  |  |  | $cad{ReglagesManuels}{$cadname}[0]{$k}=$cadence->[$i]{$k}; | 
| 76 |  |  |  |  |  |  | print "\n $k $cadence->[$i]{$k} " ; | 
| 77 |  |  |  |  |  |  | } | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | #®lage($whites,$blacks,$cadname) ; | 
| 80 |  |  |  |  |  |  | } | 
| 81 |  |  |  |  |  |  | $whites->init("ReglagesManuels Cadence" . @{$cadence} . " 0",'blancs') ; | 
| 82 |  |  |  |  |  |  | $blacks->init("ReglagesManuels Cadence" . @{$cadence} . " 0",'noirs') ; | 
| 83 |  |  |  |  |  |  | return($whites,$blacks) ; | 
| 84 |  |  |  |  |  |  | } | 
| 85 |  |  |  |  |  |  | else{ | 
| 86 |  |  |  |  |  |  | my ($type,$cad,$i)=split(' ',$cadence) ; | 
| 87 |  |  |  |  |  |  | if ( defined($sous_menu{$type}) ){ | 
| 88 |  |  |  |  |  |  | &GclkSettings::reglage($whites,$blacks,$cadence) ; | 
| 89 |  |  |  |  |  |  | return($whites,$blacks) ; | 
| 90 |  |  |  |  |  |  | } | 
| 91 |  |  |  |  |  |  | } | 
| 92 |  |  |  |  |  |  | } | 
| 93 |  |  |  |  |  |  |  | 
| 94 |  |  |  |  |  |  | =head2 display | 
| 95 |  |  |  |  |  |  |  | 
| 96 |  |  |  |  |  |  | Embedded &GclkDisplay::display | 
| 97 |  |  |  |  |  |  |  | 
| 98 |  |  |  |  |  |  | =cut | 
| 99 |  |  |  |  |  |  |  | 
| 100 |  |  |  |  |  |  | sub display{ | 
| 101 |  |  |  |  |  |  |  | 
| 102 |  |  |  |  |  |  | my ($self,$whites,$blacks,$scaling)=@_ ; | 
| 103 |  |  |  |  |  |  | &GclkDisplay::display($whites,$blacks,$scaling) ; | 
| 104 |  |  |  |  |  |  | } | 
| 105 |  |  |  |  |  |  |  | 
| 106 |  |  |  |  |  |  | =head1 NAME | 
| 107 |  |  |  |  |  |  |  | 
| 108 |  |  |  |  |  |  | GameClock - Chess and Go clock | 
| 109 |  |  |  |  |  |  |  | 
| 110 |  |  |  |  |  |  | =head1 VERSION | 
| 111 |  |  |  |  |  |  |  | 
| 112 |  |  |  |  |  |  | Version 1.2 | 
| 113 |  |  |  |  |  |  |  | 
| 114 |  |  |  |  |  |  | =cut | 
| 115 |  |  |  |  |  |  |  | 
| 116 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 117 |  |  |  |  |  |  |  | 
| 118 |  |  |  |  |  |  | use strict ; | 
| 119 |  |  |  |  |  |  |  | 
| 120 |  |  |  |  |  |  | use Tk ; | 
| 121 |  |  |  |  |  |  |  | 
| 122 |  |  |  |  |  |  | use Chess::GameClock::GclkDisplay qw(display); | 
| 123 |  |  |  |  |  |  |  | 
| 124 |  |  |  |  |  |  | use Chess::GameClock::GameClock ; | 
| 125 |  |  |  |  |  |  |  | 
| 126 |  |  |  |  |  |  | #Three Modes for settings counters: | 
| 127 |  |  |  |  |  |  |  | 
| 128 |  |  |  |  |  |  | #With Gui to set the time (no parameters): | 
| 129 |  |  |  |  |  |  |  | 
| 130 |  |  |  |  |  |  | my ($whites,$blacks)=$clock->set ; | 
| 131 |  |  |  |  |  |  |  | 
| 132 |  |  |  |  |  |  | # or from the GUI like menu | 
| 133 |  |  |  |  |  |  |  | 
| 134 |  |  |  |  |  |  | # here the set is Blitz,Usuel, 10mn (indice 1) | 
| 135 |  |  |  |  |  |  |  | 
| 136 |  |  |  |  |  |  | my ($whites,$blacks)=$clock->set("Blitz Usuel 1") ; | 
| 137 |  |  |  |  |  |  |  | 
| 138 |  |  |  |  |  |  | # or a direct cadence with the following | 
| 139 |  |  |  |  |  |  |  | 
| 140 |  |  |  |  |  |  | #array of hashes | 
| 141 |  |  |  |  |  |  |  | 
| 142 |  |  |  |  |  |  | # first cadence 15 mn/25 moves then 15 mn dead time | 
| 143 |  |  |  |  |  |  |  | 
| 144 |  |  |  |  |  |  | our ($whites,$blacks)=$clock->set( [{qw/ct 15*60 mv 25 b 0 f 0 byo 1/}, | 
| 145 |  |  |  |  |  |  |  | 
| 146 |  |  |  |  |  |  | {qw/ct 15*60 mv 0 b 0 f 0 byo 1/}] ) ; | 
| 147 |  |  |  |  |  |  |  | 
| 148 |  |  |  |  |  |  | # example of japonese  byo-yomi | 
| 149 |  |  |  |  |  |  |  | 
| 150 |  |  |  |  |  |  | # main time 7s, then 3s per move and five byo-yomi time periods | 
| 151 |  |  |  |  |  |  |  | 
| 152 |  |  |  |  |  |  | #my ($whites,$blacks)=$clock->set( | 
| 153 |  |  |  |  |  |  | #                                 [{qw/ct 7 mv 0 b 0 f 0 byo 0/}, | 
| 154 |  |  |  |  |  |  | #                                  {qw/ct 3*5 mv 1 b 3 f 0 byo | 
| 155 |  |  |  |  |  |  |  | 
| 156 |  |  |  |  |  |  | # display the counters | 
| 157 |  |  |  |  |  |  |  | 
| 158 |  |  |  |  |  |  | &GclkDisplay::display($whites,$blacks,0.75) ; | 
| 159 |  |  |  |  |  |  |  | 
| 160 |  |  |  |  |  |  | # and at last the Perl/Tk necessary statement | 
| 161 |  |  |  |  |  |  |  | 
| 162 |  |  |  |  |  |  | MainLoop ; | 
| 163 |  |  |  |  |  |  |  | 
| 164 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 165 |  |  |  |  |  |  |  | 
| 166 |  |  |  |  |  |  | The module Chess::GameClock  do the job of a Chess or Go electronic | 
| 167 |  |  |  |  |  |  | clock. You can set any types of cadences like Fisher, Bronstein, | 
| 168 |  |  |  |  |  |  | Byo-yomi selecting preset cadences or by manual interface. | 
| 169 |  |  |  |  |  |  | The left and right mouse buttons are the clock buttons for whites | 
| 170 |  |  |  |  |  |  | & blacks. | 
| 171 |  |  |  |  |  |  | The keyboard is also divided into two zones right and left who emulates | 
| 172 |  |  |  |  |  |  | the actions of the mouse, as an extended facility (letter h, at the keyboard | 
| 173 |  |  |  |  |  |  | center has been excluded). | 
| 174 |  |  |  |  |  |  | The time counters are large on the screen and move counters are also | 
| 175 |  |  |  |  |  |  | displayed. The window could be adjusted with the "$scaling" parameter, | 
| 176 |  |  |  |  |  |  | that is a floating number generally between 0.5 and 2.0 . | 
| 177 |  |  |  |  |  |  |  | 
| 178 |  |  |  |  |  |  | The counter display has three commands only accessed by keyboard keys: | 
| 179 |  |  |  |  |  |  |  | 
| 180 |  |  |  |  |  |  | Control-q , forces application to quit. | 
| 181 |  |  |  |  |  |  |  | 
| 182 |  |  |  |  |  |  | Control-h , make counters to toggle between the counting and | 
| 183 |  |  |  |  |  |  | halt (pause)  mode. | 
| 184 |  |  |  |  |  |  |  | 
| 185 |  |  |  |  |  |  | Start accessed by Control-Shift-0, Start or Restart  the counters from the beginning. | 
| 186 |  |  |  |  |  |  |  | 
| 187 |  |  |  |  |  |  | You can also toggling the display between the elapsed or remaining time with Alt-c. | 
| 188 |  |  |  |  |  |  |  | 
| 189 |  |  |  |  |  |  | Note: The window "Perl Chess Clock" must have the focus for that commands could be effective. | 
| 190 |  |  |  |  |  |  |  | 
| 191 |  |  |  |  |  |  | =head1 AUTHOR | 
| 192 |  |  |  |  |  |  |  | 
| 193 |  |  |  |  |  |  | Charles Minc, C<<  >> | 
| 194 |  |  |  |  |  |  |  | 
| 195 |  |  |  |  |  |  | =head1 BUGS | 
| 196 |  |  |  |  |  |  |  | 
| 197 |  |  |  |  |  |  | Please report any bugs or feature requests to | 
| 198 |  |  |  |  |  |  | C, or through the web interface at | 
| 199 |  |  |  |  |  |  | L. | 
| 200 |  |  |  |  |  |  | I will be notified, and then you'll automatically be notified of progress on | 
| 201 |  |  |  |  |  |  | your bug as I make changes. | 
| 202 |  |  |  |  |  |  |  | 
| 203 |  |  |  |  |  |  | =head1 SUPPORT | 
| 204 |  |  |  |  |  |  |  | 
| 205 |  |  |  |  |  |  | You can find documentation for this module with the perldoc command. | 
| 206 |  |  |  |  |  |  |  | 
| 207 |  |  |  |  |  |  | perldoc GameClock | 
| 208 |  |  |  |  |  |  |  | 
| 209 |  |  |  |  |  |  | You can also look for information at: | 
| 210 |  |  |  |  |  |  |  | 
| 211 |  |  |  |  |  |  | =over 4 | 
| 212 |  |  |  |  |  |  |  | 
| 213 |  |  |  |  |  |  | =item * AnnoCPAN: Annotated CPAN documentation | 
| 214 |  |  |  |  |  |  |  | 
| 215 |  |  |  |  |  |  | L | 
| 216 |  |  |  |  |  |  |  | 
| 217 |  |  |  |  |  |  | =item * CPAN Ratings | 
| 218 |  |  |  |  |  |  |  | 
| 219 |  |  |  |  |  |  | L | 
| 220 |  |  |  |  |  |  |  | 
| 221 |  |  |  |  |  |  | =item * RT: CPAN's request tracker | 
| 222 |  |  |  |  |  |  |  | 
| 223 |  |  |  |  |  |  | L | 
| 224 |  |  |  |  |  |  |  | 
| 225 |  |  |  |  |  |  | =item * Search CPAN | 
| 226 |  |  |  |  |  |  |  | 
| 227 |  |  |  |  |  |  | L | 
| 228 |  |  |  |  |  |  |  | 
| 229 |  |  |  |  |  |  | =back | 
| 230 |  |  |  |  |  |  |  | 
| 231 |  |  |  |  |  |  | =head1 ACKNOWLEDGEMENTS | 
| 232 |  |  |  |  |  |  |  | 
| 233 |  |  |  |  |  |  | =head1 COPYRIGHT & LICENSE | 
| 234 |  |  |  |  |  |  |  | 
| 235 |  |  |  |  |  |  | Copyright 2006 Charles Minc, all rights reserved. | 
| 236 |  |  |  |  |  |  |  | 
| 237 |  |  |  |  |  |  | This program is free software; you can redistribute it and/or modify it | 
| 238 |  |  |  |  |  |  | under the same terms as Perl itself. | 
| 239 |  |  |  |  |  |  |  | 
| 240 |  |  |  |  |  |  | =cut | 
| 241 |  |  |  |  |  |  |  | 
| 242 |  |  |  |  |  |  | 1; # End of GameClock |