author | Claus Gittinger <cg@exept.de> |
Sat, 11 Nov 1995 17:05:49 +0100 | |
changeset 114 | e577a2f332d0 |
parent 100 | 0300e64bb883 |
child 126 | 25df58661f32 |
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 |
14 |
instanceVariableNames:'leftAlignmentFraction topAlignmentFraction' |
|
15 |
classVariableNames:'' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'Graphics-Geometry' |
|
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 |
||
46 |
See also: |
|
47 |
LayoutOrigin LayoutFrame Layout |
|
48 |
||
49 |
Notice: this class was implemented using protocol information |
|
50 |
from alpha testers - it may not be complete or compatible to |
|
51 |
the corresponding ST-80 class. If you encounter any incompatibilities, |
|
52 |
please forward a note to the ST/X team. |
|
94 | 53 |
" |
93 | 54 |
! |
55 |
||
56 |
examples |
|
57 |
" |
|
58 |
using a LayoutOrigin, to control the top-left origins position of |
|
59 |
a component (i.e. origin at:0.5@0.5): |
|
60 |
||
61 |
|top button| |
|
62 |
||
63 |
top := StandardSystemView new. |
|
64 |
top extent:300@300. |
|
65 |
||
66 |
button := Button label:'component'. |
|
67 |
top add:button in:(LayoutOrigin new |
|
68 |
leftFraction:0.5; |
|
69 |
topFraction:0.5). |
|
70 |
||
71 |
top open |
|
72 |
||
73 |
||
74 |
using an AlignmentOrigin, to control the centers position of |
|
75 |
a component (i.e. center of component at:0.5@0.5): |
|
76 |
||
77 |
|top button| |
|
78 |
||
79 |
top := StandardSystemView new. |
|
80 |
top extent:300@300. |
|
81 |
||
82 |
button := Button label:'component'. |
|
83 |
top add:button in:(AlignmentOrigin new |
|
84 |
leftFraction:0.5; |
|
85 |
topFraction:0.5; |
|
86 |
leftAlignmentFraction:0.5; |
|
87 |
topAlignmentFraction:0.5). |
|
88 |
||
89 |
top open |
|
90 |
||
91 |
||
92 |
using an AlignmentOrigin, to control the bottom-right position of |
|
93 |
a component (i.e. bottom-right of component at:0.5@0.5): |
|
94 |
||
95 |
|top button| |
|
96 |
||
97 |
top := StandardSystemView new. |
|
98 |
top extent:300@300. |
|
99 |
||
100 |
button := Button label:'component'. |
|
101 |
top add:button in:(AlignmentOrigin new |
|
102 |
leftFraction:0.5; |
|
103 |
topFraction:0.5; |
|
104 |
leftAlignmentFraction:1.0; |
|
105 |
topAlignmentFraction:1.0). |
|
106 |
||
107 |
top open |
|
108 |
" |
|
109 |
! |
|
110 |
||
88 | 111 |
version |
114
e577a2f332d0
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
100
diff
changeset
|
112 |
^ '$Header: /cvs/stx/stx/libview2/AlignmentOrigin.st,v 1.7 1995-11-11 16:04:11 cg Exp $' |
88 | 113 |
! ! |
114 |
||
83 | 115 |
!AlignmentOrigin methodsFor:'accessing'! |
116 |
||
117 |
leftAlignmentFraction:something |
|
118 |
"set leftAlignmentFraction" |
|
119 |
||
120 |
leftAlignmentFraction := something. |
|
121 |
! |
|
122 |
||
123 |
leftAlignmentFraction |
|
124 |
"return leftAlignmentFraction" |
|
125 |
||
126 |
^ leftAlignmentFraction |
|
127 |
! |
|
128 |
||
129 |
topAlignmentFraction:something |
|
130 |
"set topAlignmentFraction" |
|
131 |
||
132 |
topAlignmentFraction := something. |
|
133 |
! |
|
134 |
||
135 |
topAlignmentFraction |
|
136 |
"return topAlignmentFraction" |
|
137 |
||
138 |
^ topFraction |
|
139 |
! ! |
|
140 |
||
141 |
!AlignmentOrigin methodsFor:'printing & storing'! |
|
142 |
||
143 |
displayString |
|
144 |
^ 'LayoutOrigin(' |
|
145 |
, 'l: ' , leftFraction displayString |
|
146 |
, '+' , leftOffset displayString |
|
147 |
, ' t: ' , topFraction displayString |
|
148 |
, '+' , topOffset displayString |
|
149 |
, ' a: ' , leftAlignmentFraction displayString |
|
150 |
, '@' , topAlignmentFraction displayString |
|
151 |
, ')' |
|
152 |
! ! |
|
153 |
||
154 |
||
155 |
!AlignmentOrigin methodsFor:'queries'! |
|
156 |
||
157 |
rectangleRelativeTo:superRectangle preferred:prefRect |
|
158 |
|x y| |
|
159 |
||
160 |
leftOffset isNil ifTrue:[ |
|
161 |
x := 0 |
|
162 |
] ifFalse:[ |
|
163 |
x := leftOffset |
|
164 |
]. |
|
165 |
topOffset isNil ifTrue:[ |
|
166 |
y := 0 |
|
167 |
] ifFalse:[ |
|
168 |
y := topOffset |
|
169 |
]. |
|
170 |
leftFraction notNil ifTrue:[ |
|
171 |
x := x + (superRectangle width * leftFraction) |
|
172 |
]. |
|
173 |
topFraction notNil ifTrue:[ |
|
174 |
y := y + (superRectangle height * topFraction) |
|
175 |
]. |
|
176 |
leftAlignmentFraction ~~ 0 ifTrue:[ |
|
177 |
x := x - (prefRect width * leftAlignmentFraction) |
|
178 |
]. |
|
179 |
topAlignmentFraction ~~ 0 ifTrue:[ |
|
180 |
y := y - (prefRect height * topAlignmentFraction) |
|
181 |
]. |
|
182 |
^ Rectangle origin:x@y extent:prefRect extent |
|
183 |
||
184 |
" |
|
185 |
|superRect aO| |
|
186 |
||
187 |
superRect := 0@0 corner:100@100. |
|
188 |
aO := (AlignmentOrigin new). |
|
189 |
aO leftFraction:0.5; |
|
190 |
topFraction:0.5; |
|
191 |
leftAlignmentFraction:0.5; |
|
192 |
topAlignmentFraction:0.5. |
|
193 |
aO rectangleRelativeTo:superRect preferred:(0@0 corner:30@30) |
|
194 |
" |
|
195 |
! ! |
|
196 |
||
197 |
!AlignmentOrigin methodsFor:'initialization'! |
|
198 |
||
199 |
initialize |
|
200 |
super initialize. |
|
201 |
leftAlignmentFraction := topAlignmentFraction := 0. |
|
202 |
! ! |
|
100 | 203 |
|
204 |
!AlignmentOrigin methodsFor:'converting'! |
|
205 |
||
206 |
literalArrayEncoding |
|
207 |
"encode myself as an array. |
|
208 |
The encoding is: |
|
209 |
(#AlignmentOrigin orgOffsX relOrgX orgOffsY relOrgY leftAlignFract topAlignFract)" |
|
210 |
||
211 |
^ super literalArrayEncoding |
|
212 |
, (Array |
|
213 |
with:leftAlignmentFraction |
|
214 |
with:topAlignmentFraction) |
|
215 |
||
216 |
"Modified: 1.9.1995 / 02:43:35 / claus" |
|
217 |
! |
|
218 |
||
219 |
fromLiteralArrayEncoding:encoding |
|
220 |
"read my values from an encoding. |
|
221 |
The encoding is supposed to be of the form: |
|
222 |
(AlignmentOrigin orgOffsX relOrgX orgOffsY relOrgY leftAlignFract topAlignFract)" |
|
223 |
||
224 |
leftOffset := encoding at:2. |
|
225 |
leftFraction := encoding at:3. |
|
226 |
topOffset := encoding at:4. |
|
227 |
topFraction := encoding at:5. |
|
228 |
leftAlignmentFraction := encoding at:6. |
|
229 |
topAlignmentFraction := encoding at:7. |
|
230 |
||
231 |
||
232 |
" |
|
233 |
AlignmentOrigin new fromLiteralArrayEncoding:#(#AlignmentOrigin 70 0 2 0 0.5 0.25) |
|
234 |
" |
|
235 |
||
236 |
"Modified: 1.9.1995 / 02:23:53 / claus" |
|
237 |
! ! |