source: trunk/gui/scripts/animover.tcl @ 46

Last change on this file since 46 was 11, checked in by mmc, 19 years ago

Major reorganization of the entire package. The config.xml file
is now irrelevant. All the action is in the tool.xml file. The
main program now organizes all input into 1) side-by-side pages,
2) input/result (wizard-style) pages, or 3) a series of wizard-
style pages. The <input> can have <phase> parts representing
the various pages.

Added a new ContourResult? widget based on Swaroop's vtk plotting
code.

Also, added easymesh and showmesh to the "tools" directory.
We need these for Eric Polizzi's code.

File size: 7.5 KB
Line 
1# ----------------------------------------------------------------------
2#  COMPONENT: animover - animated move
3#
4#  This widget shows an animation of movement, to show that something
5#  is happening when files are being copied or remote machines are
6#  being queried.
7# ======================================================================
8#  AUTHOR:  Michael McLennan, Purdue University
9#  Copyright (c) 2004-2005
10#  Purdue Research Foundation, West Lafayette, IN
11# ======================================================================
12package require Itk
13
14option add *Animover.width 200 widgetDefault
15option add *Animover.direction both widgetDefault
16option add *Animover.delta 5 widgetDefault
17option add *Animover.delay 50 widgetDefault
18
19itcl::class Rappture::Animover {
20    inherit itk::Widget
21
22    itk_option define -leftimage leftImage LeftImage ""
23    itk_option define -rightimage rightImage RightImage ""
24    itk_option define -middleimage middleImage MiddleImage ""
25    itk_option define -direction direction Direction ""
26    itk_option define -delta delta Delta ""
27    itk_option define -delay delay Delay 0
28    itk_option define -running running Running "disabled"
29
30    constructor {args} { # defined below }
31                                                                               
32    protected method _redraw {}
33    protected variable _x0 0   ;# min value for middle image
34    protected variable _x1 0   ;# max value for middle image
35    protected variable _x  -1  ;# current position between _x0/_x1
36    protected variable _dx 0   ;# delta for x when anim is running
37
38    protected method _animate {}
39
40    #
41    # Load various images used as backgrounds for the map
42    #
43    set dir [file dirname [info script]]
44    private common images
45    set images(bgl) [image create photo -file \
46        [file join $dir images bgl.gif]]
47    set images(bgr) [image create photo -file \
48        [file join $dir images bgr.gif]]
49}
50                                                                               
51itk::usual Animover {
52}
53
54# ----------------------------------------------------------------------
55# CONSTRUCTOR
56# ----------------------------------------------------------------------
57itcl::body Rappture::Animover::constructor {args} {
58    itk_component add area {
59        canvas $itk_interior.area \
60            -height [expr {[image height $images(bgl)]+4}]
61    } {
62        usual
63        keep -width
64    }
65    pack $itk_component(area) -expand yes -fill both
66    bind $itk_component(area) <Configure> [itcl::code $this _redraw]
67
68    eval itk_initialize $args
69}
70
71# ----------------------------------------------------------------------
72# USAGE: _redraw
73#
74# Called automatically whenever the widget changes size to redraw
75# all elements within it.
76# ----------------------------------------------------------------------
77itcl::body Rappture::Animover::_redraw {} {
78    set c $itk_component(area)
79    $c delete all
80
81    set w [winfo width $c]
82    set h [winfo height $c]
83    set hmid [expr {$h/2}]
84
85    $c create rectangle 2 0 [expr {$w-2}] $h -outline "" -fill #E5CFA1
86    $c create image 0 $hmid -anchor w -image $images(bgl)
87    $c create image $w $hmid -anchor e -image $images(bgr)
88
89    $c create line 0 2 $w 2 -width 2 -fill black
90    $c create line 0 [expr {$h-2}] $w [expr {$h-2}] -width 2 -fill black
91    $c create line 20 $hmid [expr {$w-20}] $hmid -width 2 -fill #82765B
92
93    set midw 0
94    if {$itk_option(-middleimage) != ""} {
95        set midw [expr {[image width $itk_option(-middleimage)]/2}]
96    }
97
98    if {$itk_option(-leftimage) != ""} {
99        $c create image 4 $hmid -anchor w \
100            -image $itk_option(-leftimage)
101        set _x0 [expr {4+[image width $itk_option(-leftimage)]+$midw}]
102    } else {
103        set _x0 [expr {4+$midw}]
104    }
105    if {$_x0 < 0} { set _x0 0 }
106
107    if {$itk_option(-rightimage) != ""} {
108        $c create image [expr {$w-4}] $hmid -anchor e \
109            -image $itk_option(-rightimage)
110        set _x1 [expr {$w-4-[image width $itk_option(-rightimage)]-$midw}]
111    } else {
112        set _x1 [expr {$w-4-$midw}]
113    }
114
115    if {$_x >= 0} {
116        if {$_x < $_x0} {
117            set _x $_x0
118        } elseif {$_x > $_x1} {
119            set _x $_x1
120        }
121        if {$itk_option(-middleimage) != ""} {
122            $c create image $_x $hmid -anchor c \
123                -image $itk_option(-middleimage) -tags middle
124        }
125    }
126}
127
128# ----------------------------------------------------------------------
129# USAGE: _animate
130#
131# Called periodically when an animation is in progress to update
132# the position of the middle element.  If the element reaches the
133# left or right side, then it starts over on the other side or
134# going the other direction.
135# ----------------------------------------------------------------------
136itcl::body Rappture::Animover::_animate {} {
137    if {$_x >= 0 && $_x0 < $_x1} {
138        if {$_x+$_dx <= $_x0} {
139            if {$itk_option(-direction) == "left"} {
140                set _x $_x1
141            } elseif {$itk_option(-direction) == "both"} {
142                set _dx [expr {-$_dx}]
143                set _x [expr {$_x+$_dx}]
144            }
145        } elseif {$_x+$_dx >= $_x1} {
146            if {$itk_option(-direction) == "right"} {
147                set _x $_x0
148            } elseif {$itk_option(-direction) == "both"} {
149                set _dx [expr {-$_dx}]
150                set _x [expr {$_x+$_dx}]
151            }
152        } else {
153            set _x [expr {$_x+$_dx}]
154        }
155
156        set c $itk_component(area)
157        set h [winfo height $c]
158        set hmid [expr {$h/2}]
159
160        if {[$c find withtag middle] == ""} {
161            $c create image $_x $hmid -anchor c \
162                -image $itk_option(-middleimage) -tags middle
163        } else {
164            $c coords middle $_x $hmid
165        }
166    }
167    if {$_x >= 0} {
168        after $itk_option(-delay) [itcl::code $this _animate]
169    }
170}
171
172# ----------------------------------------------------------------------
173# OPTION: -running
174# Used to start/stop the animation.
175# ----------------------------------------------------------------------
176itcl::configbody Rappture::Animover::running {
177    switch -- $itk_option(-running) {
178        normal {
179            if {$_x < 0} {
180                set _x $_x0
181                after idle [itcl::code $this _animate]
182            }
183        }
184        disabled {
185            if {$_x > 0} {
186                set _x -1
187                after cancel [itcl::code $this _animate]
188                $itk_component(area) delete middle
189            }
190        }
191        default {
192            error "bad value \"$itk_option(-running)\": should be normal or disabled"
193        }
194    }
195}
196
197# ----------------------------------------------------------------------
198# OPTION: -direction
199# Used to control the direction of movement for the animation.
200# ----------------------------------------------------------------------
201itcl::configbody Rappture::Animover::direction {
202    switch -- $itk_option(-direction) {
203        left  { set _dx [expr {-1*$itk_option(-delta)}] }
204        right { set _dx $itk_option(-delta) }
205        both  { set _dx $itk_option(-delta) }
206        default {
207            error "bad value \"$itk_option(-direction)\": should be left, right, or both"
208        }
209    }
210}
211
212# ----------------------------------------------------------------------
213# OPTION: -delta
214# Used to control the amount of movement for the animation.
215# ----------------------------------------------------------------------
216itcl::configbody Rappture::Animover::delta {
217    if {$itk_option(-delta) < 1} {
218        error "bad value \"$itk_option(-delta)\": should be int >= 1"
219    }
220}
Note: See TracBrowser for help on using the repository browser.