author | Stefan Vogel <sv@exept.de> |
Wed, 21 Nov 2007 18:24:07 +0100 | |
changeset 1917 | 61c602336f3d |
parent 1626 | 8a0e7e7151b9 |
child 1930 | 935b2870be2e |
permissions | -rw-r--r-- |
318 | 1 |
" |
2 |
COPYRIGHT (c) 1996 by Claus Gittinger |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
455
9789991dd799
do not draw the line in the filled part
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
12 |
|
979 | 13 |
"{ Package: 'stx:libbasic2' }" |
14 |
||
318 | 15 |
LineSegment subclass:#Arrow |
728
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
16 |
instanceVariableNames:'arrowHeadPosition arrowHeadLength arrowHeadAngle arrowHeadClosed' |
318 | 17 |
classVariableNames:'DefaultLength DefaultAngle' |
18 |
poolDictionaries:'' |
|
1303 | 19 |
category:'Graphics-Geometry-Objects' |
318 | 20 |
! |
21 |
||
22 |
!Arrow class methodsFor:'documentation'! |
|
23 |
||
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 1996 by Claus Gittinger |
|
27 |
All Rights Reserved |
|
28 |
||
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
38 |
documentation |
|
39 |
" |
|
40 |
Arrows are just what the name says - a directed LineSegment, which |
|
41 |
draws itself with an arrowHead. The position of the arrowhead can |
|
42 |
be set to be anywhere along the lineSegement (default is at the end). |
|
43 |
||
323 | 44 |
Arrows can be drawn stroked or filled - when filled, only the arrowHead |
45 |
is filled. |
|
46 |
||
318 | 47 |
[author:] |
48 |
Claus Gittinger |
|
49 |
||
50 |
[see also:] |
|
320 | 51 |
Rectangle Polygon EllipticalArc Circle Spline Curve Point |
331 | 52 |
LineSegment ArrowedSpline |
318 | 53 |
GraphicsContext |
331 | 54 |
StrokingWrapper FillingWrapper |
318 | 55 |
" |
56 |
! |
|
57 |
||
58 |
examples |
|
59 |
" |
|
60 |
low level use: |
|
61 |
[exBegin] |
|
62 |
|v a| |
|
63 |
||
64 |
v := (View extent:100@100) openAndWait. |
|
65 |
||
66 |
a := Arrow from:10@10 to:90@90. |
|
67 |
||
68 |
v paint:Color red. |
|
69 |
a displayStrokedOn:v. |
|
70 |
||
71 |
a start:90@10 end:10@90. |
|
72 |
v paint:Color blue. |
|
73 |
a displayStrokedOn:v. |
|
74 |
[exEnd] |
|
75 |
||
728
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
76 |
with closed arrowHead: |
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
77 |
[exBegin] |
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
78 |
|v a| |
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
79 |
|
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
80 |
v := (View extent:100@100) openAndWait. |
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
81 |
|
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
82 |
a := Arrow from:10@10 to:90@90. |
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
83 |
a arrowHeadClosed:true. |
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
84 |
v paint:Color red. |
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
85 |
a displayStrokedOn:v. |
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
86 |
|
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
87 |
a start:90@10 end:10@90. |
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
88 |
v paint:Color blue. |
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
89 |
a displayStrokedOn:v. |
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
90 |
[exEnd] |
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
91 |
|
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
92 |
with longer closed arrowHead: |
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
93 |
[exBegin] |
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
94 |
|v a| |
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
95 |
|
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
96 |
v := (View extent:100@100) openAndWait. |
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
97 |
|
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
98 |
a := Arrow from:10@10 to:90@90. |
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
99 |
a arrowHeadClosed:true. |
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
100 |
a arrowHeadLength:16. |
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
101 |
v paint:Color red. |
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
102 |
a displayStrokedOn:v. |
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
103 |
|
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
104 |
a start:90@10 end:10@90. |
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
105 |
v paint:Color blue. |
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
106 |
a displayStrokedOn:v. |
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
107 |
[exEnd] |
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
108 |
|
325 | 109 |
as component (automatic redraw): |
110 |
[exBegin] |
|
111 |
|v a| |
|
112 |
||
113 |
v := View extent:100@100. |
|
114 |
||
115 |
a := Arrow from:50@50 to:10@10. |
|
116 |
v addComponent:(StrokingWrapper on:a). |
|
117 |
||
118 |
a := Arrow from:50@50 to:90@10. |
|
119 |
v addComponent:(StrokingWrapper on:a). |
|
120 |
||
121 |
a := Arrow from:50@50 to:10@90. |
|
122 |
v addComponent:(StrokingWrapper on:a). |
|
123 |
||
124 |
a := Arrow from:50@50 to:90@90. |
|
125 |
v addComponent:(StrokingWrapper on:a). |
|
126 |
||
127 |
v open |
|
128 |
[exEnd] |
|
129 |
||
130 |
as component filled vs. stroked: |
|
323 | 131 |
[exBegin] |
132 |
|v a| |
|
133 |
||
134 |
v := View extent:100@100. |
|
135 |
||
136 |
a := Arrow from:10@10 to:90@10. |
|
137 |
v addComponent:(StrokingWrapper on:a). |
|
138 |
||
139 |
a := Arrow from:90@20 to:10@20. |
|
140 |
v addComponent:(StrokingWrapper on:a). |
|
141 |
||
142 |
a := Arrow from:10@50 to:90@50. |
|
143 |
v addComponent:(FillingWrapper on:a). |
|
144 |
||
145 |
a := Arrow from:90@60 to:10@60. |
|
146 |
v addComponent:(FillingWrapper on:a). |
|
147 |
||
148 |
v open |
|
149 |
[exEnd] |
|
150 |
||
324 | 151 |
as component (varying lineStyles): |
318 | 152 |
[exBegin] |
153 |
|v a| |
|
154 |
||
155 |
v := View extent:100@100. |
|
156 |
||
157 |
a := Arrow from:10@10 to:90@90. |
|
158 |
v addComponent:(StrokingWrapper on:a). |
|
159 |
||
160 |
a := Arrow from:10@10 to:90@10. |
|
161 |
a arrowHeadPosition:0.5. |
|
162 |
v addComponent:(StrokingWrapper on:a). |
|
163 |
||
164 |
a := Arrow from:90@10 to:10@90. |
|
165 |
v addComponent:((StrokingWrapper on:a) foregroundColor:(Color red)). |
|
166 |
||
167 |
a := Arrow from:10@50 to:90@50. |
|
168 |
a arrowHeadLength:20; arrowHeadAngle:130. |
|
169 |
||
170 |
v addComponent:((StrokingWrapper on:a) |
|
171 |
lineWidth:5; |
|
172 |
foregroundColor:(Color red)). |
|
173 |
||
174 |
a := Arrow from:50@90 to:50@10. |
|
175 |
a arrowHeadLength:10; arrowHeadAngle:170. |
|
176 |
||
177 |
v addComponent:((StrokingWrapper on:a) |
|
178 |
lineWidth:2; |
|
179 |
lineStyle:#dashed; |
|
180 |
foregroundColor:(Color red); |
|
181 |
backgroundColor:(Color yellow)). |
|
182 |
||
183 |
v open. |
|
184 |
[exEnd] |
|
321 | 185 |
varying the position: |
186 |
[exBegin] |
|
187 |
|v a| |
|
188 |
||
323 | 189 |
v := View extent:200@100. |
321 | 190 |
|
323 | 191 |
a := Arrow from:10@10 to:90@10. |
321 | 192 |
a arrowHeadPosition:0. |
193 |
v addComponent:(StrokingWrapper on:a). |
|
194 |
||
195 |
a := Arrow from:10@30 to:90@30. |
|
196 |
a arrowHeadPosition:(1/3). |
|
197 |
v addComponent:(StrokingWrapper on:a). |
|
198 |
||
199 |
a := Arrow from:10@40 to:90@40. |
|
200 |
a arrowHeadPosition:0.5. |
|
201 |
v addComponent:(StrokingWrapper on:a). |
|
202 |
||
203 |
a := Arrow from:10@50 to:90@50. |
|
204 |
a arrowHeadPosition:(2/3). |
|
205 |
v addComponent:(StrokingWrapper on:a). |
|
206 |
||
323 | 207 |
a := Arrow from:10@70 to:90@70. |
208 |
v addComponent:(StrokingWrapper on:a). |
|
209 |
||
210 |
||
211 |
a := Arrow from:100@10 to:150@90. |
|
212 |
a arrowHeadPosition:(1/3). |
|
326 | 213 |
v addComponent:(FillingWrapper on:a). |
323 | 214 |
|
215 |
a := Arrow from:110@10 to:160@90. |
|
216 |
a arrowHeadPosition:(2/3). |
|
326 | 217 |
v addComponent:(FillingWrapper on:a). |
323 | 218 |
|
219 |
a := Arrow from:120@10 to:170@90. |
|
326 | 220 |
v addComponent:(FillingWrapper on:a). |
321 | 221 |
|
222 |
v open. |
|
223 |
[exEnd] |
|
318 | 224 |
" |
225 |
! ! |
|
226 |
||
227 |
!Arrow class methodsFor:'initialization'! |
|
228 |
||
229 |
initialize |
|
230 |
DefaultAngle := 150. |
|
231 |
DefaultLength := 8 |
|
232 |
||
233 |
" |
|
234 |
Arrow initialize |
|
235 |
" |
|
236 |
! ! |
|
237 |
||
321 | 238 |
!Arrow class methodsFor:'accessing defaults'! |
239 |
||
240 |
defaultAngle |
|
241 |
^ DefaultAngle |
|
242 |
! |
|
243 |
||
244 |
defaultLength |
|
245 |
^ DefaultLength |
|
246 |
! ! |
|
247 |
||
318 | 248 |
!Arrow methodsFor:'accessing'! |
249 |
||
250 |
arrowHeadAngle |
|
251 |
"return the arrowHeads angle, in degrees. |
|
252 |
The default is 150 degrees" |
|
253 |
||
254 |
arrowHeadAngle isNil ifTrue:[^ DefaultAngle]. |
|
255 |
^ arrowHeadAngle |
|
256 |
||
257 |
"Modified: 12.5.1996 / 22:48:29 / cg" |
|
258 |
"Created: 12.5.1996 / 22:56:36 / cg" |
|
259 |
! |
|
260 |
||
261 |
arrowHeadAngle:angleInDegrees |
|
262 |
"set the arrowHeads angle, in degrees. |
|
263 |
The default is 150 degrees" |
|
264 |
||
265 |
arrowHeadAngle := angleInDegrees |
|
266 |
||
267 |
"Modified: 12.5.1996 / 22:48:29 / cg" |
|
268 |
"Created: 12.5.1996 / 22:57:47 / cg" |
|
269 |
! |
|
270 |
||
728
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
271 |
arrowHeadClosed |
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
272 |
"return the arrowHeadClosed flag; if true, the arrowHead is drawn |
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
273 |
as a closed polygon; if false (the default), the arrowHead is drawn open. |
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
274 |
This only affects non-filled drawing." |
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
275 |
|
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
276 |
^ arrowHeadClosed ? false |
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
277 |
! |
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
278 |
|
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
279 |
arrowHeadClosed:aBoolean |
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
280 |
"set the arrowHeadClosed flag; if true, the arrowHead is drawn |
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
281 |
as a closed polygon; if false (the default), the arrowHead is drawn open. |
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
282 |
This only affects non-filled drawing." |
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
283 |
|
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
284 |
|
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
285 |
arrowHeadClosed := aBoolean. |
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
286 |
! |
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
287 |
|
318 | 288 |
arrowHeadLength |
289 |
"return the arrowHeads length, in pixels. |
|
290 |
The default is 8 pixels" |
|
291 |
||
292 |
arrowHeadPosition isNil ifTrue:[^ DefaultLength]. |
|
293 |
^ arrowHeadLength |
|
294 |
||
295 |
"Created: 12.5.1996 / 22:47:32 / cg" |
|
296 |
"Modified: 12.5.1996 / 22:57:27 / cg" |
|
297 |
! |
|
298 |
||
299 |
arrowHeadLength:pixels |
|
300 |
"set the arrowHeads length, in pixels. |
|
301 |
The default is 8 pixels" |
|
302 |
||
303 |
arrowHeadLength := pixels |
|
304 |
||
305 |
"Created: 12.5.1996 / 22:47:48 / cg" |
|
306 |
"Modified: 12.5.1996 / 23:01:20 / cg" |
|
307 |
! |
|
308 |
||
309 |
arrowHeadPosition |
|
310 |
"return the arrowHeads position, as a fraction of the overall length; |
|
311 |
0 is at the beginning, 1 is at the end, 0.5 is in the center." |
|
312 |
||
313 |
arrowHeadPosition isNil ifTrue:[^ 1]. |
|
314 |
^ arrowHeadPosition |
|
315 |
||
316 |
"Created: 12.5.1996 / 22:46:21 / cg" |
|
317 |
"Modified: 12.5.1996 / 22:57:55 / cg" |
|
318 |
! |
|
319 |
||
320 |
arrowHeadPosition:aFractionOfTheLinesLength |
|
321 |
"set the arrowHeads position, as a fraction of the overall length; |
|
322 |
0 is at the beginning, 1 is at the end, 0.5 is in the center." |
|
323 |
||
324 |
arrowHeadPosition := aFractionOfTheLinesLength |
|
325 |
||
326 |
"Created: 12.5.1996 / 22:46:54 / cg" |
|
327 |
"Modified: 12.5.1996 / 23:01:09 / cg" |
|
328 |
! ! |
|
329 |
||
330 |
!Arrow methodsFor:'displaying'! |
|
331 |
||
729 | 332 |
arrowPointsFor:sP and:eP |
333 |
"return the arrowPoints for an arrow from sP to eP in a collection" |
|
318 | 334 |
|
333 | 335 |
|arrowHeadPoint len pos angle point grad x1 y1 x2 y2 |
729 | 336 |
savedLineStyle atn p1 p2 deriv dX dY| |
318 | 337 |
|
338 |
arrowHeadPosition isNil ifTrue:[ |
|
321 | 339 |
pos := 1 |
318 | 340 |
] ifFalse:[ |
321 | 341 |
pos := arrowHeadPosition max:0.0001. |
318 | 342 |
]. |
343 |
||
729 | 344 |
arrowHeadPoint := sP + ((eP - sP) * pos). |
321 | 345 |
|
318 | 346 |
len := arrowHeadLength. |
347 |
len isNil ifTrue:[ |
|
348 |
len := DefaultLength |
|
349 |
]. |
|
350 |
||
351 |
angle := arrowHeadAngle. |
|
352 |
angle isNil ifTrue:[ |
|
353 |
angle := DefaultAngle |
|
354 |
]. |
|
355 |
angle := angle degreesToRadians. |
|
356 |
||
729 | 357 |
deriv := arrowHeadPoint - sP. |
333 | 358 |
dX := deriv x. |
359 |
dY := deriv y. |
|
360 |
||
361 |
dX = 0 ifTrue: [ |
|
362 |
grad := 99999999.9 |
|
363 |
] ifFalse: [ |
|
364 |
grad := dY / dX |
|
365 |
]. |
|
322
38c88d4b3976
avoid calling arcTan too often
Claus Gittinger <cg@exept.de>
parents:
321
diff
changeset
|
366 |
|
38c88d4b3976
avoid calling arcTan too often
Claus Gittinger <cg@exept.de>
parents:
321
diff
changeset
|
367 |
atn := grad arcTan. |
333 | 368 |
x1 := len * (angle - atn) cos. |
369 |
y1 := len * (angle - atn) sin. |
|
318 | 370 |
|
333 | 371 |
x2 := len * (angle + atn) cos. |
372 |
y2 := len * (angle + atn) sin. |
|
318 | 373 |
|
333 | 374 |
dX = 0 ifTrue:[ |
375 |
dY > 0 ifTrue:[ |
|
376 |
p1 := (dX + x1) @ (dY - y1). |
|
377 |
p2 := (dX + x2) @ (dY + y2). |
|
378 |
] ifFalse:[ |
|
379 |
p1 := (dX - x1) @ (dY + y1). |
|
380 |
p2 := (dX - x2) @ (dY - y2). |
|
381 |
] |
|
382 |
] ifFalse:[ |
|
383 |
dX > 0 ifTrue:[ |
|
384 |
p1 := (dX + x1) @ (dY - y1). |
|
385 |
p2 := (dX + x2) @ (dY + y2). |
|
386 |
] ifFalse:[ |
|
387 |
p1 := (dX - x1) @ (dY + y1). |
|
388 |
p2 := (dX - x2) @ (dY - y2). |
|
389 |
] |
|
390 |
]. |
|
318 | 391 |
|
729 | 392 |
p1 := sP + p1. |
393 |
p2 := sP + p2. |
|
323 | 394 |
|
729 | 395 |
^ Array with:p1 with:arrowHeadPoint with:p2. |
354 | 396 |
|
397 |
"Created: 12.5.1996 / 23:54:35 / cg" |
|
398 |
"Modified: 13.5.1996 / 20:55:51 / cg" |
|
399 |
! |
|
400 |
||
387 | 401 |
displayFilledOn:aGC |
402 |
"display the receiver in the graphicsContext, aGC" |
|
403 |
||
404 |
self displayOn:aGC filled:true |
|
405 |
||
979 | 406 |
" |
407 |
|v| |
|
408 |
||
409 |
v := View new openAndWait. |
|
410 |
||
411 |
(Arrow from:10@10 to:50@50) displayFilledOn:v |
|
412 |
" |
|
413 |
||
387 | 414 |
"Created: 12.5.1996 / 23:58:42 / cg" |
415 |
"Modified: 4.6.1996 / 18:25:11 / cg" |
|
416 |
! |
|
417 |
||
418 |
displayOn:aGC filled:filled |
|
354 | 419 |
"display the receivers arrow in the graphicsContext, aGC" |
420 |
||
1626
8a0e7e7151b9
do not round here (transformation could be nonNil)
Claus Gittinger <cg@exept.de>
parents:
1303
diff
changeset
|
421 |
|arrowHeadPoint savedLineStyle p1 p2 p3 arrowPoints middle oldCap| |
354 | 422 |
|
423 |
savedLineStyle := aGC lineStyle. |
|
424 |
aGC lineStyle:#solid. |
|
425 |
||
1626
8a0e7e7151b9
do not round here (transformation could be nonNil)
Claus Gittinger <cg@exept.de>
parents:
1303
diff
changeset
|
426 |
arrowPoints := self arrowPointsFor:startPoint and:endPoint. |
354 | 427 |
|
1626
8a0e7e7151b9
do not round here (transformation could be nonNil)
Claus Gittinger <cg@exept.de>
parents:
1303
diff
changeset
|
428 |
p1 := arrowPoints at:1. |
8a0e7e7151b9
do not round here (transformation could be nonNil)
Claus Gittinger <cg@exept.de>
parents:
1303
diff
changeset
|
429 |
arrowHeadPoint := arrowPoints at:2. |
8a0e7e7151b9
do not round here (transformation could be nonNil)
Claus Gittinger <cg@exept.de>
parents:
1303
diff
changeset
|
430 |
p2 := arrowPoints at:3. |
354 | 431 |
|
323 | 432 |
filled ifFalse:[ |
728
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
433 |
arrowHeadClosed == true ifTrue:[ |
1626
8a0e7e7151b9
do not round here (transformation could be nonNil)
Claus Gittinger <cg@exept.de>
parents:
1303
diff
changeset
|
434 |
middle := ((p1 + p2) / 2). |
729 | 435 |
aGC displayLineFrom:startPoint to:middle. |
728
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
436 |
aGC displayLineFrom:arrowHeadPoint to:p1. |
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
437 |
aGC displayLineFrom:arrowHeadPoint to:p2. |
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
438 |
aGC displayLineFrom:p1 to:p2. |
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
439 |
] ifFalse:[ |
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
440 |
aGC displayLineFrom:startPoint to:endPoint. |
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
441 |
aGC displayLineFrom:arrowHeadPoint to:p1. |
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
442 |
aGC displayLineFrom:arrowHeadPoint to:p2. |
c7a227ec2897
added optional closed arrowHead.
Claus Gittinger <cg@exept.de>
parents:
490
diff
changeset
|
443 |
] |
323 | 444 |
] ifTrue:[ |
1626
8a0e7e7151b9
do not round here (transformation could be nonNil)
Claus Gittinger <cg@exept.de>
parents:
1303
diff
changeset
|
445 |
middle := ((p1 + p2) / 2). |
455
9789991dd799
do not draw the line in the filled part
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
446 |
oldCap := aGC capStyle. |
9789991dd799
do not draw the line in the filled part
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
447 |
aGC capStyle:#notLast. |
9789991dd799
do not draw the line in the filled part
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
448 |
aGC displayLineFrom:startPoint to:middle. |
323 | 449 |
aGC fillPolygon:(Array with:p1 with:arrowHeadPoint with:p2). |
455
9789991dd799
do not draw the line in the filled part
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
450 |
aGC capStyle:oldCap. |
323 | 451 |
]. |
318 | 452 |
|
453 |
aGC lineStyle:savedLineStyle. |
|
454 |
||
455 |
" |
|
456 |
|v| |
|
457 |
||
458 |
v := View new openAndWait. |
|
459 |
||
460 |
(Arrow from:10@10 to:50@50) displayStrokedOn:v |
|
461 |
" |
|
462 |
||
387 | 463 |
"Modified: 4.6.1996 / 18:24:53 / cg" |
464 |
"Created: 4.6.1996 / 18:25:15 / cg" |
|
323 | 465 |
! |
466 |
||
467 |
displayStrokedOn:aGC |
|
468 |
"display the receiver in the graphicsContext, aGC" |
|
469 |
||
387 | 470 |
self displayOn:aGC filled:false |
323 | 471 |
|
979 | 472 |
" |
473 |
|v| |
|
474 |
||
475 |
v := View new openAndWait. |
|
476 |
||
477 |
(Arrow from:10@10 to:50@50) displayStrokedOn:v |
|
478 |
" |
|
479 |
||
387 | 480 |
"Modified: 4.6.1996 / 18:25:07 / cg" |
318 | 481 |
! ! |
482 |
||
357 | 483 |
!Arrow methodsFor:'queries'! |
484 |
||
490
ef43c7a69346
added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents:
455
diff
changeset
|
485 |
canBeFilled |
ef43c7a69346
added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents:
455
diff
changeset
|
486 |
"return true, if the receiver can be drawn as a filled geometric. |
ef43c7a69346
added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents:
455
diff
changeset
|
487 |
Always true here. Notice, that Arrows only fill the arrowHeads." |
ef43c7a69346
added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents:
455
diff
changeset
|
488 |
|
ef43c7a69346
added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents:
455
diff
changeset
|
489 |
^ true |
ef43c7a69346
added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents:
455
diff
changeset
|
490 |
|
ef43c7a69346
added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents:
455
diff
changeset
|
491 |
! |
ef43c7a69346
added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents:
455
diff
changeset
|
492 |
|
ef43c7a69346
added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents:
455
diff
changeset
|
493 |
computeBounds |
357 | 494 |
"return the smallest enclosing rectangle" |
495 |
||
358 | 496 |
|x y minX maxX minY maxY| |
357 | 497 |
|
498 |
minX := maxX := startPoint x. |
|
499 |
x := endPoint x. |
|
500 |
minX := minX min:x. |
|
501 |
maxX := maxX max:x. |
|
502 |
||
503 |
minY := maxY := startPoint y. |
|
504 |
y := endPoint y. |
|
505 |
minY := minY min:y. |
|
506 |
maxY := maxY max:y. |
|
507 |
||
729 | 508 |
(self arrowPointsFor:startPoint and:endPoint) do:[:p | |
358 | 509 |
|x y| |
510 |
||
511 |
x := p x. |
|
512 |
y := p y. |
|
513 |
minX := minX min:x. |
|
514 |
maxX := maxX max:x. |
|
515 |
minY := minY min:y. |
|
516 |
maxY := maxY max:y. |
|
357 | 517 |
]. |
518 |
^ Rectangle left:minX right:maxX top:minY bottom:maxY |
|
519 |
||
520 |
" |
|
521 |
(Arrow from:(10@10) to:(90@90)) bounds |
|
522 |
(Arrow from:(10@10) to:(10@90)) bounds |
|
523 |
" |
|
524 |
||
358 | 525 |
"Modified: 26.5.1996 / 16:31:39 / cg" |
490
ef43c7a69346
added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents:
455
diff
changeset
|
526 |
"Created: 12.2.1997 / 11:42:22 / cg" |
357 | 527 |
! ! |
528 |
||
318 | 529 |
!Arrow class methodsFor:'documentation'! |
530 |
||
531 |
version |
|
1626
8a0e7e7151b9
do not round here (transformation could be nonNil)
Claus Gittinger <cg@exept.de>
parents:
1303
diff
changeset
|
532 |
^ '$Header: /cvs/stx/stx/libbasic2/Arrow.st,v 1.23 2006-04-07 16:29:59 cg Exp $' |
318 | 533 |
! ! |
1303 | 534 |
|
318 | 535 |
Arrow initialize! |