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 |
|
83
|
13 |
LayoutOrigin subclass:#AlignmentOrigin
|
191
|
14 |
instanceVariableNames:'leftAlignmentFraction topAlignmentFraction'
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Graphics-Geometry'
|
83
|
18 |
!
|
|
19 |
|
88
|
20 |
!AlignmentOrigin 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. Like a LayoutOrigin, it controls the components origin
|
|
41 |
via a relative part plus offset. However, in contrast to LayoutOrigin
|
|
42 |
(in which the top-left corner is specified by fraction+offset, here any
|
|
43 |
reference point within the component is positioned.
|
|
44 |
The reference point itself is specified as fraction of the components size.
|
|
45 |
|
229
|
46 |
Notice:
|
|
47 |
this class was implemented using protocol information
|
|
48 |
from alpha testers - it may not be complete or compatible to
|
|
49 |
the corresponding ST-80 class.
|
|
50 |
If you encounter any incompatibilities, please forward a note
|
|
51 |
describing the incompatibility verbal (i.e. no code) to the ST/X team.
|
216
|
52 |
|
219
|
53 |
[author:]
|
|
54 |
Claus Gittinger
|
|
55 |
|
216
|
56 |
[See also:]
|
|
57 |
LayoutOrigin LayoutFrame Layout
|
|
58 |
View
|
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 ....
|
|
66 |
|
93
|
67 |
using a LayoutOrigin, to control the top-left origins position of
|
|
68 |
a component (i.e. origin at:0.5@0.5):
|
229
|
69 |
[exBegin]
|
|
70 |
|top button|
|
93
|
71 |
|
229
|
72 |
top := StandardSystemView new.
|
|
73 |
top extent:300@300.
|
93
|
74 |
|
229
|
75 |
button := Button label:'component'.
|
|
76 |
top add:button in:(LayoutOrigin new
|
|
77 |
leftFraction:0.5;
|
|
78 |
topFraction:0.5).
|
93
|
79 |
|
229
|
80 |
top open
|
|
81 |
[exEnd]
|
93
|
82 |
|
|
83 |
|
|
84 |
using an AlignmentOrigin, to control the centers position of
|
|
85 |
a component (i.e. center of component at:0.5@0.5):
|
229
|
86 |
[exBegin]
|
|
87 |
|top button|
|
93
|
88 |
|
229
|
89 |
top := StandardSystemView new.
|
|
90 |
top extent:300@300.
|
93
|
91 |
|
229
|
92 |
button := Button label:'component'.
|
|
93 |
top add:button in:(AlignmentOrigin new
|
|
94 |
leftFraction:0.5;
|
|
95 |
topFraction:0.5;
|
|
96 |
leftAlignmentFraction:0.5;
|
|
97 |
topAlignmentFraction:0.5).
|
93
|
98 |
|
229
|
99 |
top open
|
|
100 |
[exEnd]
|
93
|
101 |
|
|
102 |
|
|
103 |
using an AlignmentOrigin, to control the bottom-right position of
|
|
104 |
a component (i.e. bottom-right of component at:0.5@0.5):
|
229
|
105 |
[exBegin]
|
|
106 |
|top button|
|
93
|
107 |
|
229
|
108 |
top := StandardSystemView new.
|
|
109 |
top extent:300@300.
|
93
|
110 |
|
229
|
111 |
button := Button label:'component'.
|
|
112 |
top add:button in:(AlignmentOrigin new
|
|
113 |
leftFraction:0.5;
|
|
114 |
topFraction:0.5;
|
|
115 |
leftAlignmentFraction:1.0;
|
|
116 |
topAlignmentFraction:1.0).
|
93
|
117 |
|
229
|
118 |
top open
|
|
119 |
[exEnd]
|
243
|
120 |
|
|
121 |
|
|
122 |
four buttons around relative 0.75@0.75:
|
|
123 |
[exBegin]
|
|
124 |
|top button|
|
|
125 |
|
|
126 |
top := StandardSystemView new.
|
|
127 |
top extent:300@300.
|
|
128 |
|
|
129 |
button := Button label:'button1'.
|
|
130 |
top add:button in:(AlignmentOrigin new
|
|
131 |
leftFraction:0.75;
|
|
132 |
topFraction:0.75;
|
|
133 |
leftAlignmentFraction:1.0;
|
|
134 |
topAlignmentFraction:1.0).
|
|
135 |
|
|
136 |
button := Button label:'button2'.
|
|
137 |
top add:button in:(AlignmentOrigin new
|
|
138 |
leftFraction:0.75;
|
|
139 |
topFraction:0.75;
|
|
140 |
leftAlignmentFraction:0.0;
|
|
141 |
topAlignmentFraction:1.0).
|
|
142 |
|
|
143 |
button := Button label:'button3'.
|
|
144 |
top add:button in:(AlignmentOrigin new
|
|
145 |
leftFraction:0.75;
|
|
146 |
topFraction:0.75;
|
244
|
147 |
leftAlignmentFraction:1.0;
|
243
|
148 |
topAlignmentFraction:0.0).
|
|
149 |
|
|
150 |
button := Button label:'button4'.
|
|
151 |
top add:button in:(AlignmentOrigin new
|
|
152 |
leftFraction:0.75;
|
|
153 |
topFraction:0.75;
|
244
|
154 |
leftAlignmentFraction:0.0;
|
243
|
155 |
topAlignmentFraction:0.0).
|
|
156 |
top open
|
|
157 |
[exEnd]
|
93
|
158 |
"
|
88
|
159 |
! !
|
|
160 |
|
83
|
161 |
!AlignmentOrigin methodsFor:'accessing'!
|
|
162 |
|
126
|
163 |
leftAlignmentFraction
|
|
164 |
"return leftAlignmentFraction"
|
|
165 |
|
|
166 |
^ leftAlignmentFraction
|
|
167 |
!
|
|
168 |
|
83
|
169 |
leftAlignmentFraction:something
|
|
170 |
"set leftAlignmentFraction"
|
|
171 |
|
|
172 |
leftAlignmentFraction := something.
|
|
173 |
!
|
|
174 |
|
544
|
175 |
leftAlignmentFraction:lF topAlignmentFraction:tF
|
|
176 |
"set both leftAlignmentFraction and topAlignmentFraction"
|
|
177 |
|
|
178 |
leftAlignmentFraction := lF.
|
|
179 |
topAlignmentFraction := tF
|
|
180 |
|
|
181 |
"Created: 18.4.1997 / 20:06:02 / cg"
|
|
182 |
!
|
|
183 |
|
126
|
184 |
topAlignmentFraction
|
|
185 |
"return topAlignmentFraction"
|
83
|
186 |
|
419
|
187 |
^ topAlignmentFraction
|
83
|
188 |
!
|
|
189 |
|
|
190 |
topAlignmentFraction:something
|
|
191 |
"set topAlignmentFraction"
|
|
192 |
|
|
193 |
topAlignmentFraction := something.
|
126
|
194 |
! !
|
|
195 |
|
|
196 |
!AlignmentOrigin methodsFor:'converting'!
|
|
197 |
|
|
198 |
fromLiteralArrayEncoding:encoding
|
|
199 |
"read my values from an encoding.
|
|
200 |
The encoding is supposed to be of the form:
|
|
201 |
(AlignmentOrigin orgOffsX relOrgX orgOffsY relOrgY leftAlignFract topAlignFract)"
|
|
202 |
|
|
203 |
leftOffset := encoding at:2.
|
|
204 |
leftFraction := encoding at:3.
|
|
205 |
topOffset := encoding at:4.
|
|
206 |
topFraction := encoding at:5.
|
|
207 |
leftAlignmentFraction := encoding at:6.
|
|
208 |
topAlignmentFraction := encoding at:7.
|
|
209 |
|
|
210 |
|
|
211 |
"
|
|
212 |
AlignmentOrigin new fromLiteralArrayEncoding:#(#AlignmentOrigin 70 0 2 0 0.5 0.25)
|
|
213 |
"
|
|
214 |
|
|
215 |
"Modified: 1.9.1995 / 02:23:53 / claus"
|
83
|
216 |
!
|
|
217 |
|
126
|
218 |
literalArrayEncoding
|
191
|
219 |
"encode myself as an array, from which a copy of the receiver
|
|
220 |
can be reconstructed with #decodeAsLiteralArray.
|
126
|
221 |
The encoding is:
|
191
|
222 |
(#AlignmentOrigin orgOffsX relOrgX orgOffsY relOrgY leftAlignFract topAlignFract)"
|
83
|
223 |
|
126
|
224 |
^ super literalArrayEncoding
|
|
225 |
, (Array
|
191
|
226 |
with:leftAlignmentFraction
|
|
227 |
with:topAlignmentFraction)
|
126
|
228 |
|
|
229 |
"Modified: 1.9.1995 / 02:43:35 / claus"
|
191
|
230 |
"Modified: 22.4.1996 / 12:59:56 / cg"
|
126
|
231 |
! !
|
|
232 |
|
|
233 |
!AlignmentOrigin methodsFor:'initialization'!
|
|
234 |
|
|
235 |
initialize
|
|
236 |
super initialize.
|
|
237 |
leftAlignmentFraction := topAlignmentFraction := 0.
|
83
|
238 |
! !
|
|
239 |
|
|
240 |
!AlignmentOrigin methodsFor:'printing & storing'!
|
|
241 |
|
|
242 |
displayString
|
379
|
243 |
"return a printed representation of the receiver for displaying"
|
|
244 |
|
413
|
245 |
^ self class name , '('
|
379
|
246 |
, 'l: ' , leftFraction displayString
|
|
247 |
, '+' , leftOffset displayString
|
|
248 |
, ' t: ' , topFraction displayString
|
|
249 |
, '+' , topOffset displayString
|
|
250 |
, ' a: ' , leftAlignmentFraction displayString
|
|
251 |
, '@' , topAlignmentFraction displayString
|
|
252 |
, ')'
|
|
253 |
|
|
254 |
"Modified: 22.1.1997 / 11:58:38 / cg"
|
83
|
255 |
! !
|
|
256 |
|
|
257 |
!AlignmentOrigin methodsFor:'queries'!
|
|
258 |
|
414
|
259 |
isAlignmentOrigin
|
|
260 |
"return true, if this is an alignmentOrigin"
|
|
261 |
|
|
262 |
^ true
|
|
263 |
|
|
264 |
|
|
265 |
!
|
|
266 |
|
83
|
267 |
rectangleRelativeTo:superRectangle preferred:prefRect
|
229
|
268 |
"compute the rectangle represented by the receiver,
|
|
269 |
given the superViews rectangle and the views preferredExtent."
|
|
270 |
|
83
|
271 |
|x y|
|
|
272 |
|
|
273 |
leftOffset isNil ifTrue:[
|
229
|
274 |
x := 0
|
83
|
275 |
] ifFalse:[
|
229
|
276 |
x := leftOffset
|
83
|
277 |
].
|
|
278 |
topOffset isNil ifTrue:[
|
229
|
279 |
y := 0
|
83
|
280 |
] ifFalse:[
|
229
|
281 |
y := topOffset
|
83
|
282 |
].
|
|
283 |
leftFraction notNil ifTrue:[
|
229
|
284 |
x := x + (superRectangle width * leftFraction)
|
83
|
285 |
].
|
|
286 |
topFraction notNil ifTrue:[
|
229
|
287 |
y := y + (superRectangle height * topFraction)
|
83
|
288 |
].
|
|
289 |
leftAlignmentFraction ~~ 0 ifTrue:[
|
229
|
290 |
x := x - (prefRect width * leftAlignmentFraction)
|
83
|
291 |
].
|
|
292 |
topAlignmentFraction ~~ 0 ifTrue:[
|
229
|
293 |
y := y - (prefRect height * topAlignmentFraction)
|
83
|
294 |
].
|
242
|
295 |
^ Rectangle left:x top:y extent:prefRect extent
|
83
|
296 |
|
|
297 |
"
|
|
298 |
|superRect aO|
|
|
299 |
|
|
300 |
superRect := 0@0 corner:100@100.
|
|
301 |
aO := (AlignmentOrigin new).
|
|
302 |
aO leftFraction:0.5;
|
229
|
303 |
topFraction:0.5;
|
|
304 |
leftAlignmentFraction:0.5;
|
|
305 |
topAlignmentFraction:0.5.
|
83
|
306 |
aO rectangleRelativeTo:superRect preferred:(0@0 corner:30@30)
|
|
307 |
"
|
229
|
308 |
|
242
|
309 |
"Modified: 8.5.1996 / 20:57:09 / cg"
|
83
|
310 |
! !
|
|
311 |
|
126
|
312 |
!AlignmentOrigin class methodsFor:'documentation'!
|
100
|
313 |
|
126
|
314 |
version
|
544
|
315 |
^ '$Header: /cvs/stx/stx/libview2/Attic/AlignOrg.st,v 1.20 1997-04-18 18:11:06 cg Exp $'
|
100
|
316 |
! !
|