From 0fcaf1d1f2b3eeed0e71fcdf67e7ad3890aafd88 Mon Sep 17 00:00:00 2001 From: lecoanet Date: Sun, 30 Mar 2003 09:10:59 +0000 Subject: Introduction dans la base --- demos/photoAlpha.tcl | 144 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 demos/photoAlpha.tcl (limited to 'demos') diff --git a/demos/photoAlpha.tcl b/demos/photoAlpha.tcl new file mode 100644 index 0000000..3f0908b --- /dev/null +++ b/demos/photoAlpha.tcl @@ -0,0 +1,144 @@ +# $Id$ +# this simple demo has been developped by P.Lecoanet + +if {![info exists zincDemo]} { + error "This script should be run from the zinc-widget demo." +} + +package require Img + +set w .photoAlpha +catch {destroy $w} +toplevel $w +wm title $w "Zinc photo transparency Demonstration" +wm iconname $w photoAlpha + +set defaultfont "-adobe-helvetica-bold-r-normal-*-120-*-*-*-*-*-*" + +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 + + + +########################################### +# Text zone +####################### +#################### + +text $w.text -relief sunken -borderwidth 2 -height 7 +pack $w.text -expand yes -fill both + +$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 "press motion %x %y" +bind $w.zinc release +bind $w.zinc "press zoom %x %y" +bind $w.zinc release +bind $w.zinc "press mouseRotate %x %y" +bind $w.zinc release + +# +# Controls for alpha and gradient +# +bind $w.zinc "press modifyAlpha %x %y" +bind $w.zinc 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 "$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 + } 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 + + set lAngle [expr atan2($y, $x)] + $w.zinc rotate $topGroup [expr $lAngle - $curAngle] + set curAngle $lAngle +} + +proc release {} { + global w + + bind $w.zinc {} +} + +proc modifyAlpha {x y} { + global w 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)] + + $w.zinc itemconfigure $topGroup -alpha $alpha +} -- cgit v1.1