From 6a08f42af3f1c3584882081936ca18c39693d8a1 Mon Sep 17 00:00:00 2001 From: carmen rocco Date: Sun, 24 Apr 2005 12:10:00 +0000 Subject: ngrid svn path=/trunk/; revision=2812 --- extensions/gui/ix/filter.wid | 4 +- extensions/gui/ix/grid.wid | 4 +- extensions/gui/ix/ngrid-demo.pd | 211 ++++++++++++++++++++++++++++++++++++++++ extensions/gui/ix/ngrid.wid | 160 ++++++++++++++++++++++++++++++ extensions/gui/ix/q.wid | 5 +- extensions/gui/ix/tile-demo.pd | 16 +-- 6 files changed, 384 insertions(+), 16 deletions(-) create mode 100644 extensions/gui/ix/ngrid-demo.pd create mode 100755 extensions/gui/ix/ngrid.wid diff --git a/extensions/gui/ix/filter.wid b/extensions/gui/ix/filter.wid index bc97307c..b05c938a 100755 --- a/extensions/gui/ix/filter.wid +++ b/extensions/gui/ix/filter.wid @@ -166,7 +166,6 @@ namespace eval ::ix { if {[winfo exists $path.filter] != 1} { canvas $path.filter -bg $bg -width $w -height $h pack $path.filter -side left - update bind $path.filter "::ix::filter_motion %W $target %x %y" # bind $path.filter "::ix::filter_resp $path $target" bind $path.filter { @@ -214,7 +213,6 @@ namespace eval ::ix { $path.filter bind $a <3> $b4 $path.filter bind $a $b3 $path.filter bind $a $b1 - $path.filter bind $a $b2 } filter_move $path $target $fn $px $py } @@ -282,7 +280,7 @@ namespace eval ::ix { #> filter frame #. -bd 3 #w 384 #h 144 #bg gray90 #div 6 #n 3 #. #log 1 #rate 44100 -#. @div ::ix::gridlines .- .| .#1 +#. @div ::ix::filter_gridlines .- .| .#1 #. @params ::ix::filter_lp .- .| .#args puts "filter .- .|" ::ix::filter_new .- .| .#w .#h .#bg .#div .#log .#rate .#n diff --git a/extensions/gui/ix/grid.wid b/extensions/gui/ix/grid.wid index 61bf665c..1d177ad8 100755 --- a/extensions/gui/ix/grid.wid +++ b/extensions/gui/ix/grid.wid @@ -18,12 +18,12 @@ namespace eval ::ix { place $path.grid -anchor nw -relwidth 1 -relheight 1 $path.grid create $shape 0 0 0 0 -fill $fg -tags ${target}sqr grid_click $path.grid $target 1 0.5 0.5 $h $w $size - gridlines $path.grid $target $div $w $h $ln + grid_lines $path.grid $target $div $w $h $ln bind $path.grid <1> "::ix::grid_click %W $target 0 %y %x $h $w $size" bind $path.grid "::ix::grid_click %W $target 0 %y %x $h $w $size" } } - proc gridlines {w target lines ww hw color} { + proc grid_lines {w target lines ww hw color} { $w delete gridlines for {set x 1} {$x <= $lines} {incr x} { if {$lines < 64} { diff --git a/extensions/gui/ix/ngrid-demo.pd b/extensions/gui/ix/ngrid-demo.pd new file mode 100644 index 00000000..45263564 --- /dev/null +++ b/extensions/gui/ix/ngrid-demo.pd @@ -0,0 +1,211 @@ +#N canvas 57 204 586 521 12; +#X obj 9 -29 widget ngrid n1 #w 382 #h 382 #move 0 #radius 8; +#X floatatom 360 365 3 2 233 0 - - -; +#X floatatom 381 382 2 4 32 0 - - -; +#X msg 394 381 radius \$1; +#X msg 382 362 spread \$1; +#X obj 403 336 bng 23 250 50 0 empty empty empty 0 -6 0 8 -24198 -1 +-1; +#X obj 9 418 osc~; +#X obj 61 418 osc~; +#X obj 35 418 osc~; +#X obj 87 418 osc~; +#X obj 113 418 osc~; +#X obj 139 418 osc~; +#X obj 9 456 dac~; +#X obj 9 399 line; +#X obj 35 399 line; +#X obj 61 399 line; +#X obj 87 399 line; +#X obj 113 399 line; +#X obj 139 399 line; +#X obj 165 418 osc~; +#X obj 191 418 osc~; +#X obj 9 380 route 0x 0y 1x 1y 2x 2y 3x 3y 4x 4y; +#X obj 296 405 until; +#X obj 328 422 + 1; +#X obj 296 424 i; +#X msg 330 405 0; +#X obj 217 418 osc~; +#X obj 243 418 osc~; +#X obj 165 399 line; +#X obj 191 399 line; +#X obj 217 399 line; +#X obj 243 399 line; +#X obj 355 446 tow . ngrid n1; +#X obj 9 361 Append 100; +#X msg 258 363 move swarm; +#X msg 312 385 5; +#X msg 326 363 move; +#X obj 86 437 prepend set; +#X obj 86 454 prepend set; +#X obj 160 442 hsl 128 15 0 2000 0 0 empty empty empty -2 -6 0 8 -262144 +-1 -1 0 1; +#X obj 160 458 hsl 128 15 0 2000 0 0 empty empty empty -2 -6 0 8 -262144 +-1 -1 0 1; +#X obj 423 50 widget ngrid m #w 64 #h 64; +#X msg 407 451 add x 1 0 10 \, add y 2 0 10; +#X obj 425 127 route x y; +#X obj 468 146 prepend set; +#X obj 400 147 prepend set; +#X obj 435 166 hsl 128 15 0 10 0 0 empty empty empty -2 -6 0 8 -262144 +-1 -1 0 1; +#X obj 435 181 hsl 128 15 0 10 0 0 empty empty empty -2 -6 0 8 -262144 +-1 -1 0 1; +#X obj 496 50 widget ngrid m #w 64 #h 64; +#X obj 510 212 widget ngrid m #w 64 #h 64; +#X obj 514 286 widget ngrid m #w 64 #h 64; +#X obj 501 367 widget ngrid m #w 64 #h 64; +#X obj 512 264 prepend pos; +#X obj 503 371 prepend pos; +#X obj 425 57 prepend setpos; +#X obj 476 59 prepend setpos; +#X msg 353 406 add \$1x 1000 0 2000; +#X msg 353 425 add \$1y 1000 0 2000; +#X msg 301 465 pos 4y \$1; +#X obj 9 437 *~ 0.033; +#X obj 513 215 prepend pos; +#X obj 417 198 prepend x; +#X obj 472 197 prepend y; +#X msg 409 414 add x 1 10 0 \, add y 2 10 0; +#X msg 407 434 add x 1 0 10 \, add y 2 10 0; +#X msg 407 470 add x 1 10 0 \, add y 2 0 10; +#X msg 303 446 pos 4x \$1; +#X msg 240 472 pos 3x \$1; +#X msg 168 472 pos 3y \$1; +#X msg 195 363 move error; +#X obj 406 219 sin; +#X obj 410 240 hsl 99 15 0 6.28 0 0 empty empty empty -2 -6 0 8 -262144 +-1 -1 0 1; +#X msg 404 297 pos 0x \$1; +#X obj 458 220 cos; +#X msg 456 295 pos 0y \$1; +#X obj 413 259 * 500; +#X obj 466 258 * 500; +#X obj 412 279 + 1000; +#X obj 468 278 + 1000; +#X obj 414 311 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 +1; +#X msg 451 315 6.28 1000; +#X obj 446 334 line; +#X obj 449 370 select 6.28 0; +#X obj 448 352 spigot; +#X msg 472 333 0 2000; +#X text 530 -25 ngrid; +#X connect 0 0 33 0; +#X connect 1 0 4 0; +#X connect 2 0 3 0; +#X connect 3 0 32 0; +#X connect 4 0 32 0; +#X connect 5 0 35 0; +#X connect 5 0 42 0; +#X connect 5 0 63 0; +#X connect 5 0 65 0; +#X connect 5 0 64 0; +#X connect 6 0 59 0; +#X connect 7 0 59 0; +#X connect 8 0 59 0; +#X connect 9 0 59 0; +#X connect 10 0 59 0; +#X connect 11 0 59 0; +#X connect 13 0 6 0; +#X connect 14 0 8 0; +#X connect 15 0 7 0; +#X connect 16 0 9 0; +#X connect 17 0 10 0; +#X connect 18 0 11 0; +#X connect 19 0 59 0; +#X connect 20 0 59 0; +#X connect 21 0 13 0; +#X connect 21 1 14 0; +#X connect 21 2 15 0; +#X connect 21 3 16 0; +#X connect 21 4 17 0; +#X connect 21 5 18 0; +#X connect 21 6 28 0; +#X connect 21 7 29 0; +#X connect 21 8 30 0; +#X connect 21 8 37 0; +#X connect 21 9 31 0; +#X connect 21 9 38 0; +#X connect 22 0 24 0; +#X connect 23 0 24 1; +#X connect 24 0 23 0; +#X connect 24 0 56 0; +#X connect 24 0 57 0; +#X connect 25 0 24 1; +#X connect 26 0 59 0; +#X connect 27 0 59 0; +#X connect 28 0 19 0; +#X connect 29 0 20 0; +#X connect 30 0 26 0; +#X connect 31 0 27 0; +#X connect 33 0 21 0; +#X connect 34 0 32 0; +#X connect 35 0 25 0; +#X connect 35 0 22 0; +#X connect 36 0 32 0; +#X connect 37 0 39 0; +#X connect 38 0 40 0; +#X connect 39 0 66 0; +#X connect 39 0 68 0; +#X connect 40 0 58 0; +#X connect 40 0 67 0; +#X connect 41 0 43 0; +#X connect 41 0 55 0; +#X connect 41 0 60 0; +#X connect 42 0 41 0; +#X connect 42 0 51 0; +#X connect 43 0 45 0; +#X connect 43 1 44 0; +#X connect 44 0 47 0; +#X connect 45 0 46 0; +#X connect 46 0 61 0; +#X connect 47 0 62 0; +#X connect 48 0 43 0; +#X connect 48 0 54 0; +#X connect 48 0 60 0; +#X connect 49 0 52 0; +#X connect 50 0 53 0; +#X connect 52 0 50 0; +#X connect 53 0 51 0; +#X connect 54 0 41 0; +#X connect 55 0 48 0; +#X connect 56 0 32 0; +#X connect 57 0 32 0; +#X connect 58 0 32 0; +#X connect 59 0 12 0; +#X connect 59 0 12 1; +#X connect 60 0 49 0; +#X connect 61 0 60 0; +#X connect 61 0 55 0; +#X connect 61 0 54 0; +#X connect 62 0 60 0; +#X connect 62 0 54 0; +#X connect 62 0 55 0; +#X connect 63 0 48 0; +#X connect 64 0 50 0; +#X connect 65 0 49 0; +#X connect 66 0 32 0; +#X connect 67 0 32 0; +#X connect 68 0 32 0; +#X connect 69 0 32 0; +#X connect 70 0 75 0; +#X connect 71 0 70 0; +#X connect 71 0 73 0; +#X connect 72 0 32 0; +#X connect 73 0 76 0; +#X connect 74 0 32 0; +#X connect 75 0 77 0; +#X connect 76 0 78 0; +#X connect 77 0 72 0; +#X connect 78 0 74 0; +#X connect 79 0 83 1; +#X connect 79 0 80 0; +#X connect 80 0 81 0; +#X connect 81 0 83 0; +#X connect 82 0 84 0; +#X connect 82 1 80 0; +#X connect 83 0 82 0; +#X connect 83 0 71 0; +#X connect 84 0 81 0; diff --git a/extensions/gui/ix/ngrid.wid b/extensions/gui/ix/ngrid.wid new file mode 100755 index 00000000..6031a05c --- /dev/null +++ b/extensions/gui/ix/ngrid.wid @@ -0,0 +1,160 @@ +namespace eval ::ix { + proc random_int {} { + return [expr "int(floor(rand()*16))"] + } + proc random_clr {} { + return [format "\#%1X%1X%1X%1X%1X%1X" [random_int] [random_int] [random_int] [random_int] [random_int] [random_int]] + } + variable _ + proc ngrid_new {path target w h bg ln div move spread radius max} { + variable _ + if {[winfo exists $path.ngrid] != 1} { + canvas $path.ngrid -bg $bg -width $w -height $h + pack $path.ngrid -side left + bind $path.ngrid <1> "::ix::ngrid_click $path $target %x %y" + bind $path.ngrid [bind $path.ngrid <1>] + ngrid_gridlines $path $target $ln $div + set bd [expr {[$path cget -bd] * 2}] + $path configure -bg $bg -width [expr [winfo width $path.ngrid] + $bd] -height [expr [winfo height $path.ngrid] + $bd] + } + set _($target:recent) 0 + set _($target:n) 0 + set _($target:move) $move + set _($target:spread) $spread + set _($target:radius) $radius + set _($target:max) $max + } + proc ngrid_pos {which path target what where} { + variable _ + array set dm {x width y height} + for {set n 0 } {$n <= $_($target:n)} {incr n} { + foreach xy {x y} { + if {[info exists _($target:box$n:$xy)] && [lindex $_($target:box$n:$xy) 0] eq $what} { + set x [expr [lindex [$path.ngrid coords sqr_$n] 0] + $_($target:radius)] + set y [expr [lindex [$path.ngrid coords sqr_$n] 1] + $_($target:radius)] + set $xy [expr ($where - [lindex $_($target:box$n:$xy) 1 ].0) / ([lindex $_($target:box$n:$xy) 2] - [lindex $_($target:box$n:$xy) 1 ].0) * [winfo $dm($xy) $path.ngrid]] + switch $which { + setpos {$path.ngrid coords sqr_$n [expr $x - $_($target:radius)] [expr $y - $_($target:radius)] [expr $x + $_($target:radius)] [expr $y + $_($target:radius)]} + pos { + set _($target:recent) $n + ngrid_click $path $target $x $y + } + } + } + } + } + } + proc ngrid_vset {path target what where} { + variable _ + set _($target:$what) $where + } + proc ngrid_add {path target name cur min max} { + variable _ + set fill [random_clr] + set n $_($target:n) + set ni 0 + while {$ni <= $n} { + foreach xy {x y} {if {[$path.ngrid itemcget name_${xy}_$ni -text] eq $name} {return}} + incr ni} + if {[$path.ngrid itemcget name_x_$n -text] eq ""} { + set _($target:box$n:x) [list $name $min $max $fill] + $path.ngrid create oval 0 0 0 0 -tags sqr_$n -fill $fill -outline white -width 2 + $path.ngrid create line 0 0 0 0 -tags hist_$n -fill $fill + $path.ngrid create text 0 [expr 5 + $n * 8.0] -tags name_y_$n -fill $fill -font {{Bitstream Vera Sans} 8} -text "" -anchor w -justify left + $path.ngrid create text [winfo width $path.ngrid] [expr 5 + $n * 8.0] -tags name_x_$n -fill $fill -font {{Bitstream Vera Sans} 8} -text "$name" -anchor e -justify right + $path.ngrid lower name_x_$n + $path.ngrid lower name_y_$n + set b1 "set ::ix::_($target:recent) $n; ::ix::ngrid_click $path $target %x %y" + $path.ngrid bind sqr_$n <1> $b1 + $path.ngrid bind sqr_$n $b1 + foreach el [list sqr_$n name_x_$n name_y_$n] { + $path.ngrid bind $el "::ix::ngrid_highlight $path $target $n grey96" + $path.ngrid bind $el "::ix::ngrid_highlight $path $target $n -" + } + ngrid_move $path $target $n [expr ($cur - $min) / ($max - $min.0) * [winfo width $path.ngrid]] [expr rand() * [winfo height $path.ngrid]] + } else { + set _($target:box$n:y) [list $name $min $max] + $path.ngrid itemconfigure name_y_$n -text "$name" + ngrid_move $path $target $n [expr [lindex [$path.ngrid coords sqr_$n] 0] + $_($target:radius)] [expr ($cur - $min.0) / ($max - $min) * [winfo height $path.ngrid]] + incr _($target:n) + } + } + proc ngrid_highlight {path target n color} { + variable _ + foreach el [list name_y_$n name_x_$n sqr_$n] { + if {$color eq "-"} { + set color [lindex $_($target:box$n:x) 3] + } + $path.ngrid itemconfigure $el -fill $color + set _($target:recent) $n + } + } + proc ngrid_click {path target x y} { + variable _ + switch $_($target:move) { + swarm { + for {set n 0} {$n <= $_($target:n)} {incr n} { + ngrid_move $path $target $n [expr rand() * $_($target:spread) - [expr $_($target:spread) / 2.0] + $x] [expr rand() * $_($target:spread) - [expr $_($target:spread) / 2.0] + $y] + } + } + trails { + for {set n 0} {$n <= $_($target:n)} {incr n} { + if {[expr rand() > 0.96] == 1} { + ngrid_move $path $target $n [expr rand() * $_($target:spread) - [expr $_($target:spread) / 2.0] + $x] [expr rand() * $_($target:spread) - [expr $_($target:spread) / 2.0] + $y] + } + } + } + error { + ngrid_move $path $target $_($target:recent) [expr rand() * $_($target:spread) - [expr $_($target:spread) / 2.0] + $x] [expr rand() * $_($target:spread) - [expr $_($target:spread) / 2.0] + $y] + } + default {ngrid_move $path $target $_($target:recent) $x $y} + } + } + proc ngrid_move {path target n px py} { + variable _ + $path.ngrid coords sqr_$n [expr $px - $_($target:radius)] [expr $py - $_($target:radius)] [expr $px + $_($target:radius)] [expr $py + $_($target:radius)] + set h [winfo height $path.ngrid] + set w [winfo width $path.ngrid] + foreach xy {x y} { + if {[info exists _($target:box$n:$xy)]} { + set l $_($target:box$n:$xy) + set name [lindex $l 0] + set min [lindex $l 1] + set max [lindex $l 2] + if {[expr $min == 0] && [expr $max == 0]} {set max $_($target:max)} + pd "$target.rp _cb [pdtk_enquote $name] [expr ($max - $min) * [set p$xy] / $w.0 + $min] \;" + } + } + } + proc ngrid_gridlines {path target ln lines} { + variable _ + puts "gridlines $ln $lines" + set w $path.ngrid + $w delete gridlines + set gh [winfo height $w] + set gw [winfo width $w] + for {set x 1} {$x <= $lines} {incr x} { + if {$lines < 16 && $lines > 0} { + set oh [expr $gh.0 * $x.0 / $lines.0] + set ow [expr $gw.0 * $x.0 / $lines.0] + $w create line $ow 0 $ow $gh -fill $ln -tags gridlines + $w create line 0 $oh $gw $oh -fill $ln -tags gridlines + set fontsize [expr int(80.0/$lines.0)] + } + } + } +} +#> ngrid frame +#. -bd 3 #w 384 #h 144 #bg gray10 #ln gray35 #div 6 #n 3 +#. #move normal #spread 96 #radius 9 #max 1 +#. @list ::ix::ngrid_add .- .| {.#1} .#2 .#3 .#4 +#. @add ::ix::ngrid_add .- .| {.#1} .#2 .#3 .#4 +#. @pos ::ix::ngrid_pos pos .- .| {.#1} .#2 +#. @setpos ::ix::ngrid_pos setpos .- .| {.#1} .#2 +#. @clear ::ix::ngrid_clear .- .| all +#. @radius ::ix::ngrid_vset .- .| radius .#1 +#. @spread ::ix::ngrid_vset .- .| spread .#1 +#. @move ::ix::ngrid_vset .- .| move .#1 +#. @max ::ix::ngrid_vset .- .| max .#1 +puts "ngrid .- .|" +::ix::ngrid_new .- .| .#w .#h .#bg .#ln .#div .#move .#spread .#radius .#max diff --git a/extensions/gui/ix/q.wid b/extensions/gui/ix/q.wid index 5efb592f..d9b36cb2 100755 --- a/extensions/gui/ix/q.wid +++ b/extensions/gui/ix/q.wid @@ -41,10 +41,9 @@ bind .- {.- xview scroll [expr {- (%D / 120) * 4}] units} bind .- {} bind .- {dnd drag %W} dnd bindtarget .- text/plain { - foreach l [split %D "\n"] {.- insert end $l} - + foreach l [split %D "\n"] {.- insert end [regsub -- {^file:[/]+} $l "/"]} } -dnd bindtarget .- text/uri-list {foreach d %D {.- insert end $d}} +dnd bindtarget .- text/uri-list {foreach d %D {.- insert end [regsub -- {^file:[/]+} $d "/"]}} dnd bindsource .- text/uri-list { set sel [.- curselection] if {$sel ne ""} { diff --git a/extensions/gui/ix/tile-demo.pd b/extensions/gui/ix/tile-demo.pd index a52619f6..4e7c845b 100755 --- a/extensions/gui/ix/tile-demo.pd +++ b/extensions/gui/ix/tile-demo.pd @@ -1,19 +1,19 @@ #N canvas 265 374 607 366 12; -#X obj 135 73 widget tile t1 #e rows -colwidth -13 -rows 12 -cols 16 +#X obj 135 73 widget tile t1 #e non -colwidth -13 -rows 12 -cols 16 -width 16 -height 12 -rowheight -13 -bd 1 -bg red; -#X msg 118 46 redefine; -#X msg 93 39 clr; -#X msg 49 50 #e \$1; -#X obj 23 8 widget dm #items #items .(rows columns non.) #arrows 0 -; +#X msg 80 87 redefine; +#X msg 198 53 clr; +#X msg 100 54 #e \$1; +#X obj 137 46 widget dm #items #items .(rows columns non.) #arrows +0 -bg pink; #X floatatom 428 3 2 0 64 0 - - -; #X floatatom 271 14 5 0 0 0 - - -; -#X floatatom 237 30 5 0 0 0 - - -; +#X floatatom 271 -2 5 0 0 0 - - -; #X obj 459 9 * -1; #X msg 419 27 -colwidth \$1 \, -rowheight \$1; #X msg 271 30 -cols \$1 \, -width \$1 \, clr; #X msg 270 49 -rows \$1 \, -height \$1 \, clr; -#X obj 175 0 bng 55 250 50 0 empty empty empty 0 -6 0 8 -241291 -1 +#X obj 199 -10 bng 55 250 50 0 empty empty empty 0 -6 0 8 -241291 -1 -1; #X obj 441 277 osc~ 440; #X obj 462 165 mtof; -- cgit v1.2.1