Sunday, November 14, 2010

gnocl::drawingArea

This little beastie got a whole lotta TLC today. Implemented most of the the gdk drawing functions only to find that these have been deprecated in Gtk +2.22 in favour of Cairo! No matter, the code will work and besides, there was already a cairo based module in the pipeline anyway!

#---------------
# test-drawingArea.tcl
#---------------
# William J Giddings
# 02-Nov-2010
#---------------

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

package require Gnocl

proc scanZone {} {

set da [gnocl::drawingArea]

$da option add [list \
    -onPointerMotion \
    -onButtonPress \
    -onButtonRelease \
    -onKeyPress \
    -onKeyRelease \
    -onExpose]

return $da
}

set sz [scanZone]

gnocl::window -child $sz

if {0} {
set pb [gnocl::pixBuf load -file EU_flag.jpg]
gnocl::window -child [gnocl::image -image "%?$pb"]
set pb [gnocl::pixBuf load -file wjg_icon.png]
}

$sz configure -onPointerMotion {

    #%w draw line [list %x 0 %x 10]
    #%w draw line [list 0 %y 10 %y ]

    set x1 [expr %x - 5] ; set y1 [expr %y - 5]
    set x2 [expr %x + 5] ; set y2 [expr %y - 5]
    set x3 [expr %x + 5] ; set y3 [expr %y + 5]
    set x4 [expr %x - 5] ; set y4 [expr %y + 5]

    #%w draw point [list %x %y]
    #%w draw points [list $x1 $y1 $x2 $y2 $x3 $y3 $x4 $y4]
    #%w draw lines [list $x1 $y1 %x %y $x2 $y2] ;#$x3 $y3 $x4 $y4 $x1 $y1]

    #%w draw pixbuf $pb -from [list %x %y 10 10] -to [list %x %y] -dither none -offset {0 0}
    #%w draw rectangle [list $x1 $y1 10 10] -filled 1

    #%w draw arc [list $x1 $y1 50 50 30 120] -filled 1
    #%w draw     polygon [list $x1 $y1 $x2 $y2 $x3 $y3 $x4 $y4] -filled 1

    set x1 %x ; set y1 [expr %y -10]
    set x2 %x ; set y2 [expr %y +10]
    set x3 [expr %x -10] ; set y3 %y
    set x4 [expr %x +10] ; set y4 %y

    #%w draw segments [list $x1 $y1 $x2 $y2 $x3 $y3 $x4 $y4]

    set y1    %y
    set x11 %x
    set x21 [expr %x + 50]
    set y2    [expr %y + 50]
    set x12 [expr %x - 50]
    set x22 [expr %x + 50]

    %w draw  trapezoids [list $y1 $x11 $x21 $y2 $x12 $x22 ]
    }

No comments: