- Timestamp:
- Jul 17, 2014, 6:51:37 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.3/gui/scripts/isomarker.tcl
r3362 r4546 30 30 private common _normalIcon [Rappture::icon nvlegendmark] 31 31 private common _activeIcon [Rappture::icon nvlegendmark2] 32 private method EnterTick {} 33 private method LeaveTick {} 34 private method StartDrag { x y } 35 private method ContinueDrag { x y } 36 private method StopDrag { x y } 32 37 33 constructor {c obj tf args} { 34 set _canvas $c 35 set _nvobj $obj 36 set _tf $tf 37 set w [winfo width $_canvas] 38 set h [winfo height $_canvas] 39 set _tick [$c create image 0 $h \ 40 -image $_normalIcon -anchor s \ 41 -tags "$this $obj" -state hidden] 42 set _label [$c create text 0 $h \ 43 -anchor n -fill white -font "Helvetica 8" \ 44 -tags "$this $obj" -state hidden] 45 $c bind $_tick <Enter> [itcl::code $this HandleEvent "enter"] 46 $c bind $_tick <Leave> [itcl::code $this HandleEvent "leave"] 47 $c bind $_tick <ButtonPress-1> \ 48 [itcl::code $this HandleEvent "start" %x %y] 49 $c bind $_tick <B1-Motion> \ 50 [itcl::code $this HandleEvent "update" %x %y] 51 $c bind $_tick <ButtonRelease-1> \ 52 [itcl::code $this HandleEvent "end" %x %y] 38 constructor {c obj tf args} {} 39 destructor {} 40 public method transferfunc {} 41 public method activate { bool } 42 public method visible { bool } 43 public method screenpos {} 44 public method absval { {x "-get"} } 45 public method relval { {x "-get"} } 46 } 47 48 itcl::body Rappture::IsoMarker::constructor {c obj tf args} { 49 set _canvas $c 50 set _nvobj $obj 51 set _tf $tf 52 set w [winfo width $_canvas] 53 set h [winfo height $_canvas] 54 set _tick [$c create image 0 $h \ 55 -image $_normalIcon -anchor s \ 56 -tags "tick $this $obj" -state hidden] 57 set _label [$c create text 0 $h \ 58 -anchor n -fill white -font "Helvetica 8" \ 59 -tags "labels $this $obj" -state hidden] 60 $c bind $_tick <Enter> [itcl::code $this EnterTick] 61 $c bind $_tick <Leave> [itcl::code $this LeaveTick] 62 $c bind $_tick <ButtonPress-1> [itcl::code $this StartDrag %x %y] 63 $c bind $_tick <B1-Motion> [itcl::code $this ContinueDrag %x %y] 64 $c bind $_tick <ButtonRelease-1> [itcl::code $this StopDrag %x %y] 65 } 66 67 itcl::body Rappture::IsoMarker::destructor {} { 68 $_canvas delete $this 69 } 70 71 itcl::body Rappture::IsoMarker::transferfunc {} { 72 return $_tf 73 } 74 75 itcl::body Rappture::IsoMarker::activate { bool } { 76 if { $bool || $_activePress || $_activeMotion } { 77 $_canvas itemconfigure $_label -state normal 78 $_canvas itemconfigure $_tick -image $_activeIcon 79 $_canvas itemconfigure title -state hidden 80 } else { 81 $_canvas itemconfigure $_label -state hidden 82 $_canvas itemconfigure $_tick -image $_normalIcon 83 $_canvas itemconfigure title -state normal 53 84 } 54 destructor { 55 $_canvas delete $this 85 } 86 87 itcl::body Rappture::IsoMarker::visible { bool } { 88 if { $bool } { 89 absval $_value 90 $_canvas itemconfigure $_tick -state normal 91 $_canvas raise $_tick 92 } else { 93 $_canvas itemconfigure $_tick -state hidden 56 94 } 57 public method transferfunc {} { 58 return $_tf 95 } 96 97 itcl::body Rappture::IsoMarker::screenpos { } { 98 set x [relval] 99 if { $x < 0.0 } { 100 set x 0.0 101 } elseif { $x > 1.0 } { 102 set x 1.0 59 103 } 60 public method activate { bool } { 61 if { $bool || $_activePress || $_activeMotion } { 62 $_canvas itemconfigure $_label -state normal 63 $_canvas itemconfigure $_tick -image $_activeIcon 64 } else { 65 $_canvas itemconfigure $_label -state hidden 66 $_canvas itemconfigure $_tick -image $_normalIcon 67 } 104 set low 10 105 set w [winfo width $_canvas] 106 set high [expr {$w - 10}] 107 set x [expr {round($x*($high - $low) + $low)}] 108 return $x 109 } 110 111 itcl::body Rappture::IsoMarker::absval { {x "-get"} } { 112 if { $x != "-get" } { 113 set _value $x 114 set y 31 115 $_canvas itemconfigure $_label -text [format %g $_value] 116 set x [screenpos] 117 $_canvas coords $_tick $x [expr {$y+3}] 118 $_canvas coords $_label $x [expr {$y+5}] 68 119 } 69 public method visible { bool } { 70 if { $bool } { 71 absval $_value 72 $_canvas itemconfigure $_tick -state normal 73 $_canvas raise $_tick 74 } else { 75 $_canvas itemconfigure $_tick -state hidden 76 } 77 } 78 public method screenpos { } { 79 set x [relval] 80 if { $x < 0.0 } { 81 set x 0.0 82 } elseif { $x > 1.0 } { 83 set x 1.0 84 } 85 set low 10 86 set w [winfo width $_canvas] 87 set high [expr {$w - 10}] 88 set x [expr {round($x*($high - $low) + $low)}] 89 return $x 90 } 91 public method absval { {x "-get"} } { 92 if { $x != "-get" } { 93 set _value $x 94 set y 31 95 $_canvas itemconfigure $_label -text [format %.2g $_value] 96 set x [screenpos] 97 $_canvas coords $_tick $x [expr {$y+3}] 98 $_canvas coords $_label $x [expr {$y+5}] 99 } 100 return $_value 101 } 102 public method relval { {x "-get"} } { 103 if { $x == "-get" } { 104 array set limits [$_nvobj limits $_tf] 105 if { $limits(vmax) == $limits(vmin) } { 106 if { $limits(vmax) == 0.0 } { 107 set limits(vmin) 0.0 108 set limits(vmax) 1.0 109 } else { 110 set limits(vmax) [expr $limits(vmin) + 1.0] 111 } 112 } 113 return [expr {($_value-$limits(vmin))/ 114 ($limits(vmax) - $limits(vmin))}] 115 } 116 array set limits [$_nvobj limits $_tf] 117 if { $limits(vmax) == $limits(vmin) } { 118 set limits(vmin) 0.0 119 set limits(vmax) 1.0 120 } 121 if { [catch {expr $limits(vmax) - $limits(vmin)} r] != 0 } { 122 return 0.0 123 } 124 absval [expr {($x * $r) + $limits(vmin)}] 125 } 126 private method HandleEvent { option args } { 127 switch -- $option { 128 enter { 129 set _activeMotion 1 130 activate yes 131 $_canvas raise $_tick 132 } 133 leave { 134 set _activeMotion 0 135 activate no 136 } 137 start { 138 $_canvas raise $_tick 139 set _activePress 1 140 activate yes 141 $_canvas itemconfigure limits -state hidden 142 } 143 update { 144 set w [winfo width $_canvas] 145 set x [lindex $args 0] 146 relval [expr {double($x-10)/($w-20)}] 147 $_nvobj overmarker $this $x 148 $_nvobj updatetransferfuncs 149 } 150 end { 151 set x [lindex $args 0] 152 if { ![$_nvobj rmdupmarker $this $x]} { 153 eval HandleEvent update $args 154 } 155 set _activePress 0 156 activate no 157 $_canvas itemconfigure limits -state normal 158 } 159 default { 160 error "bad option \"$option\": should be start, update, end" 120 return $_value 121 } 122 123 itcl::body Rappture::IsoMarker::relval { {x "-get"} } { 124 foreach {min max} [$_nvobj limits $_tf] break 125 if { $x == "-get" } { 126 if { $max == $min } { 127 if { $max == 0.0 } { 128 set min 0.0 129 set max 1.0 130 } else { 131 set max [expr $min + 1.0] 161 132 } 162 133 } 134 return [expr {($_value - $min) / ($max - $min)}] 135 } 136 if { $max == $min } { 137 set min 0.0 138 set max 1.0 163 139 } 140 if { [catch {expr $max - $min} r] != 0 } { 141 return 0.0 142 } 143 absval [expr {($x * $r) + $min}] 164 144 } 145 146 itcl::body Rappture::IsoMarker::EnterTick {} { 147 set _activeMotion 1 148 activate yes 149 $_canvas raise $_tick 150 } 151 152 itcl::body Rappture::IsoMarker::LeaveTick {} { 153 set _activeMotion 0 154 activate no 155 } 156 157 itcl::body Rappture::IsoMarker::StartDrag { x y } { 158 $_canvas raise $_tick 159 set _activePress 1 160 activate yes 161 $_canvas itemconfigure limits -state hidden 162 $_canvas itemconfigure title -state hidden 163 } 164 165 itcl::body Rappture::IsoMarker::StopDrag { x y } { 166 if { ![$_nvobj removeDuplicateMarker $this $x]} { 167 ContinueDrag $x $y 168 } 169 set _activePress 0 170 activate no 171 $_canvas itemconfigure limits -state normal 172 $_canvas itemconfigure title -state normal 173 } 174 175 itcl::body Rappture::IsoMarker::ContinueDrag { x y } { 176 set w [winfo width $_canvas] 177 relval [expr {double($x-10)/($w-20)}] 178 $_nvobj overMarker $this $x 179 $_nvobj updateTransferFunctions 180 $_canvas raise $_tick 181 set _activePress 1 182 activate yes 183 $_canvas itemconfigure limits -state hidden 184 $_canvas itemconfigure title -state hidden 185 } 186
Note: See TracChangeset
for help on using the changeset viewer.