8713
|
1 |
"{ Encoding: utf8 }"
|
|
2 |
|
7950
|
3 |
"
|
|
4 |
COPYRIGHT (c) 1992 by Claus Gittinger
|
|
5 |
All Rights Reserved
|
7057
|
6 |
|
7950
|
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 |
"
|
6695
|
14 |
"{ Package: 'stx:libview' }"
|
|
15 |
|
6747
|
16 |
"{ NameSpace: Smalltalk }"
|
|
17 |
|
6695
|
18 |
DisplayTransform variableFloatSubclass:#ScaleTransform
|
|
19 |
instanceVariableNames:'scale'
|
|
20 |
classVariableNames:''
|
|
21 |
poolDictionaries:''
|
|
22 |
category:'Graphics-Transformations'
|
|
23 |
!
|
|
24 |
|
|
25 |
!ScaleTransform class methodsFor:'documentation'!
|
|
26 |
|
7950
|
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 |
|
6695
|
41 |
documentation
|
|
42 |
"
|
|
43 |
instances of ScaleTransform can be used to scale other objects in 2D space.
|
|
44 |
This one is used, if only a scale is applied, but no translation.
|
|
45 |
|
|
46 |
All 2-D objects are supposed to be able to be transformed using instances of me.
|
|
47 |
Multiple instances of me can also be combined to form a 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 |
[author:]
|
|
54 |
Claus Gittinger
|
|
55 |
"
|
|
56 |
!
|
|
57 |
|
|
58 |
examples
|
|
59 |
"
|
|
60 |
example :
|
|
61 |
[exBegin]
|
|
62 |
|v|
|
|
63 |
|
|
64 |
v := View new extent:200@200; openAndWait.
|
|
65 |
v paint:Color green.
|
|
66 |
v fillRectangle:(10@10 corner:40@40).
|
|
67 |
v displayLineFrom:50@50 to:75@100.
|
|
68 |
|
|
69 |
v transformation:(ScaleTransform withScale:2).
|
|
70 |
v paint:Color red.
|
|
71 |
v fillRectangle:(10@10 corner:40@40).
|
|
72 |
v displayLineFrom:50@50 to:75@100.
|
|
73 |
[exEnd]
|
|
74 |
|
|
75 |
"
|
|
76 |
! !
|
|
77 |
|
|
78 |
!ScaleTransform class methodsFor:'instance creation'!
|
|
79 |
|
|
80 |
scale:scaleFactor
|
|
81 |
^ self new scale:scaleFactor
|
|
82 |
!
|
|
83 |
|
|
84 |
withScale:scaleFactor
|
|
85 |
^ self new scale:scaleFactor
|
|
86 |
! !
|
|
87 |
|
|
88 |
!ScaleTransform methodsFor:'accessing'!
|
|
89 |
|
|
90 |
inverseTransformation
|
|
91 |
"Return the inverse transformation of the receiver"
|
|
92 |
|
|
93 |
^ ScaleTransform withScale:(1 / scale)
|
|
94 |
!
|
|
95 |
|
|
96 |
scale
|
|
97 |
"return a copy of the Point that represents the
|
|
98 |
current scale of the receiver."
|
|
99 |
|
|
100 |
scale isNil ifTrue:[^ Point x:1 y:1 ].
|
|
101 |
^ scale copy
|
|
102 |
!
|
|
103 |
|
|
104 |
scale:aScale
|
|
105 |
"Set the receiver's scale to aScale, a Point or Number."
|
|
106 |
|
|
107 |
aScale isNil ifTrue:[
|
|
108 |
scale := aScale
|
|
109 |
] ifFalse:[
|
|
110 |
aScale = 1 ifTrue:[
|
|
111 |
scale := nil
|
|
112 |
] ifFalse:[
|
|
113 |
scale := aScale asPoint.
|
6749
|
114 |
(scale x = 1 and:[scale y = 1]) ifTrue:[
|
|
115 |
scale := nil
|
|
116 |
].
|
6695
|
117 |
]
|
|
118 |
].
|
|
119 |
|
|
120 |
"Modified: / 13.6.1998 / 14:04:51 / cg"
|
|
121 |
!
|
|
122 |
|
|
123 |
scaleOfOne
|
|
124 |
"Set the scale of the receiver to the identity scale"
|
|
125 |
|
|
126 |
scale := nil
|
|
127 |
!
|
|
128 |
|
|
129 |
scaleX
|
|
130 |
"return the current x-scale of the receiver."
|
|
131 |
|
|
132 |
scale isNil ifTrue:[^ 1].
|
|
133 |
^ scale x
|
|
134 |
|
|
135 |
"Created: 21.5.1996 / 21:13:49 / cg"
|
|
136 |
!
|
|
137 |
|
|
138 |
scaleY
|
|
139 |
"return the current x-scale of the receiver."
|
|
140 |
|
|
141 |
scale isNil ifTrue:[^ 1].
|
|
142 |
^ scale y
|
|
143 |
|
|
144 |
"Created: 21.5.1996 / 21:13:59 / cg"
|
|
145 |
!
|
|
146 |
|
|
147 |
translation
|
|
148 |
"return a copy of the receiver's translation."
|
|
149 |
|
|
150 |
^ Point x:0 y:0
|
|
151 |
!
|
|
152 |
|
|
153 |
translationX
|
|
154 |
"return the x part of the receiver's translation."
|
|
155 |
|
|
156 |
^ 0
|
|
157 |
!
|
|
158 |
|
|
159 |
translationY
|
|
160 |
"return the y part of the receiver's translation."
|
|
161 |
|
|
162 |
^ 0
|
|
163 |
! !
|
|
164 |
|
|
165 |
!ScaleTransform methodsFor:'applying transform'!
|
|
166 |
|
|
167 |
applyInverseScaleX:aNumber
|
|
168 |
"apply the scale only (if widths are to be transformed)"
|
|
169 |
|
|
170 |
scale isNil ifTrue:[^ aNumber].
|
|
171 |
^ aNumber / scale x
|
|
172 |
!
|
|
173 |
|
|
174 |
applyInverseScaleY:aNumber
|
|
175 |
"apply the scale only (if heights are to be transformed)"
|
|
176 |
|
|
177 |
scale isNil ifTrue:[^ aNumber].
|
|
178 |
^ aNumber / scale y
|
|
179 |
!
|
|
180 |
|
|
181 |
applyInverseTo:anObject
|
|
182 |
"Apply the inverse of the receiver to anObject
|
|
183 |
and return the result. This can be used to map back from logical
|
|
184 |
to physical coordinates, for example."
|
|
185 |
|
|
186 |
scale isNil ifTrue:[
|
|
187 |
^ anObject
|
|
188 |
].
|
|
189 |
^ anObject scaledBy:self inverseScale
|
|
190 |
!
|
|
191 |
|
|
192 |
applyInverseToX:aNumber
|
|
193 |
"Apply the receiver to a number representing an x-coordinate
|
|
194 |
and return the result."
|
|
195 |
|
|
196 |
|s|
|
|
197 |
|
|
198 |
scale isNil ifTrue:[s := 1] ifFalse:[s := scale x].
|
|
199 |
^ aNumber / s
|
|
200 |
!
|
|
201 |
|
|
202 |
applyInverseToY:aNumber
|
|
203 |
"Apply the receiver to a number representing an y-coordinate
|
|
204 |
and return the result."
|
|
205 |
|
|
206 |
|s|
|
|
207 |
|
|
208 |
scale isNil ifTrue:[s := 1] ifFalse:[s := scale y].
|
|
209 |
^ aNumber / s
|
|
210 |
!
|
|
211 |
|
|
212 |
applyScaleX:aNumber
|
|
213 |
"apply the scale only (if widths are to be transformed)"
|
|
214 |
|
|
215 |
scale isNil ifTrue:[^ aNumber].
|
|
216 |
^ aNumber * scale x
|
|
217 |
!
|
|
218 |
|
|
219 |
applyScaleY:aNumber
|
|
220 |
"apply the scale only (if heights are to be transformed)"
|
|
221 |
|
|
222 |
scale isNil ifTrue:[^ aNumber].
|
|
223 |
^ aNumber * scale y
|
|
224 |
!
|
|
225 |
|
|
226 |
transformPoint:p
|
|
227 |
"Apply the receiver to a point, returning a new point."
|
|
228 |
|
|
229 |
scale isNil ifTrue:[
|
|
230 |
^ p
|
|
231 |
].
|
|
232 |
^ p * scale
|
7057
|
233 |
!
|
|
234 |
|
|
235 |
transformRectangle:aRectangle
|
|
236 |
"Apply the receiver to a rectangle, returning a new rectangle."
|
|
237 |
|
|
238 |
scale isNil ifTrue:[
|
|
239 |
^ aRectangle.
|
|
240 |
].
|
|
241 |
^ aRectangle scaledBy:scale.
|
6695
|
242 |
! !
|
|
243 |
|
|
244 |
!ScaleTransform methodsFor:'printing & storing'!
|
|
245 |
|
|
246 |
printOn:aStream
|
|
247 |
"append a user printed representation of the receiver to aStream.
|
|
248 |
The format is suitable for a human - not meant to be read back."
|
|
249 |
|
8713
|
250 |
aStream nextPutAll:self className.
|
6695
|
251 |
aStream nextPutAll:' scale: '.
|
|
252 |
scale printOn:aStream.
|
8713
|
253 |
|
|
254 |
"Modified: / 28-06-2019 / 09:15:51 / Claus Gittinger"
|
6695
|
255 |
! !
|
|
256 |
|
|
257 |
!ScaleTransform methodsFor:'private'!
|
|
258 |
|
|
259 |
checkScale:aScale
|
|
260 |
"Converts aScale to the internal format of a floating-point Point."
|
|
261 |
|
|
262 |
|checkedScale|
|
|
263 |
|
|
264 |
checkedScale := aScale asPoint.
|
6747
|
265 |
^ (checkedScale x asFloat) @ (checkedScale y asFloat)
|
|
266 |
|
|
267 |
"Modified: / 22-01-2015 / 14:21:11 / az"
|
6695
|
268 |
!
|
|
269 |
|
|
270 |
inverseScale
|
|
271 |
"return with a Point representing the inverse of my
|
|
272 |
scale."
|
|
273 |
|
|
274 |
|newScale|
|
|
275 |
|
|
276 |
newScale := self checkScale:scale.
|
|
277 |
^ (1.0 / newScale x) @ (1.0 / newScale y)
|
|
278 |
! !
|
|
279 |
|
|
280 |
!ScaleTransform methodsFor:'testing'!
|
|
281 |
|
7415
|
282 |
isIdentityTransformation
|
|
283 |
"return true if this is an identity transformation;
|
|
284 |
return false, otherwise."
|
|
285 |
|
|
286 |
^ scale isNil or:[scale x = 1 and:[scale y = 1]]
|
|
287 |
!
|
|
288 |
|
6695
|
289 |
isNoScale
|
|
290 |
"return true if the identity scale is in effect (i.e. saleFactor is 1);
|
|
291 |
return false, otherwise."
|
|
292 |
|
|
293 |
scale isNil ifTrue:[^ true].
|
|
294 |
^ scale x = 1 and:[scale y = 1]
|
|
295 |
! !
|
|
296 |
|
|
297 |
!ScaleTransform methodsFor:'transformations'!
|
|
298 |
|
|
299 |
scaleBy:aScale
|
|
300 |
"scale the receiver.
|
|
301 |
This is a destructive operation, modifying the transformation
|
|
302 |
represented by the receiver"
|
|
303 |
|
|
304 |
|newScale|
|
|
305 |
|
|
306 |
aScale isNil ifTrue:[^ self].
|
|
307 |
|
|
308 |
scale isNil ifTrue:[
|
|
309 |
newScale := aScale asPoint
|
|
310 |
] ifFalse:[
|
|
311 |
newScale := scale * aScale
|
|
312 |
].
|
6749
|
313 |
self scale:newScale.
|
6695
|
314 |
!
|
|
315 |
|
|
316 |
scaledBy:aScale
|
|
317 |
"return a new WindowingTransformation with the scale and translation of
|
|
318 |
the receiver both scaled by aScale."
|
|
319 |
|
|
320 |
|checkedScale newScale|
|
|
321 |
|
|
322 |
aScale isNil ifTrue:[
|
|
323 |
newScale := scale.
|
|
324 |
] ifFalse:[
|
|
325 |
checkedScale := self checkScale:aScale.
|
|
326 |
scale isNil ifTrue:[
|
|
327 |
newScale := checkedScale
|
|
328 |
] ifFalse:[
|
|
329 |
newScale := scale * checkedScale
|
|
330 |
].
|
|
331 |
].
|
|
332 |
^ (self class) withScale:newScale
|
|
333 |
!
|
|
334 |
|
|
335 |
translateBy:aTranslation
|
|
336 |
"translate the receiver.
|
|
337 |
This is a destructive operation, modifying the transformation
|
|
338 |
represented by the receiver"
|
|
339 |
|
|
340 |
self error:'not allowed'
|
|
341 |
!
|
|
342 |
|
|
343 |
translatedBy:aPoint
|
|
344 |
"return a new WindowingTransformation with the same scale and
|
|
345 |
rotations as the receiver and with a translation of the current
|
|
346 |
translation plus aPoint."
|
|
347 |
|
|
348 |
^ WindowingTransformation
|
|
349 |
scale:scale
|
|
350 |
translation:aPoint
|
|
351 |
! !
|
|
352 |
|
|
353 |
!ScaleTransform class methodsFor:'documentation'!
|
|
354 |
|
|
355 |
version
|
7057
|
356 |
^ '$Header$'
|
6695
|
357 |
!
|
|
358 |
|
|
359 |
version_CVS
|
7057
|
360 |
^ '$Header$'
|
6695
|
361 |
! !
|
|
362 |
|