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