author | Claus Gittinger <cg@exept.de> |
Sun, 21 Dec 2014 23:24:49 +0100 | |
changeset 6697 | ae3d20f6846b |
parent 6690 | 57c36b83ea0e |
child 6750 | dfdcb5ea6f33 |
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 |
||
6697
ae3d20f6846b
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6690
diff
changeset
|
14 |
ScaleTransform variableFloatSubclass:#WindowingTransformation |
ae3d20f6846b
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6690
diff
changeset
|
15 |
instanceVariableNames:'translation' |
601 | 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 |
||
6690
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
131 |
scale:aScale |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
132 |
"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
|
133 |
|
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
134 |
^ self basicNew scale:aScale translation:0 |
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 |
" |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
137 |
|v| |
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 := View new realize. |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
140 |
(Delay forSeconds:3) wait. |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
141 |
v transformation:(WindowingTransformation scale:2 translation:0). |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
142 |
'now, everything is magnfied by 2'. |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
143 |
v displayLineFrom:10@10 to:30@30 |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
144 |
" |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
145 |
" |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
146 |
|v| |
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 := View new realize. |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
149 |
(Delay forSeconds:3) wait. |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
150 |
v transformation:(WindowingTransformation scale:0.5 translation:0). |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
151 |
'now, everything is shrunk by 2'. |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
152 |
v displayLineFrom:10@10 to:30@30 |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
153 |
" |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
154 |
! |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
155 |
|
601 | 156 |
scale:aScale translation:aTranslation |
157 |
"returns a windowing transformation with a scale factor of |
|
158 |
aScale and a translation offset of aTranslation." |
|
159 |
||
160 |
^ self basicNew scale:aScale translation:aTranslation |
|
161 |
||
162 |
" |
|
163 |
|v| |
|
164 |
||
165 |
v := View new realize. |
|
166 |
(Delay forSeconds:3) wait. |
|
167 |
v transformation:(WindowingTransformation scale:2 translation:0). |
|
168 |
'now, everything is magnfied by 2'. |
|
169 |
v displayLineFrom:10@10 to:30@30 |
|
170 |
" |
|
171 |
" |
|
172 |
|v| |
|
173 |
||
174 |
v := View new realize. |
|
175 |
(Delay forSeconds:3) wait. |
|
176 |
v transformation:(WindowingTransformation scale:0.5 translation:0). |
|
177 |
'now, everything is shrunk by 2'. |
|
178 |
v displayLineFrom:10@10 to:30@30 |
|
179 |
" |
|
180 |
! |
|
181 |
||
6690
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
182 |
translation:aTranslation |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
183 |
"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
|
184 |
|
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
185 |
^ self basicNew scale:nil translation: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 |
" |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
188 |
|v| |
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 := View new openAndWait. |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
191 |
v displayLineFrom:10@10 to:30@30. |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
192 |
v transformation:(WindowingTransformation scale:2 translation:0). |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
193 |
'now, everything is magnfied by 2'. |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
194 |
v displayLineFrom:10@10 to:30@30. |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
195 |
" |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
196 |
" |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
197 |
|v| |
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 := View new openAndWait. |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
200 |
v displayLineFrom:10@10 to:30@30. |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
201 |
v transformation:(WindowingTransformation translation:50). |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
202 |
'now, everything is offset by 50 pixels'. |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
203 |
v displayLineFrom:10@10 to:30@30. |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
204 |
" |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
205 |
! |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
206 |
|
601 | 207 |
unit:unitSymbol on:device |
208 |
"returns a windowing transformation with scaling |
|
209 |
for unitSymbol and no translation (0@0). |
|
210 |
With such a transformation, you can draw in your preferred |
|
211 |
units. |
|
212 |
UnitSymbol may be #mm, #cm, #inch, #point, #twip or #pixel (default). |
|
213 |
Twip is 1/20th of a point, point is 1/72th of an inch |
|
214 |
(i.e. the print-unit which is also used for font sizes etc.) |
|
215 |
- not to confuse with device pixels." |
|
216 |
||
1148 | 217 |
|ppmm ppi scale| |
218 |
||
219 |
ppmm := device pixelPerMillimeter. |
|
220 |
ppi := device pixelPerInch. |
|
72 | 221 |
|
601 | 222 |
unitSymbol == #mm ifTrue:[ |
1148 | 223 |
scale := ppmm. |
601 | 224 |
] ifFalse:[ |
1148 | 225 |
unitSymbol == #cm ifTrue:[ |
226 |
scale := ppmm * 10. |
|
227 |
] ifFalse:[ |
|
228 |
unitSymbol == #twip ifTrue:[ |
|
229 |
scale := ppi / 1440. |
|
230 |
] ifFalse:[ |
|
231 |
unitSymbol == #point ifTrue:[ |
|
232 |
scale := ppi / 72. |
|
233 |
] ifFalse:[ |
|
234 |
unitSymbol == #inch ifTrue:[ |
|
235 |
scale := ppi. |
|
236 |
] ifFalse:[ |
|
237 |
"sorry: unknown unit is taken as pixel" |
|
238 |
^ self new scale:nil translation:nil |
|
239 |
] |
|
240 |
] |
|
241 |
] |
|
242 |
] |
|
601 | 243 |
]. |
1148 | 244 |
^ self basicNew scale:scale translation:nil |
601 | 245 |
|
246 |
" |
|
247 |
|v| |
|
248 |
||
1148 | 249 |
v := View new openAndWait. |
601 | 250 |
(Delay forSeconds:3) wait. |
251 |
v transformation:(WindowingTransformation unit:#inch on:Display). |
|
252 |
'now, we can think of drawing in inches ...'. |
|
253 |
v displayLineFrom:0.5@0.5 to:1@1 |
|
254 |
" |
|
1148 | 255 |
" |
256 |
|v| |
|
257 |
||
258 |
v := View new openAndWait. |
|
259 |
(Delay forSeconds:3) wait. |
|
260 |
v transformation:(WindowingTransformation unit:#mm on:Display). |
|
261 |
'now, we can think of drawing in millimeters ...'. |
|
262 |
v displayLineFrom:2@2 to:10@10 |
|
263 |
" |
|
264 |
||
265 |
"Modified: 30.12.1996 / 16:57:59 / cg" |
|
72 | 266 |
! |
0 | 267 |
|
601 | 268 |
window:sourceRectangle viewport:destinationRectangle |
269 |
"returns a windowing transformation with a scale and |
|
270 |
translation computed from sourceRectangle and destinationRectangle. |
|
271 |
The scale and transformation are computed such that sourceRectangle |
|
272 |
is transformed to destinationRectangle. Typically sourceRectangle |
|
273 |
represents the logical coordinateSpace while destinationRectangle |
|
274 |
represents the device coordinateSpace." |
|
275 |
||
276 |
|sX sY tX tY newScale newTranslation| |
|
277 |
||
278 |
sX := destinationRectangle width / sourceRectangle width. |
|
279 |
sY := destinationRectangle height / sourceRectangle height. |
|
280 |
tX := destinationRectangle left - sourceRectangle left. |
|
281 |
tY := destinationRectangle top - sourceRectangle top. |
|
282 |
((tX = 1.0) and:[tY = 1.0]) ifTrue:[ |
|
283 |
newTranslation := nil |
|
284 |
] ifFalse:[ |
|
285 |
newTranslation := tX @ tY |
|
286 |
]. |
|
287 |
((sX = 1.0) and:[sY = 1.0]) ifTrue:[ |
|
288 |
newScale := nil |
|
289 |
] ifFalse:[ |
|
290 |
newScale := sX @ sY |
|
291 |
]. |
|
292 |
^ self basicNew scale:newScale translation:newTranslation |
|
293 |
||
294 |
" |
|
295 |
|v| |
|
296 |
||
297 |
v := View new realize. |
|
298 |
(Delay forSeconds:3) wait. |
|
299 |
v transformation:(WindowingTransformation |
|
300 |
window:(0@0 corner:1@1) |
|
301 |
viewport:(0@0 corner:100@100)). |
|
302 |
'now, we can think of drawing in 0..1/0..1 coordinates'. |
|
303 |
v displayLineFrom:0.1@0.1 to:0.9@0.9 |
|
304 |
" |
|
6690
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
305 |
! |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
306 |
|
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
307 |
withAngle:angle |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
308 |
^ MatrixTransform2x3 withAngle:angle |
601 | 309 |
! ! |
310 |
||
311 |
!WindowingTransformation methodsFor:'accessing'! |
|
312 |
||
313 |
scale:aScale translation:aTranslation |
|
314 |
"sets the scale to aScale and the translation to aTranslation." |
|
78 | 315 |
|
2148 | 316 |
aScale isNil ifTrue:[ |
317 |
scale := aScale |
|
318 |
] ifFalse:[ |
|
4162
08acaf50fad0
Scale was set wrong when old scale was 1
Stefan Vogel <sv@exept.de>
parents:
3532
diff
changeset
|
319 |
aScale = 1 ifTrue:[ |
2148 | 320 |
scale := nil |
321 |
] ifFalse:[ |
|
322 |
scale := aScale asPoint. |
|
323 |
] |
|
601 | 324 |
]. |
2148 | 325 |
aTranslation isNil ifTrue:[ |
326 |
translation := aTranslation |
|
327 |
] ifFalse:[ |
|
328 |
aTranslation = 0 ifTrue:[ |
|
329 |
translation := nil |
|
330 |
] ifFalse:[ |
|
331 |
translation := aTranslation asPoint |
|
332 |
] |
|
601 | 333 |
] |
2147 | 334 |
|
2148 | 335 |
"Modified: / 13.6.1998 / 14:04:42 / cg" |
72 | 336 |
! |
337 |
||
601 | 338 |
translation |
339 |
"return a copy of the receiver's translation." |
|
340 |
||
6697
ae3d20f6846b
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6690
diff
changeset
|
341 |
translation isNil ifTrue:[^ Point x:0 y:0 ]. |
601 | 342 |
^ translation copy |
343 |
! |
|
72 | 344 |
|
601 | 345 |
translation:aTranslation |
346 |
"Set the receiver's translation to aTranslation, a Point or Number." |
|
347 |
||
2148 | 348 |
aTranslation isNil ifTrue:[ |
349 |
translation := aTranslation |
|
350 |
] ifFalse:[ |
|
351 |
aTranslation = 0 ifTrue:[ |
|
352 |
translation := nil |
|
353 |
] ifFalse:[ |
|
354 |
translation := aTranslation asPoint |
|
355 |
] |
|
601 | 356 |
] |
2147 | 357 |
|
2148 | 358 |
"Modified: / 13.6.1998 / 14:04:15 / cg" |
705 | 359 |
! |
360 |
||
361 |
translationX |
|
362 |
"return the receiver's x-translation." |
|
363 |
||
364 |
translation isNil ifTrue:[^ 0]. |
|
365 |
^ translation x |
|
366 |
||
367 |
"Created: 21.5.1996 / 21:13:10 / cg" |
|
368 |
! |
|
369 |
||
370 |
translationY |
|
371 |
"return the receiver's x-translation." |
|
372 |
||
373 |
translation isNil ifTrue:[^ 0]. |
|
374 |
^ translation y |
|
375 |
||
376 |
"Created: 21.5.1996 / 21:13:21 / cg" |
|
46 | 377 |
! ! |
0 | 378 |
|
72 | 379 |
!WindowingTransformation methodsFor:'applying transform'! |
0 | 380 |
|
78 | 381 |
applyInverseTo:anObject |
382 |
"Apply the inverse of the receiver to anObject |
|
383 |
and return the result. This can be used to map back from logical |
|
384 |
to physical coordinates, for example." |
|
385 |
||
386 |
|transformedObject| |
|
387 |
||
388 |
translation isNil ifTrue:[ |
|
389 |
scale isNil ifTrue:[ |
|
390 |
^ anObject |
|
391 |
]. |
|
392 |
^ anObject scaledBy:self inverseScale |
|
393 |
]. |
|
394 |
transformedObject := anObject translatedBy:(self inverseTranslation). |
|
395 |
scale notNil ifTrue:[ |
|
396 |
transformedObject scaleBy:(self inverseScale). |
|
397 |
]. |
|
398 |
^ transformedObject |
|
399 |
! |
|
400 |
||
601 | 401 |
applyInverseToX:aNumber |
402 |
"Apply the receiver to a number representing an x-coordinate |
|
403 |
and return the result." |
|
404 |
||
405 |
|t s| |
|
406 |
||
407 |
scale isNil ifTrue:[s := 1] ifFalse:[s := scale x]. |
|
408 |
translation isNil ifTrue:[t := 0] ifFalse:[t := translation x]. |
|
409 |
^ (aNumber - t) / s |
|
410 |
! |
|
411 |
||
412 |
applyInverseToY:aNumber |
|
413 |
"Apply the receiver to a number representing an y-coordinate |
|
414 |
and return the result." |
|
415 |
||
416 |
|t s| |
|
417 |
||
418 |
scale isNil ifTrue:[s := 1] ifFalse:[s := scale y]. |
|
419 |
translation isNil ifTrue:[t := 0] ifFalse:[t := translation y]. |
|
420 |
^ (aNumber - t) / s |
|
421 |
! |
|
422 |
||
423 |
applyTo:anObject |
|
424 |
"Apply the receiver to anObject and return the result." |
|
425 |
||
426 |
|transformedObject| |
|
78 | 427 |
|
428 |
scale isNil ifTrue:[ |
|
429 |
translation isNil ifTrue:[ |
|
601 | 430 |
^ anObject |
78 | 431 |
]. |
601 | 432 |
^ anObject translatedBy:translation |
433 |
]. |
|
434 |
transformedObject := anObject scaledBy:scale. |
|
435 |
translation notNil ifTrue:[ |
|
436 |
transformedObject translateBy:translation. |
|
78 | 437 |
]. |
601 | 438 |
^ transformedObject |
439 |
! |
|
440 |
||
441 |
applyToX:aNumber |
|
442 |
"Apply the receiver to a number representing an x-coordinate |
|
443 |
and return the result." |
|
444 |
||
445 |
|t s| |
|
446 |
||
447 |
scale isNil ifTrue:[s := 1] ifFalse:[s := scale x]. |
|
448 |
translation isNil ifTrue:[t := 0] ifFalse:[t := translation x]. |
|
449 |
^ aNumber * s + t |
|
450 |
! |
|
451 |
||
452 |
applyToY:aNumber |
|
453 |
"Apply the receiver to a number representing an y-coordinate |
|
454 |
and return the result." |
|
455 |
||
456 |
|t s| |
|
457 |
||
458 |
scale isNil ifTrue:[s := 1] ifFalse:[s := scale y]. |
|
459 |
translation isNil ifTrue:[t := 0] ifFalse:[t := translation y]. |
|
460 |
^ aNumber * s + t |
|
78 | 461 |
! |
462 |
||
0 | 463 |
compose:aTransformation |
464 |
"return a new WindowingTransformation that is the |
|
465 |
composition of the receiver and aTransformation. |
|
466 |
The effect of applying the resulting WindowingTransformation |
|
467 |
to an object is the same as that of first applying |
|
468 |
aTransformation to the object and then applying the |
|
469 |
receiver to its result." |
|
470 |
||
471 |
|aTransformationScale newScale newTranslation| |
|
472 |
||
473 |
aTransformationScale := aTransformation scale. |
|
78 | 474 |
scale isNil ifTrue:[ |
6690
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
475 |
aTransformation isNoScale ifTrue:[ |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
476 |
newScale := nil |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
477 |
] ifFalse:[ |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
478 |
newScale := aTransformationScale |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
479 |
]. |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
480 |
newTranslation := (translation ? 0) + aTransformation translation |
0 | 481 |
] ifFalse:[ |
6690
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
482 |
aTransformation isNoScale ifTrue:[ |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
483 |
newScale := scale |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
484 |
] ifFalse:[ |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
485 |
newScale := scale * aTransformationScale |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
486 |
]. |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
487 |
newTranslation := (translation ? 0) |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
488 |
+ (scale * aTransformation translation) |
0 | 489 |
]. |
72 | 490 |
^ (self class) |
6690
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
491 |
scale:newScale |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
492 |
translation:newTranslation |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
493 |
! |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
494 |
|
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
495 |
composedWithLocal: aTransformation |
57c36b83ea0e
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6355
diff
changeset
|
496 |
^ self compose:aTransformation |
72 | 497 |
! |
498 |
||
601 | 499 |
transformPoint:p |
6697
ae3d20f6846b
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6690
diff
changeset
|
500 |
"Apply the receiver to a point, returning a new point." |
0 | 501 |
|
601 | 502 |
scale isNil ifTrue:[ |
6355 | 503 |
translation isNil ifTrue:[ |
504 |
^ p |
|
505 |
]. |
|
506 |
^ p + translation |
|
601 | 507 |
]. |
508 |
translation isNil ifTrue:[ |
|
6355 | 509 |
^ p * scale |
0 | 510 |
]. |
601 | 511 |
^ (p * scale + translation) |
512 |
! ! |
|
513 |
||
3276 | 514 |
!WindowingTransformation methodsFor:'printing & storing'! |
0 | 515 |
|
601 | 516 |
printOn:aStream |
2804 | 517 |
"append a user printed representation of the receiver to aStream. |
518 |
The format is suitable for a human - not meant to be read back." |
|
519 |
||
601 | 520 |
aStream nextPutAll:self class name. |
521 |
aStream nextPutAll:' scale: '. |
|
522 |
scale printOn:aStream. |
|
523 |
aStream nextPutAll:' translation: '. |
|
524 |
translation printOn:aStream |
|
0 | 525 |
! ! |
526 |
||
72 | 527 |
!WindowingTransformation methodsFor:'private'! |
0 | 528 |
|
529 |
inverseTranslation |
|
530 |
"return with a Point representing the inverse of my |
|
531 |
translation." |
|
532 |
||
533 |
|trans| |
|
534 |
||
535 |
trans := translation asPoint. |
|
6697
ae3d20f6846b
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6690
diff
changeset
|
536 |
^ Point x:(trans x negated) y:trans y negated |
72 | 537 |
! ! |
538 |
||
539 |
!WindowingTransformation methodsFor:'testing'! |
|
540 |
||
6355 | 541 |
isIdentityTransformation |
542 |
"return true if this is an identity transformation; |
|
543 |
return false, otherwise." |
|
544 |
||
545 |
^ (scale isNil or:[scale x = 1 and:[scale y = 1]]) |
|
546 |
and:[translation isNil or:[translation x = 0 and:[translation y = 0]]] |
|
0 | 547 |
! ! |
72 | 548 |
|
3276 | 549 |
!WindowingTransformation methodsFor:'transformations'! |
601 | 550 |
|
551 |
scaleBy:aScale |
|
552 |
"scale the receiver. |
|
553 |
This is a destructive operation, modifying the transformation |
|
554 |
represented by the receiver" |
|
555 |
||
556 |
|newScale| |
|
557 |
||
558 |
aScale isNil ifTrue:[^ self]. |
|
559 |
||
560 |
scale isNil ifTrue:[ |
|
561 |
newScale := aScale asPoint |
|
562 |
] ifFalse:[ |
|
563 |
newScale := scale * aScale |
|
564 |
]. |
|
565 |
translation notNil ifTrue:[ |
|
566 |
translation := translation * aScale. |
|
567 |
]. |
|
568 |
scale := newScale. |
|
569 |
! |
|
570 |
||
571 |
scaledBy:aScale |
|
572 |
"return a new WindowingTransformation with the scale and translation of |
|
573 |
the receiver both scaled by aScale." |
|
574 |
||
575 |
|checkedScale newScale newTranslation| |
|
72 | 576 |
|
601 | 577 |
aScale isNil ifTrue:[ |
578 |
newScale := scale. |
|
579 |
newTranslation := translation |
|
580 |
] ifFalse:[ |
|
581 |
checkedScale := self checkScale:aScale. |
|
582 |
scale isNil ifTrue:[ |
|
583 |
newScale := checkedScale |
|
584 |
] ifFalse:[ |
|
585 |
newScale := scale * checkedScale |
|
586 |
]. |
|
587 |
translation notNil ifTrue:[ |
|
588 |
newTranslation := checkedScale * translation |
|
589 |
] |
|
590 |
]. |
|
591 |
^ (self class) |
|
592 |
scale:newScale |
|
593 |
translation:newTranslation |
|
594 |
! |
|
595 |
||
596 |
translateBy:aTranslation |
|
597 |
"translate the receiver. |
|
598 |
This is a destructive operation, modifying the transformation |
|
599 |
represented by the receiver" |
|
600 |
||
601 |
aTranslation isNil ifTrue:[^ self]. |
|
602 |
||
603 |
translation isNil ifTrue:[ |
|
604 |
translation := 0@0 |
|
605 |
]. |
|
606 |
scale isNil ifTrue:[ |
|
607 |
translation := translation + aTranslation asPoint |
|
608 |
] ifFalse:[ |
|
609 |
translation := translation + (scale * aTranslation) |
|
610 |
]. |
|
611 |
! |
|
612 |
||
613 |
translatedBy:aPoint |
|
614 |
"return a new WindowingTransformation with the same scale and |
|
615 |
rotations as the receiver and with a translation of the current |
|
616 |
translation plus aPoint." |
|
617 |
||
618 |
^ (self class) |
|
619 |
scale:scale |
|
620 |
translation:(translation + aPoint) |
|
72 | 621 |
! ! |
622 |
||
2148 | 623 |
!WindowingTransformation class methodsFor:'documentation'! |
624 |
||
625 |
version |
|
6697
ae3d20f6846b
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6690
diff
changeset
|
626 |
^ '$Header: /cvs/stx/stx/libview/WindowingTransformation.st,v 1.26 2014-12-21 22:24:49 cg Exp $' |
ae3d20f6846b
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6690
diff
changeset
|
627 |
! |
ae3d20f6846b
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6690
diff
changeset
|
628 |
|
ae3d20f6846b
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6690
diff
changeset
|
629 |
version_CVS |
ae3d20f6846b
class: WindowingTransformation
Claus Gittinger <cg@exept.de>
parents:
6690
diff
changeset
|
630 |
^ '$Header: /cvs/stx/stx/libview/WindowingTransformation.st,v 1.26 2014-12-21 22:24:49 cg Exp $' |
2148 | 631 |
! ! |
6355 | 632 |