author | Claus Gittinger <cg@exept.de> |
Sun, 23 Feb 2020 16:01:31 +0100 | |
changeset 4450 | c07db2570587 |
parent 4355 | 6616dc6cedd5 |
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 |
||
4355 | 174 |
leftAlignmentFraction:aFraction |
175 |
"set leftAlignmentFraction (0..1)" |
|
83 | 176 |
|
4355 | 177 |
leftAlignmentFraction := aFraction. |
83 | 178 |
! |
179 |
||
544 | 180 |
leftAlignmentFraction:lF topAlignmentFraction:tF |
4355 | 181 |
"set both leftAlignmentFraction (0..1) and topAlignmentFraction (0..1)" |
544 | 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 |
||
4355 | 195 |
topAlignmentFraction:aFraction |
196 |
"set topAlignmentFraction (0..1)" |
|
83 | 197 |
|
4355 | 198 |
topAlignmentFraction := aFraction. |
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 |
||
4296 | 214 |
!AlignmentOrigin methodsFor:'computing'! |
215 |
||
216 |
rectangleRelativeTo:superRectangle preferred:prefRectHolder |
|
217 |
"compute the rectangle represented by the receiver, |
|
218 |
given the superView's rectangle and the view's preferredExtent." |
|
219 |
||
220 |
|x y prefRect| |
|
221 |
||
222 |
prefRect := prefRectHolder value. |
|
223 |
||
224 |
x := superRectangle left. |
|
225 |
y := superRectangle top. |
|
226 |
||
227 |
leftOffset notNil ifTrue:[ |
|
228 |
x := x + leftOffset value |
|
229 |
]. |
|
230 |
topOffset notNil ifTrue:[ |
|
231 |
y := y + topOffset value |
|
232 |
]. |
|
233 |
leftFraction notNil ifTrue:[ |
|
234 |
x := x + (superRectangle width * leftFraction value) |
|
235 |
]. |
|
236 |
topFraction notNil ifTrue:[ |
|
237 |
y := y + (superRectangle height * topFraction value) |
|
238 |
]. |
|
239 |
leftAlignmentFraction ~~ 0 ifTrue:[ |
|
240 |
x := x - (prefRect width * leftAlignmentFraction value) |
|
241 |
]. |
|
242 |
topAlignmentFraction ~~ 0 ifTrue:[ |
|
243 |
y := y - (prefRect height * topAlignmentFraction value) |
|
244 |
]. |
|
245 |
^ Rectangle left:x top:y extent:prefRect extent |
|
246 |
||
247 |
" |
|
248 |
|superRect aO| |
|
249 |
||
250 |
superRect := 0@0 corner:100@100. |
|
251 |
aO := (AlignmentOrigin new). |
|
252 |
aO leftFraction:0.5; |
|
253 |
topFraction:0.5; |
|
254 |
leftAlignmentFraction:0.5; |
|
255 |
topAlignmentFraction:0.5. |
|
256 |
aO rectangleRelativeTo:superRect preferred:(0@0 corner:30@30) |
|
257 |
" |
|
258 |
||
259 |
"Modified: / 13-08-1998 / 18:39:26 / cg" |
|
260 |
"Modified (comment): / 17-07-2019 / 10:03:04 / Claus Gittinger" |
|
261 |
! ! |
|
262 |
||
126 | 263 |
!AlignmentOrigin methodsFor:'converting'! |
264 |
||
742 | 265 |
fromLiteralArrayEncoding:encodingArray |
126 | 266 |
"read my values from an encoding. |
267 |
The encoding is supposed to be of the form: |
|
268 |
(AlignmentOrigin orgOffsX relOrgX orgOffsY relOrgY leftAlignFract topAlignFract)" |
|
269 |
||
742 | 270 |
leftOffset := encodingArray at:2. |
271 |
leftFraction := encodingArray at:3. |
|
272 |
topOffset := encodingArray at:4. |
|
273 |
topFraction := encodingArray at:5. |
|
274 |
leftAlignmentFraction := encodingArray at:6. |
|
275 |
topAlignmentFraction := encodingArray at:7. |
|
126 | 276 |
|
277 |
" |
|
278 |
AlignmentOrigin new fromLiteralArrayEncoding:#(#AlignmentOrigin 70 0 2 0 0.5 0.25) |
|
279 |
" |
|
280 |
||
742 | 281 |
"Modified: / 1.9.1995 / 02:23:53 / claus" |
282 |
"Modified: / 16.11.1997 / 23:04:16 / cg" |
|
83 | 283 |
! |
284 |
||
126 | 285 |
literalArrayEncoding |
191 | 286 |
"encode myself as an array, from which a copy of the receiver |
287 |
can be reconstructed with #decodeAsLiteralArray. |
|
126 | 288 |
The encoding is: |
742 | 289 |
(#AlignmentOrigin orgOffsX relOrgX orgOffsY relOrgY leftAlignFract topAlignFract)" |
83 | 290 |
|
126 | 291 |
^ super literalArrayEncoding |
292 |
, (Array |
|
742 | 293 |
with:leftAlignmentFraction |
294 |
with:topAlignmentFraction) |
|
126 | 295 |
|
296 |
"Modified: 1.9.1995 / 02:43:35 / claus" |
|
191 | 297 |
"Modified: 22.4.1996 / 12:59:56 / cg" |
126 | 298 |
! ! |
299 |
||
300 |
!AlignmentOrigin methodsFor:'initialization'! |
|
301 |
||
302 |
initialize |
|
3866 | 303 |
<modifier: #super> "must be called if redefined" |
304 |
||
126 | 305 |
super initialize. |
306 |
leftAlignmentFraction := topAlignmentFraction := 0. |
|
3866 | 307 |
|
308 |
"Modified: / 08-02-2017 / 00:32:15 / cg" |
|
83 | 309 |
! ! |
310 |
||
311 |
!AlignmentOrigin methodsFor:'printing & storing'! |
|
312 |
||
3017
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
313 |
displayOn:aGCOrStream |
379 | 314 |
"return a printed representation of the receiver for displaying" |
315 |
||
3017
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
316 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream; |
3924 | 317 |
"/ old ST80 means: draw-yourself on a GC. |
3017
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
318 |
(aGCOrStream isStream) ifFalse:[ |
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
319 |
^ super displayOn:aGCOrStream |
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
320 |
]. |
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
321 |
|
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
322 |
aGCOrStream |
4282 | 323 |
nextPutAll:self className; |
3017
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
324 |
nextPutAll:'(l: '. |
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
325 |
|
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
326 |
leftFraction displayOn:aGCOrStream. |
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
327 |
aGCOrStream nextPut:$+. |
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
328 |
leftOffset displayOn:aGCOrStream. |
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
329 |
aGCOrStream nextPutAll:' t: '. |
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
330 |
topFraction displayOn:aGCOrStream. |
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
331 |
aGCOrStream nextPut:$+. |
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
332 |
topOffset displayOn:aGCOrStream. |
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
333 |
aGCOrStream nextPutAll:' a: '. |
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
334 |
leftAlignmentFraction displayOn:aGCOrStream. |
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
335 |
aGCOrStream nextPut:$@. |
23ca648eacd9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
1039
diff
changeset
|
336 |
topAlignmentFraction displayOn:aGCOrStream. |
3924 | 337 |
aGCOrStream nextPut:$). |
379 | 338 |
|
3924 | 339 |
"Modified: / 22-01-1997 / 11:58:38 / cg" |
340 |
"Modified (comment): / 22-02-2017 / 16:52:08 / cg" |
|
4282 | 341 |
"Modified: / 28-06-2019 / 08:40:41 / Claus Gittinger" |
83 | 342 |
! ! |
343 |
||
344 |
!AlignmentOrigin methodsFor:'queries'! |
|
345 |
||
414 | 346 |
isAlignmentOrigin |
347 |
"return true, if this is an alignmentOrigin" |
|
348 |
||
349 |
^ true |
|
350 |
||
351 |
||
83 | 352 |
! ! |
353 |
||
126 | 354 |
!AlignmentOrigin class methodsFor:'documentation'! |
100 | 355 |
|
126 | 356 |
version |
3792 | 357 |
^ '$Header$' |
100 | 358 |
! ! |
3328 | 359 |