Wednesday, November 03, 2010

gnocl::drawingArea ----> working forward ---->

This mornings programming stint sees the bare bones in place now for drawing commands on the gnocl::drawingArea widget. I've also added pages in the docs for the cursor settings. The test script changes reflect the progress so far as a stroke based paint program begins to take shape.



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

package require Gnocl

# create and display the drawingArea widget
set da [gnocl::drawingArea]
gnocl::window -widthRequest 320 -heightRequest 200 -child $da

# add options...
$da option add -onPointerMotion
$da option add -onEnter
$da option add -onLeave
$da option add -onButtonPress
$da option add -onButtonRelease
$da option add [list -onKeyPress -onKeyRelease -onExpose]

# configure them
$da configure -onPointerMotion {addPoint %w %x %y}
$da configure -onEnter {puts "Enter -Hello!"}
$da configure -onLeave {puts "Leave -Bye!"}
$da configure -onButtonPress {
    puts "-- Start Drawing --"
    set draw 1
    $da configure -cursor pencil
    }
$da configure -onButtonRelease {
    puts "-- End Drawing --"
    set draw 0
    $da configure -cursor last
    }
$da configure -onKeyPress {puts "Press"}
$da configure -onKeyRelease {puts "Release"}
$da configure -onExpose {
    reDraw %w
    }

set draw 0
set points {}

proc addPoint { w x y } {
    if { $::draw } {
        lappend ::points [list $x $y]
        puts adding
        $w draw point [list $x $y]
    }
}

proc reDraw {w} {
    foreach point $::points {
        $w draw point $point
    }
}




No comments: