diff options
-rwxr-xr-x | extensions/gui/ix/mat.wid | 93 |
1 files changed, 57 insertions, 36 deletions
diff --git a/extensions/gui/ix/mat.wid b/extensions/gui/ix/mat.wid index 585034ff..4d2775a5 100755 --- a/extensions/gui/ix/mat.wid +++ b/extensions/gui/ix/mat.wid @@ -1,4 +1,4 @@ -package require tkpath
+foreach package {snack tkdnd tkpath} {package require $package}
namespace eval ::ix {
proc rc {} {return [format "\#%06x" [expr "int(floor(rand() * 16777216))"]]}
proc rgb {} {return [list [expr "int(floor(rand() * 256))"] [expr "int(floor(rand() * 256))"] [expr "int(floor(rand() * 256))"]]}
@@ -16,12 +16,6 @@ namespace eval ::ix { }
return $text
}
- proc mat_note {p t item} {
- variable _
- set id [lindex [$p.m itemcget $item -tags] 1]
- set len [expr {[dict get $_($t) $id xx] - [dict get $_($t) $id x]}]
- set vel [$p.m itemcget $item -fillopacity]
- pd [concat $t.rp _cb note [dict get $_($t) $id y] $vel $len \;]}
proc mat_scroll {p t d axis} {
variable _
@@ -51,11 +45,22 @@ namespace eval ::ix { $p.m coords sel [::tkpath::coords rect $xa $ya $w $h -rx 12 -ry 12]
$p.m itemconfigure sel -stroke $_($t:sc)}}}
- proc mat_item_new {p t} {
+ proc mat_item_new {p t d} {
variable _
incr _($t:i)
- $p.m create path [::tkpath::coords rect 0 0 0 0 -rx 3 -ry 3] -tags [list item i$_($t:i) $_($t:i)] -fill [color [dict get $_($t:g) 0 color]] -stroke [color [darken [dict get $_($t:g) 0 color] 0.5]] -fillopacity 0.8
- mat_item_update $p $t $_($t:i) abs 0 0 0 0 0}
+ set tags [list item i$_($t:i) $_($t:i)]
+ switch [dict get $d type] {
+ note {
+ $p.m create path [::tkpath::coords rect 0 0 0 0 -rx 3 -ry 3] -tags $tags -fill [color [dict get $_($t:g) 0 color]] -stroke [color [darken [dict get $_($t:g) 0 color] 0.5]] -fillopacity 0.8
+ }
+ sound {
+ snack:::sound s$_($t:i)
+ s$_($t:i) read [dict get $d filename]
+ $p.m create waveform 0 0 -tags $tags -sound s$_($t:i)
+ }
+ }
+ mat_item_ua $p $t $_($t:i) abs $d 1
+ }
proc mat_item_delete {p t} {
variable _
@@ -71,31 +76,32 @@ namespace eval ::ix { return $v
}
- proc mat_item_update {p t item r x y xx yy g} {
+ proc mat_item_pos {p t item r x y xx yy} {
variable _
- foreach v {x xx y yy g} {
+ foreach v {x xx y yy} {
if {[set $v] ne "-"} {
switch $r {
abs {dict set _($t) $item $v [set $v]}
rel {dict set _($t) $item $v [expr {[dict get $_($t) $item $v] + [set $v]}]}}}}
mat_redraw $p $t $item}
- proc mat_item_ua {p t item r u} {
+ proc mat_item_ua {p t item r u redraw} {
variable _
foreach a [dict keys $u] {
switch $r {
abs {dict set _($t) $item $a [dict get $u $a]
}
rel {dict set _($t) $item $a [expr {[dict get $_($t) $item $a] + [dict get $u $a]}]}}}
- mat_redraw $p $t $item}
+ if {$redraw == 1} {mat_redraw $p $t $item}
+ }
proc mat_draw {p t a x y} {
variable _
switch $a {
motion {
if {$x >= $_($t:cx)} {set xa $_($t:fx);set xb $x} else {set xa $x;set xb $_($t:fx)}
- mat_item_update $p $t $_($t:i) abs [mat_tr $p $t x i $xa] [mat_tr $p $t y i $y] [mat_tr $p $t x i $xb] [mat_tr $p $t y i $y] 0}
- first {mat_item_new $p $t}}}
+ mat_item_pos $p $t $_($t:i) abs [mat_tr $p $t x i $xa] [mat_tr $p $t y i $y] [mat_tr $p $t x i $xb] [mat_tr $p $t y i $y]}
+ first {mat_item_new $p $t [dict create type note g 0 x 0 y 0 xx 0 yy 0 v 1]}}}
proc mat_resize_canvas {p t a x y} {
variable _
@@ -115,27 +121,30 @@ namespace eval ::ix { all {set items [dict keys $_($t)]}
default {}}
foreach id $items {
- set item [$p.m find withtag i$id]
- puts "redrawing $item"
+ set cid [$p.m find withtag i$id]
set px [mat_tr $p $t x t [dict get $_($t) $id x]]
set py [mat_tr $p $t y t [dict get $_($t) $id y]]
set w [expr {[dict get $_($t) $id xx] - [dict get $_($t) $id x]}]
set h [expr {[dict get $_($t) $id yy] - [dict get $_($t) $id y]}]
- if {$h < 0.01} {set h 1}
- set sx [expr {abs([mat_tr $p $t x id $w])}]
- set sy [expr {abs([mat_tr $p $t y id $h])}]
- $p.m itemconfigure $item -fill [color [dict get $_($t:g) [dict get $_($t) $id g] color]]
- $p.m coords $item [::tkpath::coords rect $px $py $sx $sy -rx 3 -ry 3]}}
-
- proc mat_object_trans {p t a x y} {
+ switch [dict get $_($t) $id type] {
+ note {
+ if {$h < 0.01} {set h 1}
+ set sx [expr {abs([mat_tr $p $t x id $w])}]
+ set sy [expr {abs([mat_tr $p $t y id $h])}]
+ $p.m coords $cid [::tkpath::coords rect $px $py $sx $sy -rx 3 -ry 3]
+ $p.m itemconfigure $cid -fillopacity [dict get $_($t) $id v]
+ }
+ sound {
+ $p.m coords $cid $px $py
+ }
+ }
+ }
+ }
+
+ proc mat_item_v {p t a x y} {
variable _
- set velo [expr {($x - $_($t:cx)) / 100.0}]
foreach item $_($t:sel) {
- set id [$p.m find withtag i$item]
- set vel [expr {$velo + [$p.m itemcget $id -fillopacity]}]
- if {$vel > 1} {set vel 1}
- if {$vel < 0} {set vel 0}
- $p.m itemconfigure $id -fillopacity $vel
+ mat_item_ua $p $t $item rel [dict create v [expr {($x - $_($t:cx)) / 100.0}]] 1
}
}
@@ -154,7 +163,7 @@ namespace eval ::ix { variable _
set mx [mat_tr $p $t x d [expr {$x - $_($t:cx)}]]
set my [mat_tr $p $t y d [expr {$y - $_($t:cy)}]]
- foreach item $_($t:sel) {mat_item_update $p $t $item rel $mx $my $mx $my 0}
+ foreach item $_($t:sel) {mat_item_pos $p $t $item rel $mx $my $mx $my}
mat_item_info $p $t $_($t:sel)
}
@@ -167,7 +176,7 @@ namespace eval ::ix { variable _
array set ax {x x xx x y y yy y}
set m [mat_tr $p $t $ax($e) d [expr $$ax($e) - $_($t:c$ax($e))]]
- foreach item $_($t:sel) {mat_item_ua $p $t $item rel [dict create $e $m]}
+ foreach item $_($t:sel) {mat_item_ua $p $t $item rel [dict create $e $m] 1}
mat_item_info $p $t $_($t:sel)
}
@@ -248,7 +257,7 @@ namespace eval ::ix { mat_updatesel $p $t $clicked}}
2 {mat_mode $p $t resize_canvas}
3 {if {$clicked ne ""} {
- mat_mode $p $t object_trans } else {mat_rmenu $p $t $X $Y}}}}
+ mat_mode $p $t item_v } else {mat_rmenu $p $t $X $Y}}}}
motion {eval mat_$a $p $t $action $x $y}
release {
switch $button {
@@ -329,7 +338,7 @@ namespace eval ::ix { }
proc mat_mode {p t m} {
- array set cursor {draw pencil move_canvas fleur move_object dotbox object_trans box_spiral resize_canvas bogosity sel cross_reverse resize_left left_side resize_right right_side resize_top top_side resize_bottom bottom_side}
+ array set cursor {draw pencil move_canvas fleur move_object dotbox item_v box_spiral resize_canvas bogosity sel cross_reverse resize_left left_side resize_right right_side resize_top top_side resize_bottom bottom_side}
$p.m itemconfigure mode -text $m
$p.m configure -cursor $cursor($m)
}
@@ -340,7 +349,7 @@ namespace eval ::ix { proc mat_group_assign {p t group} {
variable _
foreach item $_($t:sel) {
- mat_item_ua $p $t $item abs [dict create g $group]
+ mat_item_ua $p $t $item abs [dict create g $group] 0
}
}
@@ -371,6 +380,15 @@ namespace eval ::ix { }
}
}
+
+ proc mat_drop {p t dropped x y} {
+# foreach d $dropped {
+ foreach d [split $dropped "\n"] {
+ set x [mat_tr $p $t x i $x]
+ set y [mat_tr $p $t y i $y]
+ mat_item_new $p $t [dict create type sound g 1 v 1 x $x y $y xx [expr $x + 10] yy [expr $y + 10] filename [regsub -- {^file:[/]+} $d "/"]]
+ }
+ }
proc mat_new {p t w h bg ln xa xb ya yb qx qy} {
variable _
@@ -388,6 +406,8 @@ namespace eval ::ix { pack $p.m -side left
bind $p.m <Key> "::ix::mat_key $p $t %k 1"
bind $p.m <KeyRelease> "::ix::mat_key $p $t %k 0"
+# dnd bindtarget $p.m text/uri-list <Drop> "::ix::mat_drop $p $t %D %x %y"
+ dnd bindtarget $p.m text/plain <Drop> "::ix::mat_drop $p $t %D %x %y"
bind $p.m <Motion> "::ix::mat_hover $p $t %x %y"
bind $p.m <4> "::ix::mat_scroll $p $t 1 x"
bind $p.m <5> "::ix::mat_scroll $p $t -1 x"
@@ -405,6 +425,7 @@ namespace eval ::ix { $p.m create text "10 $h" -fill red -justify left -anchor sw -font {{bitstream vera sans} 12 bold} -fill purple -tags loc -text ""
mat_gridlines $p $t}
mat_group_new $p $t default
+ mat_group_new $p $t wavs
}
proc mat_gridlines {p t} {
|