author | Claus Gittinger <cg@exept.de> |
Sat, 11 Nov 1995 17:05:49 +0100 | |
changeset 114 | e577a2f332d0 |
parent 100 | 0300e64bb883 |
child 126 | 25df58661f32 |
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 |
'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 |
114
e577a2f332d0
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
100
diff
changeset
|
96 |
^ '$Header: /cvs/stx/stx/libview2/LayoutOrigin.st,v 1.8 1995-11-11 16:04:40 cg Exp $' |
88 | 97 |
! ! |
98 |
||
77 | 99 |
!LayoutOrigin class methodsFor:'instance creation'! |
100 |
||
101 |
fractionalFromPoint:aPoint |
|
93 | 102 |
"given a point, create a layoutOrigin representing the same |
103 |
relative origin." |
|
104 |
||
83 | 105 |
^ (self new) leftFraction:aPoint x topFraction:aPoint y |
93 | 106 |
|
107 |
" |
|
108 |
LayoutOrigin fractionalFromPoint:0.5@0.5 |
|
109 |
" |
|
77 | 110 |
! |
111 |
||
112 |
offsetFromPoint:aPoint |
|
93 | 113 |
"given a point, create a layoutOrigin representing the same |
114 |
absolute (pixel) origin." |
|
115 |
||
83 | 116 |
^ self new leftOffset:aPoint x topOffset:aPoint y |
93 | 117 |
|
118 |
" |
|
119 |
LayoutOrigin offsetFromPoint:100@100 |
|
120 |
" |
|
77 | 121 |
! |
122 |
||
123 |
fromPoint:aPoint |
|
124 |
"return a new LayoutOrigin from aPoint. |
|
125 |
If the coordinates are between 0 and 1, take |
|
126 |
them as fractional parts (relative to superview). |
|
127 |
Otherwise, treat them as absolute offsets." |
|
128 |
||
129 |
|x y layout| |
|
130 |
||
131 |
x := aPoint x. |
|
132 |
y := aPoint y. |
|
133 |
layout := self new. |
|
134 |
((x between:0 and:1) |
|
135 |
and:[y between:0 and:1]) ifTrue:[ |
|
136 |
layout leftFraction:x topFraction:y |
|
137 |
] ifFalse:[ |
|
138 |
layout leftOffset:x topOffset:y |
|
139 |
]. |
|
140 |
^ layout |
|
93 | 141 |
|
142 |
" |
|
143 |
LayoutOrigin fromPoint:100@100 |
|
144 |
LayoutOrigin fromPoint:0.5@0.5 |
|
145 |
LayoutOrigin fromPoint:0.5@100 |
|
146 |
" |
|
77 | 147 |
! ! |
148 |
||
83 | 149 |
!LayoutOrigin methodsFor:'printing & storing'! |
150 |
||
151 |
displayString |
|
152 |
^ (self class name) , '(' |
|
153 |
, 'l: ' , leftFraction displayString |
|
154 |
, '+' , leftOffset displayString |
|
155 |
, ' t: ' , topFraction displayString |
|
156 |
, '+' , topOffset displayString |
|
157 |
, ')' |
|
158 |
! ! |
|
159 |
||
77 | 160 |
!LayoutOrigin methodsFor:'accessing'! |
161 |
||
162 |
leftFraction:something |
|
163 |
"set leftFraction" |
|
164 |
||
165 |
leftFraction := something. |
|
166 |
! |
|
167 |
||
168 |
leftFraction |
|
169 |
"return leftFraction" |
|
170 |
||
171 |
^ leftFraction |
|
172 |
! |
|
173 |
||
174 |
leftOffset:something |
|
175 |
"set leftOffset" |
|
176 |
||
177 |
leftOffset := something. |
|
178 |
! |
|
179 |
||
180 |
leftOffset |
|
181 |
"return leftOffset" |
|
182 |
||
183 |
^ leftOffset |
|
184 |
! |
|
185 |
||
186 |
leftFraction:something offset:o |
|
187 |
"set leftFraction and offset" |
|
188 |
||
189 |
leftFraction := something. |
|
190 |
leftOffset := o |
|
191 |
! |
|
192 |
||
193 |
topFraction:something |
|
194 |
"set topFraction" |
|
195 |
||
196 |
topFraction := something. |
|
197 |
! |
|
198 |
||
199 |
topFraction |
|
200 |
"return topFraction" |
|
201 |
||
202 |
^ topFraction |
|
203 |
! |
|
204 |
||
205 |
topOffset:something |
|
206 |
"set topOffset" |
|
207 |
||
208 |
topOffset := something. |
|
209 |
! |
|
210 |
||
211 |
topOffset |
|
212 |
"return topOffset" |
|
213 |
||
214 |
^ topOffset |
|
215 |
! |
|
216 |
||
217 |
topFraction:something offset:o |
|
218 |
"set topFraction and offset" |
|
219 |
||
220 |
topFraction := something. |
|
221 |
topOffset := o |
|
83 | 222 |
! |
223 |
||
224 |
leftFraction:newLeft topFraction:newTop |
|
225 |
"set leftFraction and topFraction" |
|
226 |
||
227 |
leftFraction := newLeft. |
|
228 |
topFraction := newTop. |
|
229 |
! |
|
230 |
||
231 |
leftOffset:newLeft topOffset:newTop |
|
232 |
"set leftOffset and topOffset" |
|
233 |
||
234 |
leftOffset := newLeft. |
|
235 |
topOffset := newTop. |
|
77 | 236 |
! ! |
237 |
||
238 |
!LayoutOrigin methodsFor:'queries'! |
|
239 |
||
240 |
rectangleRelativeTo:superRectangle preferred:prefRect |
|
241 |
|x y| |
|
242 |
||
243 |
leftOffset isNil ifTrue:[ |
|
244 |
x := 0 |
|
245 |
] ifFalse:[ |
|
246 |
x := leftOffset |
|
247 |
]. |
|
248 |
topOffset isNil ifTrue:[ |
|
249 |
y := 0 |
|
250 |
] ifFalse:[ |
|
251 |
y := topOffset |
|
252 |
]. |
|
253 |
leftFraction notNil ifTrue:[ |
|
83 | 254 |
x := x + (superRectangle width * leftFraction) |
77 | 255 |
]. |
256 |
topFraction notNil ifTrue:[ |
|
83 | 257 |
y := y + (superRectangle height * topFraction) |
77 | 258 |
]. |
259 |
^ Rectangle origin:x@y extent:prefRect extent |
|
83 | 260 |
|
261 |
" |
|
262 |
|superRect lO| |
|
263 |
||
264 |
superRect := 0@0 corner:100@100. |
|
265 |
lO := (LayoutOrigin new). |
|
266 |
lO leftFraction:0.5; |
|
267 |
topFraction:0.5. |
|
268 |
lO rectangleRelativeTo:superRect preferred:(0@0 corner:30@30) |
|
269 |
" |
|
77 | 270 |
! |
271 |
||
272 |
origin |
|
273 |
^ leftFraction asFloat @ topFraction asFloat |
|
274 |
! ! |
|
275 |
||
276 |
!LayoutOrigin methodsFor:'initialization'! |
|
277 |
||
278 |
initialize |
|
279 |
leftOffset := topOffset := 0. |
|
280 |
leftFraction := topFraction := 0. |
|
281 |
! ! |
|
100 | 282 |
|
283 |
!LayoutOrigin methodsFor:'converting'! |
|
284 |
||
285 |
literalArrayEncoding |
|
286 |
"encode myself as an array. |
|
287 |
The encoding is: |
|
288 |
(#LayoutOrigin orgOffsX relOrgX orgOffsY relOrgY) |
|
289 |
" |
|
290 |
||
291 |
^ Array |
|
292 |
with:self class name asSymbol |
|
293 |
with:leftOffset |
|
294 |
with:leftFraction |
|
295 |
with:topOffset |
|
296 |
with:topFraction |
|
297 |
||
298 |
" |
|
299 |
LayoutOrigin new fromLiteralArrayEncoding:#(#LayoutOrigin 70 0 2 0) |
|
300 |
(LayoutOrigin new leftOffset:10; leftFraction:0.2; |
|
301 |
topOffset:20; topFraction:0.4) literalArrayEncoding |
|
302 |
" |
|
303 |
||
304 |
"Modified: 1.9.1995 / 02:43:48 / claus" |
|
305 |
! |
|
306 |
||
307 |
fromLiteralArrayEncoding:encoding |
|
308 |
"read my values from an encoding. |
|
309 |
The encoding is supposed to be of the form: |
|
310 |
(#LayoutOrigin orgOffsX relOrgX orgOffsY relOrgY) |
|
311 |
This is the reverse operation to #literalArrayEncoding." |
|
312 |
||
313 |
leftOffset := encoding at:2. |
|
314 |
leftFraction := encoding at:3. |
|
315 |
topOffset := encoding at:4. |
|
316 |
topFraction := encoding at:5. |
|
317 |
||
318 |
||
319 |
" |
|
320 |
LayoutOrigin new fromLiteralArrayEncoding:#(#LayoutOrigin 70 0 2 0) |
|
321 |
" |
|
322 |
! ! |
|
323 |