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 |
|
|
176 |
leftFraction:newLeft topFraction:newTop
|
|
177 |
"set leftFraction and topFraction"
|
|
178 |
|
|
179 |
leftFraction := newLeft.
|
|
180 |
topFraction := newTop.
|
|
181 |
!
|
|
182 |
|
|
183 |
leftOffset
|
|
184 |
"return leftOffset"
|
|
185 |
|
|
186 |
^ leftOffset
|
|
187 |
!
|
|
188 |
|
|
189 |
leftOffset:something
|
|
190 |
"set leftOffset"
|
|
191 |
|
|
192 |
leftOffset := something.
|
|
193 |
!
|
|
194 |
|
|
195 |
leftOffset:newLeft topOffset:newTop
|
|
196 |
"set leftOffset and topOffset"
|
|
197 |
|
|
198 |
leftOffset := newLeft.
|
|
199 |
topOffset := newTop.
|
|
200 |
!
|
|
201 |
|
|
202 |
topFraction
|
|
203 |
"return topFraction"
|
|
204 |
|
|
205 |
^ topFraction
|
|
206 |
!
|
|
207 |
|
|
208 |
topFraction:something
|
|
209 |
"set topFraction"
|
|
210 |
|
|
211 |
topFraction := something.
|
|
212 |
!
|
|
213 |
|
|
214 |
topFraction:something offset:o
|
|
215 |
"set topFraction and offset"
|
|
216 |
|
|
217 |
topFraction := something.
|
|
218 |
topOffset := o
|
|
219 |
!
|
|
220 |
|
|
221 |
topOffset
|
|
222 |
"return topOffset"
|
|
223 |
|
|
224 |
^ topOffset
|
|
225 |
!
|
|
226 |
|
|
227 |
topOffset:something
|
|
228 |
"set topOffset"
|
|
229 |
|
|
230 |
topOffset := something.
|
|
231 |
! !
|
|
232 |
|
|
233 |
!LayoutOrigin methodsFor:'converting'!
|
|
234 |
|
|
235 |
fromLiteralArrayEncoding:encoding
|
|
236 |
"read my values from an encoding.
|
|
237 |
The encoding is supposed to be of the form:
|
|
238 |
(#LayoutOrigin orgOffsX relOrgX orgOffsY relOrgY)
|
|
239 |
This is the reverse operation to #literalArrayEncoding."
|
|
240 |
|
|
241 |
leftOffset := encoding at:2.
|
|
242 |
leftFraction := encoding at:3.
|
|
243 |
topOffset := encoding at:4.
|
|
244 |
topFraction := encoding at:5.
|
|
245 |
|
|
246 |
|
|
247 |
"
|
|
248 |
LayoutOrigin new fromLiteralArrayEncoding:#(#LayoutOrigin 70 0 2 0)
|
|
249 |
"
|
|
250 |
!
|
|
251 |
|
|
252 |
literalArrayEncoding
|
191
|
253 |
"encode myself as an array, from which a copy of the receiver
|
|
254 |
can be reconstructed with #decodeAsLiteralArray.
|
126
|
255 |
The encoding is:
|
191
|
256 |
(#LayoutOrigin orgOffsX relOrgX orgOffsY relOrgY)
|
126
|
257 |
"
|
|
258 |
|
|
259 |
^ Array
|
191
|
260 |
with:self class name asSymbol
|
|
261 |
with:leftOffset
|
|
262 |
with:leftFraction
|
|
263 |
with:topOffset
|
|
264 |
with:topFraction
|
126
|
265 |
|
|
266 |
"
|
|
267 |
LayoutOrigin new fromLiteralArrayEncoding:#(#LayoutOrigin 70 0 2 0)
|
|
268 |
(LayoutOrigin new leftOffset:10; leftFraction:0.2;
|
191
|
269 |
topOffset:20; topFraction:0.4) literalArrayEncoding
|
126
|
270 |
"
|
|
271 |
|
|
272 |
"Modified: 1.9.1995 / 02:43:48 / claus"
|
191
|
273 |
"Modified: 22.4.1996 / 13:00:21 / cg"
|
126
|
274 |
! !
|
|
275 |
|
|
276 |
!LayoutOrigin methodsFor:'initialization'!
|
|
277 |
|
|
278 |
initialize
|
|
279 |
leftOffset := topOffset := 0.
|
|
280 |
leftFraction := topFraction := 0.
|
77
|
281 |
! !
|
|
282 |
|
83
|
283 |
!LayoutOrigin methodsFor:'printing & storing'!
|
|
284 |
|
|
285 |
displayString
|
|
286 |
^ (self class name) , '('
|
|
287 |
, 'l: ' , leftFraction displayString
|
|
288 |
, '+' , leftOffset displayString
|
|
289 |
, ' t: ' , topFraction displayString
|
|
290 |
, '+' , topOffset displayString
|
|
291 |
, ')'
|
|
292 |
! !
|
|
293 |
|
126
|
294 |
!LayoutOrigin methodsFor:'queries'!
|
77
|
295 |
|
126
|
296 |
origin
|
|
297 |
^ leftFraction asFloat @ topFraction asFloat
|
77
|
298 |
!
|
|
299 |
|
|
300 |
rectangleRelativeTo:superRectangle preferred:prefRect
|
229
|
301 |
"compute the rectangle represented by the receiver,
|
|
302 |
given the superViews rectangle and the views preferredExtent."
|
|
303 |
|
77
|
304 |
|x y|
|
|
305 |
|
|
306 |
leftOffset isNil ifTrue:[
|
229
|
307 |
x := 0
|
77
|
308 |
] ifFalse:[
|
229
|
309 |
x := leftOffset
|
77
|
310 |
].
|
|
311 |
topOffset isNil ifTrue:[
|
229
|
312 |
y := 0
|
77
|
313 |
] ifFalse:[
|
229
|
314 |
y := topOffset
|
77
|
315 |
].
|
|
316 |
leftFraction notNil ifTrue:[
|
229
|
317 |
x := x + (superRectangle width * leftFraction)
|
77
|
318 |
].
|
|
319 |
topFraction notNil ifTrue:[
|
229
|
320 |
y := y + (superRectangle height * topFraction)
|
77
|
321 |
].
|
242
|
322 |
^ Rectangle left:x top:y extent:prefRect extent
|
83
|
323 |
|
|
324 |
"
|
|
325 |
|superRect lO|
|
|
326 |
|
|
327 |
superRect := 0@0 corner:100@100.
|
|
328 |
lO := (LayoutOrigin new).
|
|
329 |
lO leftFraction:0.5;
|
229
|
330 |
topFraction:0.5.
|
83
|
331 |
lO rectangleRelativeTo:superRect preferred:(0@0 corner:30@30)
|
|
332 |
"
|
229
|
333 |
|
242
|
334 |
"Modified: 8.5.1996 / 20:58:53 / cg"
|
77
|
335 |
! !
|
100
|
336 |
|
126
|
337 |
!LayoutOrigin class methodsFor:'documentation'!
|
100
|
338 |
|
126
|
339 |
version
|
242
|
340 |
^ '$Header: /cvs/stx/stx/libview2/LayoutOrigin.st,v 1.13 1996-05-08 19:07:11 cg Exp $'
|
100
|
341 |
! !
|