#!/usr/bin/env wish

lappend auto_path $::env(LUSTRE_INSTALL)/tcl 
package require Ptk


# image types:
image types
# bitmap -> bicolore
# photo -> color
# support natif: gif 


lappend auto_path ../src
package require Ptk

#ptk::debug on


namespace eval PRG {
	variable vars
}

for {set x 0} {$x < 3} {incr x} {
for {set y 0}  {$y < 3} {incr y} {
	set PRG::vars(${x}${y}) 0
}
}

proc doclic { x y } {
	set v "$PRG::vars(${x}${y})"
	puts "clic $x $y -> $v"
	set PRG::vars(${x}${y}) [expr ( $v + 1 ) % 4]
}

proc mkcell { title x y } {
	ptk::begin switch PRG::vars(${x}${y}) {0 1 2 3}
		for {set d 0} {$d < 4} {incr d} {
			set imgfile "_imgs/${title}${x}${y}${d}.gif"
			set img "img${x}${y}${d}"
			image create photo $img -file $imgfile
puts "create cell '$imgfile'"
			ptk::add button -image "$img" -command "doclic $x $y"
		}	
	ptk::end switch
}

proc mkcol { title x } {
	ptk::begin col
	for {set y 0}  {$y < 3} {incr y} {
		mkcell $title $x $y
	}
	ptk::end col
}

ptk::begin main "Puzz"
	ptk::begin line
	for {set x 0} {$x < 3} {incr x} {
		mkcol img $x
	}
	ptk::end line
ptk::end main
