|
1 'From Smalltalk/X, Version:2.10.5 on 15-apr-1995 at 12:14:46 pm'! |
|
2 |
|
3 Layout subclass:#LayoutOrigin |
|
4 instanceVariableNames:'leftFraction topFraction leftOffset |
|
5 topOffset' |
|
6 classVariableNames:'' |
|
7 poolDictionaries:'' |
|
8 category:'Graphics-Support-ST80 compatibility' |
|
9 ! |
|
10 |
|
11 !LayoutOrigin class methodsFor:'instance creation'! |
|
12 |
|
13 fractionalFromPoint:aPoint |
|
14 ^ self new leftFraction:aPointx topFraction:aPoint y |
|
15 ! |
|
16 |
|
17 offsetFromPoint:aPoint |
|
18 ^ self new leftOffset:aPointx topOffset:aPoint y |
|
19 ! |
|
20 |
|
21 fromPoint:aPoint |
|
22 "return a new LayoutOrigin from aPoint. |
|
23 If the coordinates are between 0 and 1, take |
|
24 them as fractional parts (relative to superview). |
|
25 Otherwise, treat them as absolute offsets." |
|
26 |
|
27 |x y layout| |
|
28 |
|
29 x := aPoint x. |
|
30 y := aPoint y. |
|
31 layout := self new. |
|
32 ((x between:0 and:1) |
|
33 and:[y between:0 and:1]) ifTrue:[ |
|
34 layout leftFraction:x topFraction:y |
|
35 ] ifFalse:[ |
|
36 layout leftOffset:x topOffset:y |
|
37 ]. |
|
38 ^ layout |
|
39 ! ! |
|
40 |
|
41 !LayoutOrigin methodsFor:'accessing'! |
|
42 |
|
43 leftFraction:something |
|
44 "set leftFraction" |
|
45 |
|
46 leftFraction := something. |
|
47 ! |
|
48 |
|
49 leftFraction |
|
50 "return leftFraction" |
|
51 |
|
52 ^ leftFraction |
|
53 ! |
|
54 |
|
55 leftOffset:something |
|
56 "set leftOffset" |
|
57 |
|
58 leftOffset := something. |
|
59 ! |
|
60 |
|
61 leftOffset |
|
62 "return leftOffset" |
|
63 |
|
64 ^ leftOffset |
|
65 ! |
|
66 |
|
67 leftFraction:something offset:o |
|
68 "set leftFraction and offset" |
|
69 |
|
70 leftFraction := something. |
|
71 leftOffset := o |
|
72 ! |
|
73 |
|
74 topFraction:something |
|
75 "set topFraction" |
|
76 |
|
77 topFraction := something. |
|
78 ! |
|
79 |
|
80 topFraction |
|
81 "return topFraction" |
|
82 |
|
83 ^ topFraction |
|
84 ! |
|
85 |
|
86 topOffset:something |
|
87 "set topOffset" |
|
88 |
|
89 topOffset := something. |
|
90 ! |
|
91 |
|
92 topOffset |
|
93 "return topOffset" |
|
94 |
|
95 ^ topOffset |
|
96 ! |
|
97 |
|
98 topFraction:something offset:o |
|
99 "set topFraction and offset" |
|
100 |
|
101 topFraction := something. |
|
102 topOffset := o |
|
103 ! ! |
|
104 |
|
105 |
|
106 !LayoutOrigin methodsFor:'queries'! |
|
107 |
|
108 rectangleRelativeTo:superRectangle preferred:prefRect |
|
109 |x y| |
|
110 |
|
111 leftOffset isNil ifTrue:[ |
|
112 x := 0 |
|
113 ] ifFalse:[ |
|
114 x := leftOffset |
|
115 ]. |
|
116 topOffset isNil ifTrue:[ |
|
117 y := 0 |
|
118 ] ifFalse:[ |
|
119 y := topOffset |
|
120 ]. |
|
121 leftFraction notNil ifTrue:[ |
|
122 x := x + (prefRect width * leftFraction) |
|
123 ]. |
|
124 topFraction notNil ifTrue:[ |
|
125 y := y + (prefRect height * topFraction) |
|
126 ]. |
|
127 ^ Rectangle origin:x@y extent:prefRect extent |
|
128 ! |
|
129 |
|
130 origin |
|
131 ^ leftFraction asFloat @ topFraction asFloat |
|
132 ! ! |
|
133 |
|
134 !LayoutOrigin methodsFor:'initialization'! |
|
135 |
|
136 initialize |
|
137 leftOffset := topOffset := 0. |
|
138 leftFraction := topFraction := 0. |
|
139 ! ! |