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