0
|
1 |
"
|
6
|
2 |
COPYRIGHT (c) 1992 by Claus Gittinger
|
71
|
3 |
All Rights Reserved
|
0
|
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 |
Object subclass:#GraphicsContext
|
76
|
14 |
instanceVariableNames:'paint bgPaint
|
71
|
15 |
function font
|
|
16 |
lineStyle lineWidth
|
|
17 |
joinStyle capStyle
|
|
18 |
mask maskOrigin transformation'
|
|
19 |
classVariableNames:'White Black DefaultFont'
|
0
|
20 |
poolDictionaries:''
|
46
|
21 |
category:'Graphics-Support'
|
0
|
22 |
!
|
|
23 |
|
|
24 |
GraphicsContext comment:'
|
6
|
25 |
COPYRIGHT (c) 1992 by Claus Gittinger
|
71
|
26 |
All Rights Reserved
|
54
|
27 |
|
151
|
28 |
$Header: /cvs/stx/stx/libview/Attic/GC.st,v 1.16 1995-06-06 04:06:53 claus Exp $
|
0
|
29 |
'!
|
|
30 |
|
46
|
31 |
!GraphicsContext class methodsFor:'documentation'!
|
|
32 |
|
|
33 |
copyright
|
|
34 |
"
|
|
35 |
COPYRIGHT (c) 1992 by Claus Gittinger
|
71
|
36 |
All Rights Reserved
|
46
|
37 |
|
|
38 |
This software is furnished under a license and may be used
|
|
39 |
only in accordance with the terms of that license and with the
|
|
40 |
inclusion of the above copyright notice. This software may not
|
|
41 |
be provided or otherwise made available to, or used by, any
|
|
42 |
other person. No title to or ownership of the software is
|
|
43 |
hereby transferred.
|
|
44 |
"
|
|
45 |
!
|
|
46 |
|
|
47 |
version
|
|
48 |
"
|
151
|
49 |
$Header: /cvs/stx/stx/libview/Attic/GC.st,v 1.16 1995-06-06 04:06:53 claus Exp $
|
46
|
50 |
"
|
|
51 |
!
|
|
52 |
|
|
53 |
documentation
|
|
54 |
"
|
|
55 |
this is an abstract superclass for all kinds of graphic drawables -
|
|
56 |
both windows and printed pages (i.e. printers) are inheriting from
|
|
57 |
this class (even drawables not at all associated with any device would do so).
|
|
58 |
|
76
|
59 |
Drawing is done in paint/bgPaint colors, which can be true colors (i.e.
|
|
60 |
directly supported by the underlying hardware) or simulated colors
|
|
61 |
(i.e. dithered colors or images).
|
|
62 |
The paint/bgPaint instance variables are set to the logical colors,
|
|
63 |
device specific drawable may like to keep actual colors in addition.
|
71
|
64 |
|
|
65 |
The transformation instance variable is typically nil, for a 1-to-1
|
|
66 |
coordinate mapping (i.e. x/y coordinates are pixels in the drawable).
|
|
67 |
If nonNil, the transformation must be an instance of WindowingTransformation
|
|
68 |
and offers both a scale-factor and a translation.
|
|
69 |
Also, drawing in metric- or inch-units can be done using transformations.
|
|
70 |
(see instance creation methods of WindowingTransformation, and examples
|
|
71 |
in 'doc/coding').
|
46
|
72 |
|
|
73 |
All drawing is defined upon a few basic drawing methods, which must be
|
|
74 |
implemented by subclasses (some subclasses also redefine the others for
|
|
75 |
more performance)
|
|
76 |
|
|
77 |
Instance variables:
|
|
78 |
|
71
|
79 |
paint <Color> the paint used for drawing
|
|
80 |
bgPaint <Color> the background used for drawing texts and bitmaps
|
|
81 |
function <Symbol> the drawing function (i.e. #copy, #or, #xor ...)
|
|
82 |
- not all Drawables support every function
|
|
83 |
(i.e. paper only allows #copy)
|
76
|
84 |
font <Font> the current font to be used for drawing
|
71
|
85 |
lineStyle <Symbol> the lineStyle (i.e. #solid, #dashed, #doubleDashed)
|
|
86 |
lineWidth <SmallInteger> the lineWidth (device dependent, usually pixels)
|
|
87 |
joinStyle <Symbol> the style in which lines (in polygons)
|
|
88 |
are joined (i.e. #miter, #bevel, #round)
|
|
89 |
capStyle <Symbol> the style in which the last point of a line is drawn
|
|
90 |
(i.e. #notLast, #butt, #round, #projecting)
|
|
91 |
mask <Form> a mask used for drawing
|
|
92 |
- not all Drawables support it
|
|
93 |
maskOrigin <Point> the origin of the mask relative to
|
|
94 |
the drawables origin
|
46
|
95 |
|
|
96 |
Class variables:
|
|
97 |
|
71
|
98 |
White <Color> cached white color - its needed so often
|
|
99 |
Black <Color> cached black color - its needed so often
|
46
|
100 |
|
71
|
101 |
DefaultFont <Font> default font to use
|
46
|
102 |
"
|
|
103 |
! !
|
|
104 |
|
0
|
105 |
!GraphicsContext class methodsFor:'initialization'!
|
|
106 |
|
|
107 |
initialize
|
|
108 |
"setup some defaults - these are usually redefined
|
|
109 |
during startup."
|
|
110 |
|
12
|
111 |
Color isNil ifTrue:[^ self].
|
134
|
112 |
White isNil ifTrue:[
|
|
113 |
Color initialize.
|
46
|
114 |
|
134
|
115 |
White := Color white on:Display.
|
|
116 |
Black := Color black on:Display.
|
0
|
117 |
|
134
|
118 |
Font initialize.
|
|
119 |
DefaultFont := Font family:'courier' face:'medium' style:'roman' size:12
|
|
120 |
]
|
0
|
121 |
! !
|
|
122 |
|
|
123 |
!GraphicsContext class methodsFor:'accessing defaults'!
|
|
124 |
|
|
125 |
defaultFont:aFont
|
12
|
126 |
"set the default font used for drawing"
|
|
127 |
|
0
|
128 |
DefaultFont := aFont
|
|
129 |
!
|
|
130 |
|
|
131 |
defaultFont
|
12
|
132 |
"get the default font used for drawing"
|
|
133 |
|
71
|
134 |
DefaultFont isNil ifTrue:[
|
|
135 |
DefaultFont := Font family:'courier' face:'medium' style:'roman' size:12
|
|
136 |
].
|
0
|
137 |
^ DefaultFont
|
|
138 |
! !
|
|
139 |
|
|
140 |
!GraphicsContext class methodsFor:'constants'!
|
|
141 |
|
|
142 |
joinRound
|
|
143 |
"return a constant to specify round join"
|
|
144 |
|
|
145 |
^ #round
|
|
146 |
!
|
|
147 |
|
|
148 |
joinMiter
|
|
149 |
"return a constant to specify miter join"
|
|
150 |
|
|
151 |
^ #miter
|
|
152 |
!
|
|
153 |
|
|
154 |
joinBevel
|
|
155 |
"return a constant to specify bevel join"
|
|
156 |
|
|
157 |
^ #bevel
|
|
158 |
!
|
|
159 |
|
|
160 |
capNotLast
|
|
161 |
"return a constant to specify not-last cap"
|
|
162 |
|
|
163 |
^ #notLast
|
|
164 |
!
|
|
165 |
|
|
166 |
capProjecting
|
|
167 |
"return a constant to specify projecting cap"
|
|
168 |
|
|
169 |
^ #projecting
|
|
170 |
!
|
|
171 |
|
|
172 |
capRound
|
|
173 |
"return a constant to specify round cap"
|
|
174 |
|
|
175 |
^ #round
|
|
176 |
!
|
|
177 |
|
|
178 |
capButt
|
71
|
179 |
"return a constant to specify butt cap"
|
0
|
180 |
|
|
181 |
^ #butt
|
|
182 |
! !
|
|
183 |
|
|
184 |
!GraphicsContext class methodsFor:'instance creation'!
|
|
185 |
|
|
186 |
new
|
109
|
187 |
"return a new instance of myself. Redefined to initialize
|
|
188 |
the new thingy"
|
|
189 |
|
0
|
190 |
^ self basicNew initialize
|
|
191 |
! !
|
|
192 |
|
|
193 |
!GraphicsContext methodsFor:'initialization'!
|
|
194 |
|
|
195 |
initialize
|
|
196 |
"set up some useful default values"
|
|
197 |
|
76
|
198 |
paint := Black.
|
|
199 |
bgPaint := White.
|
0
|
200 |
function := #copy.
|
|
201 |
lineWidth := 1.
|
|
202 |
lineStyle := #solid.
|
|
203 |
joinStyle := #miter.
|
|
204 |
capStyle := #butt.
|
71
|
205 |
font := DefaultFont.
|
0
|
206 |
! !
|
|
207 |
|
2
|
208 |
!GraphicsContext methodsFor:'misc'!
|
|
209 |
|
|
210 |
flush
|
|
211 |
"st-80 compatibility"
|
|
212 |
|
151
|
213 |
self device synchronizeOutput
|
2
|
214 |
! !
|
|
215 |
|
0
|
216 |
!GraphicsContext methodsFor:'accessing'!
|
|
217 |
|
|
218 |
paint
|
|
219 |
"return the current paint drawing color"
|
|
220 |
|
|
221 |
^ paint
|
|
222 |
!
|
|
223 |
|
|
224 |
paint:aColor
|
|
225 |
"set the drawing painting color, aColor can be a dithered one"
|
|
226 |
|
2
|
227 |
paint := aColor
|
0
|
228 |
!
|
|
229 |
|
|
230 |
paint:fgColor on:bgColor
|
|
231 |
"set the paint used for text and bitmaps, both colors may be
|
|
232 |
dithered colors"
|
|
233 |
|
71
|
234 |
self paint:fgColor.
|
2
|
235 |
bgPaint := bgColor
|
0
|
236 |
!
|
|
237 |
|
|
238 |
backgroundPaint
|
|
239 |
"return the background paint color.
|
|
240 |
(used for opaqueForms and opaqueStrings)"
|
|
241 |
|
|
242 |
^ bgPaint
|
|
243 |
!
|
|
244 |
|
|
245 |
backgroundPaint:aColor
|
|
246 |
"set the background painting color (which is used for
|
|
247 |
opaqueForms and opaqueStrings). aColor can be a dithered one."
|
|
248 |
|
|
249 |
^ self subclassResponsibility
|
|
250 |
!
|
|
251 |
|
|
252 |
function
|
|
253 |
"return the current drawing function"
|
|
254 |
|
|
255 |
^ function
|
|
256 |
!
|
|
257 |
|
|
258 |
function:aFunctionSymbol
|
|
259 |
"set the drawing function"
|
|
260 |
|
|
261 |
^ self subclassResponsibility
|
|
262 |
!
|
|
263 |
|
|
264 |
lineWidth
|
|
265 |
"return the current drawing linewidth"
|
|
266 |
|
|
267 |
^ lineWidth
|
|
268 |
!
|
|
269 |
|
|
270 |
lineWidth:aNumber
|
|
271 |
"set the line drawing width in pixels"
|
|
272 |
|
2
|
273 |
lineWidth := aNumber
|
0
|
274 |
!
|
|
275 |
|
|
276 |
lineStyle
|
|
277 |
"return the current line-drawing-style"
|
|
278 |
|
|
279 |
^ lineStyle
|
|
280 |
!
|
|
281 |
|
|
282 |
lineStyle:aStyleSymbol
|
|
283 |
"set the line-drawing-style;
|
|
284 |
possible styles are: #solid, #dashed, #doubleDashed"
|
|
285 |
|
2
|
286 |
lineStyle := aStyleSymbol
|
0
|
287 |
!
|
|
288 |
|
|
289 |
capStyle
|
|
290 |
"return the current cap-style for line-drawing"
|
|
291 |
|
|
292 |
^ capStyle
|
|
293 |
!
|
|
294 |
|
|
295 |
capStyle:aStyleSymbol
|
|
296 |
"set the cap-style for line-drawing;
|
|
297 |
possible styles are: #notLast, #butt, #round, #projecting"
|
|
298 |
|
|
299 |
^ self subclassResponsibility
|
|
300 |
!
|
|
301 |
|
|
302 |
joinStyle
|
|
303 |
"return the current join-style for polygon-drawing"
|
|
304 |
|
|
305 |
^ joinStyle
|
|
306 |
!
|
|
307 |
|
|
308 |
joinStyle:aStyleSymbol
|
|
309 |
"set the join-style of lines in polygon-drawing;
|
|
310 |
possible styles are: #miter, #bevel, #round"
|
|
311 |
|
|
312 |
^ self subclassResponsibility
|
|
313 |
!
|
|
314 |
|
|
315 |
mask
|
|
316 |
"return the current drawing mask"
|
|
317 |
|
|
318 |
^ mask
|
|
319 |
!
|
|
320 |
|
|
321 |
mask:aForm
|
|
322 |
"set the drawing mask"
|
|
323 |
|
|
324 |
^ self subclassResponsibility
|
|
325 |
!
|
|
326 |
|
|
327 |
font
|
|
328 |
"return the current drawing font"
|
|
329 |
|
|
330 |
^ font
|
|
331 |
!
|
|
332 |
|
|
333 |
font:aFont
|
|
334 |
"set the drawing font"
|
|
335 |
|
|
336 |
^ self subclassResponsibility
|
|
337 |
!
|
|
338 |
|
76
|
339 |
clipRect
|
|
340 |
"return the drawing clip-rectangle"
|
|
341 |
|
|
342 |
^ self subclassResponsibility
|
|
343 |
!
|
|
344 |
|
0
|
345 |
clipRect:aRectangle
|
|
346 |
"set the drawing clip-rectangle"
|
|
347 |
|
|
348 |
^ self subclassResponsibility
|
|
349 |
!
|
|
350 |
|
76
|
351 |
clippingBounds
|
|
352 |
"for ST-80 compatibility"
|
|
353 |
|
|
354 |
^ self clipRect
|
|
355 |
!
|
|
356 |
|
0
|
357 |
graphicsContext
|
|
358 |
"for ST-80 compatibility"
|
|
359 |
|
|
360 |
^ self
|
2
|
361 |
!
|
|
362 |
|
|
363 |
viewOrigin
|
12
|
364 |
"return the drawables visible origin (for scrolling)"
|
|
365 |
|
2
|
366 |
^ 0@0
|
|
367 |
!
|
|
368 |
|
151
|
369 |
phase
|
|
370 |
"return the origin within the mask (used to draw with patterns).
|
|
371 |
This is an alias for ST/X's #maskOrigin"
|
|
372 |
|
|
373 |
^ self maskOrigin
|
|
374 |
!
|
|
375 |
|
|
376 |
phase:aPoint
|
109
|
377 |
"set the origin within the mask (used to draw with patterns).
|
151
|
378 |
This is an alias for ST/X's #maskOrigin:"
|
|
379 |
|
|
380 |
^ self maskOrigin:aPoint
|
|
381 |
!
|
|
382 |
|
|
383 |
maskOrigin
|
|
384 |
"return the origin within the mask (used to draw with patterns).
|
|
385 |
Should be redefined in classes which support it.
|
|
386 |
This is an alias for ST-80's #phase"
|
|
387 |
|
|
388 |
^ maskOrigin
|
|
389 |
!
|
|
390 |
|
|
391 |
maskOrigin:aPoint
|
|
392 |
"set the origin within the mask (used to draw with patterns).
|
|
393 |
Should be redefined in classes which support it.
|
|
394 |
This is an alias for ST-80's #phase:"
|
|
395 |
|
|
396 |
^ self maskOriginX:aPoint x y:aPoint y
|
|
397 |
!
|
|
398 |
|
|
399 |
maskOriginX:x y:y
|
|
400 |
"set the origin within the mask (used to draw with patterns).
|
|
401 |
Should be redefined in classes which support it.
|
|
402 |
This is an alias for ST-80's #phase:"
|
109
|
403 |
|
12
|
404 |
^ self
|
|
405 |
!
|
|
406 |
|
151
|
407 |
setMaskOrigin:aPoint
|
|
408 |
"set the origin within the mask (used to draw with patterns).
|
|
409 |
OBSOLETE: use #maskOrigin: or #phase:"
|
|
410 |
|
|
411 |
^ self maskOrigin:aPoint
|
|
412 |
!
|
|
413 |
|
2
|
414 |
setMaskOriginX:x y:y
|
109
|
415 |
"set the origin within the mask (used to draw with patterns).
|
151
|
416 |
OBSOLETE: use #maskOriginX:y: or #phase:"
|
109
|
417 |
|
151
|
418 |
^ self maskOriginX:x y:y
|
2
|
419 |
!
|
|
420 |
|
|
421 |
withPattern:aForm do:aBlock
|
109
|
422 |
"draw with a pattern.
|
|
423 |
Should be redefined in classes which support it"
|
|
424 |
|
71
|
425 |
'pattern drawing not implemented' errorPrintNL.
|
|
426 |
|
2
|
427 |
aBlock value
|
76
|
428 |
!
|
|
429 |
|
|
430 |
transformation
|
|
431 |
"return the transformation"
|
|
432 |
|
|
433 |
^ transformation
|
|
434 |
!
|
|
435 |
|
|
436 |
transformation:aTransformation
|
|
437 |
"set the transformation"
|
|
438 |
|
|
439 |
transformation := aTransformation
|
0
|
440 |
! !
|
|
441 |
|
151
|
442 |
!GraphicsContext methodsFor:'ST-80 compatibility'!
|
|
443 |
|
|
444 |
findFont:aFontDescription
|
|
445 |
^ aFontDescription on:self device
|
|
446 |
!
|
|
447 |
|
|
448 |
widthOfString:aString
|
|
449 |
^ (font on:self device) widthOf:aString
|
|
450 |
!
|
|
451 |
|
|
452 |
widthOfString:aString from:start to:stop
|
|
453 |
^ (font on:self device) widthOf:aString from:start to:stop
|
|
454 |
! !
|
|
455 |
|
71
|
456 |
!GraphicsContext methodsFor:'ST-80 displaying'!
|
|
457 |
|
|
458 |
displayLineFrom:startPoint to:endPoint translateBy:anOffset
|
|
459 |
"draw a line - ST-80 compatibility"
|
|
460 |
|
|
461 |
self displayLineFrom:(startPoint + anOffset)
|
|
462 |
to:(endPoint + anOffset)
|
|
463 |
!
|
0
|
464 |
|
|
465 |
displayRectangularBorder:aRectangle at:aPoint
|
|
466 |
"draw a rectangle - ST-80 compatibility"
|
|
467 |
|
26
|
468 |
self displayRectangle:(aRectangle translateBy:aPoint)
|
0
|
469 |
!
|
|
470 |
|
|
471 |
displayPolyline:aPolygon
|
|
472 |
"draw a polygon - ST-80 compatibility"
|
|
473 |
|
76
|
474 |
^ self displayPolygon:aPolygon
|
35
|
475 |
!
|
|
476 |
|
71
|
477 |
displayArc:origin radius:radius from:startAngle angle:angle
|
|
478 |
"draw an arc around a point"
|
|
479 |
|
|
480 |
self displayArcX:(origin x - radius)
|
|
481 |
y:(origin y - radius)
|
|
482 |
w:(radius * 2)
|
|
483 |
h:(radius * 2)
|
|
484 |
from:startAngle angle:angle
|
|
485 |
!
|
|
486 |
|
35
|
487 |
displayArcBoundedBy:boundingBox startAngle:startAngle sweepAngle:sweepAngle at:origin
|
|
488 |
"draw an arc/circle/ellipse - ST-80 compatibility"
|
0
|
489 |
|
35
|
490 |
^ self displayArcX:(boundingBox left + origin x)
|
71
|
491 |
y:(boundingBox top + origin y)
|
|
492 |
width:(boundingBox width)
|
|
493 |
height:(boundingBox height)
|
|
494 |
from:startAngle
|
|
495 |
angle:sweepAngle
|
35
|
496 |
!
|
|
497 |
|
|
498 |
displayWedgeBoundedBy:boundingBox startAngle:startAngle sweepAngle:sweepAngle at:origin
|
|
499 |
"fill an arc/circle/ellipse - ST-80 compatibility"
|
|
500 |
|
|
501 |
^ self fillArcX:(boundingBox left + origin x)
|
71
|
502 |
y:(boundingBox top + origin y)
|
|
503 |
width:(boundingBox width)
|
|
504 |
height:(boundingBox height)
|
|
505 |
from:startAngle
|
|
506 |
angle:sweepAngle
|
0
|
507 |
! !
|
|
508 |
|
81
|
509 |
!GraphicsContext methodsFor:'bit blitting'!
|
0
|
510 |
|
71
|
511 |
copyFrom:aGC x:srcX y:srcY toX:dstX y:dstY width:w height:h
|
0
|
512 |
"copy from a drawable - maybe self"
|
|
513 |
|
|
514 |
^ self subclassResponsibility
|
|
515 |
!
|
|
516 |
|
71
|
517 |
copyFrom:aGC x:dstX y:dstY width:w height:h
|
|
518 |
"copy from a drawable - maybe self"
|
|
519 |
|
|
520 |
self copyFrom:aGC x:0 y:0 toX:dstX y:dstY width:w height:h
|
|
521 |
!
|
|
522 |
|
|
523 |
copyFrom:aGC toX:dstX y:dstY
|
0
|
524 |
"copy from a drawable - maybe self"
|
|
525 |
|
71
|
526 |
self copyFrom:aGC x:0 y:0 toX:dstX y:dstY width:aGC width height:aGC height
|
|
527 |
! !
|
|
528 |
|
76
|
529 |
!GraphicsContext methodsFor:'drawing in device coordinates'!
|
|
530 |
|
|
531 |
fillDeviceRectangleX:x y:y width:w height:h with:aPattern
|
|
532 |
"fill the rectangular area in the receiver with aPattern,
|
|
533 |
which may be a Form or Color. Use device coordinates."
|
|
534 |
|
|
535 |
self withPattern:aPattern do:[
|
|
536 |
self fillDeviceRectangleX:x y:y width:w height:h
|
|
537 |
]
|
|
538 |
!
|
|
539 |
|
|
540 |
fillDeviceRectangleX:x y:y width:w height:h
|
|
541 |
"fill a rectangle with current paint color (device coordinates)"
|
|
542 |
|
|
543 |
|sav|
|
|
544 |
|
|
545 |
sav := transformation.
|
|
546 |
transformation := nil.
|
|
547 |
self fillRectangleX:x y:y width:w height:h.
|
|
548 |
transformation := sav
|
|
549 |
!
|
|
550 |
|
|
551 |
displayDeviceLineFromX:x1 y:y1 toX:x2 y:y2
|
|
552 |
"draw a line in device coordinates"
|
|
553 |
|
|
554 |
|sav|
|
|
555 |
|
|
556 |
sav := transformation.
|
|
557 |
transformation := nil.
|
|
558 |
self displayLineFromX:x1 y:y1 toX:x2 y:y2.
|
|
559 |
transformation := sav
|
|
560 |
! !
|
|
561 |
|
71
|
562 |
!GraphicsContext methodsFor:'filling'!
|
|
563 |
|
|
564 |
fillRectangle:aRectangle
|
|
565 |
"fill a rectangle with current paint color"
|
|
566 |
|
|
567 |
self fillRectangleX:(aRectangle left)
|
|
568 |
y:(aRectangle top)
|
|
569 |
width:(aRectangle width)
|
|
570 |
height:(aRectangle height)
|
|
571 |
!
|
|
572 |
|
|
573 |
fillArc:origin radius:r from:startAngle angle:angle
|
|
574 |
"draw a filled arc around a point"
|
|
575 |
|
|
576 |
|d|
|
|
577 |
d := 2 * r.
|
|
578 |
self fillArcX:(origin x - r) y:(origin y - r)
|
|
579 |
w:d h:d
|
|
580 |
from:startAngle angle:angle
|
|
581 |
!
|
|
582 |
|
|
583 |
fillCircle:aPoint radius:aNumber
|
|
584 |
"draw a filled circle around aPoint"
|
|
585 |
|
|
586 |
self fillCircleX:(aPoint x) y:(aPoint y) radius:aNumber
|
|
587 |
!
|
|
588 |
|
|
589 |
fillCircleX:x y:y radius:r
|
|
590 |
"draw a filled circle around x@y"
|
|
591 |
|
|
592 |
|d|
|
|
593 |
|
|
594 |
d := 2 * r.
|
|
595 |
self fillArcX:(x - r) y:(y - r)
|
|
596 |
w:d h:d
|
|
597 |
from:0 angle:360
|
0
|
598 |
! !
|
|
599 |
|
|
600 |
!GraphicsContext methodsFor:'basic filling'!
|
|
601 |
|
|
602 |
fillPolygon:points
|
|
603 |
"fill a polygon with current paint color"
|
|
604 |
|
|
605 |
^ self subclassResponsibility
|
|
606 |
!
|
|
607 |
|
|
608 |
fillRectangleX:x y:y width:w height:h
|
|
609 |
"fill a rectangle with current paint color"
|
|
610 |
|
|
611 |
^ self subclassResponsibility
|
|
612 |
!
|
|
613 |
|
|
614 |
fillArcX:x y:y w:w h:h from:start angle:angle
|
|
615 |
"fill an arc with current paint color"
|
|
616 |
|
|
617 |
^ self subclassResponsibility
|
|
618 |
! !
|
|
619 |
|
71
|
620 |
!GraphicsContext methodsFor:'basic displaying'!
|
0
|
621 |
|
26
|
622 |
displayPolygon:aPolygon
|
0
|
623 |
"draw a polygon
|
|
624 |
- this could be recoded to draw using displayLine"
|
|
625 |
|
|
626 |
^ self subclassResponsibility
|
|
627 |
!
|
|
628 |
|
12
|
629 |
displayArcX:x y:y w:width h:height from:startAngle angle:angle
|
0
|
630 |
"draw an arc in a box
|
|
631 |
- this could be recoded to draw using displayLine"
|
|
632 |
|
|
633 |
^ self subclassResponsibility
|
|
634 |
!
|
|
635 |
|
26
|
636 |
displayRectangleX:x y:y width:w height:h
|
0
|
637 |
"draw a rectangle
|
|
638 |
- this could be recoded to draw using displayLine"
|
|
639 |
|
|
640 |
^ self subclassResponsibility
|
|
641 |
!
|
|
642 |
|
26
|
643 |
displayForm:aForm x:x y:y
|
0
|
644 |
"draw a form at x/y; if the form has depth 1, 1's in the form are
|
|
645 |
drawn in current fg, 0's are ignored.
|
24
|
646 |
If the form has depth ~~ 1, the result is undefined"
|
|
647 |
|
71
|
648 |
|fg bg f noColor|
|
24
|
649 |
|
71
|
650 |
fg := paint.
|
|
651 |
bg := bgPaint.
|
24
|
652 |
f := function.
|
0
|
653 |
|
71
|
654 |
f ~~ #copy ifTrue:[
|
|
655 |
self error:'function not supported'.
|
|
656 |
^ self
|
|
657 |
].
|
|
658 |
|
|
659 |
noColor := Color noColor.
|
|
660 |
"
|
|
661 |
stamp out fg-pixels
|
|
662 |
"
|
|
663 |
self paint:noColor on:Color allColor function:#and.
|
26
|
664 |
self displayOpaqueForm:aForm x:x y:y.
|
71
|
665 |
"
|
|
666 |
or-in fg-pixels
|
|
667 |
"
|
|
668 |
self paint:fg on:Color noColor function:#or.
|
26
|
669 |
self displayOpaqueForm:aForm x:x y:y.
|
71
|
670 |
self paint:fg on:fg function:f.
|
0
|
671 |
!
|
|
672 |
|
26
|
673 |
displayOpaqueForm:aForm x:x y:y
|
0
|
674 |
"draw a form at x/y; if the form has depth 1, 1's in the form are
|
|
675 |
drawn in current fg, 0's in current bg color.
|
|
676 |
If the form has depth ~~ 1, it is copied as is onto the receiver"
|
|
677 |
|
|
678 |
^ self subclassResponsibility
|
|
679 |
!
|
|
680 |
|
|
681 |
displayOpaqueString:aString from:index1 to:index2 x:x y:y
|
|
682 |
"draw part of a string with both fg and bg at x/y in current font"
|
|
683 |
|
|
684 |
^ self subclassResponsibility
|
|
685 |
!
|
|
686 |
|
|
687 |
displayString:aString from:index1 to:index2 x:x y:y
|
|
688 |
"draw part of a string with fg at x/y in current font"
|
|
689 |
|
|
690 |
^ self subclassResponsibility
|
|
691 |
! !
|
|
692 |
|
|
693 |
!GraphicsContext methodsFor:'drawing'!
|
|
694 |
|
|
695 |
displayOpaqueString:aString x:x y:y
|
|
696 |
"draw a string with both fg and bg"
|
|
697 |
|
|
698 |
self displayOpaqueString:aString from:1 to:(aString size) x:x y:y
|
|
699 |
!
|
|
700 |
|
|
701 |
displayOpaqueString:aString at:aPoint
|
|
702 |
"draw a string with both fg and bg"
|
|
703 |
|
|
704 |
self displayOpaqueString:aString x:(aPoint x) y:(aPoint y)
|
|
705 |
!
|
|
706 |
|
|
707 |
displayString:aString x:x y:y
|
|
708 |
"draw a string - drawing fg only"
|
|
709 |
|
|
710 |
self displayString:aString from:1 to:(aString size) x:x y:y
|
|
711 |
!
|
|
712 |
|
|
713 |
displayString:aString at:aPoint
|
|
714 |
"draw a string - drawing fg only"
|
|
715 |
|
|
716 |
self displayString:aString x:aPoint x y:aPoint y
|
|
717 |
!
|
|
718 |
|
24
|
719 |
displayPointX:x y:y
|
0
|
720 |
"draw a point at x/y"
|
|
721 |
|
|
722 |
self displayLineFromX:x y:y toX:x y:y
|
|
723 |
!
|
|
724 |
|
24
|
725 |
displayPoint:aPoint
|
0
|
726 |
"draw a pixel"
|
|
727 |
|
24
|
728 |
self displayPointX:(aPoint x) y:(aPoint y)
|
0
|
729 |
!
|
|
730 |
|
|
731 |
displayLineFrom:point1 to:point2
|
|
732 |
"draw a line"
|
|
733 |
|
|
734 |
self displayLineFromX:(point1 x) y:(point1 y)
|
71
|
735 |
toX:(point2 x) y:(point2 y)
|
0
|
736 |
!
|
|
737 |
|
26
|
738 |
displayRectangle:aRectangle
|
0
|
739 |
"draw a rectangle"
|
|
740 |
|
26
|
741 |
self displayRectangleX:(aRectangle left)
|
71
|
742 |
y:(aRectangle top)
|
|
743 |
width:(aRectangle width)
|
|
744 |
height:(aRectangle height)
|
0
|
745 |
!
|
|
746 |
|
26
|
747 |
displayRectangleOrigin:origin corner:corner
|
0
|
748 |
"draw a rectangle"
|
|
749 |
|
|
750 |
|top left|
|
|
751 |
|
|
752 |
left := origin x.
|
|
753 |
top := origin y.
|
26
|
754 |
self displayRectangleX:left y:top
|
71
|
755 |
width:(corner x - left)
|
|
756 |
height:(corner y - top)
|
0
|
757 |
!
|
|
758 |
|
26
|
759 |
displayForm:aForm at:aPoint
|
0
|
760 |
"draw a form"
|
|
761 |
|
26
|
762 |
self displayForm:aForm x:(aPoint x) y:(aPoint y)
|
0
|
763 |
!
|
|
764 |
|
12
|
765 |
displayArcIn:aRectangle from:startAngle angle:angle
|
|
766 |
"draw an arc in a box"
|
0
|
767 |
|
12
|
768 |
self displayArcX:(aRectangle left)
|
71
|
769 |
y:(aRectangle top)
|
|
770 |
w:(aRectangle width)
|
|
771 |
h:(aRectangle height)
|
|
772 |
from:startAngle
|
|
773 |
angle:angle
|
0
|
774 |
!
|
|
775 |
|
12
|
776 |
displayArcOrigin:origin corner:corner from:startAngle angle:angle
|
|
777 |
"draw an arc in a box"
|
0
|
778 |
|
|
779 |
|left top right bot|
|
|
780 |
|
|
781 |
left := origin x.
|
|
782 |
top := origin y.
|
|
783 |
right := corner x.
|
|
784 |
bot := corner y.
|
12
|
785 |
self displayArcX:left y:top
|
71
|
786 |
w:(right - left + 1) h:(bot - top + 1)
|
|
787 |
from:startAngle angle:angle
|
0
|
788 |
!
|
|
789 |
|
12
|
790 |
displayCircleIn:aRectangle
|
0
|
791 |
"draw a circle in a box"
|
|
792 |
|
|
793 |
self
|
71
|
794 |
displayArcX:(aRectangle left)
|
|
795 |
y:(aRectangle top)
|
|
796 |
w:(aRectangle width)
|
|
797 |
h:(aRectangle height)
|
|
798 |
from:0 angle:360
|
0
|
799 |
!
|
|
800 |
|
12
|
801 |
displayCircle:aPoint radius:r
|
|
802 |
"draw a circle around a center point"
|
0
|
803 |
|
12
|
804 |
self displayCircleX:(aPoint x) y:(aPoint y) radius:r
|
0
|
805 |
!
|
|
806 |
|
12
|
807 |
displayCircleX:x y:y radius:r
|
|
808 |
"draw a circle around a center point"
|
0
|
809 |
|
|
810 |
|d|
|
|
811 |
d := 2 * r.
|
12
|
812 |
self displayArcX:(x - r) y:(y - r)
|
71
|
813 |
w:d h:d
|
|
814 |
from:0 angle:360
|
0
|
815 |
! !
|