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