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