aboutsummaryrefslogtreecommitdiff
path: root/demos/photoAlpha.tcl
diff options
context:
space:
mode:
authorlecoanet2004-05-07 15:31:01 +0000
committerlecoanet2004-05-07 15:31:01 +0000
commit9f0d489e9cda59a8ed026be96fa56f9ecc1a33f7 (patch)
tree842972357fdc905c7353dacf88a10e78427b96d8 /demos/photoAlpha.tcl
parent752ff8735f731e8d37fb1bea60b0323af1a1ec06 (diff)
downloadtkzinc-9f0d489e9cda59a8ed026be96fa56f9ecc1a33f7.zip
tkzinc-9f0d489e9cda59a8ed026be96fa56f9ecc1a33f7.tar.gz
tkzinc-9f0d489e9cda59a8ed026be96fa56f9ecc1a33f7.tar.bz2
tkzinc-9f0d489e9cda59a8ed026be96fa56f9ecc1a33f7.tar.xz
Switched from pack to grid; Demos are put in a namespace; No more name aliases for fonts
Diffstat (limited to 'demos/photoAlpha.tcl')
-rw-r--r--demos/photoAlpha.tcl246
1 files changed, 132 insertions, 114 deletions
diff --git a/demos/photoAlpha.tcl b/demos/photoAlpha.tcl
index 212ba97..1d1b1b8 100644
--- a/demos/photoAlpha.tcl
+++ b/demos/photoAlpha.tcl
@@ -5,140 +5,158 @@ if {![info exists zincDemo]} {
error "This script should be run from the zinc-widget demo."
}
-package require Img
+namespace eval photoAlpha {
+ package require Img
-set w .photoAlpha
-catch {destroy $w}
-toplevel $w
-wm title $w "Zinc photo transparency Demonstration"
-wm iconname $w photoAlpha
+ variable girl [image create photo -file [file join $zinc_library demos images photoAlpha.png]]
+ variable texture [image create photo -file [file join $zinc_library demos images stripped_texture.gif]]
-set defaultfont [font create -family Helvetica -size 10 -weight bold]
+ variable w .photoAlpha
+ catch {destroy $w}
+ toplevel $w
+ wm title $w "Zinc photo transparency Demonstration"
+ wm iconname $w photoAlpha
-frame $w.buttons
-pack $w.buttons -side bottom -fill x -pady 2m
-button $w.buttons.dismiss -text Dismiss -command "destroy $w"
-button $w.buttons.code -text "See Code" -command "showCode $w"
-pack $w.buttons.dismiss $w.buttons.code -side left -expand 1
+ variable defaultfont [font create -family Helvetica -size 16 -weight normal]
+ grid [button $w.dismiss -text Dismiss -command "destroy $w"] -row 2 -column 0 -pady 10
+ grid [button $w.code -text "See Code" -command "showCode $w"] -row 2 -column 1 -pady 10
-###########################################
-# Text zone
-#######################
-####################
+ ###########################################
+ # Text zone
+ #######################
+ ####################
-text $w.text -relief sunken -borderwidth 2 -height 7
-pack $w.text -expand yes -fill both
+ grid [text $w.text -relief sunken -borderwidth 2 -height 7] \
+ -row 0 -column 0 -columnspan 2 -sticky ew
-$w.text insert end {This demo needs openGL for displaying the photo
-with transparent pixels and for rescaling/rotating.
- You can transform this png photo with your mouse:
- Drag-Button 1 for moving the photo,
- Drag-Button 2 for zooming the photo,
- Drag-Button 3 for rotating the photo,
- Shift-Drag-Button 1 for modifying the global photo transparency.}
+ $w.text insert end {This demo needs openGL for displaying the photo
+ with transparent pixels and for rescaling/rotating.
+ You can transform this png photo with your mouse:
+ Drag-Button 1 for moving the photo,
+ Drag-Button 2 for zooming the photo,
+ Drag-Button 3 for rotating the photo,
+ Shift-Drag-Button 1 for modifying the global photo transparency.}
-image create photo girl -file [file join $zinc_library demos images photoAlpha.png]
-image create photo texture -file [file join $zinc_library demos images stripped_texture.gif]
-
-###########################################
-# Zinc
-##########################################
-zinc $w.zinc -width 350 -height 250 -render 1 -font 10x20 \
- -borderwidth 3 -relief sunken -tile texture
-pack $w.zinc
-
-set topGroup [$w.zinc add group 1]
-
-set girl [$w.zinc add icon $topGroup -image girl \
- -composescale 1 -composerotation 1]
-
-#
-# Controls for the window transform.
-#
-bind $w.zinc <ButtonPress-1> "press motion %x %y"
-bind $w.zinc <ButtonRelease-1> release
-bind $w.zinc <ButtonPress-2> "press zoom %x %y"
-bind $w.zinc <ButtonRelease-2> release
-bind $w.zinc <ButtonPress-3> "press mouseRotate %x %y"
-bind $w.zinc <ButtonRelease-3> release
-
-#
-# Controls for alpha and gradient
-#
-bind $w.zinc <Shift-ButtonPress-1> "press modifyAlpha %x %y"
-bind $w.zinc <Shift-ButtonRelease-1> release
-
-
-set curX 0
-set curY 0
-set curAngle 0
-
-proc press {action x y} {
- global w curAngle curX curY
-
- set curX $x
- set curY $y
- set curAngle [expr atan2($y, $x)]
- bind $w.zinc <Motion> "$action %x %y"
-}
-
-proc motion {x y} {
- global w topGroup curX curY
-
- foreach {x1 y1 x2 y2} [$w.zinc transform $topGroup \
- [list $x $y $curX $curY]] break
- $w.zinc translate $topGroup [expr $x1 - $x2] [expr $y1 - $y2]
- set curX $x
- set curY $y
-}
-
-proc zoom {x y} {
- global w topGroup curX curY
-
- if {$x > $curX} {
- set maxX $x
+ ###########################################
+ # Zinc
+ ##########################################
+ if { $tcl_platform(platform) eq "unix" } {
+ zinc $w.zinc -width 350 -height 250 -render 1 -font $defaultfont \
+ -borderwidth 3 -relief sunken -tile $texture
} else {
- set maxX $curX
+ zinc $w.zinc -width 350 -height 250 -render 1 -font $defaultfont \
+ -borderwidth 3 -relief sunken -backcolor \#898A8F
}
- if {$y > $curY} {
- set maxY $y
- } else {
- set maxY $curY
+ grid $w.zinc -row 1 -column 0 -columnspan 2 -sticky news
+ grid columnconfigure $w 0 -weight 1
+ grid columnconfigure $w 1 -weight 1
+ grid rowconfigure $w 1 -weight 2
+
+ variable topGroup [$w.zinc add group 1]
+
+ variable girlItem [$w.zinc add icon $topGroup -image $girl \
+ -composescale 1 -composerotation 1]
+
+ #
+ # Controls for the window transform.
+ #
+ bind $w.zinc <ButtonPress-1> "::photoAlpha::press motion %x %y"
+ bind $w.zinc <ButtonRelease-1> ::photoAlpha::release
+ bind $w.zinc <ButtonPress-2> "::photoAlpha::press zoom %x %y"
+ bind $w.zinc <ButtonRelease-2> ::photoAlpha::release
+ bind $w.zinc <ButtonPress-3> "::photoAlpha::press mouseRotate %x %y"
+ bind $w.zinc <ButtonRelease-3> ::photoAlpha::release
+
+ #
+ # Controls for alpha and gradient
+ #
+ bind $w.zinc <Shift-ButtonPress-1> "::photoAlpha::press modifyAlpha %x %y"
+ bind $w.zinc <Shift-ButtonRelease-1> ::photoAlpha::release
+
+
+ variable curX 0
+ variable curY 0
+ variable curAngle 0
+
+ proc press {action x y} {
+ variable w
+ variable curAngle
+ variable curX
+ variable curY
+
+ set curX $x
+ set curY $y
+ set curAngle [expr atan2($y, $x)]
+ bind $w.zinc <Motion> "::photoAlpha::$action %x %y"
}
- if {($maxX == 0) || ($maxY == 0)} {
- return;
+
+ proc motion {x y} {
+ variable w
+ variable topGroup
+ variable curX
+ variable curY
+
+ foreach {x1 y1 x2 y2} [$w.zinc transform $topGroup \
+ [list $x $y $curX $curY]] break
+ $w.zinc translate $topGroup [expr $x1 - $x2] [expr $y1 - $y2]
+ set curX $x
+ set curY $y
}
- set sx [expr 1.0 + (double($x - $curX) / $maxX)]
- set sy [expr 1.0 + (double($y - $curY) / $maxY)]
- $w.zinc scale $topGroup $sx $sx
- set curX $x
- set curY $y
-}
+ proc zoom {x y} {
+ variable w
+ variable topGroup
+ variable curX
+ variable curY
+
+ if {$x > $curX} {
+ set maxX $x
+ } else {
+ set maxX $curX
+ }
+ if {$y > $curY} {
+ set maxY $y
+ } else {
+ set maxY $curY
+ }
+ if {($maxX == 0) || ($maxY == 0)} {
+ return;
+ }
+ set sx [expr 1.0 + (double($x - $curX) / $maxX)]
+ set sy [expr 1.0 + (double($y - $curY) / $maxY)]
+ $w.zinc scale $topGroup $sx $sx
+
+ set curX $x
+ set curY $y
+ }
-proc mouseRotate {x y} {
- global w curAngle topGroup
+ proc mouseRotate {x y} {
+ variable w
+ variable curAngle
+ variable topGroup
- set lAngle [expr atan2($y, $x)]
- $w.zinc rotate $topGroup [expr $lAngle - $curAngle]
- set curAngle $lAngle
-}
+ set lAngle [expr atan2($y, $x)]
+ $w.zinc rotate $topGroup [expr $lAngle - $curAngle]
+ set curAngle $lAngle
+ }
-proc release {} {
- global w
+ proc release {} {
+ variable w
- bind $w.zinc <Motion> {}
-}
+ bind $w.zinc <Motion> {}
+ }
-proc modifyAlpha {x y} {
- global w topGroup
+ proc modifyAlpha {x y} {
+ variable w
+ variable topGroup
- set xRate [expr double($x) / [$w.zinc cget -width]]
- set xRate [expr ($xRate < 0) ? 0 : ($xRate > 1) ? 1 : $xRate]
- set alpha [expr int($xRate * 100)]
+ set xRate [expr double($x) / [$w.zinc cget -width]]
+ set xRate [expr ($xRate < 0) ? 0 : ($xRate > 1) ? 1 : $xRate]
+ set alpha [expr int($xRate * 100)]
- $w.zinc itemconfigure $topGroup -alpha $alpha
+ $w.zinc itemconfigure $topGroup -alpha $alpha
+ }
}