line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
####----------------------------------- |
2
|
|
|
|
|
|
|
### File : GclkDisplay.pm |
3
|
|
|
|
|
|
|
### Author : Ch.Minc |
4
|
|
|
|
|
|
|
### Purpose : Display counters for GameClock |
5
|
|
|
|
|
|
|
### Version : 1.1 2007/12/23 |
6
|
|
|
|
|
|
|
####----------------------------------- |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package GclkDisplay ; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.1' ; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
require Exporter ; |
13
|
1
|
|
|
1
|
|
2828
|
use strict ; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
35
|
|
14
|
1
|
|
|
1
|
|
8
|
use warnings ; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
|
367
|
use Tk ; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
use Time::HiRes qw(gettimeofday tv_interval); |
18
|
|
|
|
|
|
|
use Chess::GameClock::GclkData qw (:tout) ; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our @ISA=qw(Exporter) ; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our @EXPORT_OK=qw (&display hmnsec loupe) ; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $varset ; |
25
|
|
|
|
|
|
|
my %sous_menuref ; |
26
|
|
|
|
|
|
|
my %soussous_ref ; |
27
|
|
|
|
|
|
|
my %rb ; |
28
|
|
|
|
|
|
|
my $aff ; |
29
|
|
|
|
|
|
|
my @setaff=(qw/Blitz RapidesTournois/) ; |
30
|
|
|
|
|
|
|
push(@setaff,$aff=shift(@setaff)) ; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my $whites ; #our |
33
|
|
|
|
|
|
|
my $blacks ; |
34
|
|
|
|
|
|
|
my $mw ; |
35
|
|
|
|
|
|
|
my $screensz ; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub display { |
38
|
|
|
|
|
|
|
($whites,$blacks,$screensz)=@_ ; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# window where the timestamps of the game are written by GclkCounter |
41
|
|
|
|
|
|
|
my $mwt=MainWindow->new(-title=>"LogTime") ; |
42
|
|
|
|
|
|
|
my $spytext = $mwt->Text(qw/-width 120 -height 30/)->pack; |
43
|
|
|
|
|
|
|
$mwt->iconify ; |
44
|
|
|
|
|
|
|
tie *STDOUT, ref $spytext, $spytext; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# draw the clock windows |
48
|
|
|
|
|
|
|
$mw=MainWindow->new(-title=>'Perl Chess Clock') ; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
my ($l,$v1,$v2)=&loupe($screensz) ; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
my $fr=$mw->Frame->pack ; |
54
|
|
|
|
|
|
|
my %option_mv=(qw/-height 1 -width 3 -anchor center / ) ; |
55
|
|
|
|
|
|
|
# my $wmv='W' ; |
56
|
|
|
|
|
|
|
# my $bmv='B' ; |
57
|
|
|
|
|
|
|
my $white_mv=$fr->Button(# -textvariable=>\$whites->[0]{mvt}, x |
58
|
|
|
|
|
|
|
-foreground=>'yellow', |
59
|
|
|
|
|
|
|
-font=>' Arial 24 bold', |
60
|
|
|
|
|
|
|
-activeforeground=>'yellow' |
61
|
|
|
|
|
|
|
)->pack(-side=>'left') ; |
62
|
|
|
|
|
|
|
my $black_mv=$fr->Button( #-textvariable=>\$blacks->[0]{mvt}, |
63
|
|
|
|
|
|
|
-font=>' Arial 24 bold', |
64
|
|
|
|
|
|
|
-activeforeground=>'black', |
65
|
|
|
|
|
|
|
)->pack(-side=>'left') ; |
66
|
|
|
|
|
|
|
# $white_mv->configure(%option_mv) ; x |
67
|
|
|
|
|
|
|
$white_mv->configure(-textvariable=>\$whites->[0]{mvt},%option_mv) ; # modif x |
68
|
|
|
|
|
|
|
$black_mv->configure(-textvariable=>\$blacks->[0]{mvt},%option_mv) ; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my $cn1=$mw->Canvas(-height=>'15c',-width=>'30c')->pack ; |
72
|
|
|
|
|
|
|
; |
73
|
|
|
|
|
|
|
my $txt1=$cn1->createText($l,$v1, |
74
|
|
|
|
|
|
|
-text=>'00:00:00', |
75
|
|
|
|
|
|
|
-font=>'Helvetica 200 bold', |
76
|
|
|
|
|
|
|
-fill=>'yellow', |
77
|
|
|
|
|
|
|
-justify=>'right', |
78
|
|
|
|
|
|
|
-activefill=>'yellow', |
79
|
|
|
|
|
|
|
-tags=>['txt1','box','r1'] |
80
|
|
|
|
|
|
|
) ; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
my $txt2=$cn1->createText($l,$v2,-text=>'00:00:00', |
83
|
|
|
|
|
|
|
-font=>'Helvetica 200 bold', |
84
|
|
|
|
|
|
|
-fill=>'black', |
85
|
|
|
|
|
|
|
-justify=>'right', |
86
|
|
|
|
|
|
|
-activefill=>'black', |
87
|
|
|
|
|
|
|
-tags=>['txt2','box','r2'] |
88
|
|
|
|
|
|
|
) ; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
my $rect1=$cn1->createRectangle('0.5c','1c','29c','7c',-width=>'0.3c',-outline=>'white',-tags=>['rect1', 'box', 'r1']) ; |
92
|
|
|
|
|
|
|
my $rect2=$cn1->createRectangle('0.5c','7.5c','29c','14c',-width=>'0.3c',-outline=>'black',-tags=>['rect2', 'box' ,'r2']) ; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
my $fm=$mw->Frame() ; |
95
|
|
|
|
|
|
|
$fm->pack(-side=>'bottom' |
96
|
|
|
|
|
|
|
) ; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
my $start=$fm->Button(-text=>'Start') ; |
99
|
|
|
|
|
|
|
# -command=>['start',$whites,$whites,$blacks,$mw,$black_mv]); |
100
|
|
|
|
|
|
|
my $stop=$fm->Button(-text=>'Halt') ; |
101
|
|
|
|
|
|
|
my $quit=$fm->Button(-text=>"Quit") ; |
102
|
|
|
|
|
|
|
# -command=>\&Tk::exit) ; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
my %cmd_opt=(qw/-anchor center -width 20 -height 4/); |
105
|
|
|
|
|
|
|
$start->configure(%cmd_opt) ; |
106
|
|
|
|
|
|
|
$stop->configure(%cmd_opt) ; |
107
|
|
|
|
|
|
|
$quit->configure(%cmd_opt) ; |
108
|
|
|
|
|
|
|
$start->pack(-side=>'left') ; |
109
|
|
|
|
|
|
|
$stop->pack(-side=>'left') ; |
110
|
|
|
|
|
|
|
$quit->pack(-side=>'left') ; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# cancel mouse bindings for Button mv and set Alt-c keyboard command |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
$white_mv->bindtags(['TrickyButton',$white_mv->toplevel,'all']) ; |
115
|
|
|
|
|
|
|
$black_mv->bindtags(['TrickyButton',$black_mv->toplevel,'all']) ; |
116
|
|
|
|
|
|
|
$mw->bind('<>'=>[\&cnttype,'w']) ; |
117
|
|
|
|
|
|
|
$mw->eventAdd('<>'=>'') ; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# cancel mouse bindings for Button $stop $start $quit |
120
|
|
|
|
|
|
|
$stop->bindtags(['TrickyButton',$stop->toplevel,'all']) ; |
121
|
|
|
|
|
|
|
$mw->bind('<>'=>['GclkCounter::stop',$stop,$whites,$blacks]) ; |
122
|
|
|
|
|
|
|
$mw->eventAdd('<>'=>"") ; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
$start->bindtags(['TrickyButton',$start->toplevel,'all']) ; |
125
|
|
|
|
|
|
|
$mw->bind('<>'=>['GclkCounter::start', |
126
|
|
|
|
|
|
|
$whites,$blacks,$mw,$white_mv,$black_mv]); |
127
|
|
|
|
|
|
|
$mw->eventAdd('<>'=>"") ; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
$quit->bindtags(['TrickyButton',$quit->toplevel,'all']) ; |
130
|
|
|
|
|
|
|
$mw->bind('<>'=>sub{&Tk::exit(0)} ) ; |
131
|
|
|
|
|
|
|
$mw->eventAdd('<>'=>"") ; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
# bind keyboard to toggle counters |
134
|
|
|
|
|
|
|
map{$mw->bind("",['GclkCounter::capture', 'B1-',$whites,$blacks])}(qw/a z e r t y q s d f g < w x c v b/) ; |
135
|
|
|
|
|
|
|
map{$mw->bind("",['GclkCounter::capture', 'B3-',$whites,$blacks])}(qw/u i o p Multi_key $ j k l m ugrave * n comma ; : \/ ! /) ; |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
# force the focus on window Chess Clock |
138
|
|
|
|
|
|
|
$mw->focusForce ; |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
$mw->repeat(1000=>sub { |
142
|
|
|
|
|
|
|
{ |
143
|
|
|
|
|
|
|
#my $wmv=$whites->[0]{mv} ; |
144
|
|
|
|
|
|
|
# my $bmv=$blacks->[0]{mv} ; |
145
|
|
|
|
|
|
|
# $fr->update ; |
146
|
|
|
|
|
|
|
my $elapsed =($whites->[0]{state} eq 'On')? tv_interval ($whites->[0]{ts}):0 ; |
147
|
|
|
|
|
|
|
#print $whites->[0]{state} ; |
148
|
|
|
|
|
|
|
my $td=$whites->[0]{ct} ; |
149
|
|
|
|
|
|
|
my $tj=$whites->[0]{cmpt} ; |
150
|
|
|
|
|
|
|
$td -=$elapsed ; |
151
|
|
|
|
|
|
|
$tj +=$elapsed ; |
152
|
|
|
|
|
|
|
$cn1->dchars($txt1,0,7) ; |
153
|
|
|
|
|
|
|
my $taff= $aff=~ /Blitz/ ? $td : $tj ; |
154
|
|
|
|
|
|
|
my $str1=sprintf("%02d:%02d:%02d",&hmnsec($taff)) ; |
155
|
|
|
|
|
|
|
$cn1->insert($txt1,1,$str1) ; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
; |
158
|
|
|
|
|
|
|
# affichage suivant la cadence Blitz-Fisher-Bronstein temps restant |
159
|
|
|
|
|
|
|
# KO temps écoulé/temps restant |
160
|
|
|
|
|
|
|
{ |
161
|
|
|
|
|
|
|
my $elapsed =($blacks->[0]{state} eq 'On')? tv_interval ($blacks->[0]{ts}):0 ; |
162
|
|
|
|
|
|
|
my $td=$blacks->[0]{ct} ; |
163
|
|
|
|
|
|
|
my $tj=$blacks->[0]{cmpt} ; |
164
|
|
|
|
|
|
|
$td -=$elapsed ; |
165
|
|
|
|
|
|
|
$tj +=$elapsed ; |
166
|
|
|
|
|
|
|
$cn1->dchars($txt2,0,7) ; |
167
|
|
|
|
|
|
|
my $taff= $aff=~ /Blitz/ ? $td : $tj ; |
168
|
|
|
|
|
|
|
my $str2=sprintf("%02d:%02d:%02d",&hmnsec($taff) ) ; |
169
|
|
|
|
|
|
|
$cn1->insert($txt2,1,$str2) ; |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
; |
172
|
|
|
|
|
|
|
#$mw->update ; |
173
|
|
|
|
|
|
|
} ) ; |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub loupe{ |
178
|
|
|
|
|
|
|
my $x=shift ; |
179
|
|
|
|
|
|
|
$mw->scaling($x) ; |
180
|
|
|
|
|
|
|
my $scale=0.76*$x ; |
181
|
|
|
|
|
|
|
my($l,$v1,$v2)=('550','150','400') ; |
182
|
|
|
|
|
|
|
$l *=$scale ; |
183
|
|
|
|
|
|
|
$v1 *=$scale ; |
184
|
|
|
|
|
|
|
$v2 *=$scale ; |
185
|
|
|
|
|
|
|
return($l,$v1,$v2) ; |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
sub cnttype{ |
189
|
|
|
|
|
|
|
# change counter aspect up or down |
190
|
|
|
|
|
|
|
push(@setaff,$aff=shift(@setaff)) ; |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
sub hmnsec{ |
196
|
|
|
|
|
|
|
# convert time in sec to hh:mm:ss |
197
|
|
|
|
|
|
|
my $sec=shift ; |
198
|
|
|
|
|
|
|
if ($sec < 0 || !defined($sec) ) { |
199
|
|
|
|
|
|
|
return(0,0,0); |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
my $h=int($sec / 3600) ; |
202
|
|
|
|
|
|
|
my $mn=int(($sec% 3600)/60) ; |
203
|
|
|
|
|
|
|
my $s=$sec%60 ; |
204
|
|
|
|
|
|
|
return ($h,$mn,$s) ; |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=head1 NAME |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
GclkDisplay - Display the counters |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=head1 VERSION |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
Version 1.1 |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=cut |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=head1 SYNOPSIS |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
Draw the Chess Counter Window |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
use GclkDisplay; |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
&display($whites,$blacks,$scaling) |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
where $whites and $blacks are GclkCounter object and $scaling a scalar |
226
|
|
|
|
|
|
|
for changing the size of the window displayed. |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=head1 EXPORT |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
display |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=head1 FUNCTIONS |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=head2 display |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
see SYNOPSIS |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=cut |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=head2 cnttype |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
an internal routine for toggling counters time |
243
|
|
|
|
|
|
|
between time elased and time remaining. |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
Global parameters |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=cut |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=head2 hmnsec |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
convert time in sec to hh:mm:ss format |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
my($h,$mn,$s)=hmnsec(time_in_seconds) ; |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=head2 loupe |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
adjust the parameters for the window size. |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
my ($l,$v1,$v2)=&loupe($scaling) ; |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
where $scaling is between 0.5 and 2.0 |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
(Note:This function is perhaps screen type/graphics board |
265
|
|
|
|
|
|
|
dependant, in case of malfunction). |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
=head1 AUTHOR |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
Charles Minc, C<< >> |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=head1 BUGS |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
274
|
|
|
|
|
|
|
C, or through the web interface at |
275
|
|
|
|
|
|
|
L. |
276
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on |
277
|
|
|
|
|
|
|
your bug as I make changes. |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=head1 SUPPORT |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
perldoc GameClock |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
You can also look for information at: |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
=over 4 |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
L |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
=item * CPAN Ratings |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
L |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
L |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
=item * Search CPAN |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
L |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
=back |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
Copyright 2006 Charles Minc, all rights reserved. |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
314
|
|
|
|
|
|
|
under the same terms as Perl itself. |
315
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
=cut |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
1; # End of GclkDisplay |