From 9f0d489e9cda59a8ed026be96fa56f9ecc1a33f7 Mon Sep 17 00:00:00 2001 From: lecoanet Date: Fri, 7 May 2004 15:31:01 +0000 Subject: Switched from pack to grid; Demos are put in a namespace; No more name aliases for fonts --- demos/tkZincLogo.tcl | 280 ++++++++++++++++++++++++++------------------------- 1 file changed, 145 insertions(+), 135 deletions(-) (limited to 'demos/tkZincLogo.tcl') diff --git a/demos/tkZincLogo.tcl b/demos/tkZincLogo.tcl index 2af91d4..5317f36 100644 --- a/demos/tkZincLogo.tcl +++ b/demos/tkZincLogo.tcl @@ -8,151 +8,161 @@ if {![info exists zincDemo]} { error "This script should be run from the zinc-widget demo." } -# -# We need the zincLogo support -package require zincLogo - - -set w .tkZincLogo -catch {destroy $w} -toplevel $w -wm title $w "Zinc logo Demonstration" -wm iconname $w tkZincLogo - -set defaultfont [font create -family Helvetica -size 10 -weight bold] - -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 tkZinc logo should used openGL for a correct rendering! - You can transform this logo with your mouse: - Drag-Button 1 for moving the logo, - Drag-Button 2 for zooming the logo, - Drag-Button 3 for rotating the logo, - Shift-Drag-Button 1 for modifying the logo transparency, - Shift-Drag-Button 2 for modifying the logo gradient.} - - -########################################### -# Zinc -########################################## -zinc $w.zinc -width 350 -height 250 -render 1 -font 10x20 \ - -borderwidth 3 -relief sunken -pack $w.zinc - -set topGroup [$w.zinc add group 1] - -set logo [zincLogo::create $w.zinc $topGroup 800 40 70 0.6 0.6] - -# -# 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 -bind $w.zinc "press modifyGradient %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 +namespace eval tkZincLogo { + # + # We need the zincLogo support + package require zincLogo + + + variable w .tkZincLogo + catch {destroy $w} + toplevel $w + wm title $w "Zinc logo Demonstration" + wm iconname $w tkZincLogo + + 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 + ####################### + #################### + + grid [text $w.text -relief sunken -borderwidth 2 -height 7] \ + -row 0 -column 0 -columnspan 2 -sticky ew + + $w.text insert end {This tkZinc logo should used openGL for a correct rendering! + You can transform this logo with your mouse: + Drag-Button 1 for moving the logo, + Drag-Button 2 for zooming the logo, + Drag-Button 3 for rotating the logo, + Shift-Drag-Button 1 for modifying the logo transparency, + Shift-Drag-Button 2 for modifying the logo gradient.} + + + ########################################### + # Zinc + ########################################## + grid [ zinc $w.zinc -width 350 -height 250 -render 1 \ + -borderwidth 3 -relief sunken] -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 logo [zincLogo::create $w.zinc $topGroup 800 40 70 0.6 0.6] + + # + # Controls for the window transform. + # + bind $w.zinc "::tkZincLogo::press motion %x %y" + bind $w.zinc ::tkZincLogo::release + bind $w.zinc "::tkZincLogo::press zoom %x %y" + bind $w.zinc ::tkZincLogo::release + bind $w.zinc "::tkZincLogo::press mouseRotate %x %y" + bind $w.zinc ::tkZincLogo::release + + # + # Controls for alpha and gradient + # + bind $w.zinc "::tkZincLogo::press modifyAlpha %x %y" + bind $w.zinc ::tkZincLogo::release + bind $w.zinc "::tkZincLogo::press modifyGradient %x %y" + bind $w.zinc ::tkZincLogo::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 "::tkZincLogo::$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 logo + proc mouseRotate {x y} { + variable w + variable curAngle + variable logo - set lAngle [expr atan2($y, $x)] - $w.zinc rotate $logo [expr $lAngle - $curAngle] - set curAngle $lAngle -} + set lAngle [expr atan2($y, $x)] + $w.zinc rotate $logo [expr $lAngle - $curAngle] + set curAngle $lAngle + } -proc release {} { - global w + proc release {} { + variable w - bind $w.zinc {} -} + bind $w.zinc {} + } -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 + } -proc modifyGradient {x y} { - global w + proc modifyGradient {x y} { + variable w - set yRate [expr double($y) / [$w.zinc cget -height]] - set yRate [expr ($yRate < 0) ? 0 : ($yRate > 1) ? 1 : $yRate] - set gradPercent [expr int($yRate * 100)] - - $w.zinc itemconfigure letters -fillcolor "=axial 270|#ffffff;100 0 28|#66848c;100 $gradPercent|#7192aa;100 100" + set yRate [expr double($y) / [$w.zinc cget -height]] + set yRate [expr ($yRate < 0) ? 0 : ($yRate > 1) ? 1 : $yRate] + set gradPercent [expr int($yRate * 100)] + + $w.zinc itemconfigure letters -fillcolor "=axial 270|#ffffff;100 0 28|#66848c;100 $gradPercent|#7192aa;100 100" + } } -- cgit v1.1