author | HG Automerge |
Thu, 22 Dec 2016 23:11:31 +0000 | |
branch | jv |
changeset 3815 | 021778442c82 |
parent 3794 | a7ac172485be |
child 3865 | e6f90d1cf89b |
permissions | -rw-r--r-- |
88 | 1 |
" |
2 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
93 | 3 |
All Rights Reserved |
88 | 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 |
" |
|
1600
ac585461747e
computed rectangle is truncated here.
Claus Gittinger <cg@exept.de>
parents:
1039
diff
changeset
|
12 |
"{ Package: 'stx:libview2' }" |
ac585461747e
computed rectangle is truncated here.
Claus Gittinger <cg@exept.de>
parents:
1039
diff
changeset
|
13 |
|
3794 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
77 | 16 |
Layout subclass:#LayoutOrigin |
191 | 17 |
instanceVariableNames:'leftFraction topFraction leftOffset topOffset' |
18 |
classVariableNames:'' |
|
19 |
poolDictionaries:'' |
|
20 |
category:'Graphics-Geometry' |
|
77 | 21 |
! |
22 |
||
88 | 23 |
!LayoutOrigin class methodsFor:'documentation'! |
24 |
||
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
93 | 28 |
All Rights Reserved |
88 | 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 |
||
93 | 39 |
documentation |
40 |
" |
|
41 |
This class is provided to make porting of existing ST-80 applications |
|
42 |
easier. Instances can be used to control the geometry of a subview, within |
|
43 |
its superview. It provides the same functionality as a relative origin |
|
44 |
combined with insets. |
|
45 |
A layoutOrigin controls the origin of a subcomponent, given a fractional |
|
46 |
component and an offset component. |
|
47 |
||
229 | 48 |
Notice: |
49 |
this class was implemented using protocol information |
|
50 |
from alpha testers - it may not be complete or compatible to |
|
51 |
the corresponding ST-80 class. |
|
52 |
If you encounter any incompatibilities, please forward a note |
|
53 |
describing the incompatibility verbal (i.e. no code) to the ST/X team. |
|
219 | 54 |
|
55 |
[author:] |
|
56 |
Claus Gittinger |
|
229 | 57 |
|
58 |
[see also:] |
|
59 |
View |
|
60 |
LayoutFrame AlignmentOrigin Layout |
|
61 |
Rectangle Point |
|
94 | 62 |
" |
93 | 63 |
! |
64 |
||
65 |
examples |
|
66 |
" |
|
229 | 67 |
Although the examples below use a button as component, |
68 |
they work of course with any type of subview .... |
|
93 | 69 |
|
229 | 70 |
using a LayoutOrigin, to arrange for |
71 |
the TOPLEFT of a component be positions |
|
72 |
at the center (i.e. buttons origin at:0.5 @ 0.5): |
|
73 |
[exBegin] |
|
74 |
|top button| |
|
93 | 75 |
|
229 | 76 |
top := StandardSystemView new. |
77 |
top extent:300@300. |
|
93 | 78 |
|
229 | 79 |
button := Button label:'component'. |
80 |
top add:button in:(LayoutOrigin new |
|
81 |
leftFraction:0.5; |
|
82 |
topFraction:0.5). |
|
93 | 83 |
|
229 | 84 |
top open |
85 |
[exEnd] |
|
93 | 86 |
|
87 |
||
88 |
like above, but adds an additional offset: |
|
229 | 89 |
(i.e. center of button at:0.5 @ 0.5 OFFSET by 10 @ 20): |
90 |
[exBegin] |
|
91 |
|top button| |
|
93 | 92 |
|
229 | 93 |
top := StandardSystemView new. |
94 |
top extent:300@300. |
|
93 | 95 |
|
229 | 96 |
button := Button label:'component'. |
97 |
top add:button in:(LayoutOrigin new |
|
98 |
leftFraction:0.5; |
|
99 |
topFraction:0.5; |
|
100 |
leftOffset:10; |
|
101 |
topOffset:20). |
|
93 | 102 |
|
229 | 103 |
top open |
104 |
[exEnd] |
|
93 | 105 |
" |
88 | 106 |
! ! |
107 |
||
77 | 108 |
!LayoutOrigin class methodsFor:'instance creation'! |
109 |
||
110 |
fractionalFromPoint:aPoint |
|
93 | 111 |
"given a point, create a layoutOrigin representing the same |
112 |
relative origin." |
|
113 |
||
83 | 114 |
^ (self new) leftFraction:aPoint x topFraction:aPoint y |
93 | 115 |
|
116 |
" |
|
117 |
LayoutOrigin fractionalFromPoint:0.5@0.5 |
|
118 |
" |
|
77 | 119 |
! |
120 |
||
121 |
fromPoint:aPoint |
|
1821 | 122 |
"return a new LayoutOrigin from aPoint. |
123 |
If the coordinates are between 0 and 1, |
|
124 |
take them as fractional parts (relative to superview). |
|
77 | 125 |
Otherwise, treat them as absolute offsets." |
126 |
||
127 |
|x y layout| |
|
128 |
||
129 |
x := aPoint x. |
|
130 |
y := aPoint y. |
|
131 |
layout := self new. |
|
132 |
((x between:0 and:1) |
|
133 |
and:[y between:0 and:1]) ifTrue:[ |
|
1821 | 134 |
layout leftFraction:x topFraction:y |
77 | 135 |
] ifFalse:[ |
1821 | 136 |
layout leftOffset:x topOffset:y |
77 | 137 |
]. |
138 |
^ layout |
|
93 | 139 |
|
140 |
" |
|
141 |
LayoutOrigin fromPoint:100@100 |
|
142 |
LayoutOrigin fromPoint:0.5@0.5 |
|
143 |
LayoutOrigin fromPoint:0.5@100 |
|
144 |
" |
|
126 | 145 |
! |
146 |
||
147 |
offsetFromPoint:aPoint |
|
148 |
"given a point, create a layoutOrigin representing the same |
|
149 |
absolute (pixel) origin." |
|
150 |
||
151 |
^ self new leftOffset:aPoint x topOffset:aPoint y |
|
152 |
||
153 |
" |
|
154 |
LayoutOrigin offsetFromPoint:100@100 |
|
155 |
" |
|
156 |
! ! |
|
157 |
||
158 |
!LayoutOrigin methodsFor:'accessing'! |
|
159 |
||
160 |
leftFraction |
|
161 |
"return leftFraction" |
|
162 |
||
163 |
^ leftFraction |
|
164 |
! |
|
165 |
||
166 |
leftFraction:something |
|
167 |
"set leftFraction" |
|
168 |
||
169 |
leftFraction := something. |
|
170 |
! |
|
171 |
||
172 |
leftFraction:something offset:o |
|
173 |
"set leftFraction and offset" |
|
174 |
||
175 |
leftFraction := something. |
|
176 |
leftOffset := o |
|
177 |
! |
|
178 |
||
543
1e730ed96b0b
added conversion to alignmentOrigin and another access method.
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
179 |
leftFraction:lF offset:lO topFraction:tF offset:tO |
1e730ed96b0b
added conversion to alignmentOrigin and another access method.
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
180 |
"set leftFraction, leftOffset, topFraction and topOffset" |
1e730ed96b0b
added conversion to alignmentOrigin and another access method.
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
181 |
|
1e730ed96b0b
added conversion to alignmentOrigin and another access method.
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
182 |
leftFraction := lF. leftOffset := lO. |
1e730ed96b0b
added conversion to alignmentOrigin and another access method.
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
183 |
topFraction := tF. topOffset := tO. |
1e730ed96b0b
added conversion to alignmentOrigin and another access method.
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
184 |
|
1e730ed96b0b
added conversion to alignmentOrigin and another access method.
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
185 |
"Created: 18.4.1997 / 20:07:15 / cg" |
1e730ed96b0b
added conversion to alignmentOrigin and another access method.
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
186 |
! |
1e730ed96b0b
added conversion to alignmentOrigin and another access method.
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
187 |
|
126 | 188 |
leftFraction:newLeft topFraction:newTop |
189 |
"set leftFraction and topFraction" |
|
190 |
||
191 |
leftFraction := newLeft. |
|
192 |
topFraction := newTop. |
|
193 |
! |
|
194 |
||
275 | 195 |
leftInset:pixels |
196 |
"set leftOffset for an inset at the left" |
|
197 |
||
198 |
leftOffset := pixels. |
|
199 |
||
200 |
"Created: 26.5.1996 / 17:38:55 / cg" |
|
201 |
"Modified: 26.5.1996 / 17:42:16 / cg" |
|
202 |
! |
|
203 |
||
126 | 204 |
leftOffset |
205 |
"return leftOffset" |
|
206 |
||
207 |
^ leftOffset |
|
208 |
! |
|
209 |
||
210 |
leftOffset:something |
|
211 |
"set leftOffset" |
|
212 |
||
213 |
leftOffset := something. |
|
214 |
! |
|
215 |
||
216 |
leftOffset:newLeft topOffset:newTop |
|
217 |
"set leftOffset and topOffset" |
|
218 |
||
219 |
leftOffset := newLeft. |
|
220 |
topOffset := newTop. |
|
221 |
! |
|
222 |
||
223 |
topFraction |
|
224 |
"return topFraction" |
|
225 |
||
226 |
^ topFraction |
|
227 |
! |
|
228 |
||
229 |
topFraction:something |
|
230 |
"set topFraction" |
|
231 |
||
232 |
topFraction := something. |
|
233 |
! |
|
234 |
||
235 |
topFraction:something offset:o |
|
236 |
"set topFraction and offset" |
|
237 |
||
238 |
topFraction := something. |
|
239 |
topOffset := o |
|
240 |
! |
|
241 |
||
275 | 242 |
topInset:pixels |
243 |
"set topOffset for an inset at the top" |
|
244 |
||
245 |
topOffset := pixels. |
|
246 |
||
247 |
"Created: 26.5.1996 / 17:39:00 / cg" |
|
248 |
"Modified: 26.5.1996 / 17:42:12 / cg" |
|
249 |
! |
|
250 |
||
126 | 251 |
topOffset |
252 |
"return topOffset" |
|
253 |
||
254 |
^ topOffset |
|
255 |
! |
|
256 |
||
257 |
topOffset:something |
|
258 |
"set topOffset" |
|
259 |
||
260 |
topOffset := something. |
|
261 |
! ! |
|
262 |
||
3330 | 263 |
!LayoutOrigin methodsFor:'comparing'! |
264 |
||
265 |
= anObject |
|
3331 | 266 |
^ anObject class == self class |
3330 | 267 |
and:[ anObject leftFraction = leftFraction |
268 |
and:[ anObject topFraction = topFraction |
|
269 |
and:[ anObject leftOffset = leftOffset |
|
270 |
and:[ anObject topOffset = topOffset ]]]] |
|
271 |
! |
|
272 |
||
273 |
hash |
|
274 |
^ leftFraction hash + topFraction hash + leftOffset hash + topOffset hash |
|
275 |
! ! |
|
276 |
||
126 | 277 |
!LayoutOrigin methodsFor:'converting'! |
278 |
||
543
1e730ed96b0b
added conversion to alignmentOrigin and another access method.
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
279 |
asAlignmentOrigin |
1e730ed96b0b
added conversion to alignmentOrigin and another access method.
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
280 |
"return an equivalent alignmentOrigin" |
1e730ed96b0b
added conversion to alignmentOrigin and another access method.
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
281 |
|
1e730ed96b0b
added conversion to alignmentOrigin and another access method.
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
282 |
^ AlignmentOrigin new |
1e730ed96b0b
added conversion to alignmentOrigin and another access method.
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
283 |
leftFraction:leftFraction offset:leftOffset; |
1e730ed96b0b
added conversion to alignmentOrigin and another access method.
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
284 |
topFraction:topFraction offset:topOffset; |
1e730ed96b0b
added conversion to alignmentOrigin and another access method.
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
285 |
leftAlignmentFraction:0 topAlignmentFraction: 0; |
1e730ed96b0b
added conversion to alignmentOrigin and another access method.
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
286 |
yourself |
1e730ed96b0b
added conversion to alignmentOrigin and another access method.
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
287 |
|
1e730ed96b0b
added conversion to alignmentOrigin and another access method.
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
288 |
"Created: 18.4.1997 / 20:08:14 / cg" |
1e730ed96b0b
added conversion to alignmentOrigin and another access method.
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
289 |
! |
1e730ed96b0b
added conversion to alignmentOrigin and another access method.
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
290 |
|
126 | 291 |
fromLiteralArrayEncoding:encoding |
292 |
"read my values from an encoding. |
|
293 |
The encoding is supposed to be of the form: |
|
294 |
(#LayoutOrigin orgOffsX relOrgX orgOffsY relOrgY) |
|
295 |
This is the reverse operation to #literalArrayEncoding." |
|
296 |
||
297 |
leftOffset := encoding at:2. |
|
298 |
leftFraction := encoding at:3. |
|
299 |
topOffset := encoding at:4. |
|
300 |
topFraction := encoding at:5. |
|
301 |
||
302 |
||
303 |
" |
|
304 |
LayoutOrigin new fromLiteralArrayEncoding:#(#LayoutOrigin 70 0 2 0) |
|
305 |
" |
|
306 |
! |
|
307 |
||
308 |
literalArrayEncoding |
|
191 | 309 |
"encode myself as an array, from which a copy of the receiver |
310 |
can be reconstructed with #decodeAsLiteralArray. |
|
126 | 311 |
The encoding is: |
191 | 312 |
(#LayoutOrigin orgOffsX relOrgX orgOffsY relOrgY) |
126 | 313 |
" |
314 |
||
315 |
^ Array |
|
2134 | 316 |
with:self class name |
191 | 317 |
with:leftOffset |
318 |
with:leftFraction |
|
319 |
with:topOffset |
|
320 |
with:topFraction |
|
126 | 321 |
|
322 |
" |
|
323 |
LayoutOrigin new fromLiteralArrayEncoding:#(#LayoutOrigin 70 0 2 0) |
|
324 |
(LayoutOrigin new leftOffset:10; leftFraction:0.2; |
|
191 | 325 |
topOffset:20; topFraction:0.4) literalArrayEncoding |
126 | 326 |
" |
327 |
||
328 |
"Modified: 1.9.1995 / 02:43:48 / claus" |
|
191 | 329 |
"Modified: 22.4.1996 / 13:00:21 / cg" |
126 | 330 |
! ! |
331 |
||
332 |
!LayoutOrigin methodsFor:'initialization'! |
|
333 |
||
334 |
initialize |
|
335 |
leftOffset := topOffset := 0. |
|
336 |
leftFraction := topFraction := 0. |
|
77 | 337 |
! ! |
338 |
||
83 | 339 |
!LayoutOrigin methodsFor:'printing & storing'! |
340 |
||
3016
e2374dddc45f
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2134
diff
changeset
|
341 |
displayOn:aGCOrStream |
700 | 342 |
"return a printed representation of the receiver for displaying" |
343 |
||
3016
e2374dddc45f
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2134
diff
changeset
|
344 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream; |
e2374dddc45f
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2134
diff
changeset
|
345 |
"/ ST/X (and some old ST80's) mean: draw-yourself on a GC. |
e2374dddc45f
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2134
diff
changeset
|
346 |
(aGCOrStream isStream) ifFalse:[ |
e2374dddc45f
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2134
diff
changeset
|
347 |
^ super displayOn:aGCOrStream |
e2374dddc45f
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2134
diff
changeset
|
348 |
]. |
700 | 349 |
|
3016
e2374dddc45f
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2134
diff
changeset
|
350 |
aGCOrStream |
e2374dddc45f
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2134
diff
changeset
|
351 |
nextPutAll:self class name; |
e2374dddc45f
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2134
diff
changeset
|
352 |
nextPutAll:'(l: '. |
e2374dddc45f
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2134
diff
changeset
|
353 |
|
e2374dddc45f
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2134
diff
changeset
|
354 |
leftFraction displayOn:aGCOrStream. |
e2374dddc45f
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2134
diff
changeset
|
355 |
aGCOrStream nextPut:$+. |
e2374dddc45f
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2134
diff
changeset
|
356 |
leftOffset displayOn:aGCOrStream. |
e2374dddc45f
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2134
diff
changeset
|
357 |
aGCOrStream nextPutAll:' t: '. |
e2374dddc45f
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2134
diff
changeset
|
358 |
topFraction displayOn:aGCOrStream. |
e2374dddc45f
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2134
diff
changeset
|
359 |
aGCOrStream nextPut:$+. |
e2374dddc45f
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2134
diff
changeset
|
360 |
topOffset displayOn:aGCOrStream. |
e2374dddc45f
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2134
diff
changeset
|
361 |
aGCOrStream nextPut:$). |
83 | 362 |
! ! |
363 |
||
126 | 364 |
!LayoutOrigin methodsFor:'queries'! |
77 | 365 |
|
415 | 366 |
isLayoutOrigin |
367 |
"return true, if this is a layoutOrigin" |
|
368 |
||
369 |
^ true |
|
370 |
||
371 |
! |
|
372 |
||
126 | 373 |
origin |
374 |
^ leftFraction asFloat @ topFraction asFloat |
|
77 | 375 |
! |
376 |
||
949
0eb888b21192
prefRect may now be a valueHolder or block
Claus Gittinger <cg@exept.de>
parents:
700
diff
changeset
|
377 |
rectangleRelativeTo:superRectangle preferred:prefRectHolder |
229 | 378 |
"compute the rectangle represented by the receiver, |
3794 | 379 |
given the superViews rectangle and the view's preferredExtent." |
229 | 380 |
|
949
0eb888b21192
prefRect may now be a valueHolder or block
Claus Gittinger <cg@exept.de>
parents:
700
diff
changeset
|
381 |
|x y prefRect| |
0eb888b21192
prefRect may now be a valueHolder or block
Claus Gittinger <cg@exept.de>
parents:
700
diff
changeset
|
382 |
|
0eb888b21192
prefRect may now be a valueHolder or block
Claus Gittinger <cg@exept.de>
parents:
700
diff
changeset
|
383 |
prefRect := prefRectHolder value. |
77 | 384 |
|
1039 | 385 |
x := superRectangle left. |
386 |
y := superRectangle top. |
|
387 |
||
388 |
leftOffset notNil ifTrue:[ |
|
389 |
x := x + leftOffset value |
|
77 | 390 |
]. |
1039 | 391 |
topOffset notNil ifTrue:[ |
392 |
y := y + topOffset value |
|
77 | 393 |
]. |
394 |
leftFraction notNil ifTrue:[ |
|
1601 | 395 |
x := x + (superRectangle width * leftFraction value) |
77 | 396 |
]. |
397 |
topFraction notNil ifTrue:[ |
|
1601 | 398 |
y := y + (superRectangle height * topFraction value) |
77 | 399 |
]. |
242 | 400 |
^ Rectangle left:x top:y extent:prefRect extent |
83 | 401 |
|
402 |
" |
|
403 |
|superRect lO| |
|
404 |
||
405 |
superRect := 0@0 corner:100@100. |
|
406 |
lO := (LayoutOrigin new). |
|
407 |
lO leftFraction:0.5; |
|
229 | 408 |
topFraction:0.5. |
83 | 409 |
lO rectangleRelativeTo:superRect preferred:(0@0 corner:30@30) |
410 |
" |
|
229 | 411 |
|
1039 | 412 |
"Modified: / 13.8.1998 / 18:39:49 / cg" |
77 | 413 |
! ! |
100 | 414 |
|
126 | 415 |
!LayoutOrigin class methodsFor:'documentation'! |
100 | 416 |
|
126 | 417 |
version |
3794 | 418 |
^ '$Header$' |
3331 | 419 |
! |
420 |
||
421 |
version_CVS |
|
3794 | 422 |
^ '$Header$' |
100 | 423 |
! ! |
3330 | 424 |