35 |
35 |
36 ! |
36 ! |
37 |
37 |
38 documentation |
38 documentation |
39 " |
39 " |
40 a wrapper which shifts the origin of its wrapped component. |
40 a wrapper for a geometric object, which is to be drawn stroked. |
41 This allows the wrapped thingy to think & draw in its own 0/0 based |
41 This allows any geometric thingy to be used as a component in a view. |
42 coordinates. |
42 |
|
43 (background info: geometrics are mathematical objects - they do not |
|
44 keep any color or lineStyle attributes. Wrappers add this information |
|
45 and can also be used as components of a view) |
43 |
46 |
44 Notice: |
47 Notice: |
45 this class was implemented using protocol information |
48 this class was implemented using protocol information |
46 from alpha testers and from the Hopkins/Horan book. |
49 from alpha testers and from the Hopkins/Horan book. |
47 - it may not be complete or compatible to the corresponding ST-80 class. |
50 - it may not be complete or compatible to the corresponding ST-80 class. |
48 If you encounter any incompatibilities, please forward a note |
51 If you encounter any incompatibilities, please forward a note |
49 describing the incompatibility verbal (i.e. no code) to the ST/X team. |
52 describing the incompatibility verbal (i.e. no code) to the ST/X team. |
50 |
53 |
51 [see also:] |
54 [see also:] |
52 Wrapper |
55 FillingWrapper Geometric GraphicsContext |
53 |
56 |
54 [author:] |
57 [author:] |
55 Claus Gittinger |
58 Claus Gittinger |
56 " |
59 " |
57 ! |
60 ! |
58 |
61 |
59 examples |
62 examples |
60 " |
63 " |
61 some components without translatingWrapper |
64 wrap an ellipticArc and display it |
|
65 (notice, that no automatic redraw is performed): |
|
66 [exBegin] |
|
67 |v e component| |
|
68 |
|
69 v := (StandardSystemView extent:250@250) openAndWait. |
|
70 |
|
71 e := EllipticalArc boundingBox:(10@10 corner:90@90) |
|
72 startAngle:0 |
|
73 sweepAngle:270. |
|
74 component := StrokingWrapper on:e. |
|
75 |
|
76 component displayOn:v. |
|
77 [exEnd] |
|
78 |
|
79 wrap a rectangle and an ellipticArc, |
|
80 and add them as components to a View |
|
81 (notice, that doing so makes the redraw automatic): |
|
82 [exBegin] |
|
83 |v e component| |
|
84 |
|
85 v := StandardSystemView extent:250@250. |
|
86 |
|
87 e := Rectangle origin:10@10 corner:90@90. |
|
88 component := FillingWrapper on:e. |
|
89 component foregroundColor:Color red. |
|
90 |
|
91 v addComponent:component. |
|
92 |
|
93 e := EllipticalArc boundingBox:(10@10 corner:90@90) |
|
94 startAngle:0 sweepAngle:360. |
|
95 component := StrokingWrapper on:e. |
|
96 component lineWidth:5. |
|
97 |
|
98 v addComponent:component. |
|
99 |
|
100 v addComponent:(Button label:'hello'). |
|
101 |
|
102 v open |
|
103 [exEnd] |
|
104 with lineWidth & style: |
|
105 (notice, that the redraw is automatic): |
|
106 [exBegin] |
|
107 |v e| |
|
108 |
|
109 v := StandardSystemView extent:250@250. |
|
110 |
|
111 e := EllipticalArc boundingBox:(10@10 corner:90@90) |
|
112 startAngle:0 |
|
113 sweepAngle:270. |
|
114 v addComponent:((StrokingWrapper on:e) |
|
115 lineWidth:5; |
|
116 lineStyle:#dashed; |
|
117 foregroundColor:(Color red)). |
|
118 |
|
119 e := EllipticalArc boundingBox:(30@30 corner:70@70) |
|
120 startAngle:90 |
|
121 sweepAngle:270. |
|
122 v addComponent:((StrokingWrapper on:e) |
|
123 lineWidth:5; |
|
124 lineStyle:#doubleDashed; |
|
125 foregroundColor:(Color red); |
|
126 backgroundColor:(Color green)). |
|
127 v open. |
|
128 [exEnd] |
|
129 |
|
130 scrolling: |
62 [exBegin] |
131 [exBegin] |
63 |t s v e component| |
132 |t s v e component| |
64 |
133 |
65 t := StandardSystemView extent:250@200. |
134 t := StandardSystemView extent:250@200. |
66 s := HVScrollableView for:View miniScroller:true in:t. |
135 s := HVScrollableView for:View miniScroller:true in:t. |
81 e := Arrow from:100@100 to:150@250. |
150 e := Arrow from:100@100 to:150@250. |
82 component := StrokingWrapper on:e. |
151 component := StrokingWrapper on:e. |
83 component lineWidth:2. |
152 component lineWidth:2. |
84 v addComponent:component. |
153 v addComponent:component. |
85 |
154 |
|
155 v addComponent:(Button label:'hello'). |
|
156 |
86 t open |
157 t open |
87 [exEnd] |
158 [exEnd] |
88 the same components WITH translatingWrappers |
159 |
89 [exBegin] |
160 " |
90 |t s v e component| |
161 ! ! |
91 |
162 |
92 t := StandardSystemView extent:250@200. |
163 !StrokingWrapper methodsFor:'accessing'! |
93 s := HVScrollableView for:View miniScroller:true in:t. |
|
94 s origin:0.0@0.0 corner:1.0@1.0. |
|
95 v := s scrolledView. |
|
96 |
|
97 e := Rectangle origin:0@0 corner:80@80. |
|
98 component := FillingWrapper on:e. |
|
99 component foregroundColor:Color red. |
|
100 v addComponent:(TranslatingWrapper on:component at:10@10). |
|
101 |
|
102 e := EllipticalArc boundingBox:(0@0 corner:80@80) |
|
103 startAngle:0 sweepAngle:360. |
|
104 component := StrokingWrapper on:e. |
|
105 component lineWidth:5. |
|
106 v addComponent:(TranslatingWrapper on:component at:10@10). |
|
107 |
|
108 e := Arrow from:0@0 to:50@150. |
|
109 component := StrokingWrapper on:e. |
|
110 component lineWidth:2. |
|
111 v addComponent:(TranslatingWrapper on:component at:100@100). |
|
112 |
|
113 v addComponent:(TranslatingWrapper on:(Image fromFile:'SBrowser.xbm') at:0@100). |
|
114 |
|
115 t open |
|
116 [exEnd] |
|
117 [exBegin] |
|
118 |t s v e component| |
|
119 |
|
120 t := StandardSystemView extent:250@200. |
|
121 s := HVScrollableView for:View miniScroller:true in:t. |
|
122 s origin:0.0@0.0 corner:1.0@1.0. |
|
123 v := s scrolledView. |
|
124 |
|
125 e := LabelAndIcon icon:(Image fromFile:'bitmaps/SBrowser.xbm') |
|
126 string:'hello'. |
|
127 v addComponent:(TranslatingWrapper on:e at:10@10). |
|
128 |
|
129 t open |
|
130 [exEnd] |
|
131 |
|
132 " |
|
133 ! ! |
|
134 |
|
135 !TranslatingWrapper class methodsFor:'instance creation'! |
|
136 |
|
137 on:aComponent at:originPoint |
|
138 "create and return a translatingWrapper, which positions |
|
139 aComponent at some originPoint" |
|
140 |
|
141 ^ (self on:aComponent) translation:originPoint |
|
142 |
|
143 "Created: 26.5.1996 / 16:07:29 / cg" |
|
144 "Modified: 26.5.1996 / 16:12:28 / cg" |
|
145 ! ! |
|
146 |
|
147 !TranslatingWrapper methodsFor:'accessing'! |
|
148 |
|
149 translation |
|
150 "return the origin offset" |
|
151 |
|
152 ^ origin |
|
153 |
|
154 "Modified: 26.5.1996 / 16:06:32 / cg" |
|
155 ! |
|
156 |
|
157 translation:originPoint |
|
158 "set the origin offset" |
|
159 |
|
160 origin := originPoint |
|
161 |
|
162 "Modified: 26.5.1996 / 16:06:32 / cg" |
|
163 "Created: 26.5.1996 / 16:07:47 / cg" |
|
164 ! ! |
|
165 |
|
166 !TranslatingWrapper methodsFor:'accessing - bounds'! |
|
167 |
164 |
168 bounds |
165 bounds |
169 ^ component bounds + origin |
166 "return the boundary rectangle - here, must take care of the lineWidth" |
170 |
167 |
171 "Created: 26.5.1996 / 16:13:05 / cg" |
168 ^ component bounds insetBy:(lineWidth // 2 + 1) negated |
172 "Modified: 26.5.1996 / 16:44:26 / cg" |
169 |
173 ! |
170 "Created: 8.5.1996 / 23:22:43 / cg" |
174 |
171 "Modified: 26.5.1996 / 13:03:50 / cg" |
175 bounds:newBounds |
172 ! |
176 component bounds:(newBounds - origin). |
173 |
177 |
174 capStyle |
178 "Created: 26.5.1996 / 16:44:16 / cg" |
175 "return the capStyle" |
|
176 |
|
177 ^ capStyle |
|
178 |
|
179 "Created: 8.5.1996 / 23:22:04 / cg" |
|
180 "Modified: 9.5.1996 / 00:09:12 / cg" |
|
181 ! |
|
182 |
|
183 capStyle:aSymbol |
|
184 "set the capStyle" |
|
185 |
|
186 capStyle := aSymbol |
|
187 |
|
188 "Created: 8.5.1996 / 23:22:13 / cg" |
|
189 "Modified: 9.5.1996 / 00:09:17 / cg" |
|
190 ! |
|
191 |
|
192 joinStyle |
|
193 "return the joinStyle" |
|
194 |
|
195 ^ joinStyle |
|
196 |
|
197 "Created: 8.5.1996 / 23:22:04 / cg" |
|
198 "Modified: 9.5.1996 / 00:09:12 / cg" |
|
199 ! |
|
200 |
|
201 joinStyle:aSymbol |
|
202 "set the joinStyle" |
|
203 |
|
204 joinStyle := aSymbol |
|
205 |
|
206 "Created: 8.5.1996 / 23:22:13 / cg" |
|
207 "Modified: 9.5.1996 / 00:09:17 / cg" |
|
208 ! |
|
209 |
|
210 lineStyle |
|
211 "return the lineStyle" |
|
212 |
|
213 ^ lineStyle |
|
214 |
|
215 "Created: 8.5.1996 / 23:22:04 / cg" |
|
216 "Modified: 9.5.1996 / 00:09:12 / cg" |
|
217 ! |
|
218 |
|
219 lineStyle:aSymbol |
|
220 "set the lineStyle" |
|
221 |
|
222 lineStyle := aSymbol |
|
223 |
|
224 "Created: 8.5.1996 / 23:22:13 / cg" |
|
225 "Modified: 9.5.1996 / 00:09:17 / cg" |
|
226 ! |
|
227 |
|
228 lineWidth |
|
229 "return the lineWidth" |
|
230 |
|
231 ^ lineWidth |
|
232 |
|
233 "Created: 8.5.1996 / 23:22:04 / cg" |
|
234 "Modified: 9.5.1996 / 00:09:12 / cg" |
|
235 ! |
|
236 |
|
237 lineWidth:aNumber |
|
238 "set the lineWidth" |
|
239 |
|
240 lineWidth := aNumber |
|
241 |
|
242 "Created: 8.5.1996 / 23:22:13 / cg" |
|
243 "Modified: 9.5.1996 / 00:09:17 / cg" |
179 ! |
244 ! |
180 |
245 |
181 preferredBounds |
246 preferredBounds |
182 ^ component preferredBounds + origin |
247 "return the components bounds as preferredBounds" |
183 |
248 |
184 "Modified: 26.5.1996 / 16:44:26 / cg" |
249 ^ self bounds |
185 "Created: 26.5.1996 / 16:44:53 / cg" |
250 |
186 ! ! |
251 "Created: 8.5.1996 / 23:23:00 / cg" |
187 |
252 "Modified: 9.5.1996 / 00:09:31 / cg" |
188 !TranslatingWrapper methodsFor:'displaying'! |
253 ! ! |
|
254 |
|
255 !StrokingWrapper methodsFor:'displaying'! |
189 |
256 |
190 displayOn:aGC |
257 displayOn:aGC |
191 |oldTranslation oldPaint oldBgPaint| |
258 "display myself - here, display the geometric object asStroked" |
192 |
259 |
193 oldTranslation := aGC translation. |
260 |prevLineWidth prevLineStyle prevCapStyle prevJoinStyle |
194 oldPaint := aGC paint. |
261 prevFg prevBg| |
195 oldBgPaint := aGC backgroundPaint. |
262 |
196 |
263 prevLineWidth := aGC lineWidth. |
197 aGC translation:(origin + aGC translation). |
264 prevLineStyle := aGC lineStyle. |
|
265 prevJoinStyle := aGC joinStyle. |
|
266 prevCapStyle := aGC capStyle. |
|
267 prevFg := aGC paint. |
|
268 prevBg := aGC backgroundPaint. |
|
269 |
|
270 aGC lineWidth:lineWidth. |
|
271 aGC lineStyle:lineStyle. |
|
272 aGC joinStyle:joinStyle. |
|
273 aGC capStyle:capStyle. |
198 aGC paint:fgColor on:bgColor. |
274 aGC paint:fgColor on:bgColor. |
199 |
275 |
200 component displayOn:aGC. |
276 component displayStrokedOn:aGC. |
201 |
277 |
202 aGC translation:oldTranslation. |
278 aGC lineWidth:prevLineWidth. |
203 aGC paint:oldPaint on:oldBgPaint. |
279 aGC lineStyle:prevLineStyle. |
204 |
280 aGC joinStyle:prevJoinStyle. |
205 "Created: 26.5.1996 / 15:27:54 / cg" |
281 aGC capStyle:prevCapStyle. |
206 "Modified: 26.5.1996 / 16:13:44 / cg" |
282 aGC paint:prevFg on:prevBg. |
207 ! ! |
283 |
208 |
284 "Created: 8.5.1996 / 23:24:04 / cg" |
209 !TranslatingWrapper methodsFor:'testing'! |
285 "Modified: 9.5.1996 / 00:11:17 / cg" |
210 |
286 ! ! |
211 containsPoint:aPoint |
287 |
212 ^ component containsPoint:(aPoint - origin) |
288 !StrokingWrapper methodsFor:'initialization'! |
213 |
289 |
214 "Created: 26.5.1996 / 16:48:14 / cg" |
290 initialize |
215 ! |
291 "default my lineWidth to one pixel" |
216 |
292 |
217 intersects:aRectangle |
293 super initialize. |
218 ^ component intersects:(aRectangle - origin) |
294 lineWidth := 1. |
219 |
295 |
220 "Created: 26.5.1996 / 16:48:33 / cg" |
296 "Created: 8.5.1996 / 23:49:27 / cg" |
221 ! ! |
297 "Modified: 9.5.1996 / 00:11:51 / cg" |
222 |
298 ! ! |
223 !TranslatingWrapper class methodsFor:'documentation'! |
299 |
|
300 !StrokingWrapper class methodsFor:'documentation'! |
224 |
301 |
225 version |
302 version |
226 ^ '$Header: /cvs/stx/stx/libview2/Attic/StrokeWrpr.st,v 1.10 1996-05-28 22:43:43 cg Exp $' |
303 ^ '$Header: /cvs/stx/stx/libview2/Attic/StrokeWrpr.st,v 1.11 1996-05-28 22:52:31 cg Exp $' |
227 ! ! |
304 ! ! |