diff options
Diffstat (limited to 'extensions')
-rwxr-xr-x | extensions/gui/ix/mat.wid | 101 |
1 files changed, 85 insertions, 16 deletions
diff --git a/extensions/gui/ix/mat.wid b/extensions/gui/ix/mat.wid index 305a64b3..3f8efc3c 100755 --- a/extensions/gui/ix/mat.wid +++ b/extensions/gui/ix/mat.wid @@ -1,7 +1,21 @@ package require tkpath
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))"]]}
+ proc lighten {rgb r} {set l {}; foreach c $rgb {lappend l [expr {(256 - $c) * $r + $c}]}; return $l}
+ proc darken {rgb r} {set l {}; foreach c $rgb {lappend l [expr {$c - ($c * $r)}]}; return $l}
+ proc color {rgb} {return [format "\#%02x%02x%02x" [expr int([lindex $rgb 0])] [expr int([lindex $rgb 1])] [expr int([lindex $rgb 2])]]}
+ proc random_txt {n} {
+ set i 0
+ set text ""
+ while {$i < $n} {
+ set int [expr "int(floor(rand()*62))"]
+ if {$int < 10} {incr int 48} elseif {$int < 36} {incr int 55} else {incr int 61}
+ set text "$text[format %c $int]"
+ incr i
+ }
+ return $text
+ }
proc mat_note {p t item} {
variable _
set id [lindex [$p.m itemcget $item -tags] 1]
@@ -40,7 +54,7 @@ namespace eval ::ix { proc mat_item_new {p t} {
variable _
incr _($t:i)
- mat_item_update $p $t $_($t:i) [$p.m create path [::tkpath::coords rect 0 0 0 0 -rx 3 -ry 3] -tags [list item $_($t:i)] -fill green -fillopacity 0.8] abs 0 0 0 0}
+ mat_item_update $p $t $_($t:i) [$p.m create path [::tkpath::coords rect 0 0 0 0 -rx 3 -ry 3] -tags [list item $_($t:i)] -fill [color [dict get $_($t:g) 0 color]] -stroke [color [darken [dict get $_($t:g) 0 color] 0.5]] -fillopacity 0.8] abs 0 0 0 0}
proc mat_quant {p t y v} {
variable _
@@ -56,10 +70,18 @@ namespace eval ::ix { foreach v {ci x xx y yy} {
if {[set $v] ne "-"} {
switch $r {
- abs {dict set _($t) $item $v [mat_quant $p $t $v [set $v]]}
- rel {dict set _($t) $item $v [mat_quant $p $t $v [expr {[dict get $_($t) $item $v] + [set $v]}]]}}}}
+ 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 [dict get $_($t) $item ci]}
+ proc mat_item_ua {p t item r u} {
+ 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 [dict get $_($t) $item ci]}
+
proc mat_draw {p t a x y} {
variable _
switch $a {
@@ -89,8 +111,11 @@ namespace eval ::ix { set id [lindex [$p.m itemcget $item -tags] 1]
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 sx [expr {abs([mat_tr $p $t x id [expr {[dict get $_($t) $id xx] - [dict get $_($t) $id x]}]])}]
- set sy [expr {abs([mat_tr $p $t y id 1])}]
+ 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])}]
# puts "$px $py $sx $sy"
$p.m coords $item [::tkpath::coords rect $px $py $sx $sy -rx 3 -ry 3]}}
@@ -121,7 +146,20 @@ namespace eval ::ix { 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 [lindex [$p.m itemcget $item -tags] 1] - rel $mx $my $mx $my}
- mat_info $p $t $_($t:sel)
+ mat_item_info $p $t $_($t:sel)
+ }
+
+ proc mat_resize_left {p t a x y} {mat_resize_object $p $t x $x $y}
+ proc mat_resize_right {p t a x y} {mat_resize_object $p $t xx $x $y}
+ proc mat_resize_top {p t a x y} {mat_resize_object $p $t y $x $y}
+ proc mat_resize_bottom {p t a x y} {mat_resize_object $p $t yy $x $y}
+
+ proc mat_resize_object {p t e x y} {
+ 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 [lindex [$p.m itemcget $item -tags] 1] rel [dict create $e $m]}
+ mat_item_info $p $t $_($t:sel)
}
proc mat_cleansel {p t sel} {
@@ -142,6 +180,15 @@ namespace eval ::ix { set clicked [mat_cleansel $p $t $clicked]
if {$clicked ne ""} {
mat_mode $p $t move_object
+ set id [lindex [$p.m itemcget [lindex $clicked 0] -tags] 1]
+ set eX [mat_tr $p $t x t [dict get $_($t) $id x]]
+ set eXX [mat_tr $p $t x t [dict get $_($t) $id xx]]
+ set eY [mat_tr $p $t y t [dict get $_($t) $id y]]
+ set eYY [mat_tr $p $t y t [dict get $_($t) $id yy]]
+ if {[expr {abs($eX - $x)}] < 5} {mat_mode $p $t resize_left}
+ if {[expr {abs($eXX - $x)}] < 5} {mat_mode $p $t resize_right}
+# if {[expr {abs($eY - $y)}] < 1} {mat_mode $p $t resize_top}
+# if {[expr {abs($eYY - $y)}] < 1} {mat_mode $p $t resize_bottom}
if {[$p.m find withtag sel] eq "" && [llength $_($t:sel)] > 1} {return}
mat_updatesel $p $t $clicked
} else {
@@ -149,7 +196,7 @@ namespace eval ::ix { }
}
- proc mat_info {p t clicked} {
+ proc mat_item_info {p t clicked} {
variable _
set n 0;$p.m delete hover
foreach item $clicked {
@@ -164,11 +211,11 @@ namespace eval ::ix { variable _
foreach item $_($t:sel) {
if {[lsearch -integer $clicked $item] < 0} {
- $p.m itemconfigure $item -fill blue}}
+ $p.m itemconfigure $item -fill [color [dict get $_($t:g) 0 color]]}}
foreach item $clicked {
$p.m itemconfigure $item -fill $_($t:sc)
}
- mat_info $p $t $clicked
+ mat_item_info $p $t $clicked
set _($t:sel) $clicked
}
@@ -210,7 +257,7 @@ namespace eval ::ix { set m [menu $p.rmenu -tearoff no]
$m add command -label "zoom to fit" -command "::ix::mat_zoom $p $t fit"
$m add command -label "reset zoom" -command "::ix::mat_zoom $p $t reset"
- $m add command -label "jupas" -command {} -state disabled
+ $m add command -label "add group" -command "::ix::mat_group_new $p $t -"
$m add command -label "frukas" -command {} -state disabled
} else {
# $p.rmenu entryconfigure 0 -label $x
@@ -265,7 +312,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}
+ 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}
$p.m itemconfigure mode -text $m
$p.m configure -cursor $cursor($m)
}
@@ -275,12 +322,30 @@ namespace eval ::ix { proc mat_group_new {p t grp} {
variable _
+ set color [rgb]
+ if {$grp eq "-"} {set grp [random_txt [expr "int(floor(rand() * 10 + 2))"]]}
dict set _($t:g) $_($t:gi) name $grp
- dict set _($t:g) $_($t:gi) color [rc]
-
+ dict set _($t:g) $_($t:gi) color $color
+ $p.m create text [list 8.0 [expr 38.0 + 11 * $_($t:gi).0]] -fill [color $color] -justify left -anchor w -font {{bitstream vera sans mono} 10} -tags group -text $grp
incr _($t:gi)
}
+ proc mat_key {p t k b} {
+# puts $k
+ switch $b {
+ 1 {
+ switch $k {
+ 37 {mat_mode $p $t draw}
+ }
+ }
+ 0 {
+ switch $k {
+ 37 {mat_mode $p $t {move_canvas}}
+ }
+ }
+ }
+ }
+
proc mat_new {p t w h bg ln xa xb ya yb qx qy} {
variable _
set _($t) {}
@@ -289,10 +354,12 @@ namespace eval ::ix { set sc white
foreach xy {x y} {foreach ab {a b} {set ${xy}${ab}o [set ${xy}${ab}]}}
foreach a {i sc gi hover sel ln xa xb ya yb xao xbo yao ybo qx qy} {set _($t:$a) [set $a]}
- mat_group_new $p $t default
+
if {[winfo exists $p.m] != 1} {
canvas $p.m -bg $bg -width $w -height $h
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"
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"
@@ -308,7 +375,9 @@ namespace eval ::ix { $p.m create text {20 20} -fill blue -justify left -anchor w -font {{bitstream vera sans} 18} -tags mode -text move_canvas
$p.m create text [list [expr {$w / 2.}] 5] -fill red -justify center -anchor n -font {{bitstream vera sans} 14} -tags q -text q
$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_gridlines $p $t}
+ mat_group_new $p $t default
+ }
proc mat_gridlines {p t} {
variable _
|