#!/bin/sh
# the next line restarts using tclsh \
exec tclsh "$0" "$@"

if { $argc != 1 } {
   puts "usage: $argv0 socket-XID"
}

load ../src/gnocl.so

set mainBox [gnocl::box -orientation vertical -homogeneous 0]

set canv [gnocl::canvas]
set ellipse [$canv create ellipse {20 20 30} -fill blue]
#set txt  [gnocl::label]
$mainBox add $canv 
gnocl::bind $canv button {puts "canvas: %%b: %b"}
gnocl::bind $canv {button 1} {puts "canvas: %%b: %b == 1"}
gnocl::bind $canv {button 2} {puts "canvas: %%b: %b == 2"}
gnocl::bind $canv {button 3} {puts "canvas: %%b: %b == 3"}

gnocl::bind $ellipse button {puts "item: %%b: %b"}
gnocl::bind $ellipse {button 1} {puts "item: %%b: %b == 1"}
gnocl::bind $ellipse {button 2} {puts "item: %%b: %b == 2"}
gnocl::bind $ellipse {button 3} {puts "item: %%b: %b == 3"}

if { $argc == 1 } {
   set win [gnocl::plug [lindex $argv 0] -child $mainBox]
} else {
   set win [gnocl::window -child $mainBox -width 200 -height 200]
}

gnocl::bind $win key {puts "window: %%k: %k %%K: %K %%A: \"%A\" %%s: %s"}
gnocl::bind $win {key 1} {puts "any 1"}
gnocl::bind $win {key #KP_1} {puts "numpad 1"}
gnocl::bind $win {key #1} {puts "keyboard 1"}

gnocl::mainLoop

