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