X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.web-live.git;a=blobdiff_plain;f=pctb%2Fshow-thing.tcl;h=19912cbb47aab980855ea38e441fb577ddd27e5b;hp=9a5b1d253c91a0d43093551ad4889df95b30f02c;hb=8ca929d6e99e7c48659061a7215a55cd533a4c42;hpb=ad09cd7cce6584c63c275d7ed1106e66959b3f9d diff --git a/pctb/show-thing.tcl b/pctb/show-thing.tcl index 9a5b1d2..19912cb 100755 --- a/pctb/show-thing.tcl +++ b/pctb/show-thing.tcl @@ -15,41 +15,35 @@ proc manyset {list args} { } } -set foolist { - 7 11 1 M - 13 17 0 a - 19 23 0 n -} -set unk_l 25 -set unk_r 29 -set unk_context 0 - - - set mul 6 set inter 1 -set rhsmost_max -1 - -set f [open text.xpm] -set o {} -set y -3 -while 1 { - if {[gets $f l] < 0} { error "huh? "} - if {![regexp {^"(.*)",$} $l dummy l]} { - append o "$l\n" - if {[regexp {^\}\;$} $l]} break - continue - } - if {$y==-3} { - manyset $l cols rows colours cpp - #assert {$colours==2} - #assert {$cpp==1} - set mulcols [expr {$cols*$mul+$inter}] - set mulrows [expr {$rows*$mul+$inter}] - append o "\"$mulcols $mulrows 9 1\",\n" - for {set x 0} {$x<$cols} {incr x} { set wordmap($x) 0 } - } elseif {$y==-2} { # first pixel - append o \ + +set gotsh 20 +set csrh 20 + +proc read_xpm {f} { + global foolist mul inter rhsmost_max unk_l unk_r gotsh csrh + global cols rows wordmap + + set o {} + set y -3 + while 1 { + if {[gets $f l] < 0} { error "huh? "} + if {![regexp {^"(.*)",$} $l dummy l]} { + append o "$l\n" + if {[regexp {^\}\;$} $l]} break + continue + } + if {$y==-3} { + manyset $l cols rows colours cpp + #assert {$colours==2} + #assert {$cpp==1} + set mulcols [expr {$cols*$mul+$inter}] + set mulrows [expr {$rows*$mul+$inter}] + append o "\"$mulcols $mulrows 9 1\",\n" + for {set x 0} {$x<$cols} {incr x} { set wordmap($x) 0 } + } elseif {$y==-2} { # first pixel + append o \ "\"+ c #111\", \"a c #800\", \"A c #fcc\", @@ -59,71 +53,83 @@ while 1 { \"U c #ff0\", \"q c #000\", \"Q c #ff0\",\n" - } elseif {$y==-1} { # 2nd pixel but we've already printed ours - } else { - set ybit [expr {1<<$y}] - set x 0 - set ol "\"+" - set olh $ol - foreach c [split $l ""] { - set how "u" - if {$x >= $unk_l && $x <= $unk_r} { - set how q - } else { - set ab 0 - foreach {min max context got} $foolist { - set rhsmost_max $max - if {$x >= $min && $x <= $max} { - set how [lindex {a b} $ab] - break + } elseif {$y==-1} { # 2nd pixel but we've already printed ours + } else { + set ybit [expr {1<<$y}] + set x 0 + set ol "\"+" + set olh $ol + foreach c [split $l ""] { + set how "u" + if {$x >= $unk_l && $x <= $unk_r} { + set how q + } else { + set ab 0 + foreach {min max context got} $foolist { + set rhsmost_max $max + if {$x >= $min && $x <= $max} { + set how [lindex {a b} $ab] + break + } + set ab [expr {!$ab}] } - set ab [expr {!$ab}] } - } - switch -exact $c { - " " { set p $how } - "o" { - set p [string toupper $how] - incr wordmap($x) $ybit + switch -exact $c { + " " { set p $how } + "o" { + set p [string toupper $how] + incr wordmap($x) $ybit + } + default { error "$c ?" } } - default { error "$c ?" } - } - append ol "[string repeat $p [expr {$mul-$inter}]][ + append ol "[string repeat $p [expr {$mul-$inter}]][ string repeat + $inter]" - append olh [string repeat + $mul] - incr x + append olh [string repeat + $mul] + incr x + } + set ole "\",\n" + append ol $ole + append olh $ole + set olhn [string repeat $olh $inter] + if {!$y} { append o $olhn } + append o [string repeat $ol [expr {$mul-1}]] + append o $olhn } - set ole "\",\n" - append ol $ole - append olh $ole - set olhn [string repeat $olh $inter] - if {!$y} { append o $olhn } - append o [string repeat $ol [expr {$mul-1}]] - append o $olhn + incr y + } + set data [exec xpmtoppm << $o] + image create photo main_image -data $data + + foreach w {.d .d.csr .d.got} { + $w configure -width $mulcols + } + .d configure -height [expr {$csrh+$mulrows+$gotsh}] + foreach w {0 1} { + .d.csr_$w configure -height $mulrows } - incr y + place .d.got -x 0 -y [expr {$csrh+$mulrows}] } #puts $o -set xpm [exec xpmtoppm << $o] - -set gotsh 20 -set csrh 20 - -frame .d -width $mulcols -height [expr {$csrh+$mulrows+$gotsh}] +frame .d -set mi [image create photo -data $xpm] +set mi main_image +image create bitmap main_image label .d.mi -image $mi -borderwidth 0 -frame .d.csr -bg black -width $mulcols -height $csrh -frame .d.got -bg black -width $mulcols -height $gotsh - -foreach {min max context got} $foolist { - frame .d.got.m$min -bd 0 -background \#888 - label .d.got.m$min.l -text "$got" -fg white -bg black -bd 0 - pack .d.got.m$min.l -padx 1 -pady 1 - place .d.got.m$min -x [expr {$min*$mul+$inter}] -y 0 +frame .d.csr -bg black -height $csrh +frame .d.got -bg black -height $gotsh + +proc draw_foolist {} { + global foolist mul inter + eval destroy [winfo children .d.got] + foreach {min max context got} $foolist { + frame .d.got.m$min -bd 0 -background \#888 + label .d.got.m$min.l -text "$got" -fg white -bg black -bd 0 + pack .d.got.m$min.l -padx 1 -pady 1 + place .d.got.m$min -x [expr {$min*$mul+$inter}] -y 0 + } } set imcsr [image create bitmap -data \ @@ -139,23 +145,27 @@ label .d.csr.csr.l -image $imcsr -compound left entry .d.csr.csr.e -bd 0 pack .d.csr.csr.l -side left -frame .d.csr_0 -bg white -height $mulrows -width 1 -frame .d.csr_1 -bg white -height $mulrows -width 1 +frame .d.csr_0 -bg white -width 1 +frame .d.csr_1 -bg white -width 1 place .d.csr -x 0 -y 0 place .d.mi -x 0 -y $csrh -place .d.got -x 0 -y [expr {$csrh+$mulrows}] pack .d frame .help pack .help -set cur_already [expr {[llength $foolist]/4-1}] -set cur_mode 1 ;# one of: 0 1 already text +proc startup_cursor {} { + global cur_already cur_mode cur_0 cur_1 last_ht + global foolist unk_l unk_r + + set cur_already [expr {[llength $foolist]/4-1}] + set cur_mode 1 ;# one of: 0 1 already text -set cur_0 $unk_l -set cur_1 [expr {$unk_r+1}] -set last_ht {} + set cur_0 $unk_l + set cur_1 [expr {$unk_r+1}] + set last_ht {} +} proc helptext {t} { global last_ht @@ -367,5 +377,27 @@ proc RETURN_RESULT {how what} { # bind . {} -read_database -recursor +proc test_main {} { + global foolist unk_l unk_r unk_context + + set foolist { + 7 11 1 M + 13 17 0 a + 19 23 0 n + } + set unk_l 25 + set unk_r 29 + set unk_context 0 + + set f [open text.xpm] + read_xpm $f + close $f + + draw_foolist + startup_cursor + + read_database + recursor +} + +test_main