author | Claus Gittinger <cg@exept.de> |
Tue, 13 Jul 1999 17:38:21 +0200 | |
changeset 1201 | d8c4b4f52e7e |
parent 405 | 4acab6da7d82 |
permissions | -rw-r--r-- |
245 | 1 |
" |
2 |
COPYRIGHT (c) 1996 by Claus Gittinger |
|
3 |
All Rights Reserved |
|
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 |
||
13 |
||
280 | 14 |
GeometricWrapper subclass:#StrokingWrapper |
15 |
instanceVariableNames:'lineWidth lineStyle capStyle joinStyle' |
|
245 | 16 |
classVariableNames:'' |
17 |
poolDictionaries:'' |
|
18 |
category:'Graphics-Display Objects' |
|
19 |
! |
|
20 |
||
280 | 21 |
!StrokingWrapper class methodsFor:'documentation'! |
245 | 22 |
|
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1996 by Claus Gittinger |
|
26 |
All Rights Reserved |
|
27 |
||
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
||
36 |
! |
|
37 |
||
38 |
documentation |
|
39 |
" |
|
280 | 40 |
a wrapper for a geometric object, which is to be drawn stroked. |
41 |
This allows any geometric thingy to be used as a component in a view. |
|
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) |
|
254 | 46 |
|
265 | 47 |
Notice: |
48 |
this class was implemented using protocol information |
|
365 | 49 |
from alpha testers, from reading PD programs and |
50 |
from the Hopkins/Horan book. |
|
265 | 51 |
- it may not be complete or compatible to the corresponding ST-80 class. |
52 |
If you encounter any incompatibilities, please forward a note |
|
53 |
describing the incompatibility verbal (i.e. no code) to the ST/X team. |
|
54 |
||
248 | 55 |
[see also:] |
280 | 56 |
FillingWrapper Geometric GraphicsContext |
248 | 57 |
|
245 | 58 |
[author:] |
59 |
Claus Gittinger |
|
60 |
" |
|
61 |
! |
|
62 |
||
63 |
examples |
|
64 |
" |
|
280 | 65 |
wrap an ellipticArc and display it |
66 |
(notice, that no automatic redraw is performed): |
|
67 |
[exBegin] |
|
68 |
|v e component| |
|
69 |
||
70 |
v := (StandardSystemView extent:250@250) openAndWait. |
|
71 |
||
72 |
e := EllipticalArc boundingBox:(10@10 corner:90@90) |
|
73 |
startAngle:0 |
|
74 |
sweepAngle:270. |
|
75 |
component := StrokingWrapper on:e. |
|
76 |
||
77 |
component displayOn:v. |
|
78 |
[exEnd] |
|
79 |
||
80 |
wrap a rectangle and an ellipticArc, |
|
81 |
and add them as components to a View |
|
82 |
(notice, that doing so makes the redraw automatic): |
|
83 |
[exBegin] |
|
84 |
|v e component| |
|
85 |
||
86 |
v := StandardSystemView extent:250@250. |
|
87 |
||
88 |
e := Rectangle origin:10@10 corner:90@90. |
|
89 |
component := FillingWrapper on:e. |
|
90 |
component foregroundColor:Color red. |
|
91 |
||
92 |
v addComponent:component. |
|
93 |
||
94 |
e := EllipticalArc boundingBox:(10@10 corner:90@90) |
|
95 |
startAngle:0 sweepAngle:360. |
|
96 |
component := StrokingWrapper on:e. |
|
97 |
component lineWidth:5. |
|
98 |
||
99 |
v addComponent:component. |
|
100 |
||
101 |
v addComponent:(Button label:'hello'). |
|
102 |
||
103 |
v open |
|
104 |
[exEnd] |
|
105 |
with lineWidth & style: |
|
106 |
(notice, that the redraw is automatic): |
|
107 |
[exBegin] |
|
108 |
|v e| |
|
109 |
||
110 |
v := StandardSystemView extent:250@250. |
|
111 |
||
112 |
e := EllipticalArc boundingBox:(10@10 corner:90@90) |
|
113 |
startAngle:0 |
|
114 |
sweepAngle:270. |
|
115 |
v addComponent:((StrokingWrapper on:e) |
|
116 |
lineWidth:5; |
|
117 |
lineStyle:#dashed; |
|
118 |
foregroundColor:(Color red)). |
|
119 |
||
120 |
e := EllipticalArc boundingBox:(30@30 corner:70@70) |
|
121 |
startAngle:90 |
|
122 |
sweepAngle:270. |
|
123 |
v addComponent:((StrokingWrapper on:e) |
|
124 |
lineWidth:5; |
|
125 |
lineStyle:#doubleDashed; |
|
126 |
foregroundColor:(Color red); |
|
127 |
backgroundColor:(Color green)). |
|
128 |
v open. |
|
129 |
[exEnd] |
|
130 |
||
131 |
scrolling: |
|
273 | 132 |
[exBegin] |
133 |
|t s v e component| |
|
134 |
||
135 |
t := StandardSystemView extent:250@200. |
|
136 |
s := HVScrollableView for:View miniScroller:true in:t. |
|
137 |
s origin:0.0@0.0 corner:1.0@1.0. |
|
138 |
v := s scrolledView. |
|
139 |
||
140 |
e := Rectangle origin:10@10 corner:90@90. |
|
141 |
component := FillingWrapper on:e. |
|
142 |
component foregroundColor:Color red. |
|
143 |
v addComponent:component. |
|
144 |
||
145 |
e := EllipticalArc boundingBox:(10@10 corner:90@90) |
|
146 |
startAngle:0 sweepAngle:360. |
|
147 |
component := StrokingWrapper on:e. |
|
148 |
component lineWidth:5. |
|
149 |
v addComponent:component. |
|
150 |
||
151 |
e := Arrow from:100@100 to:150@250. |
|
152 |
component := StrokingWrapper on:e. |
|
153 |
component lineWidth:2. |
|
154 |
v addComponent:component. |
|
155 |
||
280 | 156 |
v addComponent:(Button label:'hello'). |
273 | 157 |
|
158 |
t open |
|
159 |
[exEnd] |
|
160 |
||
245 | 161 |
" |
162 |
! ! |
|
163 |
||
280 | 164 |
!StrokingWrapper methodsFor:'accessing'! |
165 |
||
166 |
bounds |
|
167 |
"return the boundary rectangle - here, must take care of the lineWidth" |
|
168 |
||
295 | 169 |
^ (component bounds insetBy:(lineWidth // 2 + 1) negated) rounded |
245 | 170 |
|
280 | 171 |
"Created: 8.5.1996 / 23:22:43 / cg" |
295 | 172 |
"Modified: 5.6.1996 / 20:30:39 / cg" |
280 | 173 |
! |
245 | 174 |
|
280 | 175 |
capStyle |
176 |
"return the capStyle" |
|
177 |
||
178 |
^ capStyle |
|
262
55b430276719
added lineStyle/capStyle & joinStyle
Claus Gittinger <cg@exept.de>
parents:
254
diff
changeset
|
179 |
|
280 | 180 |
"Created: 8.5.1996 / 23:22:04 / cg" |
181 |
"Modified: 9.5.1996 / 00:09:12 / cg" |
|
182 |
! |
|
262
55b430276719
added lineStyle/capStyle & joinStyle
Claus Gittinger <cg@exept.de>
parents:
254
diff
changeset
|
183 |
|
280 | 184 |
capStyle:aSymbol |
185 |
"set the capStyle" |
|
186 |
||
187 |
capStyle := aSymbol |
|
262
55b430276719
added lineStyle/capStyle & joinStyle
Claus Gittinger <cg@exept.de>
parents:
254
diff
changeset
|
188 |
|
280 | 189 |
"Created: 8.5.1996 / 23:22:13 / cg" |
190 |
"Modified: 9.5.1996 / 00:09:17 / cg" |
|
191 |
! |
|
262
55b430276719
added lineStyle/capStyle & joinStyle
Claus Gittinger <cg@exept.de>
parents:
254
diff
changeset
|
192 |
|
280 | 193 |
joinStyle |
194 |
"return the joinStyle" |
|
262
55b430276719
added lineStyle/capStyle & joinStyle
Claus Gittinger <cg@exept.de>
parents:
254
diff
changeset
|
195 |
|
280 | 196 |
^ joinStyle |
197 |
||
198 |
"Created: 8.5.1996 / 23:22:04 / cg" |
|
199 |
"Modified: 9.5.1996 / 00:09:12 / cg" |
|
262
55b430276719
added lineStyle/capStyle & joinStyle
Claus Gittinger <cg@exept.de>
parents:
254
diff
changeset
|
200 |
! |
55b430276719
added lineStyle/capStyle & joinStyle
Claus Gittinger <cg@exept.de>
parents:
254
diff
changeset
|
201 |
|
280 | 202 |
joinStyle:aSymbol |
203 |
"set the joinStyle" |
|
262
55b430276719
added lineStyle/capStyle & joinStyle
Claus Gittinger <cg@exept.de>
parents:
254
diff
changeset
|
204 |
|
280 | 205 |
joinStyle := aSymbol |
262
55b430276719
added lineStyle/capStyle & joinStyle
Claus Gittinger <cg@exept.de>
parents:
254
diff
changeset
|
206 |
|
280 | 207 |
"Created: 8.5.1996 / 23:22:13 / cg" |
208 |
"Modified: 9.5.1996 / 00:09:17 / cg" |
|
209 |
! |
|
262
55b430276719
added lineStyle/capStyle & joinStyle
Claus Gittinger <cg@exept.de>
parents:
254
diff
changeset
|
210 |
|
280 | 211 |
lineStyle |
212 |
"return the lineStyle" |
|
262
55b430276719
added lineStyle/capStyle & joinStyle
Claus Gittinger <cg@exept.de>
parents:
254
diff
changeset
|
213 |
|
280 | 214 |
^ lineStyle |
215 |
||
216 |
"Created: 8.5.1996 / 23:22:04 / cg" |
|
217 |
"Modified: 9.5.1996 / 00:09:12 / cg" |
|
262
55b430276719
added lineStyle/capStyle & joinStyle
Claus Gittinger <cg@exept.de>
parents:
254
diff
changeset
|
218 |
! |
55b430276719
added lineStyle/capStyle & joinStyle
Claus Gittinger <cg@exept.de>
parents:
254
diff
changeset
|
219 |
|
280 | 220 |
lineStyle:aSymbol |
221 |
"set the lineStyle" |
|
222 |
||
223 |
lineStyle := aSymbol |
|
224 |
||
225 |
"Created: 8.5.1996 / 23:22:13 / cg" |
|
226 |
"Modified: 9.5.1996 / 00:09:17 / cg" |
|
227 |
! |
|
228 |
||
229 |
lineWidth |
|
230 |
"return the lineWidth" |
|
246 | 231 |
|
280 | 232 |
^ lineWidth |
233 |
||
234 |
"Created: 8.5.1996 / 23:22:04 / cg" |
|
235 |
"Modified: 9.5.1996 / 00:09:12 / cg" |
|
236 |
! |
|
237 |
||
238 |
lineWidth:aNumber |
|
239 |
"set the lineWidth" |
|
240 |
||
241 |
lineWidth := aNumber |
|
242 |
||
243 |
"Created: 8.5.1996 / 23:22:13 / cg" |
|
244 |
"Modified: 9.5.1996 / 00:09:17 / cg" |
|
245 | 245 |
! |
246 |
||
247 |
preferredBounds |
|
280 | 248 |
"return the components bounds as preferredBounds" |
246 | 249 |
|
295 | 250 |
^ (component bounds insetBy:(lineWidth / 2 + 1) negated) rounded |
280 | 251 |
|
252 |
"Created: 8.5.1996 / 23:23:00 / cg" |
|
295 | 253 |
"Modified: 5.6.1996 / 20:32:36 / cg" |
245 | 254 |
! ! |
255 |
||
280 | 256 |
!StrokingWrapper methodsFor:'displaying'! |
245 | 257 |
|
258 |
displayOn:aGC |
|
280 | 259 |
"display myself - here, display the geometric object asStroked" |
260 |
||
261 |
|prevLineWidth prevLineStyle prevCapStyle prevJoinStyle |
|
262 |
prevFg prevBg| |
|
245 | 263 |
|
280 | 264 |
prevLineWidth := aGC lineWidth. |
265 |
prevLineStyle := aGC lineStyle. |
|
266 |
prevJoinStyle := aGC joinStyle. |
|
267 |
prevCapStyle := aGC capStyle. |
|
268 |
prevFg := aGC paint. |
|
269 |
prevBg := aGC backgroundPaint. |
|
245 | 270 |
|
280 | 271 |
aGC lineWidth:lineWidth. |
272 |
aGC lineStyle:lineStyle. |
|
273 |
aGC joinStyle:joinStyle. |
|
274 |
aGC capStyle:capStyle. |
|
405
4acab6da7d82
fgColor/bgColor -> foregroundColor/backgroundColor
Claus Gittinger <cg@exept.de>
parents:
365
diff
changeset
|
275 |
aGC paint:foregroundColor on:backgroundColor. |
245 | 276 |
|
280 | 277 |
component displayStrokedOn:aGC. |
245 | 278 |
|
280 | 279 |
aGC lineWidth:prevLineWidth. |
280 |
aGC lineStyle:prevLineStyle. |
|
281 |
aGC joinStyle:prevJoinStyle. |
|
282 |
aGC capStyle:prevCapStyle. |
|
283 |
aGC paint:prevFg on:prevBg. |
|
245 | 284 |
|
280 | 285 |
"Created: 8.5.1996 / 23:24:04 / cg" |
405
4acab6da7d82
fgColor/bgColor -> foregroundColor/backgroundColor
Claus Gittinger <cg@exept.de>
parents:
365
diff
changeset
|
286 |
"Modified: 10.2.1997 / 14:21:33 / cg" |
245 | 287 |
! ! |
288 |
||
280 | 289 |
!StrokingWrapper methodsFor:'initialization'! |
245 | 290 |
|
280 | 291 |
initialize |
292 |
"default my lineWidth to one pixel" |
|
246 | 293 |
|
280 | 294 |
super initialize. |
295 |
lineWidth := 1. |
|
245 | 296 |
|
280 | 297 |
"Created: 8.5.1996 / 23:49:27 / cg" |
298 |
"Modified: 9.5.1996 / 00:11:51 / cg" |
|
245 | 299 |
! ! |
300 |
||
280 | 301 |
!StrokingWrapper class methodsFor:'documentation'! |
245 | 302 |
|
303 |
version |
|
405
4acab6da7d82
fgColor/bgColor -> foregroundColor/backgroundColor
Claus Gittinger <cg@exept.de>
parents:
365
diff
changeset
|
304 |
^ '$Header: /cvs/stx/stx/libview2/Attic/StrokeWrpr.st,v 1.14 1997-02-10 13:48:46 cg Exp $' |
245 | 305 |
! ! |