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 |
'From Smalltalk/X, Version:2.10.5 on 15-apr-1995 at 12:14:46 pm'!
|
|
14 |
|
|
15 |
Layout subclass:#LayoutOrigin
|
|
16 |
instanceVariableNames:'leftFraction topFraction leftOffset
|
|
17 |
topOffset'
|
|
18 |
classVariableNames:''
|
|
19 |
poolDictionaries:''
|
83
|
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 |
|
|
48 |
See also:
|
|
49 |
LayoutFrame AlignmentOrigin Layout
|
|
50 |
|
|
51 |
Notice: this class was implemented using protocol information
|
|
52 |
from alpha testers - it may not be complete or compatible to
|
|
53 |
the corresponding ST-80 class. If you encounter any incompatibilities,
|
|
54 |
please forward a note to the ST/X team.
|
94
|
55 |
"
|
93
|
56 |
!
|
|
57 |
|
|
58 |
examples
|
|
59 |
"
|
|
60 |
using a LayoutOrigin, to control the top-left origins position of
|
|
61 |
a component (i.e. origin at:0.5@0.5):
|
|
62 |
|
|
63 |
|top button|
|
|
64 |
|
|
65 |
top := StandardSystemView new.
|
|
66 |
top extent:300@300.
|
|
67 |
|
|
68 |
button := Button label:'component'.
|
|
69 |
top add:button in:(LayoutOrigin new
|
|
70 |
leftFraction:0.5;
|
|
71 |
topFraction:0.5).
|
|
72 |
|
|
73 |
top open
|
|
74 |
|
|
75 |
|
|
76 |
like above, but adds an additional offset:
|
|
77 |
(i.e. center of component at:0.5@0.5 OFFSET by 10@20):
|
|
78 |
|
|
79 |
|top button|
|
|
80 |
|
|
81 |
top := StandardSystemView new.
|
|
82 |
top extent:300@300.
|
|
83 |
|
|
84 |
button := Button label:'component'.
|
|
85 |
top add:button in:(LayoutOrigin new
|
|
86 |
leftFraction:0.5;
|
|
87 |
topFraction:0.5;
|
|
88 |
leftOffset:10;
|
|
89 |
topOffset:20).
|
|
90 |
|
|
91 |
top open
|
|
92 |
"
|
94
|
93 |
!
|
93
|
94 |
|
88
|
95 |
version
|
|
96 |
"
|
100
|
97 |
$Header: /cvs/stx/stx/libview2/LayoutOrigin.st,v 1.7 1995-09-09 02:29:45 claus Exp $
|
88
|
98 |
"
|
|
99 |
! !
|
|
100 |
|
77
|
101 |
!LayoutOrigin class methodsFor:'instance creation'!
|
|
102 |
|
|
103 |
fractionalFromPoint:aPoint
|
93
|
104 |
"given a point, create a layoutOrigin representing the same
|
|
105 |
relative origin."
|
|
106 |
|
83
|
107 |
^ (self new) leftFraction:aPoint x topFraction:aPoint y
|
93
|
108 |
|
|
109 |
"
|
|
110 |
LayoutOrigin fractionalFromPoint:0.5@0.5
|
|
111 |
"
|
77
|
112 |
!
|
|
113 |
|
|
114 |
offsetFromPoint:aPoint
|
93
|
115 |
"given a point, create a layoutOrigin representing the same
|
|
116 |
absolute (pixel) origin."
|
|
117 |
|
83
|
118 |
^ self new leftOffset:aPoint x topOffset:aPoint y
|
93
|
119 |
|
|
120 |
"
|
|
121 |
LayoutOrigin offsetFromPoint:100@100
|
|
122 |
"
|
77
|
123 |
!
|
|
124 |
|
|
125 |
fromPoint:aPoint
|
|
126 |
"return a new LayoutOrigin from aPoint.
|
|
127 |
If the coordinates are between 0 and 1, take
|
|
128 |
them as fractional parts (relative to superview).
|
|
129 |
Otherwise, treat them as absolute offsets."
|
|
130 |
|
|
131 |
|x y layout|
|
|
132 |
|
|
133 |
x := aPoint x.
|
|
134 |
y := aPoint y.
|
|
135 |
layout := self new.
|
|
136 |
((x between:0 and:1)
|
|
137 |
and:[y between:0 and:1]) ifTrue:[
|
|
138 |
layout leftFraction:x topFraction:y
|
|
139 |
] ifFalse:[
|
|
140 |
layout leftOffset:x topOffset:y
|
|
141 |
].
|
|
142 |
^ layout
|
93
|
143 |
|
|
144 |
"
|
|
145 |
LayoutOrigin fromPoint:100@100
|
|
146 |
LayoutOrigin fromPoint:0.5@0.5
|
|
147 |
LayoutOrigin fromPoint:0.5@100
|
|
148 |
"
|
77
|
149 |
! !
|
|
150 |
|
83
|
151 |
!LayoutOrigin methodsFor:'printing & storing'!
|
|
152 |
|
|
153 |
displayString
|
|
154 |
^ (self class name) , '('
|
|
155 |
, 'l: ' , leftFraction displayString
|
|
156 |
, '+' , leftOffset displayString
|
|
157 |
, ' t: ' , topFraction displayString
|
|
158 |
, '+' , topOffset displayString
|
|
159 |
, ')'
|
|
160 |
! !
|
|
161 |
|
77
|
162 |
!LayoutOrigin methodsFor:'accessing'!
|
|
163 |
|
|
164 |
leftFraction:something
|
|
165 |
"set leftFraction"
|
|
166 |
|
|
167 |
leftFraction := something.
|
|
168 |
!
|
|
169 |
|
|
170 |
leftFraction
|
|
171 |
"return leftFraction"
|
|
172 |
|
|
173 |
^ leftFraction
|
|
174 |
!
|
|
175 |
|
|
176 |
leftOffset:something
|
|
177 |
"set leftOffset"
|
|
178 |
|
|
179 |
leftOffset := something.
|
|
180 |
!
|
|
181 |
|
|
182 |
leftOffset
|
|
183 |
"return leftOffset"
|
|
184 |
|
|
185 |
^ leftOffset
|
|
186 |
!
|
|
187 |
|
|
188 |
leftFraction:something offset:o
|
|
189 |
"set leftFraction and offset"
|
|
190 |
|
|
191 |
leftFraction := something.
|
|
192 |
leftOffset := o
|
|
193 |
!
|
|
194 |
|
|
195 |
topFraction:something
|
|
196 |
"set topFraction"
|
|
197 |
|
|
198 |
topFraction := something.
|
|
199 |
!
|
|
200 |
|
|
201 |
topFraction
|
|
202 |
"return topFraction"
|
|
203 |
|
|
204 |
^ topFraction
|
|
205 |
!
|
|
206 |
|
|
207 |
topOffset:something
|
|
208 |
"set topOffset"
|
|
209 |
|
|
210 |
topOffset := something.
|
|
211 |
!
|
|
212 |
|
|
213 |
topOffset
|
|
214 |
"return topOffset"
|
|
215 |
|
|
216 |
^ topOffset
|
|
217 |
!
|
|
218 |
|
|
219 |
topFraction:something offset:o
|
|
220 |
"set topFraction and offset"
|
|
221 |
|
|
222 |
topFraction := something.
|
|
223 |
topOffset := o
|
83
|
224 |
!
|
|
225 |
|
|
226 |
leftFraction:newLeft topFraction:newTop
|
|
227 |
"set leftFraction and topFraction"
|
|
228 |
|
|
229 |
leftFraction := newLeft.
|
|
230 |
topFraction := newTop.
|
|
231 |
!
|
|
232 |
|
|
233 |
leftOffset:newLeft topOffset:newTop
|
|
234 |
"set leftOffset and topOffset"
|
|
235 |
|
|
236 |
leftOffset := newLeft.
|
|
237 |
topOffset := newTop.
|
77
|
238 |
! !
|
|
239 |
|
|
240 |
!LayoutOrigin methodsFor:'queries'!
|
|
241 |
|
|
242 |
rectangleRelativeTo:superRectangle preferred:prefRect
|
|
243 |
|x y|
|
|
244 |
|
|
245 |
leftOffset isNil ifTrue:[
|
|
246 |
x := 0
|
|
247 |
] ifFalse:[
|
|
248 |
x := leftOffset
|
|
249 |
].
|
|
250 |
topOffset isNil ifTrue:[
|
|
251 |
y := 0
|
|
252 |
] ifFalse:[
|
|
253 |
y := topOffset
|
|
254 |
].
|
|
255 |
leftFraction notNil ifTrue:[
|
83
|
256 |
x := x + (superRectangle width * leftFraction)
|
77
|
257 |
].
|
|
258 |
topFraction notNil ifTrue:[
|
83
|
259 |
y := y + (superRectangle height * topFraction)
|
77
|
260 |
].
|
|
261 |
^ Rectangle origin:x@y extent:prefRect extent
|
83
|
262 |
|
|
263 |
"
|
|
264 |
|superRect lO|
|
|
265 |
|
|
266 |
superRect := 0@0 corner:100@100.
|
|
267 |
lO := (LayoutOrigin new).
|
|
268 |
lO leftFraction:0.5;
|
|
269 |
topFraction:0.5.
|
|
270 |
lO rectangleRelativeTo:superRect preferred:(0@0 corner:30@30)
|
|
271 |
"
|
77
|
272 |
!
|
|
273 |
|
|
274 |
origin
|
|
275 |
^ leftFraction asFloat @ topFraction asFloat
|
|
276 |
! !
|
|
277 |
|
|
278 |
!LayoutOrigin methodsFor:'initialization'!
|
|
279 |
|
|
280 |
initialize
|
|
281 |
leftOffset := topOffset := 0.
|
|
282 |
leftFraction := topFraction := 0.
|
|
283 |
! !
|
100
|
284 |
|
|
285 |
!LayoutOrigin methodsFor:'converting'!
|
|
286 |
|
|
287 |
literalArrayEncoding
|
|
288 |
"encode myself as an array.
|
|
289 |
The encoding is:
|
|
290 |
(#LayoutOrigin orgOffsX relOrgX orgOffsY relOrgY)
|
|
291 |
"
|
|
292 |
|
|
293 |
^ Array
|
|
294 |
with:self class name asSymbol
|
|
295 |
with:leftOffset
|
|
296 |
with:leftFraction
|
|
297 |
with:topOffset
|
|
298 |
with:topFraction
|
|
299 |
|
|
300 |
"
|
|
301 |
LayoutOrigin new fromLiteralArrayEncoding:#(#LayoutOrigin 70 0 2 0)
|
|
302 |
(LayoutOrigin new leftOffset:10; leftFraction:0.2;
|
|
303 |
topOffset:20; topFraction:0.4) literalArrayEncoding
|
|
304 |
"
|
|
305 |
|
|
306 |
"Modified: 1.9.1995 / 02:43:48 / claus"
|
|
307 |
!
|
|
308 |
|
|
309 |
fromLiteralArrayEncoding:encoding
|
|
310 |
"read my values from an encoding.
|
|
311 |
The encoding is supposed to be of the form:
|
|
312 |
(#LayoutOrigin orgOffsX relOrgX orgOffsY relOrgY)
|
|
313 |
This is the reverse operation to #literalArrayEncoding."
|
|
314 |
|
|
315 |
leftOffset := encoding at:2.
|
|
316 |
leftFraction := encoding at:3.
|
|
317 |
topOffset := encoding at:4.
|
|
318 |
topFraction := encoding at:5.
|
|
319 |
|
|
320 |
|
|
321 |
"
|
|
322 |
LayoutOrigin new fromLiteralArrayEncoding:#(#LayoutOrigin 70 0 2 0)
|
|
323 |
"
|
|
324 |
! !
|
|
325 |
|