aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormescalinum <mescalinum@users.sourceforge.net>2009-09-03 10:31:11 +0000
committermescalinum <mescalinum@users.sourceforge.net>2009-09-03 10:31:11 +0000
commit525bb89c57bed484cdda1c63285f2b0dc601ea54 (patch)
tree891d2b95c6a2a07ffa36ec7ba926a8a2c04fe24e
parent2ce041bbd2fcb71a461ad3f10c8fc5afd1eef60c (diff)
tidy up && implement full sate saving
svn path=/trunk/externals/tclpd/; revision=12205
-rw-r--r--bitmap.tcl62
1 files changed, 31 insertions, 31 deletions
diff --git a/bitmap.tcl b/bitmap.tcl
index 5799a9d..7ed451d 100644
--- a/bitmap.tcl
+++ b/bitmap.tcl
@@ -1,38 +1,35 @@
source pdlib.tcl
-pd::guiproc bitmap_draw_new {self c x y sz w h} {
- set x2 [expr {$x+$w*$sz+1}]
- set y2 [expr {$y+$h*$sz+1}]
- $c create rectangle $x $y $x2 $y2 -outline black -tags [list $c border$c]
+pd::guiproc bitmap_draw_new {self c x y sz w h data} {
+ set z 0
for {set i 0} {$i < $h} {incr i} {
for {set j 0} {$j < $w} {incr j} {
$c create rectangle \
- [expr {1+$x+$j*$sz}] [expr {1+$y+$i*$sz}] \
- [expr {$x+($j+1)*$sz}] [expr {$y+($i+1)*$sz}] \
- -outline black -fill white -tags [list $c cell_${j}_${i}_$c]
+ [expr {0+$x+$j*$sz}] [expr {0+$y+$i*$sz}] \
+ [expr {1+$x+($j+1)*$sz}] [expr {1+$y+($i+1)*$sz}] \
+ -outline black -fill [lindex {white black} [lindex $data $z]] \
+ -tags [list $c cell_${j}_${i}_$c]
+ incr z
}
}
-}
-
-pd::guiproc bitmap_draw_erase {self c x y sz w h} {
- $c delete foo$c
-}
-
-pd::guiproc bitmap_draw_select {self c sel} {
- $c itemconfigure border$c -outline [lindex {black blue} $sel]
+ set x2 [expr {$x+$w*$sz+1}]
+ set y2 [expr {$y+$h*$sz+1}]
+ $c create rectangle $x $y $x2 $y2 -outline black -tags [list $c border$c]
}
pd::guiclass bitmap {
constructor {
pd::add_outlet $self float
- set @sz 8
- set @w 8
- set @h 8
+
+ set @sz [pd::default_arg 0 int 15]
+ set @w [pd::default_arg 1 int 8]
+ set @h [pd::default_arg 2 int 8]
set @data [list]
+ set z 2
for {set i 0} {$i < $@h} {incr i} {
for {set j 0} {$j < $@w} {incr j} {
- lappend @data 0
+ lappend @data [expr {0!=[pd::default_arg [incr z] int 0]}]
}
}
}
@@ -40,20 +37,20 @@ pd::guiclass bitmap {
0_getrow {
set r [list]
set n [pd::arg 0 int]
- for {set i [expr {$n*$@sz}]} {$i < [expr {($n+1)*$@sz}]} {incr i} {
+ for {set i [expr {$n*$@w}]} {$i < [expr {($n+1)*$@w}]} {incr i} {
lappend r [list float [lindex $@data $i]]
}
pd::outlet $self 0 list $r
}
object_save {
- return [list #X obj $@x $@y bitmap $@sz $@w $@h \;]
+ return [list #X obj $@x $@y bitmap $@sz $@w $@h {*}$@data \;]
}
widgetbehavior_getrect {
lassign $args x1 y1
- set x2 [expr {$x1+$@w*$@sz}]
- set y2 [expr {$y1+$@h*$@sz}]
+ set x2 [expr {1+$x1+$@w*$@sz}]
+ set y2 [expr {1+$y1+$@h*$@sz}]
return [list $x1 $y1 $x2 $y2]
}
@@ -70,7 +67,7 @@ pd::guiclass bitmap {
widgetbehavior_select {
set sel [lindex $args 0]
- sys_gui [list bitmap_draw_select $self $@c $sel]\n
+ sys_gui [list $@c itemconfigure $@c -outline [lindex {black blue} $sel]]\n
}
widgetbehavior_activate {
@@ -82,23 +79,26 @@ pd::guiclass bitmap {
set @y [lindex $args 2]
set vis [lindex $args 3]
if {$vis} {
- sys_gui [list bitmap_draw_new $self $@c $@x $@y $@sz $@w $@h]\n
+ sys_gui [list bitmap_draw_new $self $@c $@x $@y $@sz $@w $@h $@data ]\n
} else {
- sys_gui [list bitmap_draw_erase $self $@c $@x $@y $@sz $@w $@h]\n
+ sys_gui [list $@c delete $@c]\n
}
}
widgetbehavior_click {
- set xpix [lindex $args 0]
- set ypix [lindex $args 1]
+ set xpix [expr {[lindex $args 0]-$@x-1}]
+ set ypix [expr {[lindex $args 1]-$@y-1}]
+ if {$xpix < 0 || $xpix >= $@w*$@sz} {return}
+ if {$ypix < 0 || $ypix >= $@h*$@sz} {return}
set shift [lindex $args 2]
set alt [lindex $args 3]
set dbl [lindex $args 4]
set doit [lindex $args 5]
if {$doit} {
- set j [expr {($xpix-$@x)/$@sz}]
- set i [expr {($ypix-$@y)/$@sz}]
- set idx [expr {$@sz*${i}+${j}}]
+ set j [expr {$xpix/$@sz}]
+ set i [expr {$ypix/$@sz}]
+ set idx [expr {$@w*${i}+${j}}]
+ puts stderr "RELX=$xpix RELY=$ypix IDX=$idx"
set d [expr {[lindex $@data $idx]==0}]
lset @data $idx $d
sys_gui [list $@c itemconfigure cell_${j}_${i}_$@c -fill [lindex {white black} $d]]\n