author | Claus Gittinger <cg@exept.de> |
Thu, 12 Sep 2013 15:17:56 +0200 | |
changeset 3246 | d167d433053c |
parent 3017 | 23ca648eacd9 |
child 3328 | 7303f72cc0eb |
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 |
" |
|
3017
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
12 |
"{ Package: 'stx:libview2' }" |
88 | 13 |
|
83 | 14 |
LayoutOrigin subclass:#AlignmentOrigin |
191 | 15 |
instanceVariableNames:'leftAlignmentFraction topAlignmentFraction' |
16 |
classVariableNames:'' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'Graphics-Geometry' |
|
83 | 19 |
! |
20 |
||
88 | 21 |
!AlignmentOrigin class methodsFor:'documentation'! |
22 |
||
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
93 | 26 |
All Rights Reserved |
88 | 27 |
|
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
36 |
||
93 | 37 |
documentation |
38 |
" |
|
39 |
This class is provided to make porting of existing ST-80 applications |
|
40 |
easier. Instances can be used to control the geometry of a subview, within |
|
41 |
its superview. Like a LayoutOrigin, it controls the components origin |
|
42 |
via a relative part plus offset. However, in contrast to LayoutOrigin |
|
43 |
(in which the top-left corner is specified by fraction+offset, here any |
|
44 |
reference point within the component is positioned. |
|
45 |
The reference point itself is specified as fraction of the components size. |
|
46 |
||
229 | 47 |
Notice: |
742 | 48 |
this class was implemented using protocol information |
49 |
from alpha testers - it may not be complete or compatible to |
|
50 |
the corresponding ST-80 class. |
|
51 |
If you encounter any incompatibilities, please forward a note |
|
52 |
describing the incompatibility verbal (i.e. no code) to the ST/X team. |
|
216 | 53 |
|
219 | 54 |
[author:] |
742 | 55 |
Claus Gittinger |
219 | 56 |
|
216 | 57 |
[See also:] |
742 | 58 |
LayoutOrigin LayoutFrame Layout |
59 |
View |
|
94 | 60 |
" |
93 | 61 |
! |
62 |
||
63 |
examples |
|
64 |
" |
|
229 | 65 |
Although the examples below use a button as component, |
66 |
they work of course with any type of subview .... |
|
67 |
||
93 | 68 |
using a LayoutOrigin, to control the top-left origins position of |
69 |
a component (i.e. origin at:0.5@0.5): |
|
742 | 70 |
[exBegin] |
71 |
|top button| |
|
93 | 72 |
|
742 | 73 |
top := StandardSystemView new. |
74 |
top extent:300@300. |
|
93 | 75 |
|
742 | 76 |
button := Button label:'component'. |
77 |
top add:button in:(LayoutOrigin new |
|
78 |
leftFraction:0.5; |
|
79 |
topFraction:0.5). |
|
93 | 80 |
|
742 | 81 |
top open |
82 |
[exEnd] |
|
93 | 83 |
|
84 |
||
85 |
using an AlignmentOrigin, to control the centers position of |
|
86 |
a component (i.e. center of component at:0.5@0.5): |
|
742 | 87 |
[exBegin] |
88 |
|top button| |
|
93 | 89 |
|
742 | 90 |
top := StandardSystemView new. |
91 |
top extent:300@300. |
|
93 | 92 |
|
742 | 93 |
button := Button label:'component'. |
94 |
top add:button in:(AlignmentOrigin new |
|
95 |
leftFraction:0.5; |
|
96 |
topFraction:0.5; |
|
97 |
leftAlignmentFraction:0.5; |
|
98 |
topAlignmentFraction:0.5). |
|
93 | 99 |
|
742 | 100 |
top open |
101 |
[exEnd] |
|
93 | 102 |
|
103 |
||
104 |
using an AlignmentOrigin, to control the bottom-right position of |
|
105 |
a component (i.e. bottom-right of component at:0.5@0.5): |
|
742 | 106 |
[exBegin] |
107 |
|top button| |
|
93 | 108 |
|
742 | 109 |
top := StandardSystemView new. |
110 |
top extent:300@300. |
|
93 | 111 |
|
742 | 112 |
button := Button label:'component'. |
113 |
top add:button in:(AlignmentOrigin new |
|
114 |
leftFraction:0.5; |
|
115 |
topFraction:0.5; |
|
116 |
leftAlignmentFraction:1.0; |
|
117 |
topAlignmentFraction:1.0). |
|
93 | 118 |
|
742 | 119 |
top open |
120 |
[exEnd] |
|
243 | 121 |
|
122 |
||
123 |
four buttons around relative 0.75@0.75: |
|
742 | 124 |
[exBegin] |
125 |
|top button| |
|
243 | 126 |
|
742 | 127 |
top := StandardSystemView new. |
128 |
top extent:300@300. |
|
243 | 129 |
|
742 | 130 |
button := Button label:'button1'. |
131 |
top add:button in:(AlignmentOrigin new |
|
132 |
leftFraction:0.75; |
|
133 |
topFraction:0.75; |
|
134 |
leftAlignmentFraction:1.0; |
|
135 |
topAlignmentFraction:1.0). |
|
243 | 136 |
|
742 | 137 |
button := Button label:'button2'. |
138 |
top add:button in:(AlignmentOrigin new |
|
139 |
leftFraction:0.75; |
|
140 |
topFraction:0.75; |
|
141 |
leftAlignmentFraction:0.0; |
|
142 |
topAlignmentFraction:1.0). |
|
243 | 143 |
|
742 | 144 |
button := Button label:'button3'. |
145 |
top add:button in:(AlignmentOrigin new |
|
146 |
leftFraction:0.75; |
|
147 |
topFraction:0.75; |
|
148 |
leftAlignmentFraction:1.0; |
|
149 |
topAlignmentFraction:0.0). |
|
243 | 150 |
|
742 | 151 |
button := Button label:'button4'. |
152 |
top add:button in:(AlignmentOrigin new |
|
153 |
leftFraction:0.75; |
|
154 |
topFraction:0.75; |
|
155 |
leftAlignmentFraction:0.0; |
|
156 |
topAlignmentFraction:0.0). |
|
157 |
top open |
|
158 |
[exEnd] |
|
93 | 159 |
" |
88 | 160 |
! ! |
161 |
||
83 | 162 |
!AlignmentOrigin methodsFor:'accessing'! |
163 |
||
126 | 164 |
leftAlignmentFraction |
165 |
"return leftAlignmentFraction" |
|
166 |
||
167 |
^ leftAlignmentFraction |
|
168 |
! |
|
169 |
||
83 | 170 |
leftAlignmentFraction:something |
171 |
"set leftAlignmentFraction" |
|
172 |
||
173 |
leftAlignmentFraction := something. |
|
174 |
! |
|
175 |
||
544 | 176 |
leftAlignmentFraction:lF topAlignmentFraction:tF |
177 |
"set both leftAlignmentFraction and topAlignmentFraction" |
|
178 |
||
179 |
leftAlignmentFraction := lF. |
|
180 |
topAlignmentFraction := tF |
|
181 |
||
182 |
"Created: 18.4.1997 / 20:06:02 / cg" |
|
183 |
! |
|
184 |
||
126 | 185 |
topAlignmentFraction |
186 |
"return topAlignmentFraction" |
|
83 | 187 |
|
419 | 188 |
^ topAlignmentFraction |
83 | 189 |
! |
190 |
||
191 |
topAlignmentFraction:something |
|
192 |
"set topAlignmentFraction" |
|
193 |
||
194 |
topAlignmentFraction := something. |
|
126 | 195 |
! ! |
196 |
||
197 |
!AlignmentOrigin methodsFor:'converting'! |
|
198 |
||
742 | 199 |
fromLiteralArrayEncoding:encodingArray |
126 | 200 |
"read my values from an encoding. |
201 |
The encoding is supposed to be of the form: |
|
202 |
(AlignmentOrigin orgOffsX relOrgX orgOffsY relOrgY leftAlignFract topAlignFract)" |
|
203 |
||
742 | 204 |
leftOffset := encodingArray at:2. |
205 |
leftFraction := encodingArray at:3. |
|
206 |
topOffset := encodingArray at:4. |
|
207 |
topFraction := encodingArray at:5. |
|
208 |
leftAlignmentFraction := encodingArray at:6. |
|
209 |
topAlignmentFraction := encodingArray at:7. |
|
126 | 210 |
|
211 |
" |
|
212 |
AlignmentOrigin new fromLiteralArrayEncoding:#(#AlignmentOrigin 70 0 2 0 0.5 0.25) |
|
213 |
" |
|
214 |
||
742 | 215 |
"Modified: / 1.9.1995 / 02:23:53 / claus" |
216 |
"Modified: / 16.11.1997 / 23:04:16 / cg" |
|
83 | 217 |
! |
218 |
||
126 | 219 |
literalArrayEncoding |
191 | 220 |
"encode myself as an array, from which a copy of the receiver |
221 |
can be reconstructed with #decodeAsLiteralArray. |
|
126 | 222 |
The encoding is: |
742 | 223 |
(#AlignmentOrigin orgOffsX relOrgX orgOffsY relOrgY leftAlignFract topAlignFract)" |
83 | 224 |
|
126 | 225 |
^ super literalArrayEncoding |
226 |
, (Array |
|
742 | 227 |
with:leftAlignmentFraction |
228 |
with:topAlignmentFraction) |
|
126 | 229 |
|
230 |
"Modified: 1.9.1995 / 02:43:35 / claus" |
|
191 | 231 |
"Modified: 22.4.1996 / 12:59:56 / cg" |
126 | 232 |
! ! |
233 |
||
234 |
!AlignmentOrigin methodsFor:'initialization'! |
|
235 |
||
236 |
initialize |
|
237 |
super initialize. |
|
238 |
leftAlignmentFraction := topAlignmentFraction := 0. |
|
83 | 239 |
! ! |
240 |
||
241 |
!AlignmentOrigin methodsFor:'printing & storing'! |
|
242 |
||
3017
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
243 |
displayOn:aGCOrStream |
379 | 244 |
"return a printed representation of the receiver for displaying" |
245 |
||
3017
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
246 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream; |
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
247 |
"/ ST/X (and some old ST80's) mean: draw-yourself on a GC. |
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
248 |
(aGCOrStream isStream) ifFalse:[ |
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
249 |
^ super displayOn:aGCOrStream |
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
250 |
]. |
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
251 |
|
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
252 |
aGCOrStream |
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
253 |
nextPutAll:self class name; |
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
254 |
nextPutAll:'(l: '. |
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
255 |
|
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
256 |
leftFraction displayOn:aGCOrStream. |
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
257 |
aGCOrStream nextPut:$+. |
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
258 |
leftOffset displayOn:aGCOrStream. |
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
259 |
aGCOrStream nextPutAll:' t: '. |
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
260 |
topFraction displayOn:aGCOrStream. |
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
261 |
aGCOrStream nextPut:$+. |
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
262 |
topOffset displayOn:aGCOrStream. |
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
263 |
aGCOrStream nextPutAll:' a: '. |
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
264 |
leftAlignmentFraction displayOn:aGCOrStream. |
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
265 |
aGCOrStream nextPut:$@. |
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
266 |
topAlignmentFraction displayOn:aGCOrStream. |
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
267 |
aGCOrStream nextPut:$). |
379 | 268 |
|
269 |
"Modified: 22.1.1997 / 11:58:38 / cg" |
|
83 | 270 |
! ! |
271 |
||
272 |
!AlignmentOrigin methodsFor:'queries'! |
|
273 |
||
414 | 274 |
isAlignmentOrigin |
275 |
"return true, if this is an alignmentOrigin" |
|
276 |
||
277 |
^ true |
|
278 |
||
279 |
||
280 |
! |
|
281 |
||
948
50ce6c646929
prefRect may now be a valueHolder or block.
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
282 |
rectangleRelativeTo:superRectangle preferred:prefRectHolder |
229 | 283 |
"compute the rectangle represented by the receiver, |
284 |
given the superViews rectangle and the views preferredExtent." |
|
285 |
||
948
50ce6c646929
prefRect may now be a valueHolder or block.
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
286 |
|x y prefRect| |
50ce6c646929
prefRect may now be a valueHolder or block.
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
287 |
|
50ce6c646929
prefRect may now be a valueHolder or block.
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
288 |
prefRect := prefRectHolder value. |
83 | 289 |
|
1039 | 290 |
x := superRectangle left. |
291 |
y := superRectangle top. |
|
292 |
||
293 |
leftOffset notNil ifTrue:[ |
|
294 |
x := x + leftOffset value |
|
83 | 295 |
]. |
1039 | 296 |
topOffset notNil ifTrue:[ |
297 |
y := y + topOffset value |
|
83 | 298 |
]. |
299 |
leftFraction notNil ifTrue:[ |
|
948
50ce6c646929
prefRect may now be a valueHolder or block.
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
300 |
x := x + (superRectangle width * leftFraction value) |
83 | 301 |
]. |
302 |
topFraction notNil ifTrue:[ |
|
948
50ce6c646929
prefRect may now be a valueHolder or block.
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
303 |
y := y + (superRectangle height * topFraction value) |
83 | 304 |
]. |
305 |
leftAlignmentFraction ~~ 0 ifTrue:[ |
|
948
50ce6c646929
prefRect may now be a valueHolder or block.
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
306 |
x := x - (prefRect width * leftAlignmentFraction value) |
83 | 307 |
]. |
308 |
topAlignmentFraction ~~ 0 ifTrue:[ |
|
948
50ce6c646929
prefRect may now be a valueHolder or block.
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
309 |
y := y - (prefRect height * topAlignmentFraction value) |
83 | 310 |
]. |
242 | 311 |
^ Rectangle left:x top:y extent:prefRect extent |
83 | 312 |
|
313 |
" |
|
314 |
|superRect aO| |
|
315 |
||
316 |
superRect := 0@0 corner:100@100. |
|
317 |
aO := (AlignmentOrigin new). |
|
318 |
aO leftFraction:0.5; |
|
948
50ce6c646929
prefRect may now be a valueHolder or block.
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
319 |
topFraction:0.5; |
50ce6c646929
prefRect may now be a valueHolder or block.
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
320 |
leftAlignmentFraction:0.5; |
50ce6c646929
prefRect may now be a valueHolder or block.
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
321 |
topAlignmentFraction:0.5. |
83 | 322 |
aO rectangleRelativeTo:superRect preferred:(0@0 corner:30@30) |
323 |
" |
|
229 | 324 |
|
1039 | 325 |
"Modified: / 13.8.1998 / 18:39:26 / cg" |
83 | 326 |
! ! |
327 |
||
126 | 328 |
!AlignmentOrigin class methodsFor:'documentation'! |
100 | 329 |
|
126 | 330 |
version |
3017
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
331 |
^ '$Header: /cvs/stx/stx/libview2/AlignmentOrigin.st,v 1.26 2012-08-03 15:53:55 stefan Exp $' |
100 | 332 |
! ! |