author | Claus Gittinger <cg@exept.de> |
Thu, 29 Sep 2011 13:18:16 +0200 | |
changeset 5827 | d6476bd6cd74 |
parent 4162 | 08acaf50fad0 |
child 6355 | 1ddfc032a8c5 |
permissions | -rw-r--r-- |
0 | 1 |
" |
2 |
COPYRIGHT (c) 1992 by Claus Gittinger |
|
72 | 3 |
All Rights Reserved |
0 | 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 |
" |
|
3276 | 12 |
"{ Package: 'stx:libview' }" |
13 |
||
601 | 14 |
Object subclass:#WindowingTransformation |
15 |
instanceVariableNames:'scale translation' |
|
16 |
classVariableNames:'' |
|
17 |
poolDictionaries:'' |
|
2944 | 18 |
category:'Graphics-Transformations' |
601 | 19 |
! |
20 |
||
3532 | 21 |
!WindowingTransformation class methodsFor:'documentation'! |
22 |
||
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1992 by Claus Gittinger |
|
26 |
All Rights Reserved |
|
27 |
||
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
36 |
||
37 |
documentation |
|
38 |
" |
|
39 |
instances of WindowingTransformation can be used to scale, translate or |
|
40 |
generally transform other objects in 2D space. |
|
41 |
They can also be set as the translation in a graphic context, |
|
42 |
which will then apply this to all of its drawing operations |
|
43 |
(see GraphicContext>>transformation:). |
|
44 |
||
45 |
All 2-D objects are supposed to be able to be transformed using |
|
46 |
instances of me. Multiple instances of me can also be combined to form a |
|
47 |
single composite transformation. |
|
48 |
||
49 |
[Instance variables:] |
|
50 |
scale <Number> or <Point> representing a linear scaling factor. |
|
51 |
nil is interpreted as 1@1 |
|
52 |
||
53 |
translation <Number> or <Point> representing a translation in 2-D. |
|
54 |
nil is interpreted as 0@0 |
|
55 |
||
56 |
||
57 |
[author:] |
|
58 |
Claus Gittinger |
|
59 |
" |
|
60 |
||
61 |
"Modified: 25.4.1996 / 16:53:07 / cg" |
|
62 |
! |
|
63 |
||
64 |
examples |
|
65 |
" |
|
66 |
example (drawing in inches): |
|
67 |
[exBegin] |
|
68 |
|v| |
|
69 |
||
70 |
v := View new realize. |
|
71 |
(Delay forSeconds:3) wait. |
|
72 |
v transformation:(WindowingTransformation unit:#inch on:Display). |
|
73 |
'now, we can think of drawing in inches ...'. |
|
74 |
v displayLineFrom:0.5@0.5 to:1@1 |
|
75 |
[exEnd] |
|
76 |
||
77 |
||
78 |
example (drawing in millimeters): |
|
79 |
[exBegin] |
|
80 |
|v| |
|
81 |
||
82 |
v := View new realize. |
|
83 |
(Delay forSeconds:3) wait. |
|
84 |
v transformation:(WindowingTransformation unit:#mm on:Display). |
|
85 |
'now, we can think of drawing in millimeters ...'. |
|
86 |
v displayLineFrom:5@5 to:20@5 |
|
87 |
[exEnd] |
|
88 |
||
89 |
||
90 |
example (drawing magnified): |
|
91 |
[exBegin] |
|
92 |
|v| |
|
93 |
||
94 |
v := View new realize. |
|
95 |
(Delay forSeconds:3) wait. |
|
96 |
v transformation:(WindowingTransformation scale:2 translation:0). |
|
97 |
'now, everything is magnfied by 2'. |
|
98 |
v displayLineFrom:10@10 to:30@30 |
|
99 |
[exEnd] |
|
100 |
||
101 |
example (drawing shrunk): |
|
102 |
[exBegin] |
|
103 |
|v| |
|
104 |
||
105 |
v := View new realize. |
|
106 |
(Delay forSeconds:3) wait. |
|
107 |
v transformation:(WindowingTransformation scale:0.5 translation:0). |
|
108 |
'now, everything is shrunk by 2'. |
|
109 |
v displayLineFrom:10@10 to:30@30 |
|
110 |
[exEnd] |
|
111 |
" |
|
112 |
||
113 |
"Modified: 27.4.1996 / 19:45:43 / cg" |
|
114 |
! ! |
|
2148 | 115 |
|
601 | 116 |
!WindowingTransformation class methodsFor:'instance creation'! |
117 |
||
118 |
identity |
|
119 |
"returns a windowing transformation with no scaling (1@1) |
|
120 |
and no translation (0@0)." |
|
121 |
||
1148 | 122 |
^ self basicNew "/ scale:nil translation:nil |
123 |
||
124 |
" |
|
125 |
WindowingTransformation identity |
|
126 |
" |
|
127 |
||
128 |
"Modified: 30.12.1996 / 16:59:27 / cg" |
|
601 | 129 |
! |
130 |
||
131 |
scale:aScale translation:aTranslation |
|
132 |
"returns a windowing transformation with a scale factor of |
|
133 |
aScale and a translation offset of aTranslation." |
|
134 |
||
135 |
^ self basicNew scale:aScale translation:aTranslation |
|
136 |
||
137 |
" |
|
138 |
|v| |
|
139 |
||
140 |
v := View new realize. |
|
141 |
(Delay forSeconds:3) wait. |
|
142 |
v transformation:(WindowingTransformation scale:2 translation:0). |
|
143 |
'now, everything is magnfied by 2'. |
|
144 |
v displayLineFrom:10@10 to:30@30 |
|
145 |
" |
|
146 |
" |
|
147 |
|v| |
|
148 |
||
149 |
v := View new realize. |
|
150 |
(Delay forSeconds:3) wait. |
|
151 |
v transformation:(WindowingTransformation scale:0.5 translation:0). |
|
152 |
'now, everything is shrunk by 2'. |
|
153 |
v displayLineFrom:10@10 to:30@30 |
|
154 |
" |
|
155 |
! |
|
156 |
||
157 |
unit:unitSymbol on:device |
|
158 |
"returns a windowing transformation with scaling |
|
159 |
for unitSymbol and no translation (0@0). |
|
160 |
With such a transformation, you can draw in your preferred |
|
161 |
units. |
|
162 |
UnitSymbol may be #mm, #cm, #inch, #point, #twip or #pixel (default). |
|
163 |
Twip is 1/20th of a point, point is 1/72th of an inch |
|
164 |
(i.e. the print-unit which is also used for font sizes etc.) |
|
165 |
- not to confuse with device pixels." |
|
166 |
||
1148 | 167 |
|ppmm ppi scale| |
168 |
||
169 |
ppmm := device pixelPerMillimeter. |
|
170 |
ppi := device pixelPerInch. |
|
72 | 171 |
|
601 | 172 |
unitSymbol == #mm ifTrue:[ |
1148 | 173 |
scale := ppmm. |
601 | 174 |
] ifFalse:[ |
1148 | 175 |
unitSymbol == #cm ifTrue:[ |
176 |
scale := ppmm * 10. |
|
177 |
] ifFalse:[ |
|
178 |
unitSymbol == #twip ifTrue:[ |
|
179 |
scale := ppi / 1440. |
|
180 |
] ifFalse:[ |
|
181 |
unitSymbol == #point ifTrue:[ |
|
182 |
scale := ppi / 72. |
|
183 |
] ifFalse:[ |
|
184 |
unitSymbol == #inch ifTrue:[ |
|
185 |
scale := ppi. |
|
186 |
] ifFalse:[ |
|
187 |
"sorry: unknown unit is taken as pixel" |
|
188 |
^ self new scale:nil translation:nil |
|
189 |
] |
|
190 |
] |
|
191 |
] |
|
192 |
] |
|
601 | 193 |
]. |
1148 | 194 |
^ self basicNew scale:scale translation:nil |
601 | 195 |
|
196 |
" |
|
197 |
|v| |
|
198 |
||
1148 | 199 |
v := View new openAndWait. |
601 | 200 |
(Delay forSeconds:3) wait. |
201 |
v transformation:(WindowingTransformation unit:#inch on:Display). |
|
202 |
'now, we can think of drawing in inches ...'. |
|
203 |
v displayLineFrom:0.5@0.5 to:1@1 |
|
204 |
" |
|
1148 | 205 |
" |
206 |
|v| |
|
207 |
||
208 |
v := View new openAndWait. |
|
209 |
(Delay forSeconds:3) wait. |
|
210 |
v transformation:(WindowingTransformation unit:#mm on:Display). |
|
211 |
'now, we can think of drawing in millimeters ...'. |
|
212 |
v displayLineFrom:2@2 to:10@10 |
|
213 |
" |
|
214 |
||
215 |
"Modified: 30.12.1996 / 16:57:59 / cg" |
|
72 | 216 |
! |
0 | 217 |
|
601 | 218 |
window:sourceRectangle viewport:destinationRectangle |
219 |
"returns a windowing transformation with a scale and |
|
220 |
translation computed from sourceRectangle and destinationRectangle. |
|
221 |
The scale and transformation are computed such that sourceRectangle |
|
222 |
is transformed to destinationRectangle. Typically sourceRectangle |
|
223 |
represents the logical coordinateSpace while destinationRectangle |
|
224 |
represents the device coordinateSpace." |
|
225 |
||
226 |
|sX sY tX tY newScale newTranslation| |
|
227 |
||
228 |
sX := destinationRectangle width / sourceRectangle width. |
|
229 |
sY := destinationRectangle height / sourceRectangle height. |
|
230 |
tX := destinationRectangle left - sourceRectangle left. |
|
231 |
tY := destinationRectangle top - sourceRectangle top. |
|
232 |
((tX = 1.0) and:[tY = 1.0]) ifTrue:[ |
|
233 |
newTranslation := nil |
|
234 |
] ifFalse:[ |
|
235 |
newTranslation := tX @ tY |
|
236 |
]. |
|
237 |
((sX = 1.0) and:[sY = 1.0]) ifTrue:[ |
|
238 |
newScale := nil |
|
239 |
] ifFalse:[ |
|
240 |
newScale := sX @ sY |
|
241 |
]. |
|
242 |
^ self basicNew scale:newScale translation:newTranslation |
|
243 |
||
244 |
" |
|
245 |
|v| |
|
246 |
||
247 |
v := View new realize. |
|
248 |
(Delay forSeconds:3) wait. |
|
249 |
v transformation:(WindowingTransformation |
|
250 |
window:(0@0 corner:1@1) |
|
251 |
viewport:(0@0 corner:100@100)). |
|
252 |
'now, we can think of drawing in 0..1/0..1 coordinates'. |
|
253 |
v displayLineFrom:0.1@0.1 to:0.9@0.9 |
|
254 |
" |
|
255 |
! ! |
|
256 |
||
257 |
!WindowingTransformation methodsFor:'accessing'! |
|
258 |
||
259 |
scale |
|
260 |
"return a copy of the Point that represents the |
|
261 |
current scale of the receiver." |
|
72 | 262 |
|
601 | 263 |
scale isNil ifTrue:[^ (1@1) copy]. |
264 |
^ scale copy |
|
265 |
! |
|
72 | 266 |
|
601 | 267 |
scale:aScale |
268 |
"Set the receiver's scale to aScale, a Point or Number." |
|
72 | 269 |
|
2148 | 270 |
aScale isNil ifTrue:[ |
271 |
scale := aScale |
|
272 |
] ifFalse:[ |
|
4162
08acaf50fad0
Scale was set wrong when old scale was 1
Stefan Vogel <sv@exept.de>
parents:
3532
diff
changeset
|
273 |
aScale = 1 ifTrue:[ |
2148 | 274 |
scale := nil |
275 |
] ifFalse:[ |
|
276 |
scale := aScale asPoint. |
|
277 |
] |
|
72 | 278 |
]. |
2147 | 279 |
|
2148 | 280 |
"Modified: / 13.6.1998 / 14:04:51 / cg" |
72 | 281 |
! |
282 |
||
601 | 283 |
scale:aScale translation:aTranslation |
284 |
"sets the scale to aScale and the translation to aTranslation." |
|
78 | 285 |
|
2148 | 286 |
aScale isNil ifTrue:[ |
287 |
scale := aScale |
|
288 |
] ifFalse:[ |
|
4162
08acaf50fad0
Scale was set wrong when old scale was 1
Stefan Vogel <sv@exept.de>
parents:
3532
diff
changeset
|
289 |
aScale = 1 ifTrue:[ |
2148 | 290 |
scale := nil |
291 |
] ifFalse:[ |
|
292 |
scale := aScale asPoint. |
|
293 |
] |
|
601 | 294 |
]. |
2148 | 295 |
aTranslation isNil ifTrue:[ |
296 |
translation := aTranslation |
|
297 |
] ifFalse:[ |
|
298 |
aTranslation = 0 ifTrue:[ |
|
299 |
translation := nil |
|
300 |
] ifFalse:[ |
|
301 |
translation := aTranslation asPoint |
|
302 |
] |
|
601 | 303 |
] |
2147 | 304 |
|
2148 | 305 |
"Modified: / 13.6.1998 / 14:04:42 / cg" |
72 | 306 |
! |
307 |
||
601 | 308 |
scaleOfOne |
309 |
"Set the scale of the receiver to the identity scale" |
|
72 | 310 |
|
601 | 311 |
scale := nil |
72 | 312 |
! |
313 |
||
705 | 314 |
scaleX |
315 |
"return the current x-scale of the receiver." |
|
316 |
||
317 |
scale isNil ifTrue:[^ 1]. |
|
318 |
^ scale x |
|
319 |
||
320 |
"Created: 21.5.1996 / 21:13:49 / cg" |
|
321 |
! |
|
322 |
||
323 |
scaleY |
|
324 |
"return the current x-scale of the receiver." |
|
325 |
||
326 |
scale isNil ifTrue:[^ 1]. |
|
327 |
^ scale y |
|
328 |
||
329 |
"Created: 21.5.1996 / 21:13:59 / cg" |
|
330 |
! |
|
331 |
||
601 | 332 |
translation |
333 |
"return a copy of the receiver's translation." |
|
334 |
||
335 |
translation isNil ifTrue:[^ (0@0) copy]. |
|
336 |
^ translation copy |
|
337 |
! |
|
72 | 338 |
|
601 | 339 |
translation:aTranslation |
340 |
"Set the receiver's translation to aTranslation, a Point or Number." |
|
341 |
||
2148 | 342 |
aTranslation isNil ifTrue:[ |
343 |
translation := aTranslation |
|
344 |
] ifFalse:[ |
|
345 |
aTranslation = 0 ifTrue:[ |
|
346 |
translation := nil |
|
347 |
] ifFalse:[ |
|
348 |
translation := aTranslation asPoint |
|
349 |
] |
|
601 | 350 |
] |
2147 | 351 |
|
2148 | 352 |
"Modified: / 13.6.1998 / 14:04:15 / cg" |
705 | 353 |
! |
354 |
||
355 |
translationX |
|
356 |
"return the receiver's x-translation." |
|
357 |
||
358 |
translation isNil ifTrue:[^ 0]. |
|
359 |
^ translation x |
|
360 |
||
361 |
"Created: 21.5.1996 / 21:13:10 / cg" |
|
362 |
! |
|
363 |
||
364 |
translationY |
|
365 |
"return the receiver's x-translation." |
|
366 |
||
367 |
translation isNil ifTrue:[^ 0]. |
|
368 |
^ translation y |
|
369 |
||
370 |
"Created: 21.5.1996 / 21:13:21 / cg" |
|
46 | 371 |
! ! |
0 | 372 |
|
72 | 373 |
!WindowingTransformation methodsFor:'applying transform'! |
0 | 374 |
|
78 | 375 |
applyInverseScaleX:aNumber |
376 |
"apply the scale only (if widths are to be transformed)" |
|
377 |
||
378 |
scale isNil ifTrue:[^ aNumber]. |
|
379 |
^ aNumber / scale x |
|
380 |
! |
|
381 |
||
382 |
applyInverseScaleY:aNumber |
|
383 |
"apply the scale only (if heights are to be transformed)" |
|
384 |
||
385 |
scale isNil ifTrue:[^ aNumber]. |
|
386 |
^ aNumber / scale y |
|
387 |
! |
|
388 |
||
389 |
applyInverseTo:anObject |
|
390 |
"Apply the inverse of the receiver to anObject |
|
391 |
and return the result. This can be used to map back from logical |
|
392 |
to physical coordinates, for example." |
|
393 |
||
394 |
|transformedObject| |
|
395 |
||
396 |
translation isNil ifTrue:[ |
|
397 |
scale isNil ifTrue:[ |
|
398 |
^ anObject |
|
399 |
]. |
|
400 |
^ anObject scaledBy:self inverseScale |
|
401 |
]. |
|
402 |
transformedObject := anObject translatedBy:(self inverseTranslation). |
|
403 |
scale notNil ifTrue:[ |
|
404 |
transformedObject scaleBy:(self inverseScale). |
|
405 |
]. |
|
406 |
^ transformedObject |
|
407 |
! |
|
408 |
||
601 | 409 |
applyInverseToX:aNumber |
410 |
"Apply the receiver to a number representing an x-coordinate |
|
411 |
and return the result." |
|
412 |
||
413 |
|t s| |
|
414 |
||
415 |
scale isNil ifTrue:[s := 1] ifFalse:[s := scale x]. |
|
416 |
translation isNil ifTrue:[t := 0] ifFalse:[t := translation x]. |
|
417 |
^ (aNumber - t) / s |
|
418 |
! |
|
419 |
||
420 |
applyInverseToY:aNumber |
|
421 |
"Apply the receiver to a number representing an y-coordinate |
|
422 |
and return the result." |
|
423 |
||
424 |
|t s| |
|
425 |
||
426 |
scale isNil ifTrue:[s := 1] ifFalse:[s := scale y]. |
|
427 |
translation isNil ifTrue:[t := 0] ifFalse:[t := translation y]. |
|
428 |
^ (aNumber - t) / s |
|
429 |
! |
|
430 |
||
431 |
applyScaleX:aNumber |
|
432 |
"apply the scale only (if widths are to be transformed)" |
|
433 |
||
434 |
scale isNil ifTrue:[^ aNumber]. |
|
435 |
^ aNumber * scale x |
|
436 |
! |
|
437 |
||
438 |
applyScaleY:aNumber |
|
439 |
"apply the scale only (if heights are to be transformed)" |
|
440 |
||
441 |
scale isNil ifTrue:[^ aNumber]. |
|
442 |
^ aNumber * scale y |
|
443 |
! |
|
444 |
||
445 |
applyTo:anObject |
|
446 |
"Apply the receiver to anObject and return the result." |
|
447 |
||
448 |
|transformedObject| |
|
78 | 449 |
|
450 |
scale isNil ifTrue:[ |
|
451 |
translation isNil ifTrue:[ |
|
601 | 452 |
^ anObject |
78 | 453 |
]. |
601 | 454 |
^ anObject translatedBy:translation |
455 |
]. |
|
456 |
transformedObject := anObject scaledBy:scale. |
|
457 |
translation notNil ifTrue:[ |
|
458 |
transformedObject translateBy:translation. |
|
78 | 459 |
]. |
601 | 460 |
^ transformedObject |
461 |
! |
|
462 |
||
463 |
applyToX:aNumber |
|
464 |
"Apply the receiver to a number representing an x-coordinate |
|
465 |
and return the result." |
|
466 |
||
467 |
|t s| |
|
468 |
||
469 |
scale isNil ifTrue:[s := 1] ifFalse:[s := scale x]. |
|
470 |
translation isNil ifTrue:[t := 0] ifFalse:[t := translation x]. |
|
471 |
^ aNumber * s + t |
|
472 |
! |
|
473 |
||
474 |
applyToY:aNumber |
|
475 |
"Apply the receiver to a number representing an y-coordinate |
|
476 |
and return the result." |
|
477 |
||
478 |
|t s| |
|
479 |
||
480 |
scale isNil ifTrue:[s := 1] ifFalse:[s := scale y]. |
|
481 |
translation isNil ifTrue:[t := 0] ifFalse:[t := translation y]. |
|
482 |
^ aNumber * s + t |
|
78 | 483 |
! |
484 |
||
0 | 485 |
compose:aTransformation |
486 |
"return a new WindowingTransformation that is the |
|
487 |
composition of the receiver and aTransformation. |
|
488 |
The effect of applying the resulting WindowingTransformation |
|
489 |
to an object is the same as that of first applying |
|
490 |
aTransformation to the object and then applying the |
|
491 |
receiver to its result." |
|
492 |
||
493 |
|aTransformationScale newScale newTranslation| |
|
494 |
||
495 |
aTransformationScale := aTransformation scale. |
|
78 | 496 |
scale isNil ifTrue:[ |
72 | 497 |
aTransformation noScale ifTrue:[ |
498 |
newScale := nil |
|
499 |
] ifFalse:[ |
|
500 |
newScale := aTransformationScale |
|
501 |
]. |
|
502 |
newTranslation := translation + aTransformation translation |
|
0 | 503 |
] ifFalse:[ |
72 | 504 |
aTransformation noScale ifTrue:[ |
505 |
newScale := scale |
|
506 |
] ifFalse:[ |
|
507 |
newScale := scale * aTransformationScale |
|
508 |
]. |
|
509 |
newTranslation := translation |
|
510 |
+ (scale * aTransformation translation) |
|
0 | 511 |
]. |
72 | 512 |
^ (self class) |
513 |
scale:newScale |
|
514 |
translation:newTranslation |
|
515 |
! |
|
516 |
||
601 | 517 |
transformPoint:p |
518 |
"Apply the receiver to a point. |
|
519 |
This is destructive in that the point is being modified, |
|
520 |
not a copy." |
|
0 | 521 |
|
601 | 522 |
scale isNil ifTrue:[ |
523 |
translation isNil ifTrue:[ |
|
524 |
^ p |
|
72 | 525 |
]. |
601 | 526 |
^ p + translation |
527 |
]. |
|
528 |
translation isNil ifTrue:[ |
|
529 |
^ p * scale |
|
0 | 530 |
]. |
601 | 531 |
^ (p * scale + translation) |
532 |
! ! |
|
533 |
||
3276 | 534 |
!WindowingTransformation methodsFor:'printing & storing'! |
0 | 535 |
|
601 | 536 |
printOn:aStream |
2804 | 537 |
"append a user printed representation of the receiver to aStream. |
538 |
The format is suitable for a human - not meant to be read back." |
|
539 |
||
601 | 540 |
aStream nextPutAll:self class name. |
541 |
aStream nextPutAll:' scale: '. |
|
542 |
scale printOn:aStream. |
|
543 |
aStream nextPutAll:' translation: '. |
|
544 |
translation printOn:aStream |
|
0 | 545 |
! ! |
546 |
||
72 | 547 |
!WindowingTransformation methodsFor:'private'! |
0 | 548 |
|
549 |
checkScale:aScale |
|
550 |
"Converts aScale to the internal format of a floating-point Point." |
|
551 |
||
552 |
|checkedScale| |
|
553 |
||
554 |
checkedScale := aScale asPoint. |
|
555 |
^ Point x:checkedScale x asFloat |
|
72 | 556 |
y:checkedScale y asFloat |
0 | 557 |
! |
558 |
||
559 |
inverseScale |
|
560 |
"return with a Point representing the inverse of my |
|
561 |
scale." |
|
562 |
||
563 |
|newScale| |
|
564 |
||
565 |
newScale := self checkScale:scale. |
|
566 |
^ Point x:(1.0 / newScale x) |
|
72 | 567 |
y:(1.0 / newScale y) |
0 | 568 |
! |
569 |
||
570 |
inverseTranslation |
|
571 |
"return with a Point representing the inverse of my |
|
572 |
translation." |
|
573 |
||
574 |
|trans| |
|
575 |
||
576 |
trans := translation asPoint. |
|
577 |
^ Point x:trans x negated |
|
72 | 578 |
y:trans y negated |
579 |
! ! |
|
580 |
||
581 |
!WindowingTransformation methodsFor:'testing'! |
|
582 |
||
583 |
noScale |
|
584 |
"return true if the identity scale is in effect; |
|
585 |
return false, otherwise." |
|
0 | 586 |
|
705 | 587 |
scale isNil ifTrue:[^ true]. |
588 |
^ scale x = 1 and:[scale y = 1] |
|
589 |
||
590 |
"Modified: 21.5.1996 / 21:15:21 / cg" |
|
0 | 591 |
! ! |
72 | 592 |
|
3276 | 593 |
!WindowingTransformation methodsFor:'transformations'! |
601 | 594 |
|
595 |
scaleBy:aScale |
|
596 |
"scale the receiver. |
|
597 |
This is a destructive operation, modifying the transformation |
|
598 |
represented by the receiver" |
|
599 |
||
600 |
|newScale| |
|
601 |
||
602 |
aScale isNil ifTrue:[^ self]. |
|
603 |
||
604 |
scale isNil ifTrue:[ |
|
605 |
newScale := aScale asPoint |
|
606 |
] ifFalse:[ |
|
607 |
newScale := scale * aScale |
|
608 |
]. |
|
609 |
translation notNil ifTrue:[ |
|
610 |
translation := translation * aScale. |
|
611 |
]. |
|
612 |
scale := newScale. |
|
613 |
! |
|
614 |
||
615 |
scaledBy:aScale |
|
616 |
"return a new WindowingTransformation with the scale and translation of |
|
617 |
the receiver both scaled by aScale." |
|
618 |
||
619 |
|checkedScale newScale newTranslation| |
|
72 | 620 |
|
601 | 621 |
aScale isNil ifTrue:[ |
622 |
newScale := scale. |
|
623 |
newTranslation := translation |
|
624 |
] ifFalse:[ |
|
625 |
checkedScale := self checkScale:aScale. |
|
626 |
scale isNil ifTrue:[ |
|
627 |
newScale := checkedScale |
|
628 |
] ifFalse:[ |
|
629 |
newScale := scale * checkedScale |
|
630 |
]. |
|
631 |
translation notNil ifTrue:[ |
|
632 |
newTranslation := checkedScale * translation |
|
633 |
] |
|
634 |
]. |
|
635 |
^ (self class) |
|
636 |
scale:newScale |
|
637 |
translation:newTranslation |
|
638 |
! |
|
639 |
||
640 |
translateBy:aTranslation |
|
641 |
"translate the receiver. |
|
642 |
This is a destructive operation, modifying the transformation |
|
643 |
represented by the receiver" |
|
644 |
||
645 |
aTranslation isNil ifTrue:[^ self]. |
|
646 |
||
647 |
translation isNil ifTrue:[ |
|
648 |
translation := 0@0 |
|
649 |
]. |
|
650 |
scale isNil ifTrue:[ |
|
651 |
translation := translation + aTranslation asPoint |
|
652 |
] ifFalse:[ |
|
653 |
translation := translation + (scale * aTranslation) |
|
654 |
]. |
|
655 |
! |
|
656 |
||
657 |
translatedBy:aPoint |
|
658 |
"return a new WindowingTransformation with the same scale and |
|
659 |
rotations as the receiver and with a translation of the current |
|
660 |
translation plus aPoint." |
|
661 |
||
662 |
^ (self class) |
|
663 |
scale:scale |
|
664 |
translation:(translation + aPoint) |
|
72 | 665 |
! ! |
666 |
||
2148 | 667 |
!WindowingTransformation class methodsFor:'documentation'! |
668 |
||
669 |
version |
|
5827 | 670 |
^ '$Header: /cvs/stx/stx/libview/WindowingTransformation.st,v 1.23 2011-09-29 11:18:16 cg Exp $' |
2148 | 671 |
! ! |