[Tkabber-dev] r1471 - in trunk/tkabber-plugins: . whiteboard

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Tue Jul 8 22:46:05 MSD 2008


Author: sergei
Date: 2008-07-08 22:46:04 +0400 (Tue, 08 Jul 2008)
New Revision: 1471

Modified:
   trunk/tkabber-plugins/ChangeLog
   trunk/tkabber-plugins/whiteboard/svgrender.tcl
   trunk/tkabber-plugins/whiteboard/whiteboard.tcl
Log:
	* whiteboard/svgrender.tcl: Fixed rotation transform. Changed id
	  canvas tags from id$id to [list id $id] form.

	* whiteboard/whiteboard.tcl: Added several object transformations.


Modified: trunk/tkabber-plugins/ChangeLog
===================================================================
--- trunk/tkabber-plugins/ChangeLog	2008-07-08 12:07:03 UTC (rev 1470)
+++ trunk/tkabber-plugins/ChangeLog	2008-07-08 18:46:04 UTC (rev 1471)
@@ -1,3 +1,10 @@
+2008-07-08  Sergei Golovan <sgolovan at nes.ru>
+
+	* whiteboard/svgrender.tcl: Fixed rotation transform. Changed id
+	  canvas tags from id$id to [list id $id] form.
+
+	* whiteboard/whiteboard.tcl: Added several object transformations.
+
 2008-07-07  Sergei Golovan <sgolovan at nes.ru>
 
 	* whiteboard/msgs/de.msg: Updated German translation (thanks to Roger

Modified: trunk/tkabber-plugins/whiteboard/svgrender.tcl
===================================================================
--- trunk/tkabber-plugins/whiteboard/svgrender.tcl	2008-07-08 12:07:03 UTC (rev 1470)
+++ trunk/tkabber-plugins/whiteboard/svgrender.tcl	2008-07-08 18:46:04 UTC (rev 1471)
@@ -453,7 +453,7 @@
 		    bevel {lappend opts -joinstyle bevel}
 		}
 	    }
-	    id {lappend opts -tags [list id$val]}
+	    id {lappend opts -tags [list [list id $val]]}
 	}
     }
     return $opts
@@ -483,7 +483,7 @@
 		    bevel {lappend opts -joinstyle bevel}
 		}
 	    }
-	    id {lappend opts -tags [list id$val]}
+	    id {lappend opts -tags [list [list id $val]]}
 	}
     }
     return $opts
@@ -511,7 +511,7 @@
 		}
 	    }
 	    stroke-width {lappend opts -width $val}
-	    id {lappend opts -tags [list id$val]}
+	    id {lappend opts -tags [list [list id $val]]}
 	}
     }
     return $opts
@@ -553,7 +553,7 @@
 			     }
 	    dx   { # How to do this in Tk? }
 	    dy   { # How to do this in Tk? }
-	    id {lappend opts -tags [list id$val]}
+	    id {lappend opts -tags [list [list id $val]]}
 	}
     }
     return [list $opts $fontopts]
