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