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