@@ -623,11 +623,11 @@
 	    rotate/3 {
 		foreach {a cx cy} $param break
 		set a [expr {3.1415926 * $a / 180}]
-		set matrix [Tcompose $matrix [list 1 0 0 1 [expr {-$cx}] [expr {-$cy}]]]
+		set matrix [Tcompose $matrix [list 1 0 0 1 $cx $cy]]
 		set matrix [Tcompose $matrix \
 				    [list [expr {cos($a)}]  [expr {sin($a)}] \
 					  [expr {-sin($a)}] [expr {cos($a)}] 0 0]]
-		set matrix [Tcompose $matrix [list 1 0 0 1 $cx $cy]]
+		set matrix [Tcompose $matrix [list 1 0 0 1 [expr {-$cx}] [expr {-$cy}]]]
 	    }
 	    skewX/1 {
 		foreach a $param break

Modified: trunk/tkabber-plugins/whiteboard/whiteboard.tcl
===================================================================
--- trunk/tkabber-plugins/whiteboard/whiteboard.tcl	2008-07-08 12:07:03 UTC (rev 1470)
+++ trunk/tkabber-plugins/whiteboard/whiteboard.tcl	2008-07-08 18:46:04 UTC (rev 1471)
@@ -156,14 +156,14 @@
     set id [$c find withtag current]
     set tags {}
     foreach t [$c gettags $id] {
-	if {[llength $t] == 2} {
+	if {[lindex $t 0] == "time"} {
 	    lappend tags $t
 	}
     }
 
     set msgs {}
-    foreach t [lsort -index 0 -integer $tags] {
-	lappend msgs [lindex $t 1]
+    foreach t [lsort -index 1 -integer $tags] {
+	lappend msgs [lindex $t 2]
     }
 
     balloon::default_balloon $c:$id $action $X $Y -text [join $msgs "\n"]
@@ -310,7 +310,7 @@
 	    foreach child $children {
 		set id [svg::parseSVGItem $w.c {} {} $child]
 		if {$id != ""} {
-		    $w.c addtag tag:$child withtag $id
+		    $w.c addtag [list tag $child] withtag $id
 		    $w.c addtag [time_tag created $from $seconds] withtag $id
 		}
 	    }
@@ -318,40 +318,31 @@
 	transform {
 	    set id [jlib::wrapper:getattr $vars id]
 	    set transform [jlib::wrapper:getattr $vars transform]
-	    set tags [$w.c gettags id$id]
+	    set transform1 $transform
+	    set tags [$w.c gettags [list id $id]]
 	    set child {}
 	    foreach t $tags {
-		if {[string range $t 0 3] == "tag:"} {
-		    set child [string range $t 4 end]
+		if {[lindex $t 0] == "tag"} {
+		    set child [lindex $t 1]
 		    break
 		}
 	    }
+	    foreach t $tags {
+		if {[lindex $t 0] == "transform"} {
+		    set transform "$transform [lindex $t 1]"
+		    break
+		}
+	    }
 	    if {$child != {}} {
-		$w.c delete id$id
-		jlib::wrapper:splitxml $child tag1 vars1 isempty1 chdata1 children1
-		set vars2 {}
-		set q 0
-		foreach {key val} $vars1 {
-		    if {$key == "transform"} {
-			lappend vars2 $key "$transform $val"
-			set q 1
-		    } else {
-			lappend vars2 $key $val
+		$w.c delete [list id $id]
+		set id1 [svg::parseSVGItem $w.c [svg::ParseTransform $transform] {} $child]
+		if {$id1 != ""} {
+		    foreach t $tags {
+			$w.c addtag $t withtag $id1
 		    }
+		    add_transform_tag $w.c $id $transform1
+		    $w.c addtag [time_tag transformed $from $seconds] withtag $id1
 		}
-		if {!$q} {
-		    lappend vars2 transform $transform
-		}
-		set child [jlib::wrapper:createtag $tag1 \
-			       -vars $vars2 \
-			       -chdata $chdata1 \
-			       -subtags $children1]
-
-		set id [svg::parseSVGItem $w.c {} {} $child]
-		if {$id != ""} {
-		    $w.c addtag tag:$child withtag $id
-		    $w.c addtag [time_tag created $from $seconds] withtag $id
-		}
 	    }
 	}
 	move {
@@ -360,11 +351,12 @@
 	    set dy [jlib::wrapper:getattr $vars dy]
 	    if {![string is double $dx] || $dx == ""} {set dx 0}
 	    if {![string is double $dy] || $dy == ""} {set dy 0}
-	    $w.c addtag [time_tag moved $from $seconds] withtag id$id
-	    $w.c move id$id $dx $dy
+	    add_transform_tag $w.c $id translate($dx,$dy)
+	    $w.c addtag [time_tag moved $from $seconds] withtag [list id $id]
+	    $w.c move [list id $id] $dx $dy
 	}
 	remove {
-	    $w.c delete id[jlib::wrapper:getattr $vars id]
+	    $w.c delete [list id [jlib::wrapper:getattr $vars id]]
 	}
 	clear {
 	    $w.c delete all
@@ -374,6 +366,18 @@
 
 ###############################################################################
 
+proc wb::add_transform_tag {c id transform} {
+    set tags [$c gettags [list id $id]]
+    foreach t $tags {
+	if {[lindex $t 0] == "transform"} {
+	    set transform "$transform [lindex $t 1]"
+	    $c dtag [list id $id] $t
+	    break
+	}
+    }
+    $c addtag [list transform $transform] withtag [list id $id]
+}
+
 proc wb::time_tag {type jid {seconds ""}} {
     set seconds_now [clock seconds]
     set format $::plugins::options(timestamp_format)
@@ -388,11 +392,14 @@
     set time [clock format $seconds -format $format]
     switch -- $type {
 	created {
-	    return [list $seconds [::msgcat::mc "%s created: %s" $time $jid]]
+	    return [list time $seconds [::msgcat::mc "%s created: %s" $time $jid]]
 	}
 	moved {
-	    return [list $seconds [::msgcat::mc "%s moved: %s" $time $jid]]
+	    return [list time $seconds [::msgcat::mc "%s moved: %s" $time $jid]]
 	}
+	transformed {
+	    return [list time $seconds [::msgcat::mc "%s transformed: %s" $time $jid]]
+	}
 	default {
 	    return ""
 	}
@@ -424,8 +431,8 @@
     set tags [$c gettags current]
     set id ""
     foreach t $tags {
-	if {[string range $t 0 1] == "id"} {
-	    set id [string range $t 2 end]
+	if {[lindex $t 0] == "id"} {
+	    set id [lindex $t 1]
 	    break
 	}
     }
@@ -452,6 +459,25 @@
     }
 
     $m add separator
+
+    set mm [menu $m.transform -tearoff 0]
+    $mm add command -label [::msgcat::mc "Flip horizontally"] \
+		    -command [list [namespace current]::flip_h $c $chatid $id]
+    $mm add command -label [::msgcat::mc "Flip vertically"] \
+		    -command [list [namespace current]::flip_v $c $chatid $id]
+    $mm add command -label [::msgcat::mc "Rotate 45\u00b0"] \
+		    -command [list [namespace current]::rotate $c $chatid $id -45]
+    $mm add command -label [::msgcat::mc "Rotate 90\u00b0"] \
+		    -command [list [namespace current]::rotate $c $chatid $id -90]
+    $mm add command -label [::msgcat::mc "Rotate 135\u00b0"] \
+		    -command [list [namespace current]::rotate $c $chatid $id -135]
+    $mm add command -label [::msgcat::mc "Rotate 180\u00b0"] \
+		    -command [list [namespace current]::rotate $c $chatid $id -180]
+
+    $m add cascade -label [::msgcat::mc "Transform"] \
+		   -menu $mm \
+		   -state $state
+    $m add separator
     $m add command -label [::msgcat::mc "Remove"] \
 		   -command [list [namespace current]::remove_b1p $c $chatid $id] \
 		   -state $state
@@ -461,7 +487,51 @@
 
 ###############################################################################
 
+proc wb::flip_h {c chatid id} {
+    lassign [$c bbox [list id $id]] x1 y1 x2 y2
+    set x02 [expr {$x1+$x2}]
+    transform $c $chatid $id "translate($x02,0) scale(-1,1)"
+}
+
+proc wb::flip_v {c chatid id} {
+    lassign [$c bbox [list id $id]] x1 y1 x2 y2
+    set y02 [expr {$y1+$y2}]
+    transform $c $chatid $id "translate(0,$y02) scale(1,-1)"
+}
+
+proc wb::rotate {c chatid id angle} {
+    lassign [$c bbox [list id $id]] x1 y1 x2 y2
+    set x0 [expr {($x1+$x2)/2}]
+    set y0 [expr {($y1+$y2)/2}]
+    transform $c $chatid $id "rotate($angle,$x0,$y0)"
+}
+
+proc wb::transform {c chatid id transform} {
+    if {[chat::is_groupchat $chatid]} {
+	set type groupchat
+    } else {
+	set type chat
+	set jid [jlib::connection_jid [chat::get_connid $chatid]]
+	add_transform_tag $w.c $id $transform
+	$c addtag [time_tag transformed $jid] withtag [list id $id]
+    }
+
+    set vars [list id $id transform $transform]
+
+    set connid [chat::get_connid $chatid]
+    set jid [chat::get_jid $chatid]
+    jlib::send_msg $jid \
+	-connection $connid \
+	-type $type \
+	-xlist [list [jlib::wrapper:createtag x \
+			  -vars {xmlns tkabber:whiteboard} \
+			  -subtags [list [jlib::wrapper:createtag transform \
+					      -vars $vars]]]]
+}
+
 ###############################################################################
+
+###############################################################################
 # Line
 
 proc wb::line_bind {c chatid} {
@@ -529,7 +599,7 @@
 	    $c delete $line(temp)
 	} else {
 	    set jid [jlib::connection_jid [chat::get_connid $chatid]]
-	    $c addtag tag:$tag withtag $line(temp)
+	    $c addtag [list tag $tag] withtag $line(temp)
 	    $c addtag [time_tag created $jid] withtag $line(temp)
 	}
 
@@ -647,7 +717,7 @@
 		$c delete $polygon(temp)
 	    } else {
 		set jid [jlib::connection_jid [chat::get_connid $chatid]]
-		$c addtag tag:$tag withtag $polygon(temp)
+		$c addtag [list tag $tag] withtag $polygon(temp)
 		$c addtag [time_tag created $jid] withtag $polygon(temp)
 	    }
 
@@ -725,7 +795,7 @@
 	    $c delete $rectangle(temp)
 	} else {
 	    set jid [jlib::connection_jid [chat::get_connid $chatid]]
-	    $c addtag tag:$tag withtag $rectangle(temp)
+	    $c addtag [list tag $tag] withtag $rectangle(temp)
 	    $c addtag [time_tag created $jid] withtag $rectangle(temp)
 	}
 
@@ -836,7 +906,7 @@
 	    $c delete $circle(temp)
 	} else {
 	    set jid [jlib::connection_jid [chat::get_connid $chatid]]
-	    $c addtag tag:$tag withtag $circle(temp)
+	    $c addtag [list tag $tag] withtag $circle(temp)
 	    $c addtag [time_tag created $jid] withtag $circle(temp)
 	}
 
@@ -942,7 +1012,7 @@
 	    $c delete $line(temp)
 	} else {
 	    set jid [jlib::connection_jid [chat::get_connid $chatid]]
-	    $c addtag tag:$tag withtag $line(temp)
+	    $c addtag [list tag $tag] withtag $line(temp)
 	    $c addtag [time_tag created $jid] withtag $line(temp)
 	}
 
@@ -978,7 +1048,7 @@
 	set type groupchat
     } else {
 	set type chat
-	$c delete id$id
+	$c delete [list id $id]
     }
     if {$id != ""} {
 	jlib::send_msg $jid \
@@ -1003,8 +1073,8 @@
     set tags [$c gettags current]
     set id ""
     foreach t $tags {
-	if {[string range $t 0 1] == "id"} {
-	    set id [string range $t 2 end]
+	if {[lindex $t 0] == "id"} {
+	    set id [lindex $t 1]
 	    break
 	}
     }
@@ -1032,7 +1102,7 @@
 	set x [$c canvasx $x]
 	set y [$c canvasy $y]
 
-	$c move id$id [expr {$x - $move(lastx)}] [expr {$y - $move(lasty)}]
+	$c move [list id $id] [expr {$x - $move(lastx)}] [expr {$y - $move(lasty)}]
 
 	set move(lastx) $x
 	set move(lasty) $y
@@ -1058,11 +1128,11 @@
 
 	if {[chat::is_groupchat $chatid]} {
 	    set type groupchat
-	    $c move id$id [expr {-$dx}] [expr {-$dy}]
+	    $c move [list id $id] [expr {-$dx}] [expr {-$dy}]
 	} else {
 	    set type chat
 	    set jid [jlib::connection_jid [chat::get_connid $chatid]]
-	    $c addtag [time_tag moved $jid] withtag id$id
+	    $c addtag [time_tag moved $jid] withtag [list id $id]
 	}
 
 	set vars [list id $id dx $dx dy $dy]
@@ -1158,7 +1228,7 @@
     if {![chat::is_groupchat $chatid]} {
 	set textid [svg::parseSVGItem $c {} {} $tag]
 	set jid [jlib::connection_jid [chat::get_connid $chatid]]
-	$c addtag tag:$tag withtag $textid
+	$c addtag [list tag $tag] withtag $textid
 	$c addtag [time_tag created $jid] withtag $textid
     }
 



More information about the Tkabber-dev mailing list