author | Claus Gittinger <cg@exept.de> |
Thu, 24 Oct 2002 21:16:06 +0200 | |
changeset 1646 | da8d044c7c0d |
parent 1039 | 4095e7721dad |
child 3017 | 23ca648eacd9 |
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 |
||
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: |
742 | 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:] |
742 | 54 |
Claus Gittinger |
219 | 55 |
|
216 | 56 |
[See also:] |
742 | 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): |
|
742 | 69 |
[exBegin] |
70 |
|top button| |
|
93 | 71 |
|
742 | 72 |
top := StandardSystemView new. |
73 |
top extent:300@300. |
|
93 | 74 |
|
742 | 75 |
button := Button label:'component'. |
76 |
top add:button in:(LayoutOrigin new |
|
77 |
leftFraction:0.5; |
|
78 |
topFraction:0.5). |
|
93 | 79 |
|
742 | 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): |
|
742 | 86 |
[exBegin] |
87 |
|top button| |
|
93 | 88 |
|
742 | 89 |
top := StandardSystemView new. |
90 |
top extent:300@300. |
|
93 | 91 |
|
742 | 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 |
|
742 | 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): |
|
742 | 105 |
[exBegin] |
106 |
|top button| |
|
93 | 107 |
|
742 | 108 |
top := StandardSystemView new. |
109 |
top extent:300@300. |
|
93 | 110 |
|
742 | 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 |
|
742 | 118 |
top open |
119 |
[exEnd] |
|
243 | 120 |
|
121 |
||
122 |
four buttons around relative 0.75@0.75: |
|
742 | 123 |
[exBegin] |
124 |
|top button| |
|
243 | 125 |
|
742 | 126 |
top := StandardSystemView new. |
127 |
top extent:300@300. |
|
243 | 128 |
|
742 | 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). |
|
243 | 135 |
|
742 | 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). |
|
243 | 142 |
|
742 | 143 |
button := Button label:'button3'. |
144 |
top add:button in:(AlignmentOrigin new |
|
145 |
leftFraction:0.75; |
|
146 |
topFraction:0.75; |
|
147 |
leftAlignmentFraction:1.0; |
|
148 |
topAlignmentFraction:0.0). |
|
243 | 149 |
|
742 | 150 |
button := Button label:'button4'. |
151 |
top add:button in:(AlignmentOrigin new |
|
152 |
leftFraction:0.75; |
|
153 |
topFraction:0.75; |
|
154 |
leftAlignmentFraction:0.0; |
|
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 |
||
742 | 198 |
fromLiteralArrayEncoding:encodingArray |
126 | 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 |
||
742 | 203 |
leftOffset := encodingArray at:2. |
204 |
leftFraction := encodingArray at:3. |
|
205 |
topOffset := encodingArray at:4. |
|
206 |
topFraction := encodingArray at:5. |
|
207 |
leftAlignmentFraction := encodingArray at:6. |
|
208 |
topAlignmentFraction := encodingArray at:7. |
|
126 | 209 |
|
210 |
" |
|
211 |
AlignmentOrigin new fromLiteralArrayEncoding:#(#AlignmentOrigin 70 0 2 0 0.5 0.25) |
|
212 |
" |
|
213 |
||
742 | 214 |
"Modified: / 1.9.1995 / 02:23:53 / claus" |
215 |
"Modified: / 16.11.1997 / 23:04:16 / cg" |
|
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: |
742 | 222 |
(#AlignmentOrigin orgOffsX relOrgX orgOffsY relOrgY leftAlignFract topAlignFract)" |
83 | 223 |
|
126 | 224 |
^ super literalArrayEncoding |
225 |
, (Array |
|
742 | 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 , '(' |
742 | 246 |
, 'l: ' , leftFraction displayString |
247 |
, '+' , leftOffset displayString |
|
248 |
, ' t: ' , topFraction displayString |
|
249 |
, '+' , topOffset displayString |
|
250 |
, ' a: ' , leftAlignmentFraction displayString |
|
251 |
, '@' , topAlignmentFraction displayString |
|
252 |
, ')' |
|
379 | 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 |
||
948
50ce6c646929
prefRect may now be a valueHolder or block.
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
267 |
rectangleRelativeTo:superRectangle preferred:prefRectHolder |
229 | 268 |
"compute the rectangle represented by the receiver, |
269 |
given the superViews rectangle and the views preferredExtent." |
|
270 |
||
948
50ce6c646929
prefRect may now be a valueHolder or block.
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
271 |
|x y prefRect| |
50ce6c646929
prefRect may now be a valueHolder or block.
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
272 |
|
50ce6c646929
prefRect may now be a valueHolder or block.
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
273 |
prefRect := prefRectHolder value. |
83 | 274 |
|
1039 | 275 |
x := superRectangle left. |
276 |
y := superRectangle top. |
|
277 |
||
278 |
leftOffset notNil ifTrue:[ |
|
279 |
x := x + leftOffset value |
|
83 | 280 |
]. |
1039 | 281 |
topOffset notNil ifTrue:[ |
282 |
y := y + topOffset value |
|
83 | 283 |
]. |
284 |
leftFraction notNil ifTrue:[ |
|
948
50ce6c646929
prefRect may now be a valueHolder or block.
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
285 |
x := x + (superRectangle width * leftFraction value) |
83 | 286 |
]. |
287 |
topFraction notNil ifTrue:[ |
|
948
50ce6c646929
prefRect may now be a valueHolder or block.
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
288 |
y := y + (superRectangle height * topFraction value) |
83 | 289 |
]. |
290 |
leftAlignmentFraction ~~ 0 ifTrue:[ |
|
948
50ce6c646929
prefRect may now be a valueHolder or block.
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
291 |
x := x - (prefRect width * leftAlignmentFraction value) |
83 | 292 |
]. |
293 |
topAlignmentFraction ~~ 0 ifTrue:[ |
|
948
50ce6c646929
prefRect may now be a valueHolder or block.
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
294 |
y := y - (prefRect height * topAlignmentFraction value) |
83 | 295 |
]. |
242 | 296 |
^ Rectangle left:x top:y extent:prefRect extent |
83 | 297 |
|
298 |
" |
|
299 |
|superRect aO| |
|
300 |
||
301 |
superRect := 0@0 corner:100@100. |
|
302 |
aO := (AlignmentOrigin new). |
|
303 |
aO leftFraction:0.5; |
|
948
50ce6c646929
prefRect may now be a valueHolder or block.
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
304 |
topFraction:0.5; |
50ce6c646929
prefRect may now be a valueHolder or block.
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
305 |
leftAlignmentFraction:0.5; |
50ce6c646929
prefRect may now be a valueHolder or block.
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
306 |
topAlignmentFraction:0.5. |
83 | 307 |
aO rectangleRelativeTo:superRect preferred:(0@0 corner:30@30) |
308 |
" |
|
229 | 309 |
|
1039 | 310 |
"Modified: / 13.8.1998 / 18:39:26 / cg" |
83 | 311 |
! ! |
312 |
||
126 | 313 |
!AlignmentOrigin class methodsFor:'documentation'! |
100 | 314 |
|
126 | 315 |
version |
1039 | 316 |
^ '$Header: /cvs/stx/stx/libview2/AlignmentOrigin.st,v 1.25 1998-08-13 16:40:40 cg Exp $' |
100 | 317 |
! ! |