5 namespace eval ::ptrack {}
8 set ::ptrack::select d1
9 set ::ptrack::moves(start) 1
10 set ::ptrack::moves(end) 20
11 set ::ptrack::mode "-games"
12 set ::ptrack::color blue
13 set ::ptrack::colors [list black red yellow cyan blue xblack xred xyellow xcyan xblue]
15 trace variable ::ptrack::moves(start) w {::utils::validate::Integer 999 0}
16 trace variable ::ptrack::moves(end) w {::utils::validate::Integer 999 0}
21 proc ::ptrack::sq {n} {
22 set sq [
lindex [list a b c d e f g h] [
expr {$n % 8}]]
23 append sq [
expr {int($n/8) + 1}]
30 proc ::ptrack::unselect {} {
32 set ::ptrack::select {}
33 foreach i {a1 c1 e1 g1 b2 d2 f2 h2 a7 c7 e7 g7 b8 d8 f8 h8} {
34 $w.bd.p$i configure -background $::dark
36 foreach i {b1 d1 f1 h1 a2 c2 e2 g2 b7 d7 f7 h7 a8 c8 e8 g8} {
37 $w.bd.p$i configure -background $::lite
44 proc ::ptrack::select {plist} {
47 lappend ::ptrack::select $p
48 .ptracker.bd.p$p configure -background $::highcolor
55 proc ::ptrack::status {{text ""}} {
56 set t .ptracker.status
60 $t configure -text $text
67 proc ::ptrack::recolor {color} {
68 set ::ptrack::color $color
69 .ptracker.t.color.b configure -image ptrack_$::ptrack::color
77 proc ::ptrack::color {pct {col ""}} {
79 set col $::ptrack::color
82 if {$x > 100.0} {
set x 100.0}
83 if {$x < 0.01} {
set x 0.01}
84 set y [
expr {255 - round($x * 0.5 + 10 * log($x))}]
85 set yb [
expr {255 - round($x * 2.0 + 10 * log($x))}]
86 if {$y > 255} {
set y 255}
87 if {$yb > 255} {
set yb 255}
88 if {$yb < 0} {
set yb 0}
89 if {$y < 0} {
set y 0}
90 if {$pct > 0.0 && $y == 0} {
set y 1}
91 if {$pct > 0.0 && $yb == 0} {
set yb 1}
92 set xy [
expr {255 - $y}]
93 set xyb [
expr {255 - $yb}]
95 black {
set color [
format "\#%02X%02X%02X" $yb $yb $yb]}
96 red {
set color [
format "\#%02X%02X%02X" $y $yb $yb]}
97 yellow {
set color [
format "\#%02X%02X%02X" $y $y $yb]}
98 cyan {
set color [
format "\#%02X%02X%02X" $yb $y $y]}
99 blue {
set color [
format "\#%02X%02X%02X" $yb $yb $y]}
100 xblack {
set color [
format "\#%02X%02X%02X" $xyb $xyb $xyb]}
101 xred {
set color [
format "\#%02X%02X%02X" $xyb $xy $xy]}
102 xyellow {
set color [
format "\#%02X%02X%02X" $xyb $xyb $xy]}
103 xcyan {
set color [
format "\#%02X%02X%02X" $xy $xyb $xyb]}
104 xblue {
set color [
format "\#%02X%02X%02X" $xy $xy $xyb]}
112 proc ::ptrack::make {} {
114 if {[
winfo exists $w]} {
return}
116 toplevel $w -background [ttk::style lookup . -background]
117 wm title $w "Scid: [
tr ToolsTracker]"
119 bind $w <Escape> "destroy $w"
120 bind $w <F1> {helpWindow PTracker}
121 image create photo ptrack -width $::ptrack::psize -height $::ptrack::psize
122 ttk::label $w.status -width 1 -anchor w -relief sunken -font font_Small
123 pack $w.status -side bottom -fill x
125 canvas $w.progress -height 20 -width 400 -bg white -relief solid -border 1
126 $w.progress create rectangle 0 0 0 0 -fill blue -outline blue -tags bar
127 $w.progress create text 395 10 -anchor e -font font_Regular -tags time \
128 -fill black -text "0:00 / 0:00"
129 pack $w.progress -side bottom -pady 2
132 pack $w.bd -side left -padx 2 -pady 4
135 pack $w.t -side right -fill y -expand yes
136 pack [ttk::frame $w.gap -width 5] -side left
138 ttk::frame $w.t.color
140 ttk::frame $w.t.moves
141 ttk::frame $w.t.buttons
142 pack $w.t.buttons -side bottom -fill x
143 pack $w.t.moves -side bottom
144 pack $w.t.mode -side bottom
145 pack $w.t.color -side bottom
147 set ::ptrack::shade {}
148 for {
set i 0} {$i < 64} {
incr i} {
149 ttk::label $w.bd.sq$i -image ptrack -background white -border 1 -relief raised
150 set rank [
expr {$i / 8}]
151 set file [
expr {$i % 8}]
152 grid $w.bd.sq$i -row [
expr {7 - $rank}] -column [
expr {$file + 1}]
153 lappend ::ptrack::shade 0.0
156 foreach rank {1 2 3 4 5 6 7 8} {
157 ttk::label $w.bd.r$rank -text $rank -width 2
158 grid $w.bd.r$rank -column 0 -row [
expr {8 - $rank}]
161 foreach column {1 2 3 4 5 6 7 8} file {a b c d e f g h} {
162 ttk::label $w.bd.f$file -text $file
163 grid $w.bd.f$file -row 8 -column $column
166 grid [ttk::frame $w.bd.gap1 -height 5] -row 9 -column 0
168 foreach file {a b c d e f g h} c {1 2 3 4 5 6 7 8} p {r n b q k b n r} {
171 ttk::label $b -image b$p$::ptrack::psize -border 1 -relief raised
172 grid $b -row 10 -column $c
173 bind $b <1> "::ptrack::select $sq"
175 foreach file {a b c d e f g h} c {1 2 3 4 5 6 7 8} p {p p p p p p p p} {
178 ttk::label $b -image b$p$::ptrack::psize -border 1 -relief raised
179 grid $b -row 11 -column $c
180 bind $b <1> "::ptrack::select $sq"
181 bind $b <$::MB3> "::ptrack::select {a7 b7 c7 d7 e7 f7 g7 h7}"
183 grid [ttk::frame $w.bd.gap2 -height 5] -row 12 -column 0
184 foreach file {a b c d e f g h} c {1 2 3 4 5 6 7 8} p {p p p p p p p p} {
187 ttk::label $b -image w$p$::ptrack::psize -border 1 -relief raised
188 grid $b -row 13 -column $c
189 bind $b <ButtonPress-1> "::ptrack::select $sq"
190 bind $b <$::MB3> "::ptrack::select {a2 b2 c2 d2 e2 f2 g2 h2}"
192 foreach file {a b c d e f g h} c {1 2 3 4 5 6 7 8} p {r n b q k b n r} {
195 ttk::label $b -image w$p$::ptrack::psize -border 1 -relief raised
196 grid $b -row 14 -column $c
197 bind $b <Button-1> "::ptrack::select $sq"
201 foreach sq {d1 e1 d8 e8} {
202 bind $w.bd.p$sq <$::MB3> [list ::ptrack::select $sq]
204 foreach left {a b c} right {h g f} {
205 set cmd [list ::ptrack::select [list ${left}1 ${right}1]]
206 bind $w.bd.p${left}1 <ButtonPress-$::MB3> $cmd
207 bind $w.bd.p${right}1 <ButtonPress-$::MB3> $cmd
208 set cmd [list ::ptrack::select [list ${left}8 ${right}8]]
209 bind $w.bd.p${left}8 <ButtonPress-$::MB3> $cmd
210 bind $w.bd.p${right}8 <ButtonPress-$::MB3> $cmd
214 foreach sq {d1 e1 d8 e8} {
215 bind $w.bd.p$sq <Any-Enter> {
216 ::ptrack::status $::tr(TrackerSelectSingle)
218 bind $w.bd.p$sq <Any-Leave> ::ptrack::status
221 foreach sq {a1 b1 c1 f1 g1 h1 a8 b8 c8 f8 g8 h8} {
222 bind $w.bd.p$sq <Any-Enter> {
223 ::ptrack::status $::tr(TrackerSelectPair)
225 bind $w.bd.p$sq <Any-Leave> ::ptrack::status
227 foreach sq {a2 b2 c2 d2 e2 f2 g2 h2 a7 b7 c7 d7 e7 f7 g7 h7} {
228 bind $w.bd.p$sq <Any-Enter> {
229 ::ptrack::status $::tr(TrackerSelectPawn)
231 bind $w.bd.p$sq <Any-Leave> ::ptrack::status
233 set plist $::ptrack::select
238 pack [ttk::frame $f] -side top -fill both -expand yes -padx 2 -pady 2
239 text $f.text -width 28 -height 1 -foreground black -background white \
240 -yscrollcommand "$f.ybar set" -relief sunken -takefocus 0 \
241 -wrap none -font font_Small
242 set xwidth [font measure [$f.text cget -font] "x"]
243 foreach {tab justify} {3 r 5 l 19 r 29 r} {
244 set tabwidth [
expr {$xwidth * $tab}]
245 lappend tablist $tabwidth $justify
247 $f.text configure -tabs $tablist
248 ttk::scrollbar $f.ybar -takefocus 0 -command "$f.text yview"
249 pack $f.ybar -side right -fill y
250 pack $f.text -side left -fill y -expand yes
254 menubutton $f.b -menu $f.b.menu -indicatoron 0 -relief raised
256 foreach col $::ptrack::colors {
257 image create photo ptrack_$col -width 101 -height 20
258 for {
set i 0} {$i <= 100} {
incr i} {
260 ptrack_$col put $color -to $i 0 [
expr {$i+1}] 19
262 $f.b.menu add command -image ptrack_$col \
263 -command "::ptrack::recolor $col"
265 $f.b configure -image ptrack_$::ptrack::color
266 ttk::label $f.label -text $::tr(GlistColor:) -font font_Bold
267 pack $f.label $f.b -side left -pady 5
270 ttk::label $f.mode -text $::tr(TrackerStat:) -font font_Bold
271 grid $f.mode -row 0 -column 0
272 ttk::radiobutton $f.games -text $::tr(TrackerGames) \
273 -variable ::ptrack::mode -value "-games"
274 ttk::radiobutton $f.time -text $::tr(TrackerTime) \
275 -variable ::ptrack::mode -value "-time"
276 grid $f.games -row 1 -column 0 -sticky we
277 grid $f.time -row 2 -column 0 -sticky we
280 ttk::label $f.lfrom -text $::tr(TrackerMoves:) -font font_Bold
281 ttk::entry $f.from -width 3 -justify right -textvariable ::ptrack::moves(start)
282 ttk::label $f.lto -text "-"
283 ttk::entry $f.to -width 3 -justify right -textvariable ::ptrack::moves(end)
284 pack $f.lfrom $f.from $f.lto $f.to -side left -pady 5
287 bind $f.from <FocusIn> [list +::ptrack::status $::tr(TrackerMovesStart)]
288 bind $f.from <FocusOut> +::ptrack::status
289 bind $f.to <FocusIn> [list +::ptrack::status $::tr(TrackerMovesStop)]
290 bind $f.to <FocusOut> +::ptrack::status
293 ttk::button $f.stop -text $::tr(Stop) -command progressBarCancel -state disabled
294 ttk::button $f.update -text $::tr(Update) -command ::ptrack::refresh
295 ttk::button $f.close -text $::tr(Close) -command "destroy $w"
296 pack $f.close $f.update $f.stop -side right -padx 3 -pady 5
298 bind $w <Configure> "recordWinSize $w"
300 focus $w.t.buttons.update
306 proc ::ptrack::refresh {{type "all"}} {
308 if {! [
winfo exists $w]} {
return}
311 if {$type == "color"} {
312 for {
set i 0} {$i < 64} {
incr i} {
313 set x [
lindex $::ptrack::shade $i]
319 $w.t.buttons.update configure -state disabled
320 $w.t.buttons.close configure -state disabled
321 $w.t.buttons.stop configure -state normal
322 catch {grab $w.t.buttons.stop}
324 if {$::ptrack::moves(end) < $::ptrack::moves(start)} {
325 set ::ptrack::moves(end) $::ptrack::moves(start)
329 if {$::ptrack::mode == "-time"} {
set timeMode 1}
332 set err [
catch {
eval sc_base piecetrack $::ptrack::mode \
333 $::ptrack::moves(start) $::ptrack::moves(end) \
334 $::ptrack::select} ::ptrack::data]
336 catch {grab release $w.t.buttons.stop}
337 $w.t.buttons.stop configure -state disabled
338 $w.t.buttons.update configure -state normal
339 $w.t.buttons.close configure -state normal
347 set nmoves [
expr {$::ptrack::moves(end) + 1 - $::ptrack::moves(start)}]
348 set dfilter [
expr {$dfilter * $nmoves}]
350 if {$dfilter == 0} {
set dfilter 1}
353 for {
set i 0} {$i < 64} {
incr i} {
354 set freq [
lindex $::ptrack::data $i]
355 if {$freq > $max} {
set max $freq}
358 set ::ptrack::shade {}
359 for {
set i 0} {$i < 64} {
incr i} {
360 set freq [
lindex $::ptrack::data $i]
361 set x [
expr {$freq * 100.0 / $max}]
363 lappend ::ptrack::shade $x
364 $w.bd.sq$i configure -background $color
368 set text $w.t.text.text
371 for {
set top 1} {$top <= 64} {
incr top} {
374 for {
set i 0} {$i < 64} {
incr i} {
375 set n [
lindex $::ptrack::data $i]
376 if {$n > $best && ![
info exists printed($i)]} {
383 set pct [
expr {round(double($best) * 10000.0 / double($dfilter)) / 100.0}]
384 set line [
format "\t%2d.\t%s\t%7s\t%6.2f %%" $top \
386 $text insert end "$line\n"
388 bind $w.bd.sq$idx <Any-Enter> [list ::ptrack::status $status]
389 bind $w.bd.sq$idx <Any-Leave> ::ptrack::status