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

# an example with canvas lines
load ../src/gnocl.so

set pi2 [expr {-2.*atan(1)}]

set canvas [gnocl::canvas -antialiased 1 -width 500 -height 500 \
      -scrollRegion {0 0 500 500} -scrollbar never]

# capStyle
set x 180
set y 270
foreach cap {"notLast" "butt" "round" "projecting"} {
   $canvas create line [list $x $y $x [expr {$y+100}]] -width 10 \
         -fill blue -capStyle $cap
   set tx [expr {$x-15}]
   set ty [expr {$y+50}]
   set txt [$canvas create text [list $tx $ty] -label "capStyle $cap"]
   $canvas rotate $txt [list $tx $ty $pi2]
   incr x 30
}

# joinStyle
set x 250
set y 30
foreach joinStyle { "miter" "round" "bevel" } {
   $canvas create line \
         [list  $x $y [expr {$x+130}] [expr {$y+20}] $x [expr {$y+40}] ] \
         -width 10 -fill blue -joinStyle $joinStyle
   set tx [expr {$x+80}]
   set ty [expr {$y-5}]
   set txt [$canvas create text [list $tx $ty] -label "joinStyle $joinStyle"]
   $canvas rotate $txt [list $tx $ty [expr {atan2(20,130)}]]
   incr y 50
}

# arrow side
set x 30
set y 270
foreach arrow {"none" "first" "last" "both"} {
   $canvas create line [list $x $y $x [expr {$y+100}]] -width 5 \
         -fill red -arrow $arrow -arrowShape {5 10 5}
   set tx [expr {$x-15}]
   set ty [expr {$y+50}]
   set txt [$canvas create text [list $tx $ty] -label "arrow $arrow"]
   $canvas rotate $txt [list $tx $ty $pi2]
   incr x 30 
}

# arrow form
set x 100
set y 70
foreach shape {{5 5 5} {10 5 5} {5 10 5} {5 5 10} } {
   $canvas create line [list $x $y [expr {$x+100}] $y] -width 5 \
         -fill red -arrow both -arrowShape $shape
   $canvas create text [list [expr {$x+50}] [expr {$y-15}]] \
         -label "arrowShape $shape"
   incr y 30
}

#smooth # not yet implemented in gnome-canvas-line.c
# set x 290
# set y 220
# $canvas create text [list [expr {$x+80}] $y] -anchor S \
#       -fill red -label "smooth does not work?"
# foreach smooth {1 0} {
#    set x1 [expr {$x+100}]
#    set dx 20
#    $canvas create line \
#          [list  $x $y $x1 [expr {$y+$dx/2}] \
#                $x [expr {$y+$dx}] $x1 [expr {$y+5*$dx/2}] \
#                $x [expr {$y+5*$dx}]] \
#          -smooth $smooth -splineSteps 100 -fill darkgreen 
#    incr x 60
# }

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

gnocl::mainLoop

