~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Open Mash Cross Reference
mash/tcl/psvp/rect_subregion-ui.tcl

Component: ~ [ mash ] ~ [ apps ] ~ [ gsm ] ~ [ lib ] ~ [ otcl ] ~ [ srm ] ~ [ tcl8.3 ] ~ [ tclcl ] ~ [ tk8.3 ] ~ [ tutorials ] ~

  1 # rect_subregion-ui.tcl --
  2 #
  3 #       FIXME: This file needs a description here.
  4 #
  5 # Copyright (c) 1999-2002 The Regents of the University of California.
  6 # All rights reserved.
  7 #
  8 # Redistribution and use in source and binary forms, with or without
  9 # modification, are permitted provided that the following conditions are met:
 10 #
 11 # A. Redistributions of source code must retain the above copyright notice,
 12 #    this list of conditions and the following disclaimer.
 13 # B. Redistributions in binary form must reproduce the above copyright notice,
 14 #    this list of conditions and the following disclaimer in the documentation
 15 #    and/or other materials provided with the distribution.
 16 # C. Neither the names of the copyright holders nor the names of its
 17 #    contributors may be used to endorse or promote products derived from this
 18 #    software without specific prior written permission.
 19 #
 20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
 21 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 22 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 23 # ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
 24 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 25 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 26 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 27 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 28 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 30 
 31 Class RectSubregionUI;
 32 
 33 RectSubregionUI instproc init {pframe} {
 34     $self instvar can_;
 35 
 36     set can_ [canvas $pframe.$self -width 120 -height 120];
 37     pack $can_ -side top;
 38 
 39     $self instvar outter_ inner_ ul_ ur_ ll_ lr_;
 40 
 41     set outter_ [$can_ create rect 10 10 110 110];
 42     set inner_ [$can_ create rect 20 20 100 100];
 43     set ul_ [$can_ create rect 15 15 25 25 -fill green];
 44     set ur_ [$can_ create rect 95 15 105 25 -fill green];
 45     set ll_ [$can_ create rect 15 95 25 105 -fill green];
 46     set lr_ [$can_ create rect 95 95 105 105 -fill green];
 47 
 48     $can_ bind $ul_ <B1-Motion> "$self move_handle ul %x %y";
 49     $can_ bind $ur_ <B1-Motion> "$self move_handle ur %x %y";
 50     $can_ bind $ll_ <B1-Motion> "$self move_handle ll %x %y";
 51     $can_ bind $lr_ <B1-Motion> "$self move_handle lr %x %y";
 52     $can_ bind $ul_ <B2-Motion> "$self move_box ul %x %y";
 53     $can_ bind $ur_ <B2-Motion> "$self move_box ur %x %y";
 54     $can_ bind $ll_ <B2-Motion> "$self move_box ll %x %y";
 55     $can_ bind $lr_ <B2-Motion> "$self move_box lr %x %y";
 56 
 57 }
 58 
 59 RectSubregionUI instproc move_box {hndl x y} {
 60     $self instvar inner_ ul_ ur_ ll_ lr_ can_;
 61 
 62     set ic [$can_ coords $inner_];
 63 
 64     set x1 [lindex $ic 0];
 65     set x2 [lindex $ic 2];
 66     set y1 [lindex $ic 1];
 67     set y2 [lindex $ic 3];
 68 
 69     if {$x1 > $x2} {
 70         set t $x2;
 71         set x2 $x1;
 72         set x1 $t;
 73     }
 74     if {$y1 > $y2} {
 75         set t $y2;
 76         set y2 $y1;
 77         set y1 $t;
 78     }
 79 
 80     set width [expr $x2 - $x1];
 81     set height [expr $y2 - $y1];
 82 
 83     if {$hndl == "ul"} {
 84         set x1 $x;
 85         set y1 $y;
 86         set x2 [expr $x1+$width];
 87         set y2 [expr $y1+$height];
 88     } elseif {$hndl == "ur"} {
 89         set x2 $x;
 90         set y1 $y;
 91         set x1 [expr $x2-$width];
 92         set y2 [expr $y1+$height];
 93     } elseif {$hndl == "ll"} {
 94         set x1 $x;
 95         set y2 $y;
 96         set x2 [expr $x1+$width];
 97         set y1 [expr $y2-$height];
 98     } else {
 99         set x2 $x;
100         set y2 $y;
101         set x1 [expr $x2-$width];
102         set y1 [expr $y2-$height];
103     }
104 
105     if {$x1 < 10} {
106         set x1 10;
107         set x2 [expr 10+$width];
108     }
109     if {$x2 > 110} {
110         set x2 110;
111         set x1 [expr 110-$width];
112     }
113     if {$y1 < 10} {
114         set y1 10;
115         set y2 [expr 10+$height];
116     }
117     if {$y2 > 110} {
118         set y2 110;
119         set y1 [expr 110-$height];
120     }
121 
122     $can_ coords $inner_ $x1 $y1 $x2 $y2;
123     $can_ coords $ul_ [expr $x1 - 5] [expr $y1 - 5] [expr $x1 + 5] [expr $y1 + 5]
124     $can_ coords $ur_ [expr $x2 - 5] [expr $y1 - 5] [expr $x2 + 5] [expr $y1 + 5]
125     $can_ coords $ll_ [expr $x1 - 5] [expr $y2 - 5] [expr $x1 + 5] [expr $y2 + 5]
126     $can_ coords $lr_ [expr $x2 - 5] [expr $y2 - 5] [expr $x2 + 5] [expr $y2 + 5]
127 
128     $self do_command;
129 }
130 
131 RectSubregionUI instproc move_handle {hndl x y} {
132     $self instvar ul_ ur_ ll_ lr_ can_;
133 
134     if {$x < 10} {
135         set x 10;
136     }
137     if {$y < 10} {
138         set y 10;
139     }
140     if {$x > 110} {
141         set x 110;
142     }
143     if {$y > 110} {
144         set y 110;
145     }
146 
147     if {$hndl == "ul"} {
148         set h1 $ul_;
149         set h2 $ll_;
150         set h3 $ur_;
151     }
152     if {$hndl == "ll"} {
153         set h1 $ll_;
154         set h2 $ul_;
155         set h3 $lr_;
156     }
157     if {$hndl == "ur"} {
158         set h1 $ur_;
159         set h2 $lr_;
160         set h3 $ul_;
161     }
162     if {$hndl == "lr"} {
163         set h1 $lr_;
164         set h2 $ur_;
165         set h3 $ll_;
166     }
167 
168     $can_ coords $h1 [expr $x - 5] [expr $y - 5] [expr $x + 5] [expr $y + 5];
169 
170     set h2c [$can_ coords $h2];
171     $can_ coords $h2 [expr $x - 5] [lindex $h2c 1] [expr $x+5] [lindex $h2c 3];
172 
173     set h3c [$can_ coords $h3];
174     $can_ coords $h3 [lindex $h3c 0] [expr $y - 5] [lindex $h3c 2] [expr $y+5];
175 
176     $self instvar inner_
177 
178     set x1 [expr int(([lindex [$can_ coords $ul_] 0] + [lindex [$can_ coords $ul_] 2]) / 2)];
179     set x2 [expr int(([lindex [$can_ coords $lr_] 0] + [lindex [$can_ coords $lr_] 2]) / 2)];
180     set y1 [expr int(([lindex [$can_ coords $ul_] 1] + [lindex [$can_ coords $ul_] 3]) / 2)];
181     set y2 [expr int(([lindex [$can_ coords $lr_] 1] + [lindex [$can_ coords $lr_] 3]) / 2)];
182 
183     $can_ coords $inner_ $x1 $y1 $x2 $y2;
184 
185     $self do_command;
186 }
187 
188 RectSubregionUI instproc get {} {
189     $self instvar inner_ can_;
190 
191     set c [$can_ coords $inner_];
192 
193     set x1 [expr ([lindex $c 0] - 10.0) / 100.0];
194     set x2 [expr ([lindex $c 2] - 10.0) / 100.0];
195     set y1 [expr ([lindex $c 1] - 10.0) / 100.0];
196     set y2 [expr ([lindex $c 3] - 10.0) / 100.0];
197 
198     if {$x1 > $x2} {
199         set t $x2;
200         set x2 $x1;
201         set x1 $t;
202     }
203 
204     if {$y1 > $y2} {
205         set t $y2;
206         set y2 $y1;
207         set y1 $t;
208     }
209 
210     return [list $x1 $y1 $x2 $y2];
211 }
212 
213 RectSubregionUI instproc set {c} {
214 
215     set x1 [expr int(([lindex $c 0] * 100.0) + 10.0)];
216     set x2 [expr int(([lindex $c 2] * 100.0) + 10.0)];
217     set y1 [expr int(([lindex $c 1] * 100.0) + 10.0)];
218     set y2 [expr int(([lindex $c 3] * 100.0) + 10.0)];
219 
220     $self move_handle ul $x1 $y1;
221     $self move_handle lr $x2 $y2;
222 }
223 
224 RectSubregionUI instproc set_command {cmd} {
225     $self instvar cmd_;
226 
227     set cmd_ $cmd;
228 }
229 
230 RectSubregionUI instproc do_command {} {
231     $self instvar cmd_;
232 
233     if {[info exists cmd_]} {
234         eval $cmd_ [list [$self get]];
235     }
236 }
237 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.