author | Claus Gittinger <cg@exept.de> |
Thu, 25 Apr 1996 18:26:07 +0200 | |
changeset 611 | e0442439a3c6 |
parent 585 | 426d2018cdc8 |
child 619 | a46cb2ef56bf |
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 |
|
519 | 14 |
instanceVariableNames:'paint bgPaint function font lineStyle lineWidth joinStyle |
15 |
capStyle mask maskOrigin transformation' |
|
16 |
classVariableNames:'White Black DefaultFont' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'Graphics-Support' |
|
0 | 19 |
! |
20 |
||
46 | 21 |
!GraphicsContext class methodsFor:'documentation'! |
22 |
||
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1992 by Claus Gittinger |
|
71 | 26 |
All Rights Reserved |
46 | 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 |
documentation |
|
38 |
" |
|
39 |
this is an abstract superclass for all kinds of graphic drawables - |
|
40 |
both windows and printed pages (i.e. printers) are inheriting from |
|
41 |
this class (even drawables not at all associated with any device would do so). |
|
42 |
||
76 | 43 |
Drawing is done in paint/bgPaint colors, which can be true colors (i.e. |
44 |
directly supported by the underlying hardware) or simulated colors |
|
45 |
(i.e. dithered colors or images). |
|
46 |
The paint/bgPaint instance variables are set to the logical colors, |
|
47 |
device specific drawable may like to keep actual colors in addition. |
|
71 | 48 |
|
49 |
The transformation instance variable is typically nil, for a 1-to-1 |
|
50 |
coordinate mapping (i.e. x/y coordinates are pixels in the drawable). |
|
51 |
If nonNil, the transformation must be an instance of WindowingTransformation |
|
52 |
and offers both a scale-factor and a translation. |
|
53 |
Also, drawing in metric- or inch-units can be done using transformations. |
|
54 |
(see instance creation methods of WindowingTransformation, and examples |
|
55 |
in 'doc/coding'). |
|
46 | 56 |
|
57 |
All drawing is defined upon a few basic drawing methods, which must be |
|
58 |
implemented by subclasses (some subclasses also redefine the others for |
|
59 |
more performance) |
|
60 |
||
611 | 61 |
[Instance variables:] |
46 | 62 |
|
611 | 63 |
paint <Color> the paint used for drawing |
64 |
bgPaint <Color> the background used for drawing texts and bitmaps |
|
65 |
function <Symbol> the drawing function (i.e. #copy, #or, #xor ...) |
|
66 |
- not all Drawables support every function |
|
67 |
(i.e. paper only allows #copy) |
|
68 |
font <Font> the current font to be used for drawing |
|
69 |
lineStyle <Symbol> the lineStyle (i.e. #solid, #dashed, #doubleDashed) |
|
70 |
lineWidth <SmallInteger> the lineWidth (device dependent, usually pixels) |
|
71 |
joinStyle <Symbol> the style in which lines (in polygons) |
|
72 |
are joined (i.e. #miter, #bevel, #round) |
|
73 |
capStyle <Symbol> the style in which the last point of a line is drawn |
|
74 |
(i.e. #notLast, #butt, #round, #projecting) |
|
75 |
mask <Form> a mask used for drawing |
|
76 |
- not all Drawables support it |
|
77 |
maskOrigin <Point> the origin of the mask relative to |
|
78 |
the drawables origin |
|
46 | 79 |
|
611 | 80 |
[Class variables:[ |
81 |
||
82 |
White <Color> cached white color - its needed so often |
|
83 |
Black <Color> cached black color - its needed so often |
|
46 | 84 |
|
611 | 85 |
DefaultFont <Font> default font to use |
46 | 86 |
|
611 | 87 |
[author:] |
88 |
Claus Gittinger |
|
46 | 89 |
" |
563 | 90 |
! |
91 |
||
92 |
examples |
|
93 |
" |
|
94 |
drawing uses a paint color (which may be a dithered one) which is |
|
95 |
used like a `pen'. |
|
96 |
A few drawing operations (opaqueForm and opaqueString drawing) |
|
97 |
use two colors, the paint and a backgroundPaint. For example, |
|
98 |
normal string drawing (#displayString:...) only draws the fonts |
|
99 |
on-pixels in the current paint, leaving off-pixels unchanged. |
|
100 |
In contrast, #drawOpaqueString:.. also changes these to the bgPaint color. |
|
101 |
The bgPaint can be changed with #backgroundPaint: or #paint:on: (which modifies both). |
|
102 |
||
103 |
lets try it in a view: |
|
104 |
||
105 |
|v| |
|
106 |
||
107 |
v := View new. |
|
108 |
v openAndWait. |
|
109 |
||
110 |
v paint:(Color red). |
|
111 |
v displayString:'hello' x:10 y:50 |
|
112 |
||
113 |
the same using opaque drawing: |
|
114 |
|v| |
|
115 |
||
116 |
v := View new. |
|
117 |
v openAndWait. |
|
118 |
||
119 |
v paint:(Color red) on:(Color yellow). |
|
120 |
v displayOpaqueString:'hello' x:10 y:50 |
|
121 |
||
122 |
||
123 |
||
124 |
Lines are drawn using the paint color (if solid) or both paint and bgPaint |
|
125 |
(dashed lines). The look of the line is controlled by joinStyle, capStyle, |
|
126 |
lineWidth and lineStyle. |
|
127 |
`lineStyle' can be one of #solid, #dashed, #doubleDashed |
|
128 |
where: #solid - is for solid lines, drawn with the current paint color |
|
129 |
||
130 |
#dashed - for dashed lines, where only the on-dashes are drawn |
|
131 |
with the current paint color |
|
132 |
||
133 |
#doubleDashed - dashed lines, draws on-dashes with paint color, |
|
134 |
off-dashes with bgPaint |
|
135 |
||
136 |
for example: |
|
137 |
||
138 |
|v| |
|
139 |
||
140 |
v := View new. |
|
141 |
v openAndWait. |
|
142 |
||
143 |
v paint:(Color red) on:(Color blue). |
|
144 |
v displayLineFrom:(10@10) to:(90@90). |
|
145 |
||
146 |
v lineStyle:#dashed. |
|
147 |
v displayLineFrom:(90@10) to:(10@90). |
|
148 |
||
149 |
v lineStyle:#doubleDashed. |
|
150 |
v displayRectangle:((5@5) corner:(95@95)). |
|
151 |
||
152 |
changing the line-width: |
|
153 |
||
154 |
|v| |
|
155 |
||
156 |
v := View new. |
|
157 |
v openAndWait. |
|
158 |
||
159 |
v paint:(Color red). |
|
160 |
v displayLineFrom:(20@20) to:(80@80). |
|
161 |
||
162 |
v lineWidth:5. |
|
163 |
v displayLineFrom:(80@20) to:(20@80). |
|
164 |
||
165 |
v lineWidth:8. |
|
166 |
v displayRectangle:((5@5) corner:(95@95)). |
|
167 |
||
168 |
with wide lines, the corners (of polygons or rectangles) can be |
|
169 |
one of the joinStyles: #miter, #bevel, #round. The default is #miter. |
|
170 |
||
171 |
|v| |
|
172 |
||
173 |
v := View new extent:200@200. |
|
174 |
v openAndWait. |
|
175 |
||
176 |
v lineWidth:15. |
|
177 |
v paint:(Color red). |
|
178 |
||
179 |
v displayRectangle:((65@65) corner:(135@135)). |
|
180 |
||
181 |
v joinStyle:#bevel. |
|
182 |
v displayRectangle:((45@45) corner:(155@155)). |
|
183 |
||
184 |
v joinStyle:#round. |
|
185 |
v displayRectangle:((25@25) corner:(175@175)). |
|
186 |
||
187 |
||
188 |
the endPoints look is controlled with capStyle; |
|
189 |
possible values are: #notLast, #butt, #round, #projecting. |
|
190 |
The default is #butt. |
|
191 |
#notLast is mostly useful when exoring (inverting): it will not draw the |
|
192 |
endPoint, to allow another line to join the previous line without inverting |
|
193 |
this point twice. (See the X manual for more info). |
|
194 |
||
195 |
|v| |
|
196 |
||
197 |
v := View new extent:200@200. |
|
198 |
v openAndWait. |
|
199 |
||
200 |
v lineWidth:15. |
|
201 |
v paint:(Color red). |
|
202 |
||
203 |
v displayLineFrom:(25@25) to:(175@25). |
|
204 |
||
205 |
v capStyle:#round. |
|
206 |
v displayLineFrom:(25@55) to:(175@55). |
|
207 |
||
208 |
v capStyle:#projecting. |
|
209 |
v displayLineFrom:(25@85) to:(175@85). |
|
210 |
||
211 |
||
212 |
You can use a bitmap as a point color: |
|
213 |
(this may be slow on some graphics devices, though) |
|
214 |
||
215 |
|v| |
|
216 |
||
217 |
v := View new extent:200@200. |
|
218 |
v openAndWait. |
|
219 |
||
220 |
v lineWidth:15. |
|
221 |
v paint:(Image fromFile:'granite_small.tiff'). |
|
222 |
||
223 |
v displayLineFrom:(25@25) to:(175@25). |
|
224 |
||
225 |
v capStyle:#round. |
|
226 |
v displayLineFrom:(25@55) to:(175@55). |
|
227 |
||
228 |
v capStyle:#projecting. |
|
229 |
v displayLineFrom:(25@85) to:(175@85). |
|
230 |
||
231 |
all views support a translation and scale, so you can draw in another |
|
232 |
coordinate system: |
|
233 |
||
234 |
|v| |
|
235 |
||
236 |
v := View new extent:200@200. |
|
237 |
v openAndWait. |
|
238 |
||
239 |
v displayForm:(Image fromFile:'SBrowser.xbm') x:10 y:10. |
|
240 |
||
241 |
v scale:(2@2); translation:50. |
|
242 |
v displayForm:(Image fromFile:'SBrowser.xbm') x:10 y:10. |
|
243 |
||
244 |
v scale:(0.5@0.5); translation:0. |
|
245 |
v displayForm:(Image fromFile:'SBrowser.xbm') x:10 y:10. |
|
246 |
||
247 |
if scaling is on, it is often useful to be able to draw individual |
|
248 |
things unscaled - this still translates the position, but |
|
249 |
uses the unscaled font (for example, to draw strings in a graphic): |
|
250 |
||
251 |
|v| |
|
252 |
||
253 |
v := View new extent:200@200. |
|
254 |
v openAndWait. |
|
255 |
||
256 |
v displayForm:(Image fromFile:'SBrowser.xbm') x:10 y:10. |
|
257 |
v displayString:'hello' x:50 y:40. |
|
258 |
||
259 |
v scale:(2@4). |
|
260 |
v displayForm:(Image fromFile:'SBrowser.xbm') x:10 y:10. |
|
261 |
v displayUnscaledString:'hello' x:50 y:40. |
|
262 |
||
263 |
Filled objects are drawin using the #fillXXX methods; for example, |
|
264 |
displayRectangleXXX draws the outline, while fillRectangleXXX draws a |
|
265 |
filled one: |
|
266 |
|v| |
|
267 |
||
268 |
v := View new extent:200@200. |
|
269 |
v openAndWait. |
|
270 |
||
271 |
v displayArcIn:(20@20 corner:50@50) from:0 angle:180. |
|
272 |
v paint:Color yellow. |
|
273 |
v fillArcIn:(120@120 corner:150@150) from:0 angle:180. |
|
274 |
||
275 |
v paint:Color red. |
|
276 |
v displayCircle:150@50 radius:30. |
|
277 |
v paint:Color blue. |
|
278 |
v fillCircle:50@150 radius:30. |
|
279 |
" |
|
46 | 280 |
! ! |
281 |
||
0 | 282 |
!GraphicsContext class methodsFor:'initialization'! |
283 |
||
284 |
initialize |
|
285 |
"setup some defaults - these are usually redefined |
|
286 |
during startup." |
|
287 |
||
134 | 288 |
White isNil ifTrue:[ |
386 | 289 |
Color isNil ifTrue:[^ self]. |
290 |
Display isNil ifTrue:[^ self]. |
|
291 |
||
134 | 292 |
Color initialize. |
46 | 293 |
|
134 | 294 |
White := Color white on:Display. |
295 |
Black := Color black on:Display. |
|
0 | 296 |
|
134 | 297 |
Font initialize. |
298 |
DefaultFont := Font family:'courier' face:'medium' style:'roman' size:12 |
|
299 |
] |
|
0 | 300 |
! ! |
301 |
||
519 | 302 |
!GraphicsContext class methodsFor:'instance creation'! |
0 | 303 |
|
519 | 304 |
new |
305 |
"return a new instance of myself. Redefined to initialize |
|
306 |
the new thingy" |
|
12 | 307 |
|
519 | 308 |
^ self basicNew initialize |
309 |
! ! |
|
310 |
||
311 |
!GraphicsContext class methodsFor:'accessing defaults'! |
|
0 | 312 |
|
313 |
defaultFont |
|
12 | 314 |
"get the default font used for drawing" |
315 |
||
71 | 316 |
DefaultFont isNil ifTrue:[ |
317 |
DefaultFont := Font family:'courier' face:'medium' style:'roman' size:12 |
|
318 |
]. |
|
0 | 319 |
^ DefaultFont |
519 | 320 |
! |
321 |
||
322 |
defaultFont:aFont |
|
323 |
"set the default font used for drawing" |
|
324 |
||
325 |
DefaultFont := aFont |
|
0 | 326 |
! ! |
327 |
||
328 |
!GraphicsContext class methodsFor:'constants'! |
|
329 |
||
519 | 330 |
capButt |
331 |
"return a constant to specify butt cap" |
|
0 | 332 |
|
519 | 333 |
^ #butt |
0 | 334 |
! |
335 |
||
336 |
capNotLast |
|
337 |
"return a constant to specify not-last cap" |
|
338 |
||
339 |
^ #notLast |
|
340 |
! |
|
341 |
||
342 |
capProjecting |
|
343 |
"return a constant to specify projecting cap" |
|
344 |
||
345 |
^ #projecting |
|
346 |
! |
|
347 |
||
348 |
capRound |
|
349 |
"return a constant to specify round cap" |
|
350 |
||
351 |
^ #round |
|
352 |
! |
|
353 |
||
519 | 354 |
joinBevel |
355 |
"return a constant to specify bevel join" |
|
356 |
||
357 |
^ #bevel |
|
358 |
! |
|
0 | 359 |
|
519 | 360 |
joinMiter |
361 |
"return a constant to specify miter join" |
|
362 |
||
363 |
^ #miter |
|
364 |
! |
|
365 |
||
366 |
joinRound |
|
367 |
"return a constant to specify round join" |
|
368 |
||
369 |
^ #round |
|
0 | 370 |
! ! |
371 |
||
519 | 372 |
!GraphicsContext methodsFor:'ST-80 compatibility'! |
373 |
||
374 |
findFont:aFontDescription |
|
585 | 375 |
"given a fontDescription, return a device font for it |
376 |
on my device." |
|
377 |
||
519 | 378 |
^ aFontDescription on:self device |
585 | 379 |
|
380 |
"Modified: 22.4.1996 / 19:45:41 / cg" |
|
519 | 381 |
! |
0 | 382 |
|
519 | 383 |
widthOfString:aString |
585 | 384 |
"given a string, return its width in pixels if |
385 |
drawn on the receivers device." |
|
386 |
||
519 | 387 |
^ (font on:self device) widthOf:aString |
585 | 388 |
|
389 |
"Modified: 22.4.1996 / 19:46:10 / cg" |
|
519 | 390 |
! |
109 | 391 |
|
519 | 392 |
widthOfString:aString from:start to:stop |
585 | 393 |
"given a string, return the width in pixels if |
394 |
a substring is drawn on the receivers device." |
|
395 |
||
519 | 396 |
^ (font on:self device) widthOf:aString from:start to:stop |
585 | 397 |
|
398 |
"Modified: 22.4.1996 / 19:46:25 / cg" |
|
0 | 399 |
! ! |
400 |
||
519 | 401 |
!GraphicsContext methodsFor:'ST-80 displaying'! |
402 |
||
403 |
displayArc:origin radius:radius from:startAngle angle:angle |
|
404 |
"draw an arc around a point" |
|
405 |
||
406 |
self displayArcX:(origin x - radius) |
|
407 |
y:(origin y - radius) |
|
408 |
w:(radius * 2) |
|
409 |
h:(radius * 2) |
|
410 |
from:startAngle angle:angle |
|
411 |
! |
|
0 | 412 |
|
519 | 413 |
displayArcBoundedBy:boundingBox startAngle:startAngle sweepAngle:sweepAngle at:origin |
414 |
"draw an arc/circle/ellipse - ST-80 compatibility" |
|
415 |
||
416 |
^ self displayArcX:(boundingBox left + origin x) |
|
417 |
y:(boundingBox top + origin y) |
|
418 |
width:(boundingBox width) |
|
419 |
height:(boundingBox height) |
|
420 |
from:startAngle |
|
421 |
angle:sweepAngle |
|
422 |
! |
|
423 |
||
424 |
displayLineFrom:startPoint to:endPoint translateBy:anOffset |
|
425 |
"draw a line - ST-80 compatibility" |
|
0 | 426 |
|
519 | 427 |
self displayLineFrom:(startPoint + anOffset) |
428 |
to:(endPoint + anOffset) |
|
429 |
! |
|
430 |
||
431 |
displayPolyline:aPolygon |
|
432 |
"draw a polygon - ST-80 compatibility" |
|
433 |
||
434 |
^ self displayPolygon:aPolygon |
|
435 |
! |
|
436 |
||
437 |
displayRectangularBorder:aRectangle at:aPoint |
|
438 |
"draw a rectangle - ST-80 compatibility" |
|
0 | 439 |
|
519 | 440 |
self displayRectangle:(aRectangle translateBy:aPoint) |
441 |
! |
|
442 |
||
443 |
displayWedgeBoundedBy:boundingBox startAngle:startAngle sweepAngle:sweepAngle at:origin |
|
444 |
"fill an arc/circle/ellipse - ST-80 compatibility" |
|
2 | 445 |
|
519 | 446 |
^ self fillArcX:(boundingBox left + origin x) |
447 |
y:(boundingBox top + origin y) |
|
448 |
width:(boundingBox width) |
|
449 |
height:(boundingBox height) |
|
450 |
from:startAngle |
|
451 |
angle:sweepAngle |
|
2 | 452 |
! ! |
453 |
||
0 | 454 |
!GraphicsContext methodsFor:'accessing'! |
455 |
||
456 |
backgroundPaint |
|
457 |
"return the background paint color. |
|
458 |
(used for opaqueForms and opaqueStrings)" |
|
459 |
||
460 |
^ bgPaint |
|
461 |
! |
|
462 |
||
463 |
backgroundPaint:aColor |
|
464 |
"set the background painting color (which is used for |
|
465 |
opaqueForms and opaqueStrings). aColor can be a dithered one." |
|
466 |
||
467 |
^ self subclassResponsibility |
|
468 |
! |
|
469 |
||
470 |
capStyle |
|
471 |
"return the current cap-style for line-drawing" |
|
472 |
||
473 |
^ capStyle |
|
474 |
! |
|
475 |
||
476 |
capStyle:aStyleSymbol |
|
477 |
"set the cap-style for line-drawing; |
|
478 |
possible styles are: #notLast, #butt, #round, #projecting" |
|
479 |
||
480 |
^ self subclassResponsibility |
|
481 |
! |
|
482 |
||
76 | 483 |
clipRect |
484 |
"return the drawing clip-rectangle" |
|
485 |
||
486 |
^ self subclassResponsibility |
|
487 |
! |
|
488 |
||
0 | 489 |
clipRect:aRectangle |
490 |
"set the drawing clip-rectangle" |
|
491 |
||
492 |
^ self subclassResponsibility |
|
493 |
! |
|
494 |
||
76 | 495 |
clippingBounds |
563 | 496 |
"return the drawing clip-rectangle - name alias ST-80 compatibility" |
76 | 497 |
|
498 |
^ self clipRect |
|
563 | 499 |
|
500 |
"Modified: 13.4.1996 / 20:13:04 / cg" |
|
76 | 501 |
! |
502 |
||
561
3c1ec7798f77
added #clippingRectangleOrNil for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
519
diff
changeset
|
503 |
clippingRectangleOrNil |
563 | 504 |
"return the drawing clip-rectangle, or nil if there is none" |
505 |
||
561
3c1ec7798f77
added #clippingRectangleOrNil for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
519
diff
changeset
|
506 |
^ self subclassResponsibility |
3c1ec7798f77
added #clippingRectangleOrNil for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
519
diff
changeset
|
507 |
|
3c1ec7798f77
added #clippingRectangleOrNil for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
519
diff
changeset
|
508 |
"Created: 10.4.1996 / 14:31:19 / cg" |
563 | 509 |
"Modified: 13.4.1996 / 20:12:43 / cg" |
561
3c1ec7798f77
added #clippingRectangleOrNil for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
519
diff
changeset
|
510 |
! |
3c1ec7798f77
added #clippingRectangleOrNil for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
519
diff
changeset
|
511 |
|
519 | 512 |
font |
513 |
"return the current drawing font" |
|
514 |
||
515 |
^ font |
|
516 |
! |
|
517 |
||
518 |
font:aFont |
|
519 |
"set the drawing font" |
|
520 |
||
521 |
^ self subclassResponsibility |
|
522 |
! |
|
523 |
||
524 |
function |
|
525 |
"return the current drawing function" |
|
526 |
||
527 |
^ function |
|
528 |
! |
|
529 |
||
530 |
function:aFunctionSymbol |
|
531 |
"set the drawing function" |
|
532 |
||
533 |
^ self subclassResponsibility |
|
534 |
! |
|
535 |
||
0 | 536 |
graphicsContext |
537 |
"for ST-80 compatibility" |
|
538 |
||
539 |
^ self |
|
2 | 540 |
! |
541 |
||
519 | 542 |
joinStyle |
543 |
"return the current join-style for polygon-drawing" |
|
544 |
||
545 |
^ joinStyle |
|
546 |
! |
|
12 | 547 |
|
519 | 548 |
joinStyle:aStyleSymbol |
549 |
"set the join-style of lines in polygon-drawing; |
|
550 |
possible styles are: #miter, #bevel, #round" |
|
551 |
||
552 |
^ self subclassResponsibility |
|
553 |
! |
|
554 |
||
555 |
lineStyle |
|
556 |
"return the current line-drawing-style" |
|
557 |
||
558 |
^ lineStyle |
|
2 | 559 |
! |
560 |
||
519 | 561 |
lineStyle:aStyleSymbol |
562 |
"set the line-drawing-style; |
|
563 |
possible styles are: #solid, #dashed, #doubleDashed" |
|
151 | 564 |
|
519 | 565 |
lineStyle := aStyleSymbol |
566 |
! |
|
567 |
||
568 |
lineWidth |
|
569 |
"return the current drawing linewidth" |
|
570 |
||
571 |
^ lineWidth |
|
151 | 572 |
! |
573 |
||
519 | 574 |
lineWidth:aNumber |
575 |
"set the line drawing width in pixels" |
|
576 |
||
577 |
lineWidth := aNumber |
|
578 |
! |
|
151 | 579 |
|
519 | 580 |
mask |
581 |
"return the current drawing mask" |
|
582 |
||
583 |
^ mask |
|
584 |
! |
|
585 |
||
586 |
mask:aForm |
|
587 |
"set the drawing mask" |
|
588 |
||
589 |
^ self subclassResponsibility |
|
151 | 590 |
! |
591 |
||
592 |
maskOrigin |
|
593 |
"return the origin within the mask (used to draw with patterns). |
|
594 |
Should be redefined in classes which support it. |
|
595 |
This is an alias for ST-80's #phase" |
|
596 |
||
597 |
^ maskOrigin |
|
598 |
! |
|
599 |
||
600 |
maskOrigin:aPoint |
|
601 |
"set the origin within the mask (used to draw with patterns). |
|
602 |
Should be redefined in classes which support it. |
|
603 |
This is an alias for ST-80's #phase:" |
|
604 |
||
605 |
^ self maskOriginX:aPoint x y:aPoint y |
|
606 |
! |
|
607 |
||
608 |
maskOriginX:x y:y |
|
609 |
"set the origin within the mask (used to draw with patterns). |
|
610 |
Should be redefined in classes which support it. |
|
611 |
This is an alias for ST-80's #phase:" |
|
109 | 612 |
|
12 | 613 |
^ self |
614 |
! |
|
615 |
||
519 | 616 |
paint |
617 |
"return the current paint drawing color" |
|
618 |
||
619 |
^ paint |
|
620 |
! |
|
621 |
||
622 |
paint:aColor |
|
623 |
"set the drawing painting color, aColor can be a dithered one" |
|
624 |
||
625 |
paint := aColor |
|
626 |
! |
|
627 |
||
628 |
paint:fgColor on:bgColor |
|
563 | 629 |
"set the paint and backgroundPaint, used for text and bitmaps. |
630 |
Both colors may be dithered colors" |
|
519 | 631 |
|
632 |
self paint:fgColor. |
|
633 |
bgPaint := bgColor |
|
563 | 634 |
|
635 |
"Modified: 13.4.1996 / 20:20:24 / cg" |
|
519 | 636 |
! |
637 |
||
638 |
phase |
|
639 |
"return the origin within the mask (used to draw with patterns). |
|
640 |
This is an alias for ST/X's #maskOrigin" |
|
641 |
||
642 |
^ self maskOrigin |
|
643 |
! |
|
644 |
||
645 |
phase:aPoint |
|
646 |
"set the origin within the mask (used to draw with patterns). |
|
647 |
This is an alias for ST/X's #maskOrigin:" |
|
648 |
||
649 |
^ self maskOrigin:aPoint |
|
650 |
! |
|
651 |
||
151 | 652 |
setMaskOrigin:aPoint |
653 |
"set the origin within the mask (used to draw with patterns). |
|
654 |
OBSOLETE: use #maskOrigin: or #phase:" |
|
655 |
||
656 |
^ self maskOrigin:aPoint |
|
657 |
! |
|
658 |
||
2 | 659 |
setMaskOriginX:x y:y |
109 | 660 |
"set the origin within the mask (used to draw with patterns). |
151 | 661 |
OBSOLETE: use #maskOriginX:y: or #phase:" |
109 | 662 |
|
151 | 663 |
^ self maskOriginX:x y:y |
2 | 664 |
! |
665 |
||
519 | 666 |
viewOrigin |
667 |
"return the drawables visible origin (for scrolling)" |
|
668 |
||
669 |
^ 0@0 |
|
670 |
! |
|
671 |
||
2 | 672 |
withPattern:aForm do:aBlock |
109 | 673 |
"draw with a pattern. |
674 |
Should be redefined in classes which support it" |
|
675 |
||
519 | 676 |
'GC: pattern drawing not implemented' infoPrintNL. |
71 | 677 |
|
2 | 678 |
aBlock value |
519 | 679 |
|
680 |
"Modified: 7.3.1996 / 19:17:05 / cg" |
|
418
0e10e256d5b2
scale access methods moved from SimpleView
Claus Gittinger <cg@exept.de>
parents:
386
diff
changeset
|
681 |
! ! |
0e10e256d5b2
scale access methods moved from SimpleView
Claus Gittinger <cg@exept.de>
parents:
386
diff
changeset
|
682 |
|
0e10e256d5b2
scale access methods moved from SimpleView
Claus Gittinger <cg@exept.de>
parents:
386
diff
changeset
|
683 |
!GraphicsContext methodsFor:'accessing-transformation'! |
0e10e256d5b2
scale access methods moved from SimpleView
Claus Gittinger <cg@exept.de>
parents:
386
diff
changeset
|
684 |
|
0e10e256d5b2
scale access methods moved from SimpleView
Claus Gittinger <cg@exept.de>
parents:
386
diff
changeset
|
685 |
scale |
0e10e256d5b2
scale access methods moved from SimpleView
Claus Gittinger <cg@exept.de>
parents:
386
diff
changeset
|
686 |
"return the scale factor (as point) of the transformation" |
0e10e256d5b2
scale access methods moved from SimpleView
Claus Gittinger <cg@exept.de>
parents:
386
diff
changeset
|
687 |
|
0e10e256d5b2
scale access methods moved from SimpleView
Claus Gittinger <cg@exept.de>
parents:
386
diff
changeset
|
688 |
transformation isNil ifTrue:[^ 1]. |
0e10e256d5b2
scale access methods moved from SimpleView
Claus Gittinger <cg@exept.de>
parents:
386
diff
changeset
|
689 |
^ transformation scale |
0e10e256d5b2
scale access methods moved from SimpleView
Claus Gittinger <cg@exept.de>
parents:
386
diff
changeset
|
690 |
! |
0e10e256d5b2
scale access methods moved from SimpleView
Claus Gittinger <cg@exept.de>
parents:
386
diff
changeset
|
691 |
|
0e10e256d5b2
scale access methods moved from SimpleView
Claus Gittinger <cg@exept.de>
parents:
386
diff
changeset
|
692 |
scale:aPoint |
0e10e256d5b2
scale access methods moved from SimpleView
Claus Gittinger <cg@exept.de>
parents:
386
diff
changeset
|
693 |
"set the scale factor of the transformation" |
0e10e256d5b2
scale access methods moved from SimpleView
Claus Gittinger <cg@exept.de>
parents:
386
diff
changeset
|
694 |
|
0e10e256d5b2
scale access methods moved from SimpleView
Claus Gittinger <cg@exept.de>
parents:
386
diff
changeset
|
695 |
transformation isNil ifTrue:[ |
0e10e256d5b2
scale access methods moved from SimpleView
Claus Gittinger <cg@exept.de>
parents:
386
diff
changeset
|
696 |
aPoint = 1 ifTrue:[^ self]. |
0e10e256d5b2
scale access methods moved from SimpleView
Claus Gittinger <cg@exept.de>
parents:
386
diff
changeset
|
697 |
transformation := WindowingTransformation scale:aPoint translation:0 |
0e10e256d5b2
scale access methods moved from SimpleView
Claus Gittinger <cg@exept.de>
parents:
386
diff
changeset
|
698 |
]. |
0e10e256d5b2
scale access methods moved from SimpleView
Claus Gittinger <cg@exept.de>
parents:
386
diff
changeset
|
699 |
|
0e10e256d5b2
scale access methods moved from SimpleView
Claus Gittinger <cg@exept.de>
parents:
386
diff
changeset
|
700 |
transformation scale:aPoint. |
76 | 701 |
! |
702 |
||
703 |
transformation |
|
704 |
"return the transformation" |
|
705 |
||
706 |
^ transformation |
|
707 |
! |
|
708 |
||
709 |
transformation:aTransformation |
|
710 |
"set the transformation" |
|
711 |
||
712 |
transformation := aTransformation |
|
0 | 713 |
! ! |
714 |
||
71 | 715 |
!GraphicsContext methodsFor:'basic displaying'! |
0 | 716 |
|
12 | 717 |
displayArcX:x y:y w:width h:height from:startAngle angle:angle |
0 | 718 |
"draw an arc in a box |
719 |
- this could be recoded to draw using displayLine" |
|
720 |
||
721 |
^ self subclassResponsibility |
|
722 |
! |
|
723 |
||
26 | 724 |
displayForm:aForm x:x y:y |
0 | 725 |
"draw a form at x/y; if the form has depth 1, 1's in the form are |
726 |
drawn in current fg, 0's are ignored. |
|
24 | 727 |
If the form has depth ~~ 1, the result is undefined" |
728 |
||
71 | 729 |
|fg bg f noColor| |
24 | 730 |
|
71 | 731 |
fg := paint. |
732 |
bg := bgPaint. |
|
24 | 733 |
f := function. |
0 | 734 |
|
71 | 735 |
f ~~ #copy ifTrue:[ |
736 |
self error:'function not supported'. |
|
737 |
^ self |
|
738 |
]. |
|
739 |
||
740 |
noColor := Color noColor. |
|
741 |
" |
|
742 |
stamp out fg-pixels |
|
743 |
" |
|
744 |
self paint:noColor on:Color allColor function:#and. |
|
26 | 745 |
self displayOpaqueForm:aForm x:x y:y. |
71 | 746 |
" |
747 |
or-in fg-pixels |
|
748 |
" |
|
749 |
self paint:fg on:Color noColor function:#or. |
|
26 | 750 |
self displayOpaqueForm:aForm x:x y:y. |
71 | 751 |
self paint:fg on:fg function:f. |
0 | 752 |
! |
753 |
||
26 | 754 |
displayOpaqueForm:aForm x:x y:y |
0 | 755 |
"draw a form at x/y; if the form has depth 1, 1's in the form are |
756 |
drawn in current fg, 0's in current bg color. |
|
757 |
If the form has depth ~~ 1, it is copied as is onto the receiver" |
|
758 |
||
759 |
^ self subclassResponsibility |
|
760 |
! |
|
761 |
||
762 |
displayOpaqueString:aString from:index1 to:index2 x:x y:y |
|
763 |
"draw part of a string with both fg and bg at x/y in current font" |
|
764 |
||
765 |
^ self subclassResponsibility |
|
766 |
! |
|
767 |
||
519 | 768 |
displayPolygon:aPolygon |
769 |
"draw a polygon |
|
770 |
- this could be recoded to draw using displayLine" |
|
771 |
||
772 |
^ self subclassResponsibility |
|
773 |
! |
|
774 |
||
775 |
displayRectangleX:x y:y width:w height:h |
|
776 |
"draw a rectangle |
|
777 |
- this could be recoded to draw using displayLine" |
|
778 |
||
779 |
^ self subclassResponsibility |
|
780 |
! |
|
781 |
||
0 | 782 |
displayString:aString from:index1 to:index2 x:x y:y |
783 |
"draw part of a string with fg at x/y in current font" |
|
784 |
||
785 |
^ self subclassResponsibility |
|
786 |
! ! |
|
787 |
||
519 | 788 |
!GraphicsContext methodsFor:'basic filling'! |
0 | 789 |
|
519 | 790 |
fillArcX:x y:y w:w h:h from:start angle:angle |
791 |
"fill an arc with current paint color" |
|
0 | 792 |
|
519 | 793 |
^ self subclassResponsibility |
0 | 794 |
! |
795 |
||
519 | 796 |
fillPolygon:points |
797 |
"fill a polygon with current paint color" |
|
0 | 798 |
|
519 | 799 |
^ self subclassResponsibility |
157 | 800 |
! |
801 |
||
519 | 802 |
fillRectangleX:x y:y width:w height:h |
803 |
"fill a rectangle with current paint color" |
|
0 | 804 |
|
519 | 805 |
^ self subclassResponsibility |
806 |
! ! |
|
0 | 807 |
|
519 | 808 |
!GraphicsContext methodsFor:'bit blitting'! |
0 | 809 |
|
519 | 810 |
copyFrom:aGC toX:dstX y:dstY |
811 |
"copy from a drawable - maybe self" |
|
0 | 812 |
|
519 | 813 |
self copyFrom:aGC x:0 y:0 toX:dstX y:dstY width:aGC width height:aGC height |
0 | 814 |
! |
815 |
||
519 | 816 |
copyFrom:aGC x:srcX y:srcY toX:dstX y:dstY width:w height:h |
817 |
"copy from a drawable - maybe self" |
|
0 | 818 |
|
519 | 819 |
^ self subclassResponsibility |
0 | 820 |
! |
821 |
||
519 | 822 |
copyFrom:aGC x:dstX y:dstY width:w height:h |
823 |
"copy from a drawable - maybe self" |
|
0 | 824 |
|
519 | 825 |
self copyFrom:aGC x:0 y:0 toX:dstX y:dstY width:w height:h |
826 |
! ! |
|
0 | 827 |
|
519 | 828 |
!GraphicsContext methodsFor:'drawing'! |
0 | 829 |
|
12 | 830 |
displayArcIn:aRectangle from:startAngle angle:angle |
831 |
"draw an arc in a box" |
|
0 | 832 |
|
12 | 833 |
self displayArcX:(aRectangle left) |
71 | 834 |
y:(aRectangle top) |
835 |
w:(aRectangle width) |
|
836 |
h:(aRectangle height) |
|
837 |
from:startAngle |
|
838 |
angle:angle |
|
0 | 839 |
! |
840 |
||
12 | 841 |
displayArcOrigin:origin corner:corner from:startAngle angle:angle |
842 |
"draw an arc in a box" |
|
0 | 843 |
|
844 |
|left top right bot| |
|
845 |
||
846 |
left := origin x. |
|
847 |
top := origin y. |
|
848 |
right := corner x. |
|
849 |
bot := corner y. |
|
12 | 850 |
self displayArcX:left y:top |
71 | 851 |
w:(right - left + 1) h:(bot - top + 1) |
852 |
from:startAngle angle:angle |
|
0 | 853 |
! |
854 |
||
519 | 855 |
displayCircle:aPoint radius:r |
856 |
"draw a circle around a center point" |
|
857 |
||
858 |
self displayCircleX:(aPoint x) y:(aPoint y) radius:r |
|
859 |
! |
|
860 |
||
12 | 861 |
displayCircleIn:aRectangle |
0 | 862 |
"draw a circle in a box" |
863 |
||
864 |
self |
|
71 | 865 |
displayArcX:(aRectangle left) |
866 |
y:(aRectangle top) |
|
867 |
w:(aRectangle width) |
|
868 |
h:(aRectangle height) |
|
869 |
from:0 angle:360 |
|
0 | 870 |
! |
871 |
||
12 | 872 |
displayCircleX:x y:y radius:r |
873 |
"draw a circle around a center point" |
|
0 | 874 |
|
875 |
|d| |
|
876 |
d := 2 * r. |
|
12 | 877 |
self displayArcX:(x - r) y:(y - r) |
71 | 878 |
w:d h:d |
879 |
from:0 angle:360 |
|
519 | 880 |
! |
881 |
||
882 |
displayForm:aForm at:aPoint |
|
883 |
"draw a form" |
|
884 |
||
885 |
self displayForm:aForm x:(aPoint x) y:(aPoint y) |
|
886 |
! |
|
887 |
||
888 |
displayLineFrom:point1 to:point2 |
|
889 |
"draw a line" |
|
890 |
||
891 |
self displayLineFromX:(point1 x) y:(point1 y) |
|
892 |
toX:(point2 x) y:(point2 y) |
|
893 |
! |
|
894 |
||
895 |
displayOpaqueString:aString at:aPoint |
|
896 |
"draw a string with both fg and bg" |
|
897 |
||
898 |
self displayOpaqueString:aString x:(aPoint x) y:(aPoint y) |
|
899 |
! |
|
900 |
||
901 |
displayOpaqueString:aString from:start to:stop at:aPoint |
|
902 |
"draw part of a string - drawing both fg and bg" |
|
903 |
||
904 |
^ self displayOpaqueString:aString from:start to:stop x:aPoint x y:aPoint y |
|
905 |
! |
|
906 |
||
907 |
displayOpaqueString:aString x:x y:y |
|
908 |
"draw a string with both fg and bg" |
|
909 |
||
910 |
self displayOpaqueString:aString from:1 to:(aString size) x:x y:y |
|
911 |
! |
|
912 |
||
913 |
displayPoint:aPoint |
|
914 |
"draw a pixel" |
|
915 |
||
916 |
self displayPointX:(aPoint x) y:(aPoint y) |
|
917 |
! |
|
918 |
||
919 |
displayPointX:x y:y |
|
920 |
"draw a point at x/y" |
|
921 |
||
922 |
self displayLineFromX:x y:y toX:x y:y |
|
923 |
! |
|
924 |
||
925 |
displayRectangle:aRectangle |
|
926 |
"draw a rectangle" |
|
927 |
||
928 |
self displayRectangleX:(aRectangle left) |
|
929 |
y:(aRectangle top) |
|
930 |
width:(aRectangle width) |
|
931 |
height:(aRectangle height) |
|
932 |
! |
|
933 |
||
934 |
displayRectangleOrigin:origin corner:corner |
|
935 |
"draw a rectangle" |
|
936 |
||
937 |
|top left| |
|
938 |
||
939 |
left := origin x. |
|
940 |
top := origin y. |
|
941 |
self displayRectangleX:left y:top |
|
563 | 942 |
width:(corner x - left) |
943 |
height:(corner y - top) |
|
944 |
||
945 |
"Modified: 13.4.1996 / 20:58:31 / cg" |
|
519 | 946 |
! |
947 |
||
948 |
displayString:aString at:aPoint |
|
949 |
"draw a string - drawing fg only" |
|
950 |
||
951 |
self displayString:aString x:aPoint x y:aPoint y |
|
952 |
! |
|
953 |
||
954 |
displayString:aString from:start to:stop at:aPoint |
|
955 |
"draw part of a string - drawing fg only" |
|
956 |
||
957 |
^ self displayString:aString from:start to:stop x:aPoint x y:aPoint y |
|
958 |
! |
|
959 |
||
960 |
displayString:aString x:x y:y |
|
961 |
"draw a string - drawing fg only" |
|
962 |
||
963 |
self displayString:aString from:1 to:(aString size) x:x y:y |
|
0 | 964 |
! ! |
519 | 965 |
|
966 |
!GraphicsContext methodsFor:'drawing in device coordinates'! |
|
967 |
||
968 |
displayDeviceLineFromX:x1 y:y1 toX:x2 y:y2 |
|
969 |
"draw a line in device coordinates" |
|
970 |
||
971 |
|sav| |
|
972 |
||
973 |
sav := transformation. |
|
974 |
transformation := nil. |
|
975 |
self displayLineFromX:x1 y:y1 toX:x2 y:y2. |
|
976 |
transformation := sav |
|
977 |
! |
|
978 |
||
979 |
fillDeviceRectangleX:x y:y width:w height:h |
|
980 |
"fill a rectangle with current paint color (device coordinates)" |
|
981 |
||
982 |
|sav| |
|
983 |
||
984 |
sav := transformation. |
|
985 |
transformation := nil. |
|
986 |
self fillRectangleX:x y:y width:w height:h. |
|
987 |
transformation := sav |
|
988 |
! |
|
989 |
||
990 |
fillDeviceRectangleX:x y:y width:w height:h with:aPattern |
|
991 |
"fill the rectangular area in the receiver with aPattern, |
|
992 |
which may be a Form or Color. Use device coordinates." |
|
993 |
||
994 |
self withPattern:aPattern do:[ |
|
995 |
self fillDeviceRectangleX:x y:y width:w height:h |
|
996 |
] |
|
997 |
! ! |
|
998 |
||
999 |
!GraphicsContext methodsFor:'filling'! |
|
1000 |
||
1001 |
fillArc:origin radius:r from:startAngle angle:angle |
|
1002 |
"draw a filled arc around a point" |
|
1003 |
||
1004 |
|d| |
|
1005 |
d := 2 * r. |
|
1006 |
self fillArcX:(origin x - r) y:(origin y - r) |
|
1007 |
w:d h:d |
|
1008 |
from:startAngle angle:angle |
|
1009 |
! |
|
1010 |
||
563 | 1011 |
fillArcIn:aRectangle from:startAngle angle:angle |
1012 |
"draw a filled arc in a box" |
|
1013 |
||
1014 |
self fillArcX:(aRectangle left) |
|
1015 |
y:(aRectangle top) |
|
1016 |
w:(aRectangle width) |
|
1017 |
h:(aRectangle height) |
|
1018 |
from:startAngle |
|
1019 |
angle:angle |
|
1020 |
||
1021 |
"Created: 13.4.1996 / 20:56:03 / cg" |
|
1022 |
! |
|
1023 |
||
1024 |
fillArcOrigin:origin corner:corner from:startAngle angle:angle |
|
1025 |
"draw a filled arc in a box" |
|
1026 |
||
1027 |
|left top right bot| |
|
1028 |
||
1029 |
left := origin x. |
|
1030 |
top := origin y. |
|
1031 |
right := corner x. |
|
1032 |
bot := corner y. |
|
1033 |
self |
|
1034 |
fillArcX:left |
|
1035 |
y:top |
|
1036 |
w:(right - left + 1) |
|
1037 |
h:(bot - top + 1) |
|
1038 |
from:startAngle |
|
1039 |
angle:angle |
|
1040 |
||
1041 |
"Created: 13.4.1996 / 20:56:56 / cg" |
|
1042 |
! |
|
1043 |
||
519 | 1044 |
fillCircle:aPoint radius:aNumber |
1045 |
"draw a filled circle around aPoint" |
|
1046 |
||
1047 |
self fillCircleX:(aPoint x) y:(aPoint y) radius:aNumber |
|
1048 |
! |
|
1049 |
||
563 | 1050 |
fillCircleIn:aRectangle |
1051 |
"draw a filled circle in a box" |
|
1052 |
||
1053 |
self |
|
1054 |
fillArcX:(aRectangle left) |
|
1055 |
y:(aRectangle top) |
|
1056 |
w:(aRectangle width) |
|
1057 |
h:(aRectangle height) |
|
1058 |
from:0 |
|
1059 |
angle:360 |
|
1060 |
||
1061 |
"Created: 13.4.1996 / 20:57:41 / cg" |
|
1062 |
! |
|
1063 |
||
519 | 1064 |
fillCircleX:x y:y radius:r |
1065 |
"draw a filled circle around x@y" |
|
1066 |
||
1067 |
|d| |
|
1068 |
||
1069 |
d := 2 * r. |
|
1070 |
self fillArcX:(x - r) y:(y - r) |
|
1071 |
w:d h:d |
|
1072 |
from:0 angle:360 |
|
1073 |
! |
|
1074 |
||
1075 |
fillRectangle:aRectangle |
|
1076 |
"fill a rectangle with current paint color" |
|
1077 |
||
1078 |
self fillRectangleX:(aRectangle left) |
|
1079 |
y:(aRectangle top) |
|
1080 |
width:(aRectangle width) |
|
1081 |
height:(aRectangle height) |
|
563 | 1082 |
! |
1083 |
||
1084 |
fillRectangleOrigin:origin corner:corner |
|
1085 |
"draw a filled rectangle" |
|
1086 |
||
1087 |
|top left| |
|
1088 |
||
1089 |
left := origin x. |
|
1090 |
top := origin y. |
|
1091 |
self fillRectangleX:left y:top |
|
1092 |
width:(corner x - left) |
|
1093 |
height:(corner y - top) |
|
1094 |
||
1095 |
"Created: 13.4.1996 / 20:58:16 / cg" |
|
519 | 1096 |
! ! |
1097 |
||
1098 |
!GraphicsContext methodsFor:'initialization'! |
|
1099 |
||
1100 |
initialize |
|
1101 |
"set up some useful default values" |
|
1102 |
||
1103 |
paint := Black. |
|
1104 |
bgPaint := White. |
|
1105 |
function := #copy. |
|
1106 |
lineWidth := 1. |
|
1107 |
lineStyle := #solid. |
|
1108 |
joinStyle := #miter. |
|
1109 |
capStyle := #butt. |
|
1110 |
font := DefaultFont. |
|
1111 |
! ! |
|
1112 |
||
1113 |
!GraphicsContext methodsFor:'misc'! |
|
1114 |
||
1115 |
flush |
|
585 | 1116 |
"send all buffered drawing to the device." |
519 | 1117 |
|
1118 |
self device flush |
|
585 | 1119 |
|
1120 |
"Modified: 22.4.1996 / 19:47:19 / cg" |
|
519 | 1121 |
! ! |
1122 |
||
1123 |
!GraphicsContext class methodsFor:'documentation'! |
|
1124 |
||
1125 |
version |
|
611 | 1126 |
^ '$Header: /cvs/stx/stx/libview/GraphicsContext.st,v 1.27 1996-04-25 16:26:07 cg Exp $' |
519 | 1127 |
! ! |
1128 |
GraphicsContext initialize! |