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