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
|
|
112 |
"
|
96
|
113 |
$Header: /cvs/stx/stx/libview2/AlignmentOrigin.st,v 1.5 1995-08-29 17:42:57 claus Exp $
|
88
|
114 |
"
|
|
115 |
! !
|
|
116 |
|
83
|
117 |
!AlignmentOrigin methodsFor:'accessing'!
|
|
118 |
|
|
119 |
leftAlignmentFraction:something
|
|
120 |
"set leftAlignmentFraction"
|
|
121 |
|
|
122 |
leftAlignmentFraction := something.
|
|
123 |
!
|
|
124 |
|
|
125 |
leftAlignmentFraction
|
|
126 |
"return leftAlignmentFraction"
|
|
127 |
|
|
128 |
^ leftAlignmentFraction
|
|
129 |
!
|
|
130 |
|
|
131 |
topAlignmentFraction:something
|
|
132 |
"set topAlignmentFraction"
|
|
133 |
|
|
134 |
topAlignmentFraction := something.
|
|
135 |
!
|
|
136 |
|
|
137 |
topAlignmentFraction
|
|
138 |
"return topAlignmentFraction"
|
|
139 |
|
|
140 |
^ topFraction
|
|
141 |
! !
|
|
142 |
|
|
143 |
!AlignmentOrigin methodsFor:'printing & storing'!
|
|
144 |
|
|
145 |
displayString
|
|
146 |
^ 'LayoutOrigin('
|
|
147 |
, 'l: ' , leftFraction displayString
|
|
148 |
, '+' , leftOffset displayString
|
|
149 |
, ' t: ' , topFraction displayString
|
|
150 |
, '+' , topOffset displayString
|
|
151 |
, ' a: ' , leftAlignmentFraction displayString
|
|
152 |
, '@' , topAlignmentFraction displayString
|
|
153 |
, ')'
|
|
154 |
! !
|
|
155 |
|
|
156 |
|
|
157 |
!AlignmentOrigin methodsFor:'queries'!
|
|
158 |
|
|
159 |
rectangleRelativeTo:superRectangle preferred:prefRect
|
|
160 |
|x y|
|
|
161 |
|
|
162 |
leftOffset isNil ifTrue:[
|
|
163 |
x := 0
|
|
164 |
] ifFalse:[
|
|
165 |
x := leftOffset
|
|
166 |
].
|
|
167 |
topOffset isNil ifTrue:[
|
|
168 |
y := 0
|
|
169 |
] ifFalse:[
|
|
170 |
y := topOffset
|
|
171 |
].
|
|
172 |
leftFraction notNil ifTrue:[
|
|
173 |
x := x + (superRectangle width * leftFraction)
|
|
174 |
].
|
|
175 |
topFraction notNil ifTrue:[
|
|
176 |
y := y + (superRectangle height * topFraction)
|
|
177 |
].
|
|
178 |
leftAlignmentFraction ~~ 0 ifTrue:[
|
|
179 |
x := x - (prefRect width * leftAlignmentFraction)
|
|
180 |
].
|
|
181 |
topAlignmentFraction ~~ 0 ifTrue:[
|
|
182 |
y := y - (prefRect height * topAlignmentFraction)
|
|
183 |
].
|
|
184 |
^ Rectangle origin:x@y extent:prefRect extent
|
|
185 |
|
|
186 |
"
|
|
187 |
|superRect aO|
|
|
188 |
|
|
189 |
superRect := 0@0 corner:100@100.
|
|
190 |
aO := (AlignmentOrigin new).
|
|
191 |
aO leftFraction:0.5;
|
|
192 |
topFraction:0.5;
|
|
193 |
leftAlignmentFraction:0.5;
|
|
194 |
topAlignmentFraction:0.5.
|
|
195 |
aO rectangleRelativeTo:superRect preferred:(0@0 corner:30@30)
|
|
196 |
"
|
|
197 |
! !
|
|
198 |
|
|
199 |
!AlignmentOrigin methodsFor:'initialization'!
|
|
200 |
|
|
201 |
initialize
|
|
202 |
super initialize.
|
|
203 |
leftAlignmentFraction := topAlignmentFraction := 0.
|
|
204 |
! !
|