author | Claus Gittinger <cg@exept.de> |
Wed, 12 Jun 1996 13:04:34 +0200 | |
changeset 832 | 064890dcfabd |
parent 786 | af5fecf93126 |
child 844 | 17d0f74d7d02 |
permissions | -rw-r--r-- |
732 | 1 |
" |
2 |
COPYRIGHT (c) 1992 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 |
GraphicsContext subclass:#DeviceGraphicsContext |
|
14 |
instanceVariableNames:'drawableId gcId deviceFont foreground background' |
|
15 |
classVariableNames:'CachedScaledForms CachedScales Lobby' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'Graphics-Support' |
|
18 |
! |
|
19 |
||
20 |
!DeviceGraphicsContext class methodsFor:'documentation'! |
|
21 |
||
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1992 by Claus Gittinger |
|
25 |
All Rights Reserved |
|
26 |
||
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
36 |
documentation |
|
37 |
" |
|
38 |
I provide the common protocol for a graphicsContext which is associated with a particular |
|
39 |
device (i.e. Bitmaps, Pixmaps, RootWindow and Windows in Xs world, but also postscript |
|
40 |
printer pages or fax pages). |
|
41 |
||
42 |
My instance variables are mainly caching device-related stuff (such as font- and color-Ids) |
|
43 |
to avoid needless message traffic. This class is abstract, no direct instances of it |
|
44 |
exist in the system. |
|
45 |
All real work is done by my device, which is accessed via the device instance variable. |
|
46 |
Most drawing requests are simply forwarded to it, others are simulated by using more basic |
|
47 |
drawing functions (see GraphicsContext drawing vs. basic drawing category). |
|
48 |
||
49 |
The added variables foreground/background are the drawing colors actually |
|
50 |
used; these are the real (i.e. non dithered) colors supported by the device. |
|
51 |
Direct access to fg/bg is discouraged, since in the future, these may be |
|
52 |
totally replaced by paint/bgPaint |
|
53 |
(there are some operations and special cases, for which a direct access to |
|
54 |
fg/bg makes sense) |
|
55 |
||
56 |
[Instance variables:] |
|
57 |
||
58 |
drawableId <SmallInteger> my drawableId on the device (a device handle) |
|
59 |
||
60 |
gcId <SmallInteger> my gc's ID on the device (a device handle) |
|
61 |
||
62 |
deviceFont <Font> the actual font, currently set in the device |
|
63 |
||
64 |
foreground <Color> the device foreground color used for drawing |
|
65 |
||
66 |
background <Color> the device background color used for drawing |
|
67 |
||
68 |
[see also:] |
|
69 |
DeviceWorkstation |
|
70 |
Color Font Cursor |
|
71 |
||
72 |
[author:] |
|
73 |
Claus Gittinger |
|
74 |
||
75 |
" |
|
76 |
! ! |
|
77 |
||
78 |
!DeviceGraphicsContext class methodsFor:'initialization'! |
|
79 |
||
80 |
initialize |
|
81 |
Lobby isNil ifTrue:[ |
|
82 |
Lobby := Registry new. |
|
83 |
] |
|
84 |
! ! |
|
85 |
||
86 |
!DeviceGraphicsContext class methodsFor:'instance creation'! |
|
87 |
||
88 |
new |
|
89 |
"create a new drawable - take the current display as |
|
90 |
its device (for now, this may be changed until the view is |
|
91 |
physically created)" |
|
92 |
||
93 |
" |
|
94 |
'Warning: DeviceGraphicsContext (' print. self name print. ') should not be created with new' printNL. |
|
95 |
" |
|
96 |
^ self onDevice:Screen current "Display" |
|
97 |
! |
|
98 |
||
99 |
on:aDevice |
|
100 |
"create a new drawable on aDevice" |
|
101 |
||
102 |
^ self onDevice:aDevice |
|
103 |
! |
|
104 |
||
105 |
onDevice:aDevice |
|
106 |
"create a new drawable on aDevice" |
|
107 |
||
108 |
|newDrawable| |
|
109 |
||
110 |
newDrawable := self basicNew. |
|
111 |
||
112 |
" |
|
113 |
set display before its initialized |
|
114 |
- so it can do something useful (i.e. get font sizes etc.) in its |
|
115 |
intitialize method(s) |
|
116 |
" |
|
117 |
newDrawable device:aDevice. |
|
118 |
newDrawable initialize. |
|
119 |
Lobby register:newDrawable. |
|
120 |
^ newDrawable |
|
121 |
! ! |
|
122 |
||
123 |
!DeviceGraphicsContext class methodsFor:'cleanup'! |
|
124 |
||
125 |
lowSpaceCleanup |
|
126 |
CachedScaledForms := CachedScales := nil |
|
127 |
! ! |
|
128 |
||
129 |
!DeviceGraphicsContext methodsFor:'accessing'! |
|
130 |
||
131 |
at:aPoint |
|
132 |
"return the pixel at the coordinate given by aPoint" |
|
133 |
||
134 |
^ device |
|
135 |
getPixelX:(aPoint x) |
|
136 |
y:(aPoint y) |
|
137 |
from:drawableId |
|
138 |
! |
|
139 |
||
140 |
at:aPoint put:aPixel |
|
141 |
"set a pixel" |
|
142 |
||
143 |
|oldFg| |
|
144 |
||
145 |
oldFg := foreground. |
|
146 |
self foreground:aPixel. |
|
147 |
self displayPointX:(aPoint x) y:(aPoint y). |
|
148 |
self foreground:oldFg |
|
149 |
! |
|
150 |
||
151 |
atX:x y:y |
|
152 |
"return the pixel at the coordinate given by x/y" |
|
153 |
||
154 |
^ device getPixelX:x y:y from:drawableId |
|
155 |
! |
|
156 |
||
157 |
atX:x y:y put:aPixel |
|
158 |
"set a pixel" |
|
159 |
||
160 |
|oldFg| |
|
161 |
||
162 |
oldFg := foreground. |
|
163 |
self foreground:aPixel. |
|
164 |
self displayPointX:x y:y. |
|
165 |
self foreground:oldFg |
|
166 |
! |
|
167 |
||
168 |
backgroundPaint:aColor |
|
169 |
"set the background-paint color; this is used in opaque-draw |
|
170 |
operations" |
|
171 |
||
172 |
(aColor ~~ bgPaint) ifTrue:[ |
|
173 |
aColor notNil ifTrue:[ |
|
174 |
bgPaint := aColor. |
|
175 |
gcId notNil ifTrue:[ |
|
176 |
bgPaint isColor ifTrue:[ |
|
177 |
bgPaint := aColor on:device. |
|
178 |
bgPaint colorId notNil ifTrue:[ |
|
179 |
background := bgPaint. |
|
180 |
device setBackground:(bgPaint colorId) in:drawableId. |
|
181 |
^ self |
|
182 |
] |
|
183 |
]. |
|
184 |
self paint:paint on:aColor |
|
185 |
] |
|
186 |
] |
|
187 |
]. |
|
188 |
! |
|
189 |
||
190 |
basicFont |
|
191 |
"return set the font for drawing" |
|
192 |
||
193 |
^ font |
|
194 |
||
195 |
"Created: 12.5.1996 / 11:17:59 / cg" |
|
196 |
! |
|
197 |
||
198 |
basicFont:aFont |
|
199 |
"set the font for drawing if it has changed. |
|
200 |
This is a low level entry, which is not to be redefined |
|
201 |
(i.e. it must not imply a redraw operation)" |
|
202 |
||
203 |
|id| |
|
204 |
||
205 |
(aFont ~~ font) ifTrue:[ |
|
206 |
aFont notNil ifTrue:[ |
|
207 |
font := aFont. |
|
208 |
gcId notNil ifTrue:[ |
|
209 |
font := font on:device. |
|
210 |
id := font fontId. |
|
211 |
id notNil ifTrue:[ |
|
212 |
device setFont:id in:gcId |
|
213 |
] |
|
214 |
] |
|
215 |
] |
|
216 |
] |
|
217 |
||
218 |
"Modified: 23.2.1996 / 17:01:06 / cg" |
|
219 |
"Created: 23.2.1996 / 17:16:51 / cg" |
|
220 |
! |
|
221 |
||
222 |
capStyle:aSymbol |
|
223 |
"set the style in which the endpoints of lines |
|
224 |
are drawn - aSymbol may be #notLast, #butt, #round, #projecting" |
|
225 |
||
226 |
|s| |
|
227 |
||
228 |
(s := aSymbol) isNil ifTrue:[ |
|
229 |
s := #butt. |
|
230 |
||
231 |
]. |
|
232 |
(s ~~ capStyle) ifTrue:[ |
|
233 |
capStyle := s. |
|
234 |
gcId notNil ifTrue:[ |
|
235 |
device setLineWidth:lineWidth |
|
236 |
style:lineStyle |
|
237 |
cap:s |
|
238 |
join:joinStyle |
|
239 |
in:gcId |
|
240 |
] |
|
241 |
] |
|
242 |
||
243 |
"Modified: 12.5.1996 / 22:23:03 / cg" |
|
244 |
! |
|
245 |
||
246 |
clipRect |
|
247 |
"return the clipping rectangle for drawing. If there is currently no clipRect, |
|
248 |
a dummy is created." |
|
249 |
||
250 |
|rect| |
|
251 |
||
252 |
clipRect isNil ifTrue:[ |
|
253 |
rect := 0@0 extent:(self extent). |
|
254 |
transformation notNil ifTrue:[ |
|
255 |
rect := transformation applyInverseTo:rect. |
|
256 |
]. |
|
257 |
^ rect |
|
258 |
]. |
|
259 |
^ clipRect |
|
260 |
||
261 |
"Modified: 10.4.1996 / 14:32:22 / cg" |
|
262 |
! |
|
263 |
||
735 | 264 |
clippingRectangle:aRectangleOrNil |
732 | 265 |
"set the clipping rectangle for drawing (in logical coordinates); |
266 |
a nil argument turn off clipping (i.e. whole view is drawable)" |
|
267 |
||
268 |
|x y w h| |
|
269 |
||
270 |
aRectangleOrNil isNil ifTrue:[ |
|
271 |
clipRect isNil ifTrue:[^ self]. |
|
272 |
gcId notNil ifTrue:[ |
|
273 |
device noClipIn:gcId |
|
274 |
] |
|
275 |
] ifFalse:[ |
|
276 |
clipRect notNil ifTrue:[ |
|
277 |
(clipRect = aRectangleOrNil) ifTrue:[^ self] |
|
278 |
]. |
|
279 |
gcId notNil ifTrue:[ |
|
280 |
x := aRectangleOrNil left. |
|
281 |
y := aRectangleOrNil top. |
|
282 |
w := aRectangleOrNil width. |
|
283 |
h := aRectangleOrNil height. |
|
284 |
transformation notNil ifTrue:[ |
|
285 |
x := transformation applyToX:x. |
|
286 |
y := transformation applyToY:y. |
|
287 |
w := transformation applyScaleX:w. |
|
288 |
h := transformation applyScaleY:h. |
|
289 |
]. |
|
290 |
(x class == SmallInteger) ifFalse:[ |
|
291 |
w := w + (x - x truncated). |
|
292 |
x := x truncated |
|
293 |
]. |
|
294 |
(y class == SmallInteger) ifFalse:[ |
|
295 |
h := h + (y - y truncated). |
|
296 |
y := y truncated |
|
297 |
]. |
|
298 |
(w class == SmallInteger) ifFalse:[ |
|
299 |
w := w truncated + 1 |
|
300 |
]. |
|
301 |
(h class == SmallInteger) ifFalse:[ |
|
302 |
h := h truncated + 1 |
|
303 |
]. |
|
304 |
||
305 |
device setClipX:x y:y width:w height:h in:gcId |
|
306 |
] |
|
307 |
]. |
|
308 |
clipRect := aRectangleOrNil |
|
309 |
||
310 |
"Modified: 22.5.1996 / 13:12:07 / cg" |
|
735 | 311 |
"Created: 28.5.1996 / 19:40:20 / cg" |
732 | 312 |
! |
313 |
||
314 |
clippingRectangleOrNil |
|
315 |
"return the clipping rectangle for drawing, nil if there is none." |
|
316 |
||
317 |
^ clipRect |
|
318 |
||
319 |
"Created: 10.4.1996 / 14:32:02 / cg" |
|
320 |
! |
|
321 |
||
786 | 322 |
dashStyle:aDashList offset:dashOffset |
323 |
"define dashes. Each element of the dashList specifies the length |
|
324 |
of a corresponding dash. For example, setting it to [4 4] |
|
325 |
defines 4on-4off dashing; |
|
326 |
Setting it to [1 2 4 2] defines 1on-2off-4on-2off dashes. |
|
327 |
The dashOffset specifies where in the dashList the dashing starts. |
|
328 |
This may not be supported by all graphics devices." |
|
329 |
||
330 |
gcId notNil ifTrue:[ |
|
331 |
device setDashes:(ByteArray withAll:aDashList) |
|
332 |
dashOffset:dashOffset |
|
333 |
in:gcId |
|
334 |
] |
|
335 |
||
336 |
"Modified: 4.6.1996 / 19:03:06 / cg" |
|
337 |
! |
|
338 |
||
732 | 339 |
device |
340 |
"return the device, the receiver is associated with" |
|
341 |
||
342 |
^ device |
|
343 |
! |
|
344 |
||
345 |
device:aDevice |
|
346 |
"set the device" |
|
347 |
||
348 |
device := aDevice |
|
349 |
! |
|
350 |
||
351 |
font:aFont |
|
352 |
"set the font for drawing if it has changed. |
|
353 |
This should be redefined in some widget to perform an automatic |
|
354 |
redraw. See also: #basicFont:" |
|
355 |
||
356 |
(aFont ~~ font) ifTrue:[ |
|
357 |
self basicFont:aFont |
|
358 |
] |
|
359 |
||
360 |
"Modified: 6.3.1996 / 18:17:40 / cg" |
|
361 |
! |
|
362 |
||
363 |
function:aSymbol |
|
364 |
"set the drawing function if it has changed" |
|
365 |
||
366 |
(aSymbol ~~ function) ifTrue:[ |
|
367 |
function := aSymbol. |
|
368 |
gcId notNil ifTrue:[ |
|
369 |
device setFunction:aSymbol in:gcId |
|
370 |
] |
|
371 |
] |
|
372 |
! |
|
373 |
||
374 |
gcId |
|
375 |
"return the receivers graphic context id on the device" |
|
376 |
||
377 |
^ gcId |
|
378 |
! |
|
379 |
||
380 |
graphicsDevice |
|
381 |
"return the device, the receiver is associated with. |
|
382 |
Same as #device, for ST-80 compatibility." |
|
383 |
||
384 |
^ device |
|
385 |
||
386 |
"Created: 9.5.1996 / 01:37:58 / cg" |
|
387 |
! |
|
388 |
||
389 |
id |
|
390 |
"return the id of the dravable on the device" |
|
391 |
||
392 |
^ drawableId |
|
393 |
! |
|
394 |
||
395 |
joinStyle:aSymbol |
|
396 |
"set the style in which 2 lines are connected in polygons - |
|
397 |
aSymbol may be #miter, #bevel, #round" |
|
398 |
||
399 |
|s| |
|
400 |
||
401 |
(s := aSymbol) isNil ifTrue:[ |
|
402 |
s := #miter |
|
403 |
]. |
|
404 |
(s ~~ joinStyle) ifTrue:[ |
|
405 |
joinStyle := s. |
|
406 |
||
407 |
gcId notNil ifTrue:[ |
|
408 |
device setLineWidth:lineWidth |
|
409 |
style:lineStyle |
|
410 |
cap:capStyle |
|
411 |
join:s |
|
412 |
in:gcId |
|
413 |
] |
|
414 |
] |
|
415 |
||
416 |
"Modified: 12.5.1996 / 22:20:43 / cg" |
|
417 |
! |
|
418 |
||
419 |
lineStyle:aSymbol |
|
420 |
"set the style in which lines are drawn - |
|
421 |
aSymbol may be #solid, #dashed, #doubleDashed" |
|
422 |
||
423 |
|s| |
|
424 |
||
425 |
(s := aSymbol) isNil ifTrue:[ |
|
426 |
s := #solid |
|
427 |
]. |
|
428 |
(s ~~ lineStyle) ifTrue:[ |
|
429 |
lineStyle := s. |
|
430 |
gcId notNil ifTrue:[ |
|
431 |
device setLineWidth:lineWidth |
|
432 |
style:s |
|
433 |
cap:capStyle |
|
434 |
join:joinStyle |
|
435 |
in:gcId |
|
436 |
] |
|
437 |
] |
|
438 |
||
439 |
"Modified: 12.5.1996 / 22:21:25 / cg" |
|
440 |
! |
|
441 |
||
442 |
lineWidth:aNumber |
|
443 |
"set the line width for drawing if it has changed" |
|
444 |
||
445 |
|n| |
|
446 |
||
447 |
(aNumber ~~ lineWidth) ifTrue:[ |
|
448 |
lineWidth := aNumber. |
|
449 |
transformation isNil ifTrue:[ |
|
450 |
n := aNumber. |
|
451 |
] ifFalse:[ |
|
452 |
n := transformation applyScaleX:aNumber. |
|
453 |
n := n rounded |
|
454 |
]. |
|
455 |
gcId notNil ifTrue:[ |
|
456 |
device setLineWidth:n |
|
457 |
style:lineStyle |
|
458 |
cap:capStyle |
|
459 |
join:joinStyle |
|
460 |
in:gcId |
|
461 |
] |
|
462 |
] |
|
463 |
! |
|
464 |
||
465 |
mask:aForm |
|
466 |
"set the mask form for drawing" |
|
467 |
||
468 |
|id| |
|
469 |
||
470 |
(aForm ~~ mask) ifTrue:[ |
|
471 |
mask := aForm. |
|
472 |
gcId notNil ifTrue:[ |
|
473 |
(mask == nil) ifTrue:[ |
|
474 |
device setBitmapMask:nil in:gcId |
|
475 |
] ifFalse:[ |
|
476 |
mask := mask on:device. |
|
477 |
id := mask id. |
|
478 |
(mask depth == 1) ifTrue:[ |
|
479 |
device setBitmapMask:id in:gcId |
|
480 |
] ifFalse:[ |
|
481 |
device setPixmapMask:id in:gcId |
|
482 |
] |
|
483 |
] |
|
484 |
] |
|
485 |
] |
|
486 |
! |
|
487 |
||
488 |
paint:aColor |
|
489 |
"set the drawing color, which may be a real color, a dithered one |
|
490 |
or even an image." |
|
491 |
||
492 |
(aColor ~~ paint) ifTrue:[ |
|
493 |
aColor notNil ifTrue:[ |
|
494 |
paint := aColor. |
|
495 |
self setGCForPaint. |
|
496 |
] |
|
497 |
] |
|
498 |
||
499 |
"Modified: 16.5.1996 / 15:35:57 / cg" |
|
500 |
! |
|
501 |
||
502 |
paint:fgColor on:bgColor |
|
503 |
"set the paint and background-paint color. |
|
504 |
The bg-paint is used in opaque-draw operations" |
|
505 |
||
506 |
|fgId bgId| |
|
507 |
||
508 |
((fgColor ~~ paint) or:[bgColor ~~ bgPaint]) ifTrue:[ |
|
509 |
fgColor notNil ifTrue:[ |
|
510 |
paint := fgColor |
|
511 |
]. |
|
512 |
bgColor notNil ifTrue:[ |
|
513 |
bgPaint := bgColor |
|
514 |
]. |
|
515 |
gcId notNil ifTrue:[ |
|
516 |
paint := paint on:device. |
|
517 |
paint isColor ifTrue:[ |
|
518 |
fgId := paint colorId. |
|
519 |
fgId notNil ifTrue:[ |
|
520 |
mask notNil ifTrue:[ |
|
521 |
mask := nil. |
|
522 |
device setBitmapMask:nil in:gcId |
|
523 |
]. |
|
524 |
bgPaint := bgPaint on:device. |
|
525 |
bgPaint isColor ifTrue:[ |
|
526 |
bgId := bgPaint colorId. |
|
527 |
bgId notNil ifTrue:[ |
|
528 |
"the common case, both are real colors" |
|
529 |
(paint ~~ foreground) ifTrue:[ |
|
530 |
foreground := paint. |
|
531 |
(bgPaint ~~ background) ifTrue:[ |
|
532 |
background := bgPaint. |
|
533 |
device setForeground:fgId background:bgId in:gcId. |
|
534 |
^ self |
|
535 |
]. |
|
536 |
device setForeground:fgId in:gcId. |
|
537 |
^ self |
|
538 |
]. |
|
539 |
(bgPaint ~~ background) ifTrue:[ |
|
540 |
background := bgPaint. |
|
541 |
device setBackground:bgId in:gcId. |
|
542 |
]. |
|
543 |
^ self |
|
544 |
]. |
|
545 |
"bgPaint is dithered, setup paint here, leave bgPaint |
|
546 |
till next opaque draw comes around." |
|
547 |
||
548 |
(paint ~~ foreground) ifTrue:[ |
|
549 |
foreground := paint. |
|
550 |
device setForeground:fgId in:gcId |
|
551 |
]. |
|
552 |
^ self |
|
553 |
] |
|
554 |
] |
|
555 |
]. |
|
556 |
"either paint or bgPaint (or both) are dithered colors, |
|
557 |
setup for paint, leave bg-problem till next opaque draw |
|
558 |
comes around. |
|
559 |
" |
|
560 |
self setGCForPaint. |
|
561 |
] |
|
562 |
] |
|
563 |
||
564 |
"Modified: 16.5.1996 / 15:37:05 / cg" |
|
565 |
! |
|
566 |
||
567 |
paint:fgColor on:bgColor function:f |
|
568 |
"set paint, background-paint and function" |
|
569 |
||
570 |
self paint:fgColor on:bgColor. |
|
571 |
self function:f |
|
572 |
||
573 |
"Modified: 16.5.1996 / 15:36:35 / cg" |
|
574 |
! |
|
575 |
||
576 |
setGraphicsExposures:aBoolean |
|
577 |
"want to if aBoolean is true - or dont want to be notified |
|
578 |
of graphics exposures" |
|
579 |
||
580 |
gcId notNil ifTrue:[ |
|
581 |
device setGraphicsExposures:aBoolean in:gcId |
|
582 |
] |
|
583 |
! |
|
584 |
||
585 |
setMaskOrigin:aPoint |
|
586 |
"set the origin of the fill pattern" |
|
587 |
||
588 |
(maskOrigin isNil or:[maskOrigin ~= aPoint]) ifTrue:[ |
|
589 |
transformation isNil ifTrue:[ |
|
590 |
maskOrigin := aPoint. |
|
591 |
] ifFalse:[ |
|
592 |
maskOrigin := transformation applyTo:aPoint |
|
593 |
]. |
|
594 |
gcId notNil ifTrue:[ |
|
595 |
device setMaskOriginX:maskOrigin x rounded |
|
596 |
y:maskOrigin y rounded |
|
597 |
in:gcId |
|
598 |
] |
|
599 |
] |
|
600 |
! |
|
601 |
||
602 |
setMaskOriginX:orgX y:orgY |
|
603 |
"set the origin of the pattern" |
|
604 |
||
605 |
|x y| |
|
606 |
||
607 |
transformation notNil ifTrue:[ |
|
608 |
x := transformation applyToX:orgX. |
|
609 |
y := transformation applyToY:orgY. |
|
610 |
] ifFalse:[ |
|
611 |
x := orgX. |
|
612 |
y := orgY |
|
613 |
]. |
|
614 |
x := x rounded. |
|
615 |
y := y rounded. |
|
616 |
||
617 |
(maskOrigin isNil or:[ |
|
618 |
((x ~~ maskOrigin x) or:[y ~~ maskOrigin y]) ]) ifTrue:[ |
|
619 |
||
620 |
maskOrigin := x @ y. |
|
621 |
gcId notNil ifTrue:[ |
|
622 |
device setMaskOriginX:x y:y in:gcId |
|
623 |
] |
|
624 |
] |
|
625 |
! ! |
|
626 |
||
627 |
!DeviceGraphicsContext methodsFor:'accessing - internals'! |
|
628 |
||
629 |
background |
|
630 |
"return the current background drawing color. |
|
631 |
OBSOLETE: use #paint: / #backgroundPaint: / #paint:on:" |
|
632 |
||
633 |
^ background |
|
634 |
||
635 |
"Modified: 12.5.1996 / 22:28:09 / cg" |
|
636 |
! |
|
637 |
||
638 |
background:aColor |
|
639 |
"set the internal background color for drawing - aColor must be a real color. |
|
640 |
OBSOLETE: this method will vanish; use #paint: / #backgroundPaint: / #paint:on:" |
|
641 |
||
642 |
|bgId| |
|
643 |
||
644 |
(aColor ~~ background) ifTrue:[ |
|
645 |
aColor notNil ifTrue:[ |
|
646 |
background := aColor. |
|
647 |
gcId notNil ifTrue:[ |
|
648 |
background := background on:device. |
|
649 |
bgId := background colorId. |
|
650 |
||
651 |
" |
|
652 |
mhmh the following is a kludge .... |
|
653 |
" |
|
654 |
bgId isNil ifTrue:[ |
|
745 | 655 |
(background grayIntensity >= 50) ifTrue:[ |
732 | 656 |
bgId := device whitepixel |
657 |
] ifFalse:[ |
|
658 |
bgId := device blackpixel |
|
659 |
] |
|
660 |
]. |
|
661 |
device setBackground:bgId in:gcId |
|
662 |
] |
|
663 |
] |
|
664 |
] |
|
665 |
||
745 | 666 |
"Modified: 28.5.1996 / 20:44:55 / cg" |
732 | 667 |
! |
668 |
||
669 |
foreground |
|
670 |
"return the current foreground drawing color. |
|
671 |
OBSOLETE: use #paint: / #paint:on:" |
|
672 |
||
673 |
^ foreground |
|
674 |
||
675 |
"Modified: 12.5.1996 / 22:28:03 / cg" |
|
676 |
! |
|
677 |
||
678 |
foreground:aColor |
|
679 |
"set the internal foreground color for drawing - aColor must be a real color. |
|
680 |
OBSOLETE: this method will vanish; use #paint: / #paint:on:" |
|
681 |
||
682 |
|fgId| |
|
683 |
||
684 |
(aColor ~~ foreground) ifTrue:[ |
|
685 |
aColor notNil ifTrue:[ |
|
686 |
foreground := aColor. |
|
687 |
gcId notNil ifTrue:[ |
|
688 |
(foreground class == SmallInteger) ifTrue:[ |
|
689 |
fgId := foreground |
|
690 |
] ifFalse:[ |
|
691 |
foreground := foreground on:device. |
|
692 |
fgId := foreground colorId. |
|
693 |
]. |
|
694 |
||
695 |
"mhmh the following is a kludge ...." |
|
696 |
fgId isNil ifTrue:[ |
|
745 | 697 |
(foreground grayIntensity >= 50) ifTrue:[ |
732 | 698 |
fgId := device whitepixel |
699 |
] ifFalse:[ |
|
700 |
fgId := device blackpixel |
|
701 |
] |
|
702 |
]. |
|
703 |
device setForeground:fgId in:gcId. |
|
704 |
paint := foreground |
|
705 |
] |
|
706 |
] |
|
707 |
] |
|
708 |
||
745 | 709 |
"Modified: 28.5.1996 / 20:45:02 / cg" |
732 | 710 |
! |
711 |
||
712 |
foreground:fgColor background:bgColor |
|
713 |
"set both internal foreground and internal background colors |
|
714 |
- these must be real colors. |
|
715 |
OBSOLETE: this method will vanish; use #paint: / #paint:on:" |
|
716 |
||
717 |
|fgPixel bgPixel| |
|
718 |
||
719 |
((fgColor ~~ foreground) or:[bgColor ~~ background]) ifTrue:[ |
|
720 |
fgColor notNil ifTrue:[ |
|
721 |
foreground := fgColor |
|
722 |
]. |
|
723 |
bgColor notNil ifTrue:[ |
|
724 |
background := bgColor |
|
725 |
]. |
|
726 |
gcId notNil ifTrue:[ |
|
727 |
foreground := foreground on:device. |
|
728 |
background := background on:device. |
|
729 |
fgPixel := foreground colorId. |
|
730 |
bgPixel := background colorId. |
|
731 |
||
732 |
"mhmh the following is a kludge ...." |
|
733 |
fgPixel isNil ifTrue:[ |
|
745 | 734 |
(foreground grayIntensity >= 50) ifTrue:[ |
732 | 735 |
fgPixel := device whitepixel |
736 |
] ifFalse:[ |
|
737 |
fgPixel := device blackpixel |
|
738 |
] |
|
739 |
]. |
|
740 |
bgPixel isNil ifTrue:[ |
|
745 | 741 |
(background grayIntensity >= 50) ifTrue:[ |
732 | 742 |
bgPixel := device whitepixel |
743 |
] ifFalse:[ |
|
744 |
bgPixel := device blackpixel |
|
745 |
] |
|
746 |
]. |
|
747 |
device setForeground:fgPixel background:bgPixel in:gcId. |
|
748 |
paint := foreground |
|
749 |
] |
|
750 |
] |
|
751 |
||
745 | 752 |
"Modified: 28.5.1996 / 20:45:27 / cg" |
732 | 753 |
! |
754 |
||
755 |
foreground:fgColor background:bgColor function:fun |
|
756 |
"set foreground, background colors and function. |
|
757 |
OBSOLETE: this method will vanish; use #paint: / #paint:on:" |
|
758 |
||
759 |
self foreground:fgColor background:bgColor. |
|
760 |
self function:fun |
|
761 |
||
762 |
"Modified: 12.5.1996 / 22:28:34 / cg" |
|
763 |
! |
|
764 |
||
765 |
foreground:aColor function:fun |
|
766 |
"set the foreground color and function for drawing. |
|
767 |
OBSOLETE: this method will vanish; use #paint: / #paint:on:" |
|
768 |
||
769 |
|fgPixel| |
|
770 |
||
771 |
((aColor ~~ foreground) or:[fun ~~ function]) ifTrue:[ |
|
772 |
foreground := aColor. |
|
773 |
function := fun. |
|
774 |
gcId notNil ifTrue:[ |
|
775 |
foreground := foreground on:device. |
|
776 |
fgPixel := foreground colorId. |
|
777 |
||
778 |
"mhmh the following is a kludge ...." |
|
779 |
fgPixel isNil ifTrue:[ |
|
745 | 780 |
(foreground grayIntensity >= 50) ifTrue:[ |
732 | 781 |
fgPixel := device whitepixel |
782 |
] ifFalse:[ |
|
783 |
fgPixel := device blackpixel |
|
784 |
] |
|
785 |
]. |
|
786 |
device setForeground:fgPixel in:gcId. |
|
787 |
device setFunction:fun in:gcId. |
|
788 |
paint := foreground |
|
789 |
] |
|
790 |
] |
|
791 |
||
745 | 792 |
"Modified: 28.5.1996 / 20:45:09 / cg" |
732 | 793 |
! ! |
794 |
||
795 |
!DeviceGraphicsContext methodsFor:'bit blitting'! |
|
796 |
||
797 |
copyBitsFrom:aByteArray bitsPerPixel:bpp depth:depth width:srcW height:srcH x:srcX y:srcY toX:dstX y:dstY |
|
798 |
"copy bits from a smalltalk byteArray. |
|
799 |
The bits found there are supposed to be in the devices native format (i.e. |
|
800 |
translated to allocated color indices on pseudoColor devices and padded as required. |
|
801 |
The byteOrder is MSB and will be converted as appropriate by the underlying devices |
|
802 |
method to whatever the device needs." |
|
803 |
||
804 |
device |
|
805 |
drawBits:aByteArray bitsPerPixel:bpp depth:depth |
|
806 |
width:srcW height:srcH |
|
807 |
x:srcX y:srcY |
|
808 |
into:drawableId |
|
809 |
x:dstX y:dstY |
|
810 |
width:(self width) height:(self height) |
|
811 |
with:gcId. |
|
812 |
||
813 |
"Created: 21.10.1995 / 00:04:22 / cg" |
|
814 |
! |
|
815 |
||
816 |
copyFrom:aDrawable x:srcX y:srcY toX:dstX y:dstY width:w height:h |
|
817 |
"copy from aDrawable into the receiver; |
|
818 |
the source may be the receiver as well - in this case its a scroll. |
|
819 |
All coordinates are in device coordinates." |
|
820 |
||
821 |
|id| |
|
822 |
||
823 |
id := aDrawable id. |
|
824 |
||
825 |
"temporary ... |
|
826 |
this fixes a problem after restart on another display, |
|
827 |
when a file-bitmap wasnt found. In this case, the id of the |
|
828 |
bitmap will be nil. This will be fixed soon. |
|
829 |
" |
|
830 |
(id isNil |
|
831 |
or:[aDrawable graphicsDevice ~~ device]) ifTrue:[ |
|
832 |
'DEVDRAW: invalid bitmap copy - ignored' errorPrintNL. |
|
833 |
^ self |
|
834 |
]. |
|
835 |
||
836 |
gcId isNil ifTrue:[ |
|
837 |
self initGC |
|
838 |
]. |
|
839 |
||
840 |
"this is a workaround for a bug (or a feature ?) in many X-servers; |
|
841 |
copy is only copy if fg==1 and bg==0" |
|
842 |
||
843 |
"/No: it was my fault - shame, shame |
|
844 |
"/ |
|
845 |
"/ ((aDrawable == self) and:[function == #copy]) ifTrue:[ |
|
846 |
"/ device setForeground:1 background:0 in:gcId. |
|
847 |
"/ background := nil. |
|
848 |
"/ foreground := nil. |
|
849 |
"/ paint := nil |
|
850 |
"/ ]. |
|
851 |
"/ |
|
852 |
((aDrawable depth == 1) and:[device depth ~~ 1]) ifTrue:[ |
|
853 |
device |
|
854 |
copyPlaneFromId:id |
|
855 |
x:srcX y:srcY |
|
856 |
to:drawableId |
|
857 |
x:dstX y:dstY |
|
858 |
width:w |
|
859 |
height:h |
|
860 |
with:gcId |
|
861 |
] ifFalse:[ |
|
862 |
device |
|
863 |
copyFromId:id |
|
864 |
x:srcX y:srcY |
|
865 |
to:drawableId |
|
866 |
x:dstX y:dstY |
|
867 |
width:w |
|
868 |
height:h |
|
869 |
with:gcId |
|
870 |
] |
|
871 |
! |
|
872 |
||
873 |
copyPlaneFrom:aDrawable x:srcX y:srcY toX:dstX y:dstY width:w height:h |
|
874 |
"copy one plane from aDrawable into the receiver. 0's are drawn in |
|
875 |
background, while 1's are drawn with foreground color. |
|
876 |
The depth of aDrawable must (should) be 1. |
|
877 |
The drawable must have been allocated on the same device. |
|
878 |
All coordinates are in device coordinates." |
|
879 |
||
880 |
|id| |
|
881 |
||
882 |
id := aDrawable id. |
|
883 |
||
884 |
"temporary ... |
|
885 |
this fixes a problem after restart on another display, |
|
886 |
when a file-bitmap wasnt found. In this case, the id of the |
|
887 |
bitmap will be nil. This will be fixed soon. |
|
888 |
" |
|
889 |
(id isNil |
|
890 |
or:[aDrawable graphicsDevice ~~ device]) ifTrue:[ |
|
891 |
'DEVDRAW: invalid copyPlane - ignored' errorPrintNL. |
|
892 |
^ self |
|
893 |
]. |
|
894 |
||
895 |
gcId isNil ifTrue:[ |
|
896 |
self initGC |
|
897 |
]. |
|
898 |
||
899 |
device |
|
900 |
copyPlaneFromId:id |
|
901 |
x:srcX y:srcY |
|
902 |
to:drawableId |
|
903 |
x:dstX y:dstY |
|
904 |
width:w |
|
905 |
height:h |
|
906 |
with:gcId |
|
907 |
! ! |
|
908 |
||
909 |
!DeviceGraphicsContext methodsFor:'copying'! |
|
910 |
||
911 |
postCopy |
|
912 |
"this may not be enough to allow copying of views ..." |
|
913 |
||
914 |
super postCopy. |
|
915 |
device := drawableId := gcId := nil. |
|
916 |
self recreate |
|
917 |
! ! |
|
918 |
||
919 |
!DeviceGraphicsContext methodsFor:'drawing'! |
|
920 |
||
921 |
displayArcX:x y:y width:w height:h from:startAngle angle:angle |
|
922 |
"draw an arc; apply transformation if nonNil" |
|
923 |
||
784 | 924 |
|pX pY rpX rpY nW nH| |
732 | 925 |
|
926 |
gcId isNil ifTrue:[ |
|
927 |
self initGC |
|
928 |
]. |
|
929 |
transformation notNil ifTrue:[ |
|
930 |
pX := transformation applyToX:x. |
|
931 |
pY := transformation applyToY:y. |
|
932 |
nW := transformation applyScaleX:w. |
|
933 |
nH := transformation applyScaleY:h. |
|
934 |
nW < 0 ifTrue:[ |
|
935 |
nW := nW abs. |
|
936 |
pX := pX - nW. |
|
937 |
]. |
|
938 |
nH < 0 ifTrue:[ |
|
939 |
nH := nH abs. |
|
940 |
pY := pY - nH. |
|
941 |
]. |
|
942 |
] ifFalse:[ |
|
943 |
pX := x. |
|
944 |
pY := y. |
|
945 |
nW := w. |
|
946 |
nH := h. |
|
947 |
]. |
|
948 |
||
949 |
pX := pX rounded. |
|
950 |
pY := pY rounded. |
|
951 |
nW := nW rounded. |
|
952 |
nH := nH rounded. |
|
953 |
||
954 |
device |
|
955 |
displayArcX:pX |
|
956 |
y:pY |
|
957 |
width:nW |
|
958 |
height:nH |
|
959 |
from:startAngle |
|
960 |
angle:angle |
|
961 |
in:drawableId |
|
962 |
with:gcId |
|
963 |
||
784 | 964 |
"/ rpX := pX rounded. |
965 |
"/ rpY := pY rounded. |
|
966 |
"/ nW := (nW + (rpX - pX)) rounded. |
|
967 |
"/ nH := (nH + (rpY - pY)) rounded. |
|
968 |
"/ |
|
969 |
"/ device |
|
970 |
"/ displayArcX:rpX |
|
971 |
"/ y:rpY |
|
972 |
"/ width:nW |
|
973 |
"/ height:nH |
|
974 |
"/ from:startAngle |
|
975 |
"/ angle:angle |
|
976 |
"/ in:drawableId |
|
977 |
"/ with:gcId |
|
978 |
||
732 | 979 |
"Created: 8.5.1996 / 08:31:30 / cg" |
784 | 980 |
"Modified: 4.6.1996 / 17:59:28 / cg" |
732 | 981 |
! |
982 |
||
983 |
displayForm:formToDraw x:x y:y |
|
984 |
"draw a form; if its a 1-plane bitmap, 1-bits are drawn in the |
|
985 |
current paint-color, leaving pixels with 0-bits unchanged |
|
986 |
(i.e. only 1-bits are drawn from the form). |
|
987 |
If its a deep form (i.e. a pixmap) the current paint |
|
988 |
settings are ignored and the form is drawn as-is. |
|
989 |
Care must be taken, that the paint color is correctly allocated |
|
990 |
(by sending #on: to the color) before doing so. |
|
991 |
Using functions other than #copy only makes sense if you are |
|
992 |
certain, that the colors are real colors (actually, only for |
|
993 |
noColor or allColor)." |
|
994 |
||
995 |
|realForm pX pY w h nW nH| |
|
996 |
||
997 |
realForm := formToDraw. |
|
998 |
||
999 |
transformation notNil ifTrue:[ |
|
1000 |
pX := transformation applyToX:x. |
|
1001 |
pY := transformation applyToY:y. |
|
1002 |
||
1003 |
transformation noScale ifFalse:[ |
|
1004 |
w := formToDraw width. |
|
1005 |
h := formToDraw height. |
|
1006 |
||
1007 |
nW := (transformation applyScaleX:w) rounded. |
|
1008 |
nH := (transformation applyScaleY:h) rounded. |
|
1009 |
||
1010 |
((nW ~= w) or:[nH ~= h]) ifTrue:[ |
|
1011 |
"/ |
|
1012 |
"/ hard case - someone is drawing forms with scaling in effect |
|
1013 |
"/ look if we have a scaled version in our pocket ... |
|
1014 |
"/ |
|
1015 |
realForm := nil. |
|
1016 |
CachedScaledForms notNil ifTrue:[ |
|
1017 |
(CachedScales at:formToDraw ifAbsent:nil) = transformation scale ifTrue:[ |
|
1018 |
realForm := CachedScaledForms at:formToDraw ifAbsent:nil. |
|
1019 |
] |
|
1020 |
]. |
|
1021 |
realForm isNil ifTrue:[ |
|
1022 |
"/ |
|
1023 |
"/ nope - must do the work ... |
|
1024 |
"/ |
|
1025 |
realForm := formToDraw magnifiedBy:(nW / w) @ (nH / h). |
|
1026 |
CachedScaledForms isNil ifTrue:[ |
|
1027 |
CachedScaledForms := WeakIdentityDictionary new. |
|
1028 |
CachedScales := WeakIdentityDictionary new. |
|
1029 |
]. |
|
1030 |
CachedScaledForms at:formToDraw put:realForm. |
|
1031 |
CachedScales at:formToDraw put:transformation scale. |
|
1032 |
] |
|
1033 |
] |
|
1034 |
] |
|
1035 |
] ifFalse:[ |
|
1036 |
pX := x. |
|
1037 |
pY := y. |
|
1038 |
]. |
|
1039 |
pX := pX rounded. |
|
1040 |
pY := pY rounded. |
|
1041 |
||
1042 |
self displayDeviceForm:realForm x:pX y:pY |
|
1043 |
||
1044 |
"Modified: 21.5.1996 / 21:15:44 / cg" |
|
1045 |
! |
|
1046 |
||
1047 |
displayLineFromX:x0 y:y0 toX:x1 y:y1 |
|
1048 |
"draw a line (with current paint-color); apply transformation if nonNil" |
|
1049 |
||
1050 |
|pX0 pY0 pX1 pY1 easy fgId bgId| |
|
1051 |
||
1052 |
gcId isNil ifTrue:[ |
|
1053 |
self initGC |
|
1054 |
]. |
|
1055 |
||
1056 |
lineStyle == #doubleDashed ifTrue:[ |
|
1057 |
" |
|
1058 |
if bgPaint or paint is not a real color, we have to do it the hard way ... |
|
1059 |
" |
|
1060 |
easy := true. |
|
1061 |
paint isColor ifFalse:[ |
|
1062 |
easy := false |
|
1063 |
] ifTrue:[ |
|
1064 |
fgId := paint colorId. |
|
1065 |
fgId isNil ifTrue:[ |
|
1066 |
easy := false |
|
1067 |
] |
|
1068 |
]. |
|
1069 |
bgPaint isColor ifFalse:[ |
|
1070 |
easy := false |
|
1071 |
] ifTrue:[ |
|
1072 |
bgId := bgPaint colorId. |
|
1073 |
bgId isNil ifTrue:[ |
|
1074 |
easy := false |
|
1075 |
] |
|
1076 |
]. |
|
1077 |
||
1078 |
easy ifTrue:[ |
|
1079 |
((foreground ~~ paint) or:[background ~~ bgPaint]) ifTrue:[ |
|
1080 |
device setForeground:fgId background:bgId in:gcId. |
|
1081 |
foreground := paint. |
|
1082 |
background := bgPaint. |
|
1083 |
]. |
|
1084 |
] ifFalse:[ |
|
1085 |
'DEVDRAW: cannot draw dashes with dithered colors' errorPrintNL |
|
1086 |
]. |
|
1087 |
]. |
|
1088 |
||
1089 |
transformation notNil ifTrue:[ |
|
1090 |
pX0 := transformation applyToX:x0. |
|
1091 |
pY0 := transformation applyToY:y0. |
|
1092 |
pX1 := transformation applyToX:x1. |
|
1093 |
pY1 := transformation applyToY:y1. |
|
1094 |
] ifFalse:[ |
|
1095 |
pX0 := x0. |
|
1096 |
pY0 := y0. |
|
1097 |
pX1 := x1. |
|
1098 |
pY1 := y1 |
|
1099 |
]. |
|
1100 |
||
1101 |
pX0 := pX0 rounded. |
|
1102 |
pY0 := pY0 rounded. |
|
1103 |
pX1 := pX1 rounded. |
|
1104 |
pY1 := pY1 rounded. |
|
1105 |
||
1106 |
device displayLineFromX:pX0 y:pY0 toX:pX1 y:pY1 in:drawableId with:gcId |
|
1107 |
||
1108 |
"Modified: 13.4.1996 / 20:31:19 / cg" |
|
1109 |
! |
|
1110 |
||
1111 |
displayOpaqueForm:formToDraw x:x y:y |
|
1112 |
"draw a form; if its a 1-plane bitmap, 1-bits are drawn in the |
|
1113 |
current paint-color and 0-bits in the bgPaint color. |
|
1114 |
If its a deep form (i.e. a pixmap) the current paint/bgPaint |
|
1115 |
settings are ignored and the form drawn as-is. |
|
1116 |
In the 1-plane case, special care must be taken if paint and/or bgPaint |
|
1117 |
dithered colors or patterns, since are that the colors are correctly allocated |
|
1118 |
(by sending #on: to the colors) before doing so. |
|
1119 |
If there is a transformation, the image is scaled as appropiate." |
|
1120 |
||
1121 |
|w h realForm pX pY nW nH| |
|
1122 |
||
1123 |
bgPaint isNil ifTrue:[ |
|
1124 |
"/ |
|
1125 |
"/ actually not an opaque draw |
|
1126 |
"/ |
|
1127 |
self displayForm:formToDraw x:x y:y. |
|
1128 |
^ self |
|
1129 |
]. |
|
1130 |
||
1131 |
realForm := formToDraw. |
|
1132 |
||
1133 |
transformation notNil ifTrue:[ |
|
1134 |
pX := transformation applyToX:x. |
|
1135 |
pY := transformation applyToY:y. |
|
1136 |
||
1137 |
transformation noScale ifFalse:[ |
|
1138 |
w := formToDraw width. |
|
1139 |
h := formToDraw height. |
|
1140 |
||
1141 |
nW := (transformation applyScaleX:w) rounded. |
|
1142 |
nH := (transformation applyScaleY:h) rounded. |
|
1143 |
||
1144 |
((nW ~= w) or:[nH ~= h]) ifTrue:[ |
|
1145 |
"/ |
|
1146 |
"/ hard case - someone is drawing forms with scaling in effect |
|
1147 |
"/ look if we have a scaled version in our pocket ... |
|
1148 |
"/ |
|
1149 |
realForm := nil. |
|
1150 |
CachedScaledForms notNil ifTrue:[ |
|
1151 |
(CachedScales at:formToDraw ifAbsent:nil) = transformation scale ifTrue:[ |
|
1152 |
realForm := CachedScaledForms at:formToDraw ifAbsent:nil. |
|
1153 |
] |
|
1154 |
]. |
|
1155 |
realForm isNil ifTrue:[ |
|
1156 |
"/ |
|
1157 |
"/ nope - must do the work ... |
|
1158 |
"/ |
|
1159 |
realForm := formToDraw magnifiedBy:(nW / w) @ (nH / h). |
|
1160 |
CachedScaledForms isNil ifTrue:[ |
|
1161 |
CachedScaledForms := WeakIdentityDictionary new. |
|
1162 |
CachedScales := WeakIdentityDictionary new. |
|
1163 |
]. |
|
1164 |
CachedScaledForms at:formToDraw put:realForm. |
|
1165 |
CachedScales at:formToDraw put:transformation scale. |
|
1166 |
] |
|
1167 |
] |
|
1168 |
] |
|
1169 |
] ifFalse:[ |
|
1170 |
pX := x. |
|
1171 |
pY := y. |
|
1172 |
]. |
|
1173 |
||
1174 |
pX := pX rounded. |
|
1175 |
pY := pY rounded. |
|
1176 |
||
1177 |
self displayDeviceOpaqueForm:realForm x:pX y:pY |
|
1178 |
||
1179 |
"Modified: 21.5.1996 / 21:15:54 / cg" |
|
1180 |
! |
|
1181 |
||
1182 |
displayOpaqueString:aString from:index1 to:index2 x:x y:y |
|
1183 |
"draw a substring at the coordinate x/y - draw foreground pixels in |
|
1184 |
paint-color and background pixels in bgPaint-color. |
|
1185 |
If the transformation involves scaling, |
|
1186 |
the fonts point-size is scaled as appropriate. |
|
1187 |
Assuming that device can only draw in device colors, we have to handle |
|
1188 |
the case where paint and/or bgPaint are dithered colors" |
|
1189 |
||
1190 |
|easy w h savedPaint fgId bgId |
|
1191 |
id pX pY fontUsed sz s| |
|
1192 |
||
1193 |
" |
|
1194 |
if backgroundPaint color is nil, we assume |
|
1195 |
this is a non-opaque draw |
|
1196 |
" |
|
1197 |
bgPaint isNil ifTrue:[ |
|
1198 |
self displayString:aString from:index1 to:index2 x:x y:y. |
|
1199 |
^ self |
|
1200 |
]. |
|
1201 |
||
1202 |
(aString isString not |
|
1203 |
or:[aString isText]) ifTrue:[ |
|
1204 |
" |
|
1205 |
hook for non-strings (i.e. attributed text) |
|
1206 |
that 'thing' should know how to display itself ... |
|
1207 |
" |
|
1208 |
aString displayOpaqueOn:self x:x y:y from:index1 to:index2. |
|
1209 |
^ self |
|
1210 |
]. |
|
1211 |
||
1212 |
gcId isNil ifTrue:[ |
|
1213 |
self initGC |
|
1214 |
]. |
|
1215 |
||
1216 |
fontUsed := font. |
|
1217 |
transformation notNil ifTrue:[ |
|
1218 |
pX := transformation applyToX:x. |
|
1219 |
pY := transformation applyToY:y. |
|
1220 |
transformation noScale ifFalse:[ |
|
1221 |
sz := font size. |
|
1222 |
sz isNil ifTrue:[ |
|
1223 |
"/ oops - not a real font; use original font |
|
1224 |
fontUsed := font |
|
1225 |
] ifFalse:[ |
|
1226 |
fontUsed := font size:(transformation applyScaleY:sz) rounded. |
|
1227 |
] |
|
1228 |
] |
|
1229 |
] ifFalse:[ |
|
1230 |
pX := x. |
|
1231 |
pY := y. |
|
1232 |
]. |
|
1233 |
pX := pX rounded. |
|
1234 |
pY := pY rounded. |
|
1235 |
||
1236 |
fontUsed := fontUsed on:device. |
|
1237 |
||
1238 |
id := fontUsed fontId. |
|
1239 |
id isNil ifTrue:[ |
|
1240 |
" |
|
1241 |
hook for alien fonts |
|
1242 |
that 'font' should know how to display the string ... |
|
1243 |
" |
|
1244 |
fontUsed displayOpaqueString:aString from:index1 to:index2 x:x y:y in:self. |
|
1245 |
^ self |
|
1246 |
]. |
|
1247 |
||
1248 |
s := aString. |
|
1249 |
s encoding ~~ font encoding ifTrue:[ |
|
1250 |
s := s encodeInto:(font encoding). |
|
1251 |
]. |
|
1252 |
||
1253 |
" |
|
1254 |
if bgPaint or paint is not a real Color, we have to do it the hard way ... |
|
1255 |
" |
|
1256 |
easy := true. |
|
1257 |
paint isColor ifFalse:[ |
|
1258 |
easy := false |
|
1259 |
] ifTrue:[ |
|
1260 |
fgId := paint colorId. |
|
1261 |
fgId isNil ifTrue:[ |
|
1262 |
easy := false |
|
1263 |
] |
|
1264 |
]. |
|
1265 |
bgPaint isColor ifFalse:[ |
|
1266 |
easy := false |
|
1267 |
] ifTrue:[ |
|
1268 |
bgId := bgPaint colorId. |
|
1269 |
bgId isNil ifTrue:[ |
|
1270 |
easy := false |
|
1271 |
] |
|
1272 |
]. |
|
1273 |
||
1274 |
easy ifTrue:[ |
|
1275 |
deviceFont ~~ fontUsed ifTrue:[ |
|
1276 |
device setFont:id in:gcId. |
|
1277 |
deviceFont := fontUsed |
|
1278 |
]. |
|
1279 |
||
1280 |
device setForeground:fgId background:bgId in:gcId. |
|
1281 |
foreground := paint. |
|
1282 |
background := bgPaint. |
|
1283 |
device displayOpaqueString:s |
|
1284 |
from:index1 to:index2 |
|
1285 |
x:pX y:pY |
|
1286 |
in:drawableId with:gcId. |
|
1287 |
^ self |
|
1288 |
]. |
|
1289 |
||
1290 |
w := fontUsed widthOf:s from:index1 to:index2. |
|
1291 |
h := fontUsed height. |
|
1292 |
||
1293 |
(fgId notNil and:[function == #copy]) ifTrue:[ |
|
1294 |
deviceFont ~~ fontUsed ifTrue:[ |
|
1295 |
device setFont:id in:gcId. |
|
1296 |
deviceFont := fontUsed |
|
1297 |
]. |
|
1298 |
" |
|
1299 |
only bg is dithered; fill with bg first ... |
|
1300 |
" |
|
1301 |
savedPaint := paint. |
|
1302 |
self paint:bgPaint. |
|
1303 |
self fillDeviceRectangleX:pX y:(pY - fontUsed ascent) width:w height:h. |
|
1304 |
self paint:savedPaint. |
|
1305 |
||
1306 |
" |
|
1307 |
then draw using fgPaint (which is a real color) |
|
1308 |
" |
|
1309 |
device displayString:s |
|
1310 |
from:index1 to:index2 |
|
1311 |
x:pX y:pY |
|
1312 |
in:drawableId with:gcId. |
|
1313 |
^ self |
|
1314 |
]. |
|
1315 |
||
832
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
1316 |
"/ the very hard case (fg-dither) |
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
1317 |
|
732 | 1318 |
self displayDeviceOpaqueString:s from:index1 to:index2 in:fontUsed x:pX y:pY. |
1319 |
||
832
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
1320 |
"Modified: 12.6.1996 / 12:36:33 / cg" |
732 | 1321 |
! |
1322 |
||
1323 |
displayOpaqueString:aString x:x y:y |
|
1324 |
"draw a string at the coordinate x/y - draw foreground pixels in paint-color, |
|
1325 |
background pixels in bgPaint color. If the transformation involves scaling, |
|
1326 |
the fonts point-size is scaled as appropriate. |
|
1327 |
Assuming that device can only draw in device colors, we have to handle |
|
1328 |
the case where paint and/or bgPaint are dithered colors or images." |
|
1329 |
||
1330 |
|id easy fgId bgId pX pY fontUsed sz s| |
|
1331 |
||
1332 |
" |
|
1333 |
if backgroundPaint color is nil, we assume |
|
1334 |
this is a non-opaque draw |
|
1335 |
" |
|
1336 |
bgPaint isNil ifTrue:[ |
|
1337 |
self displayString:aString x:x y:y. |
|
1338 |
^ self |
|
1339 |
]. |
|
1340 |
||
1341 |
(aString isString not |
|
1342 |
or:[aString isText]) ifTrue:[ |
|
1343 |
" |
|
1344 |
hook for non-strings (i.e. attributed text) |
|
1345 |
that 'thing' should know how to display itself ... |
|
1346 |
" |
|
1347 |
aString displayOpaqueOn:self x:x y:y. |
|
1348 |
^ self |
|
1349 |
]. |
|
1350 |
||
1351 |
" |
|
1352 |
if bgPaint or paint is not a real Color, we have to do it the hard way ... |
|
1353 |
" |
|
1354 |
easy := true. |
|
1355 |
paint isColor ifFalse:[ |
|
1356 |
easy := false |
|
1357 |
] ifTrue:[ |
|
1358 |
fgId := paint colorId. |
|
1359 |
fgId isNil ifTrue:[ |
|
1360 |
easy := false |
|
1361 |
] |
|
1362 |
]. |
|
1363 |
bgPaint isColor ifFalse:[ |
|
1364 |
easy := false |
|
1365 |
] ifTrue:[ |
|
1366 |
bgId := bgPaint colorId. |
|
1367 |
bgId isNil ifTrue:[ |
|
1368 |
easy := false |
|
1369 |
] |
|
1370 |
]. |
|
1371 |
easy ifFalse:[ |
|
1372 |
" |
|
1373 |
for the hard case, use the general drawing method |
|
1374 |
(no need for optimizations - its slow anyway) |
|
1375 |
" |
|
1376 |
self displayOpaqueString:aString |
|
1377 |
from:1 to:(aString size) |
|
1378 |
x:x y:y. |
|
1379 |
^ self |
|
1380 |
]. |
|
1381 |
||
1382 |
gcId isNil ifTrue:[ |
|
1383 |
self initGC |
|
1384 |
]. |
|
1385 |
||
1386 |
fontUsed := font. |
|
1387 |
transformation notNil ifTrue:[ |
|
1388 |
pX := transformation applyToX:x. |
|
1389 |
pY := transformation applyToY:y. |
|
1390 |
transformation noScale ifFalse:[ |
|
1391 |
sz := font size. |
|
1392 |
sz isNil ifTrue:[ |
|
1393 |
"/ oops - not a real font; use original font |
|
1394 |
fontUsed := font |
|
1395 |
] ifFalse:[ |
|
1396 |
fontUsed := font size:(transformation applyScaleY:sz) rounded. |
|
1397 |
] |
|
1398 |
] |
|
1399 |
] ifFalse:[ |
|
1400 |
pX := x. |
|
1401 |
pY := y. |
|
1402 |
]. |
|
1403 |
pX := pX rounded. |
|
1404 |
pY := pY rounded. |
|
1405 |
||
1406 |
fontUsed := fontUsed on:device. |
|
1407 |
||
1408 |
id := fontUsed fontId. |
|
1409 |
id isNil ifTrue:[ |
|
1410 |
" |
|
1411 |
hook for alien fonts |
|
1412 |
that 'font' should know how to display the string ... |
|
1413 |
" |
|
1414 |
fontUsed displayOpaqueString:aString from:1 to:(aString size) x:x y:y in:self. |
|
1415 |
^ self |
|
1416 |
]. |
|
1417 |
||
1418 |
s := aString. |
|
1419 |
s encoding ~~ font encoding ifTrue:[ |
|
1420 |
s := s encodeInto:(font encoding). |
|
1421 |
]. |
|
1422 |
||
1423 |
deviceFont ~~ fontUsed ifTrue:[ |
|
1424 |
device setFont:id in:gcId. |
|
1425 |
deviceFont := fontUsed |
|
1426 |
]. |
|
1427 |
||
1428 |
||
1429 |
device setForeground:fgId background:bgId in:gcId. |
|
1430 |
foreground := paint. |
|
1431 |
background := bgPaint. |
|
1432 |
device displayOpaqueString:s |
|
1433 |
x:pX y:pY |
|
1434 |
in:drawableId with:gcId. |
|
1435 |
||
1436 |
"Modified: 21.5.1996 / 21:16:17 / cg" |
|
1437 |
! |
|
1438 |
||
1439 |
displayPointX:x y:y |
|
1440 |
"draw a point (with current paint-color); apply transformation if nonNil" |
|
1441 |
||
1442 |
|pX pY| |
|
1443 |
||
1444 |
gcId isNil ifTrue:[ |
|
1445 |
self initGC |
|
1446 |
]. |
|
1447 |
transformation notNil ifTrue:[ |
|
1448 |
pX := transformation applyToX:x. |
|
1449 |
pY := transformation applyToY:y. |
|
1450 |
] ifFalse:[ |
|
1451 |
pX := x. |
|
1452 |
pY := y |
|
1453 |
]. |
|
1454 |
pX := pX rounded. |
|
1455 |
pY := pY rounded. |
|
1456 |
||
1457 |
device displayPointX:pX y:pY in:drawableId with:gcId |
|
1458 |
! |
|
1459 |
||
1460 |
displayPolygon:aPolygon |
|
1461 |
"draw (the outline of) a polygon (with current paint-color). |
|
1462 |
Apply transformation if nonNil" |
|
1463 |
||
1464 |
|newPolygon| |
|
1465 |
||
1466 |
gcId isNil ifTrue:[ |
|
1467 |
self initGC |
|
1468 |
]. |
|
1469 |
transformation notNil ifTrue:[ |
|
1470 |
newPolygon := aPolygon collect:[:point | transformation applyTo:point]. |
|
1471 |
] ifFalse:[ |
|
1472 |
newPolygon := aPolygon |
|
1473 |
]. |
|
1474 |
(newPolygon findFirst:[:p | |
|
1475 |
(p isPoint not |
|
1476 |
or:[(p x class ~~ SmallInteger) |
|
1477 |
or:[(p y class ~~ SmallInteger)]]) |
|
1478 |
]) ~~ 0 ifTrue:[ |
|
1479 |
newPolygon := newPolygon collect:[:p | p asPoint rounded] |
|
1480 |
]. |
|
1481 |
||
1482 |
device displayPolygon:newPolygon in:drawableId with:gcId |
|
1483 |
! |
|
1484 |
||
1485 |
displayRectangleX:x y:y width:w height:h |
|
1486 |
"draw a rectangle (with current paint-color). |
|
1487 |
If transformation is nonNil, drawing is in logical coordinates." |
|
1488 |
||
784 | 1489 |
|pX pY rpX rpY nW nH easy fgId bgId| |
732 | 1490 |
|
1491 |
gcId isNil ifTrue:[ |
|
1492 |
self initGC |
|
1493 |
]. |
|
1494 |
||
1495 |
lineStyle == #doubleDashed ifTrue:[ |
|
1496 |
" |
|
1497 |
if bgPaint or paint is not a real color, we have to do it the hard way ... |
|
1498 |
" |
|
1499 |
easy := true. |
|
1500 |
paint isColor ifFalse:[ |
|
1501 |
easy := false |
|
1502 |
] ifTrue:[ |
|
1503 |
fgId := paint colorId. |
|
1504 |
fgId isNil ifTrue:[ |
|
1505 |
easy := false |
|
1506 |
] |
|
1507 |
]. |
|
1508 |
bgPaint isColor ifFalse:[ |
|
1509 |
easy := false |
|
1510 |
] ifTrue:[ |
|
1511 |
bgId := bgPaint colorId. |
|
1512 |
bgId isNil ifTrue:[ |
|
1513 |
easy := false |
|
1514 |
] |
|
1515 |
]. |
|
1516 |
||
1517 |
easy ifTrue:[ |
|
1518 |
((foreground ~~ paint) or:[background ~~ bgPaint]) ifTrue:[ |
|
1519 |
device setForeground:fgId background:bgId in:gcId. |
|
1520 |
foreground := paint. |
|
1521 |
background := bgPaint. |
|
1522 |
]. |
|
1523 |
] ifFalse:[ |
|
1524 |
'DEVDRAW: cannot draw dashes with dithered colors' errorPrintNL |
|
1525 |
]. |
|
1526 |
]. |
|
1527 |
||
1528 |
transformation notNil ifTrue:[ |
|
1529 |
pX := transformation applyToX:x. |
|
1530 |
pY := transformation applyToY:y. |
|
1531 |
nW := transformation applyScaleX:w. |
|
1532 |
nH := transformation applyScaleY:h. |
|
1533 |
nW < 0 ifTrue:[ |
|
1534 |
nW := nW abs. |
|
1535 |
pX := pX - nW. |
|
1536 |
]. |
|
1537 |
nH < 0 ifTrue:[ |
|
1538 |
nH := nH abs. |
|
1539 |
pY := pY - nH. |
|
1540 |
]. |
|
1541 |
] ifFalse:[ |
|
1542 |
pX := x. |
|
1543 |
pY := y. |
|
1544 |
nW := w. |
|
1545 |
nH := h |
|
1546 |
]. |
|
1547 |
||
1548 |
pX := pX rounded. |
|
1549 |
pY := pY rounded. |
|
1550 |
nW := nW rounded. |
|
1551 |
nH := nH rounded. |
|
1552 |
||
1553 |
"I asked myself many times if we should draw w/h or (w-1)/(h-1) bits - |
|
1554 |
this one seems mathematically incorrect but allows to draw and fill |
|
1555 |
a rectangle using the same extents. |
|
1556 |
I'm not certain if is the right thing to do ... |
|
1557 |
" |
|
784 | 1558 |
device displayRectangleX:pX |
1559 |
y:pY |
|
1560 |
width:(nW - 1) |
|
1561 |
height:(nH - 1) |
|
1562 |
in:drawableId with:gcId |
|
1563 |
||
1564 |
"/ rpX := pX rounded. |
|
1565 |
"/ rpY := pY rounded. |
|
1566 |
"/ nW := (nW + (rpX - pX)) rounded. |
|
1567 |
"/ nH := (nH + (rpY - pY)) rounded. |
|
1568 |
"/ |
|
1569 |
"/ "I asked myself many times if we should draw w/h or (w-1)/(h-1) bits - |
|
1570 |
"/ this one seems mathematically incorrect but allows to draw and fill |
|
1571 |
"/ a rectangle using the same extents. |
|
1572 |
"/ I'm not certain if is the right thing to do ... |
|
1573 |
"/ " |
|
1574 |
"/ device displayRectangleX:rpX |
|
1575 |
"/ y:rpY |
|
1576 |
"/ width:(nW - 1) |
|
1577 |
"/ height:(nH - 1) |
|
1578 |
"/ in:drawableId with:gcId |
|
1579 |
||
1580 |
"Modified: 4.6.1996 / 18:00:03 / cg" |
|
732 | 1581 |
! |
1582 |
||
1583 |
displayString:aString from:index1 to:index2 x:x y:y |
|
1584 |
"draw a substring at the coordinate x/y - |
|
1585 |
draw foreground-pixels only (in current paint-color), |
|
1586 |
leaving background as-is. If the transformation involves scaling, |
|
1587 |
the fonts point-size is scaled as appropriate." |
|
1588 |
||
1589 |
|id pX pY fontUsed sz s| |
|
1590 |
||
1591 |
"hook for non-strings (i.e. attributed text)" |
|
1592 |
aString isString ifFalse:[ |
|
1593 |
^ aString displayOn:self x:x y:y from:index1 to:index2 |
|
1594 |
]. |
|
1595 |
||
1596 |
gcId isNil ifTrue:[ |
|
1597 |
self initGC |
|
1598 |
]. |
|
1599 |
||
1600 |
fontUsed := font. |
|
1601 |
transformation notNil ifTrue:[ |
|
1602 |
pX := transformation applyToX:x. |
|
1603 |
pY := transformation applyToY:y. |
|
1604 |
transformation noScale ifFalse:[ |
|
1605 |
sz := font size. |
|
1606 |
sz isNil ifTrue:[ |
|
1607 |
"/ oops - not a real font; use original font |
|
1608 |
fontUsed := font |
|
1609 |
] ifFalse:[ |
|
1610 |
fontUsed := font size:(transformation applyScaleY:sz) rounded. |
|
1611 |
] |
|
1612 |
] |
|
1613 |
] ifFalse:[ |
|
1614 |
pX := x. |
|
1615 |
pY := y. |
|
1616 |
]. |
|
1617 |
pX := pX rounded. |
|
1618 |
pY := pY rounded. |
|
1619 |
||
1620 |
fontUsed := fontUsed on:device. |
|
1621 |
||
1622 |
id := fontUsed fontId. |
|
1623 |
id isNil ifTrue:[ |
|
1624 |
"hook for alien fonts" |
|
1625 |
font displayString:aString from:index1 to:index2 x:x y:y in:self. |
|
1626 |
^ self |
|
1627 |
]. |
|
1628 |
||
1629 |
s := aString. |
|
1630 |
s encoding ~~ font encoding ifTrue:[ |
|
1631 |
s := s encodeInto:(font encoding). |
|
1632 |
]. |
|
1633 |
||
1634 |
deviceFont ~~ fontUsed ifTrue:[ |
|
1635 |
device setFont:id in:gcId. |
|
1636 |
deviceFont := fontUsed |
|
1637 |
]. |
|
1638 |
device displayString:s from:index1 to:index2 |
|
1639 |
x:pX y:pY in:drawableId with:gcId |
|
1640 |
||
1641 |
"Modified: 21.5.1996 / 21:16:24 / cg" |
|
1642 |
! |
|
1643 |
||
1644 |
displayString:aString x:x y:y |
|
1645 |
"draw a string at the coordinate x/y - |
|
1646 |
draw foreground-pixels only (in current paint-color), |
|
1647 |
leaving background as-is. If the transformation involves scaling, |
|
1648 |
the fonts point-size is scaled as appropriate." |
|
1649 |
||
1650 |
|id pX pY fontUsed sz s| |
|
1651 |
||
1652 |
"hook for non-strings (i.e. attributed text)" |
|
1653 |
(aString isString not |
|
1654 |
or:[aString isText]) ifTrue:[ |
|
1655 |
^ aString displayOn:self x:x y:y |
|
1656 |
]. |
|
1657 |
||
1658 |
gcId isNil ifTrue:[ |
|
1659 |
self initGC |
|
1660 |
]. |
|
1661 |
||
1662 |
fontUsed := font. |
|
1663 |
transformation notNil ifTrue:[ |
|
1664 |
pX := transformation applyToX:x. |
|
1665 |
pY := transformation applyToY:y. |
|
1666 |
transformation noScale ifFalse:[ |
|
1667 |
sz := font size. |
|
1668 |
sz isNil ifTrue:[ |
|
1669 |
"/ oops - not a real font; use original font |
|
1670 |
fontUsed := font |
|
1671 |
] ifFalse:[ |
|
1672 |
fontUsed := font size:(transformation applyScaleY:sz) rounded. |
|
1673 |
] |
|
1674 |
] |
|
1675 |
] ifFalse:[ |
|
1676 |
pX := x. |
|
1677 |
pY := y. |
|
1678 |
]. |
|
1679 |
pX := pX rounded. |
|
1680 |
pY := pY rounded. |
|
1681 |
||
1682 |
fontUsed := fontUsed on:device. |
|
1683 |
||
1684 |
id := fontUsed fontId. |
|
1685 |
id isNil ifTrue:[ |
|
1686 |
"hook for alien fonts" |
|
1687 |
fontUsed displayString:aString x:x y:y in:self |
|
1688 |
] ifFalse:[ |
|
1689 |
s := aString. |
|
1690 |
s encoding ~~ fontUsed encoding ifTrue:[ |
|
1691 |
s := s encodeInto:(fontUsed encoding). |
|
1692 |
]. |
|
1693 |
||
1694 |
deviceFont ~~ fontUsed ifTrue:[ |
|
1695 |
device setFont:id in:gcId. |
|
1696 |
deviceFont := fontUsed |
|
1697 |
]. |
|
1698 |
device displayString:s x:pX y:pY in:drawableId with:gcId |
|
1699 |
] |
|
1700 |
||
1701 |
"Modified: 21.5.1996 / 21:16:30 / cg" |
|
1702 |
! |
|
1703 |
||
1704 |
displayUnscaledForm:formToDraw x:x y:y |
|
1705 |
"draw a form; if its a 1-plane bitmap, 1-bits are drawn in the |
|
1706 |
current paint-color, leaving pixels with 0-bits unchanged |
|
1707 |
(i.e. only 1-bits are drawn from the form). |
|
1708 |
If its a deep form (i.e. a pixmap) the current paint |
|
1709 |
settings are ignored and the form is drawn as-is. |
|
1710 |
Care must be taken, that the paint color is correctly allocated |
|
1711 |
(by sending #on: to the color) before doing so. |
|
1712 |
Using functions other than #copy only makes sense if you are |
|
1713 |
certain, that the colors are real colors (actually, only for |
|
1714 |
noColor or allColor). |
|
1715 |
The origins coordinate is transformed, but the image itself is unscaled." |
|
1716 |
||
1717 |
|pX pY| |
|
1718 |
||
1719 |
transformation notNil ifTrue:[ |
|
1720 |
pX := transformation applyToX:x. |
|
1721 |
pY := transformation applyToY:y. |
|
1722 |
] ifFalse:[ |
|
1723 |
pX := x. |
|
1724 |
pY := y. |
|
1725 |
]. |
|
1726 |
pX := pX rounded. |
|
1727 |
pY := pY rounded. |
|
1728 |
||
1729 |
self displayDeviceForm:formToDraw x:pX y:pY |
|
1730 |
! |
|
1731 |
||
1732 |
displayUnscaledOpaqueForm:formToDraw x:x y:y |
|
1733 |
"draw a form; if its a 1-plane bitmap, 1-bits are drawn in the |
|
1734 |
current paint-color, 0 bits in background color. |
|
1735 |
If its a deep form (i.e. a pixmap) the current paint |
|
1736 |
settings are ignored and the form is drawn as-is (opaque). |
|
1737 |
The origins coordinate is transformed, but the image itself is unscaled." |
|
1738 |
||
1739 |
|pX pY| |
|
1740 |
||
1741 |
transformation notNil ifTrue:[ |
|
1742 |
pX := transformation applyToX:x. |
|
1743 |
pY := transformation applyToY:y. |
|
1744 |
] ifFalse:[ |
|
1745 |
pX := x. |
|
1746 |
pY := y. |
|
1747 |
]. |
|
1748 |
pX := pX rounded. |
|
1749 |
pY := pY rounded. |
|
1750 |
||
1751 |
self displayDeviceOpaqueForm:formToDraw x:pX y:pY |
|
1752 |
! |
|
1753 |
||
1754 |
displayUnscaledOpaqueString:aString from:index1 to:index2 x:x y:y |
|
1755 |
"draw a substring at the transformed coordinate x/y but do not scale the font. |
|
1756 |
Draw foreground pixels in paint-color, background pixels in bgPaint color." |
|
1757 |
||
1758 |
|pX pY| |
|
1759 |
||
1760 |
transformation notNil ifTrue:[ |
|
1761 |
pX := transformation applyToX:x. |
|
1762 |
pY := transformation applyToY:y. |
|
1763 |
] ifFalse:[ |
|
1764 |
pX := x. |
|
1765 |
pY := y. |
|
1766 |
]. |
|
1767 |
self displayDeviceOpaqueString:aString from:index1 to:index2 in:font x:pX y:pY |
|
1768 |
! |
|
1769 |
||
1770 |
displayUnscaledOpaqueString:aString x:x y:y |
|
1771 |
"draw a string at the transformed coordinate x/y but do not scale the font. |
|
1772 |
Draw foreground pixels in paint-color, background pixels in bgPaint color." |
|
1773 |
||
1774 |
|pX pY| |
|
1775 |
||
1776 |
transformation notNil ifTrue:[ |
|
1777 |
pX := transformation applyToX:x. |
|
1778 |
pY := transformation applyToY:y. |
|
1779 |
] ifFalse:[ |
|
1780 |
pX := x. |
|
1781 |
pY := y. |
|
1782 |
]. |
|
1783 |
self displayDeviceOpaqueString:aString from:1 to:(aString size) in:font x:pX y:pY |
|
1784 |
! |
|
1785 |
||
1786 |
displayUnscaledString:aString from:index1 to:index2 x:x y:y |
|
1787 |
"draw a substring at the transformed coordinate x/y but do not scale the font. |
|
1788 |
draw foreground-pixels only (in current paint-color), leaving background as-is." |
|
1789 |
||
1790 |
|pX pY| |
|
1791 |
||
1792 |
transformation notNil ifTrue:[ |
|
1793 |
pX := transformation applyToX:x. |
|
1794 |
pY := transformation applyToY:y. |
|
1795 |
] ifFalse:[ |
|
1796 |
pX := x. |
|
1797 |
pY := y. |
|
1798 |
]. |
|
1799 |
self displayDeviceString:aString from:index1 to:index2 in:font x:pX y:pY |
|
1800 |
! |
|
1801 |
||
1802 |
displayUnscaledString:aString x:x y:y |
|
1803 |
"draw a string at the transformed coordinate x/y but do not scale the font. |
|
1804 |
draw foreground-pixels only (in current paint-color), leaving background as-is." |
|
1805 |
||
1806 |
|pX pY| |
|
1807 |
||
1808 |
transformation notNil ifTrue:[ |
|
1809 |
pX := transformation applyToX:x. |
|
1810 |
pY := transformation applyToY:y. |
|
1811 |
] ifFalse:[ |
|
1812 |
pX := x. |
|
1813 |
pY := y. |
|
1814 |
]. |
|
1815 |
self displayDeviceString:aString from:1 to:(aString size) in:font x:pX y:pY |
|
1816 |
! ! |
|
1817 |
||
1818 |
!DeviceGraphicsContext methodsFor:'drawing in device coordinates'! |
|
1819 |
||
1820 |
displayDeviceForm:aForm x:x y:y |
|
1821 |
"draw a form; if its a 1-plane bitmap, 1-bits are drawn in the |
|
1822 |
current paint-color, leaving pixels with 0-bits unchanged |
|
1823 |
(i.e. only 1-bits are drawn from the form). |
|
1824 |
The form must have been allocated on the same device. |
|
1825 |
No transformation or scaling is done. |
|
1826 |
If its a deep form (i.e. a pixmap) the current paint |
|
1827 |
settings are ignored and the form is drawn as-is. |
|
1828 |
Care must be taken, that the paint color is correctly allocated |
|
1829 |
(by sending #on: to the color) before doing so. |
|
1830 |
Using functions other than #copy only makes sense if you are |
|
1831 |
certain, that the colors are real colors (actually, only for |
|
1832 |
noColor or allColor)." |
|
1833 |
||
1834 |
|id w h easy paintDither tmpForm |
|
1835 |
fgId noColor allColor allBits pX pY| |
|
1836 |
||
1837 |
w := aForm width. |
|
1838 |
h := aForm height. |
|
1839 |
||
1840 |
pX := x rounded. |
|
1841 |
pY := y rounded. |
|
1842 |
||
1843 |
id := aForm id. |
|
1844 |
||
1845 |
"temporary ..." |
|
1846 |
(id isNil |
|
1847 |
or:[aForm graphicsDevice ~~ device]) ifTrue:[ |
|
768 | 1848 |
id := (aForm on:device) id. |
1849 |
id isNil ifTrue:[ |
|
1850 |
'DEVDRAW: invalid form draw - ignored' errorPrintNL. |
|
1851 |
^ self |
|
1852 |
]. |
|
732 | 1853 |
]. |
1854 |
gcId isNil ifTrue:[ |
|
768 | 1855 |
self initGC |
732 | 1856 |
]. |
1857 |
||
1858 |
" |
|
1859 |
a deep form ignores paint/bgPaint settings |
|
1860 |
" |
|
1861 |
(aForm depth ~~ 1) ifTrue:[ |
|
768 | 1862 |
device |
1863 |
copyFromId:id |
|
1864 |
x:0 y:0 |
|
1865 |
to:drawableId |
|
1866 |
x:pX y:pY |
|
1867 |
width:w |
|
1868 |
height:h |
|
1869 |
with:gcId. |
|
1870 |
^ self |
|
732 | 1871 |
]. |
1872 |
||
1873 |
" |
|
1874 |
the following code is somewhat complicated, since it has to deal |
|
1875 |
with dithered paint colors, which cannot be done directly on most |
|
1876 |
devices (actually, a test for the devices capabilities has to be added here) |
|
1877 |
(just assume drawing a bitmap with dithered paint color ... sigh) |
|
1878 |
" |
|
1879 |
||
1880 |
" |
|
1881 |
if paint is not a real color, we have to do it the hard way ... |
|
1882 |
" |
|
1883 |
easy := (function == #copy). |
|
1884 |
easy ifTrue:[ |
|
768 | 1885 |
paint isColor ifFalse:[ |
1886 |
paintDither := paint. |
|
1887 |
easy := false |
|
1888 |
] ifTrue:[ |
|
1889 |
paintDither := paint ditherForm. |
|
1890 |
paintDither notNil ifTrue:[ |
|
1891 |
easy := false. |
|
1892 |
] |
|
1893 |
]. |
|
732 | 1894 |
]. |
1895 |
||
1896 |
allColor := Color allColor. |
|
1897 |
allBits := allColor colorId. |
|
1898 |
||
1899 |
easy ifTrue:[ |
|
768 | 1900 |
" |
1901 |
paint is a real color |
|
1902 |
" |
|
1903 |
||
1904 |
" |
|
1905 |
if paint color is all-0 or all-1's, we can do it in one |
|
1906 |
operation ... |
|
1907 |
" |
|
1908 |
fgId := paint colorId. |
|
1909 |
||
1910 |
((fgId ~~ ((1 bitShift:device depth)-1)) |
|
1911 |
and:[fgId ~~ allBits]) ifTrue:[ |
|
1912 |
" |
|
1913 |
clear fg-bits ... |
|
1914 |
" |
|
1915 |
device setForeground:0 background:allBits in:gcId. |
|
1916 |
device setFunction:#and in:gcId. |
|
1917 |
device |
|
1918 |
copyPlaneFromId:id |
|
1919 |
x:0 y:0 |
|
1920 |
to:drawableId |
|
1921 |
x:pX y:pY |
|
1922 |
width:w |
|
1923 |
height:h |
|
1924 |
with:gcId. |
|
1925 |
]. |
|
1926 |
||
1927 |
fgId ~~ 0 ifTrue:[ |
|
1928 |
" |
|
1929 |
or-in fg-bits ... |
|
1930 |
" |
|
1931 |
device setForeground:fgId background:0 in:gcId. |
|
1932 |
device setFunction:#or in:gcId. |
|
1933 |
device |
|
1934 |
copyPlaneFromId:id |
|
1935 |
x:0 y:0 |
|
1936 |
to:drawableId |
|
1937 |
x:pX y:pY |
|
1938 |
width:w |
|
1939 |
height:h |
|
1940 |
with:gcId. |
|
1941 |
]. |
|
1942 |
" |
|
1943 |
flush foreground/background cache |
|
1944 |
" |
|
1945 |
foreground := nil. |
|
1946 |
background := nil. |
|
1947 |
device setFunction:function in:gcId. |
|
1948 |
^ self |
|
732 | 1949 |
]. |
1950 |
||
1951 |
||
1952 |
" |
|
1953 |
hard case; paint is a dithered color |
|
1954 |
" |
|
1955 |
||
1956 |
noColor := Color noColor. |
|
1957 |
||
1958 |
" |
|
1959 |
create temp-form; |
|
1960 |
" |
|
1961 |
tmpForm := Form width:w height:h depth:device depth on:device. |
|
1962 |
" |
|
1963 |
fill tempform |
|
1964 |
" |
|
1965 |
tmpForm paint:paint. |
|
1966 |
tmpForm fillRectangleX:0 y:0 width:w height:h. |
|
1967 |
" |
|
1968 |
stamp out background |
|
1969 |
" |
|
1970 |
tmpForm paint:allColor on:noColor. |
|
1971 |
tmpForm function:#and. |
|
1972 |
tmpForm displayOpaqueForm:aForm x:0 y:0. |
|
1973 |
" |
|
1974 |
stamp out foreground from destination |
|
1975 |
" |
|
1976 |
device setForeground:0 background:allBits in:gcId. |
|
1977 |
device setFunction:#and in:gcId. |
|
1978 |
device |
|
768 | 1979 |
copyPlaneFromId:id |
1980 |
x:0 y:0 |
|
1981 |
to:drawableId |
|
1982 |
x:pX y:pY |
|
1983 |
width:w |
|
1984 |
height:h |
|
1985 |
with:gcId. |
|
732 | 1986 |
" |
1987 |
or-in temp into destination |
|
1988 |
" |
|
1989 |
device setForeground:allBits background:0 in:gcId. |
|
1990 |
device setFunction:#or in:gcId. |
|
1991 |
||
1992 |
device |
|
768 | 1993 |
copyFromId:tmpForm id |
1994 |
x:0 y:0 |
|
1995 |
to:drawableId |
|
1996 |
x:pX y:pY |
|
1997 |
width:w |
|
1998 |
height:h |
|
1999 |
with:gcId. |
|
732 | 2000 |
" |
2001 |
flush foreground/background cache |
|
2002 |
" |
|
2003 |
foreground := nil. |
|
2004 |
background := nil. |
|
2005 |
device setFunction:function in:gcId. |
|
768 | 2006 |
|
2007 |
"Modified: 30.5.1996 / 09:22:09 / cg" |
|
732 | 2008 |
! |
2009 |
||
2010 |
displayDeviceLineFromX:x0 y:y0 toX:x1 y:y1 |
|
2011 |
"draw a line (with current paint-color) in device coordinate space. |
|
2012 |
This ignores any transformations. The coordinates must be integers." |
|
2013 |
||
2014 |
gcId isNil ifTrue:[ |
|
2015 |
self initGC |
|
2016 |
]. |
|
2017 |
device displayLineFromX:x0 y:y0 toX:x1 y:y1 in:drawableId with:gcId |
|
2018 |
! |
|
2019 |
||
2020 |
displayDeviceOpaqueForm:aForm x:x y:y |
|
2021 |
"draw a form; if its a 1-plane bitmap, 1-bits are drawn in the |
|
2022 |
current paint-color and 0-bits in the bgPaint color. |
|
2023 |
If its a deep form (i.e. a pixmap) the current paint/bgPaint |
|
2024 |
settings are ignored and the form drawn as-is. |
|
2025 |
In the 1-plane case, special care must be taken if paint and/or bgPaint |
|
2026 |
dithered colors or patterns, since are that the colors are correctly allocated (by sending #on: |
|
2027 |
to the colors) before doing so. |
|
2028 |
The form must have been allocated on the same device. |
|
2029 |
Drawing is in device coordinates; no scaling is done." |
|
2030 |
||
2031 |
|id w h easy savedPaint bgForm fgForm tmpForm |
|
2032 |
fgId bgId noColor allColor allBits dx dy |
|
2033 |
pX pY deviceDepth| |
|
2034 |
||
2035 |
bgPaint isNil ifTrue:[ |
|
2036 |
self displayDeviceForm:aForm x:x y:y. |
|
2037 |
^ self |
|
2038 |
]. |
|
2039 |
||
2040 |
w := aForm width. |
|
2041 |
h := aForm height. |
|
2042 |
||
2043 |
pX := x rounded. |
|
2044 |
pY := y rounded. |
|
2045 |
||
2046 |
id := aForm id. |
|
2047 |
||
2048 |
"temporary ..." |
|
2049 |
(id isNil |
|
2050 |
or:[aForm graphicsDevice ~~ device]) ifTrue:[ |
|
2051 |
id := (aForm on:device) id. |
|
2052 |
id isNil ifTrue:[ |
|
2053 |
'DEVDRAW: invalid form draw - ignored' errorPrintNL. |
|
2054 |
^ self |
|
2055 |
]. |
|
2056 |
]. |
|
2057 |
||
2058 |
gcId isNil ifTrue:[ |
|
2059 |
self initGC |
|
2060 |
]. |
|
2061 |
||
2062 |
" |
|
2063 |
a deep form ignores paint/bgPaint settings |
|
2064 |
" |
|
2065 |
(aForm depth ~~ 1) ifTrue:[ |
|
2066 |
device |
|
2067 |
copyFromId:id |
|
2068 |
x:0 y:0 |
|
2069 |
to:drawableId |
|
2070 |
x:pX y:pY |
|
2071 |
width:w |
|
2072 |
height:h |
|
2073 |
with:gcId. |
|
2074 |
^ self |
|
2075 |
]. |
|
2076 |
||
2077 |
"the following code is somewhat complicated, since it has to deal |
|
2078 |
with dithered fg/bg colors, which cannot be done directly on most |
|
2079 |
devices (actually, a test for the devices capabilities has to be added here) |
|
2080 |
(just assume drawing a bitmap with dithered fg/bg colors ... sigh) |
|
2081 |
" |
|
2082 |
||
2083 |
" |
|
2084 |
if bgPaint or paint is not a real color, we have to do it the hard way ... |
|
2085 |
" |
|
2086 |
easy := true. |
|
2087 |
paint isColor ifFalse:[ |
|
2088 |
easy := false |
|
2089 |
] ifTrue:[ |
|
2090 |
fgId := paint colorId. |
|
2091 |
fgId isNil ifTrue:[ |
|
2092 |
easy := false |
|
2093 |
] |
|
2094 |
]. |
|
2095 |
bgPaint isColor ifFalse:[ |
|
2096 |
easy := false |
|
2097 |
] ifTrue:[ |
|
2098 |
bgId := bgPaint colorId. |
|
2099 |
bgId isNil ifTrue:[ |
|
2100 |
easy := false |
|
2101 |
] |
|
2102 |
]. |
|
2103 |
||
2104 |
easy ifTrue:[ |
|
2105 |
" |
|
2106 |
easy: both paint and bgPaint are real colors |
|
2107 |
" |
|
2108 |
((foreground ~~ paint) or:[background ~~ bgPaint]) ifTrue:[ |
|
2109 |
device setForeground:fgId background:bgId in:gcId. |
|
2110 |
foreground := paint. |
|
2111 |
background := bgPaint. |
|
2112 |
]. |
|
2113 |
device |
|
2114 |
copyPlaneFromId:id |
|
2115 |
x:0 y:0 |
|
2116 |
to:drawableId |
|
2117 |
x:pX y:pY |
|
2118 |
width:w |
|
2119 |
height:h |
|
2120 |
with:gcId. |
|
2121 |
^ self |
|
2122 |
]. |
|
2123 |
||
2124 |
" |
|
2125 |
hard case: paint and/or bgPaint are dithered or patterns |
|
2126 |
" |
|
2127 |
allColor := Color allColor. |
|
2128 |
allBits := allColor colorId. |
|
2129 |
deviceDepth := device depth. |
|
2130 |
||
2131 |
(fgId notNil and:[function == #copy]) ifTrue:[ |
|
2132 |
" |
|
2133 |
only bg is dithered; fill with bg first ... |
|
2134 |
" |
|
2135 |
savedPaint := paint. |
|
2136 |
self paint:bgPaint. |
|
2137 |
self fillDeviceRectangleX:pX y:pY width:w height:h. |
|
2138 |
self paint:savedPaint. |
|
2139 |
||
2140 |
" |
|
2141 |
if paint color is all-0 or all-1's, we can do it in one |
|
2142 |
operation ... |
|
2143 |
" |
|
2144 |
((fgId ~~ ((1 bitShift:deviceDepth)-1)) |
|
2145 |
and:[fgId ~~ allBits]) ifTrue:[ |
|
2146 |
" |
|
2147 |
clear fg-bits ... |
|
2148 |
" |
|
2149 |
device setForeground:0 background:allBits in:gcId. |
|
2150 |
device setFunction:#and in:gcId. |
|
2151 |
device |
|
2152 |
copyPlaneFromId:id |
|
2153 |
x:0 y:0 |
|
2154 |
to:drawableId |
|
2155 |
x:pX y:pY |
|
2156 |
width:w |
|
2157 |
height:h |
|
2158 |
with:gcId. |
|
2159 |
]. |
|
2160 |
||
2161 |
fgId ~~ 0 ifTrue:[ |
|
2162 |
" |
|
2163 |
or-in fg-bits ... |
|
2164 |
" |
|
2165 |
device setForeground:fgId background:0 in:gcId. |
|
2166 |
device setFunction:#or in:gcId. |
|
2167 |
device |
|
2168 |
copyPlaneFromId:id |
|
2169 |
x:0 y:0 |
|
2170 |
to:drawableId |
|
2171 |
x:pX y:pY |
|
2172 |
width:w |
|
2173 |
height:h |
|
2174 |
with:gcId. |
|
2175 |
]. |
|
2176 |
" |
|
2177 |
flush foreground/background cache |
|
2178 |
" |
|
2179 |
foreground := nil. |
|
2180 |
background := nil. |
|
2181 |
device setFunction:function in:gcId. |
|
2182 |
^ self |
|
2183 |
]. |
|
2184 |
||
2185 |
(bgId notNil and:[function == #copy]) ifTrue:[ |
|
2186 |
" |
|
2187 |
only fg is dithered; fill with fg first ... |
|
2188 |
" |
|
2189 |
self fillDeviceRectangleX:pX y:pY width:w height:h. |
|
2190 |
||
2191 |
" |
|
2192 |
if paint color is all-0 or all-1's, we can do it in one |
|
2193 |
operation ... |
|
2194 |
" |
|
2195 |
((bgId ~~ ((1 bitShift:deviceDepth)-1)) |
|
2196 |
and:[bgId ~~ allBits]) ifTrue:[ |
|
2197 |
" |
|
2198 |
clear bg-bits ... |
|
2199 |
" |
|
2200 |
device setForeground:allBits background:0 in:gcId. |
|
2201 |
device setFunction:#and in:gcId. |
|
2202 |
device |
|
2203 |
copyPlaneFromId:id |
|
2204 |
x:0 y:0 |
|
2205 |
to:drawableId |
|
2206 |
x:pX y:pY |
|
2207 |
width:w |
|
2208 |
height:h |
|
2209 |
with:gcId. |
|
2210 |
]. |
|
2211 |
||
2212 |
" |
|
2213 |
or-in bg-bits ... |
|
2214 |
" |
|
2215 |
bgId ~~ 0 ifTrue:[ |
|
2216 |
device setForeground:0 background:bgId in:gcId. |
|
2217 |
device setFunction:#or in:gcId. |
|
2218 |
device |
|
2219 |
copyPlaneFromId:id |
|
2220 |
x:0 y:0 |
|
2221 |
to:drawableId |
|
2222 |
x:pX y:pY |
|
2223 |
width:w |
|
2224 |
height:h |
|
2225 |
with:gcId. |
|
2226 |
]. |
|
2227 |
" |
|
2228 |
flush foreground/background cache |
|
2229 |
" |
|
2230 |
foreground := nil. |
|
2231 |
background := nil. |
|
2232 |
device setFunction:function in:gcId. |
|
2233 |
^ self |
|
2234 |
]. |
|
2235 |
||
2236 |
" |
|
2237 |
very hard case; both fg and bg are dithered colors |
|
2238 |
" |
|
2239 |
noColor := Color noColor. |
|
2240 |
||
2241 |
" |
|
2242 |
create temp-forms; |
|
2243 |
" |
|
2244 |
bgForm := Form width:w height:h depth:deviceDepth on:device. |
|
2245 |
fgForm := Form width:w height:h depth:deviceDepth on:device. |
|
2246 |
tmpForm := Form width:w height:h depth:deviceDepth on:device. |
|
2247 |
||
2248 |
" |
|
2249 |
fill |
|
2250 |
" |
|
2251 |
dx := dy := 0. |
|
2252 |
maskOrigin notNil ifTrue:[ |
|
2253 |
dx := maskOrigin x. |
|
2254 |
dy := maskOrigin y |
|
2255 |
]. |
|
2256 |
||
2257 |
bgForm paint:bgPaint. |
|
2258 |
bgForm setMaskOriginX:(x negated + dx) y:(y negated + dy). |
|
2259 |
bgForm fillRectangleX:0 y:0 width:w height:h. |
|
2260 |
fgForm paint:paint. |
|
2261 |
fgForm setMaskOriginX:(x negated + dx) y:(y negated + dy). |
|
2262 |
fgForm fillRectangleX:0 y:0 width:w height:h. |
|
2263 |
||
2264 |
" |
|
2265 |
stamp-out background |
|
2266 |
" |
|
2267 |
bgForm paint:noColor on:allColor. |
|
2268 |
bgForm function:#and. |
|
2269 |
bgForm displayOpaqueForm:aForm x:0 y:0. |
|
2270 |
||
2271 |
" |
|
2272 |
stamp-out foreground |
|
2273 |
" |
|
2274 |
fgForm paint:allColor on:noColor. |
|
2275 |
fgForm function:#and. |
|
2276 |
fgForm displayOpaqueForm:aForm x:0 y:0. |
|
2277 |
||
2278 |
" |
|
2279 |
clear tempform |
|
2280 |
" |
|
2281 |
tmpForm paint:noColor. |
|
2282 |
tmpForm fillRectangleX:0 y:0 width:w height:h. |
|
2283 |
||
2284 |
" |
|
2285 |
merge fg-temp and bg-temp into tmp |
|
2286 |
" |
|
2287 |
tmpForm function:#or. |
|
2288 |
tmpForm paint:noColor on:allColor. |
|
2289 |
tmpForm copyFrom:fgForm x:0 y:0 toX:0 y:0 width:w height:h. |
|
2290 |
tmpForm copyFrom:bgForm x:0 y:0 toX:0 y:0 width:w height:h. |
|
2291 |
||
2292 |
" |
|
2293 |
finally, draw it |
|
2294 |
" |
|
2295 |
device setForeground:0 background:allBits in:gcId. |
|
2296 |
device |
|
2297 |
copyFromId:tmpForm id |
|
2298 |
x:0 y:0 |
|
2299 |
to:drawableId |
|
2300 |
x:pX y:pY |
|
2301 |
width:w |
|
2302 |
height:h |
|
2303 |
with:gcId. |
|
2304 |
" |
|
2305 |
flush foreground/background cache |
|
2306 |
" |
|
2307 |
foreground := nil. |
|
2308 |
background := nil. |
|
2309 |
! |
|
2310 |
||
2311 |
displayDeviceOpaqueString:aString from:index1 to:index2 in:font x:x y:y |
|
2312 |
"draw a substring at the coordinate x/y - draw foreground pixels in |
|
2313 |
paint-color and background pixels in bgPaint-color. |
|
2314 |
Assuming that device can only draw in device colors, we have to handle |
|
2315 |
the case where paint and/or bgPaint are dithered colors. |
|
2316 |
No translation or scaling is done." |
|
2317 |
||
2318 |
|easy w h savedPaint fgId bgId allColor allBits noColor |
|
2319 |
id bgForm fgForm tmpForm maskForm dx dy pX pY fontUsed s |
|
2320 |
deviceDepth| |
|
2321 |
||
2322 |
" |
|
2323 |
if backgroundPaint color is nil, we assume |
|
2324 |
this is a non-opaque draw |
|
2325 |
" |
|
2326 |
bgPaint isNil ifTrue:[ |
|
2327 |
self displayDeviceString:aString from:index1 to:index2 x:x y:y. |
|
2328 |
^ self |
|
2329 |
]. |
|
2330 |
||
2331 |
(aString isString not |
|
2332 |
or:[aString isText]) ifTrue:[ |
|
2333 |
" |
|
2334 |
hook for non-strings (i.e. attributed text) |
|
2335 |
that 'thing' should know how to display itself ... |
|
2336 |
" |
|
2337 |
aString displayOpaqueOn:self x:x y:y from:index1 to:index2. |
|
2338 |
^ self |
|
2339 |
]. |
|
2340 |
||
2341 |
gcId isNil ifTrue:[ |
|
2342 |
self initGC |
|
2343 |
]. |
|
2344 |
||
2345 |
pX := x rounded. |
|
2346 |
pY := y rounded. |
|
2347 |
||
2348 |
fontUsed := font on:device. |
|
2349 |
||
2350 |
id := fontUsed fontId. |
|
2351 |
id isNil ifTrue:[ |
|
2352 |
" |
|
2353 |
hook for alien fonts |
|
2354 |
that 'font' should know how to display the string ... |
|
2355 |
" |
|
2356 |
font displayOpaqueString:aString from:index1 to:index2 x:x y:y in:self. |
|
2357 |
^ self |
|
2358 |
]. |
|
2359 |
||
2360 |
s := aString. |
|
2361 |
s encoding ~~ font encoding ifTrue:[ |
|
2362 |
s := s encodeInto:(font encoding). |
|
2363 |
]. |
|
2364 |
||
2365 |
deviceFont ~~ fontUsed ifTrue:[ |
|
2366 |
device setFont:id in:gcId. |
|
2367 |
deviceFont := fontUsed |
|
2368 |
]. |
|
2369 |
||
2370 |
" |
|
2371 |
if bgPaint or paint is not a real Color, we have to do it the hard way ... |
|
2372 |
" |
|
2373 |
easy := true. |
|
2374 |
paint isColor ifFalse:[ |
|
2375 |
easy := false |
|
2376 |
] ifTrue:[ |
|
2377 |
fgId := paint colorId. |
|
2378 |
fgId isNil ifTrue:[ |
|
2379 |
easy := false |
|
2380 |
] |
|
2381 |
]. |
|
2382 |
bgPaint isColor ifFalse:[ |
|
2383 |
easy := false |
|
2384 |
] ifTrue:[ |
|
2385 |
bgId := bgPaint colorId. |
|
2386 |
bgId isNil ifTrue:[ |
|
2387 |
easy := false |
|
2388 |
] |
|
2389 |
]. |
|
2390 |
||
2391 |
easy ifTrue:[ |
|
2392 |
device setForeground:fgId background:bgId in:gcId. |
|
2393 |
foreground := paint. |
|
2394 |
background := bgPaint. |
|
2395 |
device displayOpaqueString:s |
|
2396 |
from:index1 to:index2 |
|
2397 |
x:pX y:pY |
|
2398 |
in:drawableId with:gcId. |
|
2399 |
^ self |
|
2400 |
]. |
|
2401 |
||
2402 |
w := fontUsed widthOf:s from:index1 to:index2. |
|
2403 |
h := fontUsed height. |
|
2404 |
||
2405 |
(fgId notNil and:[function == #copy]) ifTrue:[ |
|
2406 |
" |
|
2407 |
only bg is dithered; fill with bg first ... |
|
2408 |
" |
|
2409 |
savedPaint := paint. |
|
2410 |
self paint:bgPaint. |
|
2411 |
self fillRectangleX:pX y:(pY - fontUsed ascent) width:w height:h. |
|
2412 |
self paint:savedPaint. |
|
2413 |
||
2414 |
" |
|
2415 |
then draw using fgPaint (which is a real color) |
|
2416 |
" |
|
2417 |
device displayString:s |
|
2418 |
from:index1 to:index2 |
|
2419 |
x:pX y:pY |
|
2420 |
in:drawableId with:gcId. |
|
2421 |
^ self |
|
2422 |
]. |
|
2423 |
||
2424 |
allColor := Color allColor. |
|
2425 |
allBits := allColor colorId. |
|
2426 |
||
2427 |
deviceDepth := device depth. |
|
2428 |
||
2429 |
" |
|
2430 |
the code below is correct, but some (all?) implementations of the |
|
2431 |
X Window system seem to not support ALU-functions when drawing opaque strings. |
|
2432 |
Therefore we use the slower code below. |
|
2433 |
" |
|
2434 |
||
2435 |
"/ (bgId notNil and:[function == #copy]) ifTrue:[ |
|
2436 |
"/ " |
|
2437 |
"/ only fg is dithered; fill with fg first ... |
|
2438 |
"/ " |
|
2439 |
"/ self fillRectangleX:pX y:(pY - fontUsed ascent) width:w height:h. |
|
2440 |
"/ |
|
2441 |
"/ " |
|
2442 |
"/ if bgPaint color is all-0 or all-1's, we can do it in one |
|
2443 |
"/ operation ... |
|
2444 |
"/ " |
|
2445 |
"/ ((bgId ~~ ((1 bitShift:deviceDepth)-1)) |
|
2446 |
"/ and:[bgId ~~ allBits]) ifTrue:[ |
|
2447 |
"/ " |
|
2448 |
"/ clear bg bits ... |
|
2449 |
"/ " |
|
2450 |
"/ device setForeground:allBits background:0 in:gcId. |
|
2451 |
"/ device setFunction:#and in:gcId. |
|
2452 |
"/ device displayOpaqueString:s |
|
2453 |
"/ from:index1 to:index2 |
|
2454 |
"/ x:pX y:pY |
|
2455 |
"/ in:drawableId with:gcId. |
|
2456 |
"/ ]. |
|
2457 |
"/ |
|
2458 |
"/ " |
|
2459 |
"/ or-in bg bits ... |
|
2460 |
"/ " |
|
2461 |
"/ bgId ~~ 0 ifTrue:[ |
|
2462 |
"/ device setForeground:0 background:bgId in:gcId. |
|
2463 |
"/ device setFunction:#or in:gcId. |
|
2464 |
"/ device displayOpaqueString:s |
|
2465 |
"/ from:index1 to:index2 |
|
2466 |
"/ x:pX y:pY |
|
2467 |
"/ in:drawableId with:gcId. |
|
2468 |
"/ ]. |
|
2469 |
"/ " |
|
2470 |
"/ flush foreground/background cache |
|
2471 |
"/ " |
|
2472 |
"/ foreground := nil. |
|
2473 |
"/ background := nil. |
|
2474 |
"/ device setFunction:function in:gcId. |
|
2475 |
"/ ^ self |
|
2476 |
"/ ]. |
|
2477 |
||
768 | 2478 |
(bgId notNil and:[function == #copy]) ifTrue:[ |
2479 |
" |
|
2480 |
only fg is dithered; fill with bg first ... |
|
2481 |
" |
|
2482 |
device setForeground:bgId in:gcId. |
|
2483 |
device setFunction:#copy in:gcId. |
|
832
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
2484 |
device setBitmapMask:nil in:gcId. |
768 | 2485 |
self fillRectangleX:pX y:(pY - fontUsed ascent) width:w height:h. |
2486 |
||
832
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
2487 |
"/ draw fg dithered |
768 | 2488 |
(mask depth == 1) ifTrue:[ |
832
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
2489 |
device setBitmapMask:mask id in:gcId. |
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
2490 |
device setForeground:foreground colorId background:background colorId in:gcId. |
768 | 2491 |
] ifFalse:[ |
2492 |
device setPixmapMask:mask id in:gcId |
|
2493 |
]. |
|
2494 |
||
2495 |
device displayString:s |
|
2496 |
from:index1 to:index2 |
|
2497 |
x:pX y:pY |
|
2498 |
in:drawableId with:gcId. |
|
2499 |
^ self. |
|
2500 |
"/ |
|
2501 |
"/ " |
|
2502 |
"/ if bgPaint color is all-0 or all-1's, we can do it in one |
|
2503 |
"/ operation ... |
|
2504 |
"/ " |
|
2505 |
"/ ((bgId ~~ ((1 bitShift:deviceDepth)-1)) |
|
2506 |
"/ and:[bgId ~~ allBits]) ifTrue:[ |
|
2507 |
"/ " |
|
2508 |
"/ clear bg bits ... |
|
2509 |
"/ " |
|
2510 |
"/ device setForeground:allBits background:0 in:gcId. |
|
2511 |
"/ device setFunction:#and in:gcId. |
|
2512 |
"/ device displayOpaqueString:s |
|
2513 |
"/ from:index1 to:index2 |
|
2514 |
"/ x:pX y:pY |
|
2515 |
"/ in:drawableId with:gcId. |
|
2516 |
"/ ]. |
|
2517 |
"/ |
|
2518 |
"/ " |
|
2519 |
"/ or-in bg bits ... |
|
2520 |
"/ " |
|
2521 |
"/ bgId ~~ 0 ifTrue:[ |
|
2522 |
"/ device setForeground:0 background:bgId in:gcId. |
|
2523 |
"/ device setFunction:#or in:gcId. |
|
2524 |
"/ device displayOpaqueString:s |
|
2525 |
"/ from:index1 to:index2 |
|
2526 |
"/ x:pX y:pY |
|
2527 |
"/ in:drawableId with:gcId. |
|
2528 |
"/ ]. |
|
2529 |
"/ " |
|
2530 |
"/ flush foreground/background cache |
|
2531 |
"/ " |
|
2532 |
"/ foreground := nil. |
|
2533 |
"/ background := nil. |
|
2534 |
"/ device setFunction:function in:gcId. |
|
2535 |
"/ ^ self |
|
832
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
2536 |
]. |
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
2537 |
|
732 | 2538 |
" |
832
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
2539 |
very hard case, both fg and bg are dithered colors/images |
732 | 2540 |
" |
2541 |
noColor := Color noColor. |
|
832
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
2542 |
"/ 'hard: ' print. aString print. ' ' print. paint print. ' ' print. bgPaint printCR. |
732 | 2543 |
" |
2544 |
create temp-forms; |
|
2545 |
" |
|
2546 |
bgForm := Form width:w height:h depth:deviceDepth on:device. |
|
2547 |
fgForm := Form width:w height:h depth:deviceDepth on:device. |
|
2548 |
tmpForm := Form width:w height:h depth:deviceDepth on:device. |
|
2549 |
maskForm := Form width:w height:h depth:deviceDepth on:device. |
|
2550 |
||
2551 |
" |
|
2552 |
fill |
|
2553 |
" |
|
2554 |
dx := 0. |
|
2555 |
dy := fontUsed ascent. |
|
2556 |
maskOrigin notNil ifTrue:[ |
|
2557 |
dx := maskOrigin x. |
|
2558 |
dy := dy + maskOrigin y |
|
2559 |
]. |
|
2560 |
||
2561 |
bgForm paint:bgPaint. |
|
2562 |
bgForm setMaskOriginX:(pX negated + dx) y:(pY negated + dy). |
|
2563 |
bgForm fillRectangleX:0 y:0 width:w height:h. |
|
2564 |
||
2565 |
fgForm paint:paint. |
|
2566 |
fgForm setMaskOriginX:(pX negated + dx) y:(pY negated + dy). |
|
2567 |
fgForm fillRectangleX:0 y:0 width:w height:h. |
|
2568 |
||
2569 |
" |
|
2570 |
stamp-out background (have now bg-bits with fg=0 in bgForm) |
|
2571 |
" |
|
2572 |
bgForm font:fontUsed. |
|
2573 |
bgForm paint:noColor on:allColor. |
|
2574 |
bgForm function:#and. |
|
2575 |
bgForm displayString:s |
|
2576 |
from:index1 to:index2 |
|
2577 |
x:0 y:fontUsed ascent. |
|
2578 |
||
2579 |
" |
|
2580 |
stamp-out foreground |
|
2581 |
" |
|
2582 |
maskForm font:fontUsed. |
|
2583 |
maskForm paint:allColor on:noColor. |
|
2584 |
maskForm displayOpaqueString:s |
|
2585 |
from:index1 to:index2 |
|
2586 |
x:0 y:fontUsed ascent. |
|
2587 |
||
2588 |
fgForm function:#and. |
|
2589 |
fgForm copyFrom:maskForm x:0 y:0 toX:0 y:0 width:w height:h. |
|
2590 |
||
2591 |
" |
|
2592 |
clear tempform |
|
2593 |
" |
|
2594 |
tmpForm paint:noColor. |
|
2595 |
tmpForm fillRectangleX:0 y:0 width:w height:h. |
|
2596 |
||
2597 |
" |
|
2598 |
merge fg-temp and bg-temp into tmp |
|
2599 |
" |
|
2600 |
tmpForm function:#or. |
|
2601 |
tmpForm paint:noColor on:allColor. |
|
2602 |
tmpForm copyFrom:fgForm x:0 y:0 toX:0 y:0 width:w height:h. |
|
2603 |
tmpForm copyFrom:bgForm x:0 y:0 toX:0 y:0 width:w height:h. |
|
2604 |
" |
|
2605 |
finally, draw it |
|
2606 |
" |
|
2607 |
device setForeground:0 background:allBits in:gcId. |
|
2608 |
device |
|
2609 |
copyFromId:tmpForm id |
|
2610 |
x:0 y:0 |
|
2611 |
to:drawableId |
|
2612 |
x:pX y:pY-fontUsed ascent |
|
2613 |
width:w |
|
2614 |
height:h |
|
2615 |
with:gcId. |
|
2616 |
" |
|
2617 |
flush foreground/background cache |
|
2618 |
" |
|
2619 |
foreground := nil. |
|
2620 |
background := nil. |
|
2621 |
||
832
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
2622 |
"Modified: 12.6.1996 / 12:50:12 / cg" |
732 | 2623 |
! |
2624 |
||
2625 |
displayDeviceOpaqueString:aString from:index1 to:index2 x:x y:y |
|
2626 |
"draw a substring at the coordinate x/y - draw foreground pixels in |
|
2627 |
paint-color and background pixels in bgPaint-color. |
|
2628 |
Assuming that device can only draw in device colors, we have to handle |
|
2629 |
the case where paint and/or bgPaint are dithered colors. |
|
2630 |
No translation or scaling is done." |
|
2631 |
||
2632 |
self displayDeviceOpaqueString:aString from:index1 to:index2 in:font x:x y:y |
|
2633 |
! |
|
2634 |
||
2635 |
displayDeviceOpaqueString:aString x:x y:y |
|
2636 |
"draw a string at the coordinate x/y - draw foreground pixels in |
|
2637 |
paint-color and background pixels in bgPaint-color. |
|
2638 |
No translation or scaling is done" |
|
2639 |
||
2640 |
self displayDeviceOpaqueString:aString from:1 to:(aString size) in:font x:x y:y |
|
2641 |
! |
|
2642 |
||
2643 |
displayDeviceString:aString from:index1 to:index2 in:font x:x y:y |
|
2644 |
"draw a substring at the coordinate x/y - |
|
2645 |
draw foreground-pixels only (in current paint-color), leaving background as-is. |
|
2646 |
No translation or scaling is done" |
|
2647 |
||
2648 |
|id pX pY fontUsed s| |
|
2649 |
||
2650 |
" |
|
2651 |
hook for non-strings (i.e. attributed text) |
|
2652 |
" |
|
2653 |
(aString isString not |
|
2654 |
or:[aString isText]) ifTrue:[ |
|
2655 |
^ aString displayOn:self x:x y:y from:index1 to:index2 |
|
2656 |
]. |
|
2657 |
||
2658 |
gcId isNil ifTrue:[ |
|
2659 |
self initGC |
|
2660 |
]. |
|
2661 |
||
2662 |
pX := x rounded. |
|
2663 |
pY := y rounded. |
|
2664 |
||
2665 |
fontUsed := font on:device. |
|
2666 |
||
2667 |
id := fontUsed fontId. |
|
2668 |
id isNil ifTrue:[ |
|
2669 |
"hook for alien fonts" |
|
2670 |
font displayString:aString from:index1 to:index2 x:x y:y in:self |
|
2671 |
] ifFalse:[ |
|
2672 |
s := aString. |
|
2673 |
s encoding ~~ font encoding ifTrue:[ |
|
2674 |
s := s encodeInto:(font encoding). |
|
2675 |
]. |
|
2676 |
||
2677 |
deviceFont ~~ fontUsed ifTrue:[ |
|
2678 |
device setFont:id in:gcId. |
|
2679 |
deviceFont := fontUsed |
|
2680 |
]. |
|
2681 |
device displayString:s from:index1 to:index2 |
|
2682 |
x:pX y:pY in:drawableId with:gcId |
|
2683 |
] |
|
2684 |
||
2685 |
"Modified: 12.5.1996 / 17:49:22 / cg" |
|
2686 |
! |
|
2687 |
||
2688 |
displayDeviceString:aString from:index1 to:index2 x:x y:y |
|
2689 |
"draw a substring at the coordinate x/y - |
|
2690 |
draw foreground-pixels only (in current paint-color), leaving background as-is. |
|
2691 |
No translation or scaling is done" |
|
2692 |
||
2693 |
self displayDeviceString:aString from:index1 to:index2 in:font x:x y:y |
|
2694 |
! |
|
2695 |
||
2696 |
displayDeviceString:aString x:x y:y |
|
2697 |
"draw a string at the coordinate x/y - |
|
2698 |
draw foreground-pixels only (in current paint-color), leaving background as-is. |
|
2699 |
No translation or scaling is done" |
|
2700 |
||
2701 |
self displayDeviceString:aString from:1 to:(aString size) in:font x:x y:y |
|
2702 |
! |
|
2703 |
||
2704 |
fillDeviceRectangleX:x y:y width:w height:h |
|
2705 |
"draw a filled rectangle in device coordinate space. |
|
2706 |
This ignores any transformations. The coordinates must be integers." |
|
2707 |
||
2708 |
gcId isNil ifTrue:[ |
|
2709 |
self initGC |
|
2710 |
]. |
|
2711 |
device |
|
2712 |
fillRectangleX:x |
|
2713 |
y:y |
|
2714 |
width:w |
|
2715 |
height:h |
|
2716 |
in:drawableId with:gcId |
|
2717 |
! ! |
|
2718 |
||
2719 |
!DeviceGraphicsContext methodsFor:'evaluating in another context'! |
|
2720 |
||
2721 |
reverseDo:aBlock |
|
2722 |
"evaluate aBlock with foreground and background interchanged. |
|
2723 |
This can be reimplemented here in a faster way." |
|
2724 |
||
2725 |
|oldFg oldBg| |
|
2726 |
||
2727 |
oldFg := foreground on:device. |
|
2728 |
oldBg := background on:device. |
|
2729 |
self foreground:background background:foreground. |
|
2730 |
aBlock value. |
|
2731 |
self foreground:oldFg background:oldBg |
|
2732 |
! |
|
2733 |
||
2734 |
withBackground:fgColor do:aBlock |
|
2735 |
"evaluate aBlock with changed background." |
|
2736 |
||
2737 |
|oldBg| |
|
2738 |
||
2739 |
oldBg := background. |
|
2740 |
self background:fgColor. |
|
2741 |
aBlock value. |
|
2742 |
self background:oldBg |
|
2743 |
! |
|
2744 |
||
2745 |
withForeground:fgColor background:bgColor do:aBlock |
|
2746 |
"evaluate aBlock with changed foreground and background." |
|
2747 |
||
2748 |
|oldFg oldBg| |
|
2749 |
||
2750 |
oldFg := foreground. |
|
2751 |
oldBg := background. |
|
2752 |
self foreground:fgColor background:bgColor. |
|
2753 |
aBlock value. |
|
2754 |
self foreground:oldFg background:oldBg |
|
2755 |
! |
|
2756 |
||
2757 |
withForeground:fgColor background:bgColor function:aFunction do:aBlock |
|
2758 |
"evaluate aBlock with foreground, background and function" |
|
2759 |
||
2760 |
|oldFg oldBg oldFun| |
|
2761 |
||
2762 |
oldFg := foreground. |
|
2763 |
oldBg := background. |
|
2764 |
oldFun := function. |
|
2765 |
self foreground:fgColor background:bgColor function:aFunction. |
|
2766 |
aBlock value. |
|
2767 |
self foreground:oldFg background:oldBg function:oldFun |
|
2768 |
! |
|
2769 |
||
2770 |
withForeground:fgColor background:bgColor mask:aMask do:aBlock |
|
2771 |
"evaluate aBlock with foreground, background and mask" |
|
2772 |
||
2773 |
|oldFg oldBg oldMask| |
|
2774 |
||
2775 |
oldFg := foreground. |
|
2776 |
oldBg := background. |
|
2777 |
oldMask := mask. |
|
2778 |
self foreground:fgColor background:bgColor. |
|
2779 |
self mask:aMask. |
|
2780 |
aBlock value. |
|
2781 |
self foreground:oldFg background:oldBg. |
|
2782 |
self mask:oldMask |
|
2783 |
! |
|
2784 |
||
2785 |
withForeground:fgColor do:aBlock |
|
2786 |
"evaluate aBlock with changed foreground." |
|
2787 |
||
2788 |
|oldFg| |
|
2789 |
||
2790 |
oldFg := foreground. |
|
2791 |
self foreground:fgColor. |
|
2792 |
aBlock value. |
|
2793 |
self foreground:oldFg |
|
2794 |
! |
|
2795 |
||
2796 |
withForeground:fgColor function:aFunction do:aBlock |
|
2797 |
"evaluate aBlock with changed foreground and function." |
|
2798 |
||
2799 |
|oldFg oldFun| |
|
2800 |
||
2801 |
oldFg := foreground. |
|
2802 |
oldFun := function. |
|
2803 |
self foreground:fgColor background:background function:aFunction. |
|
2804 |
aBlock value. |
|
2805 |
self foreground:oldFg background:background function:oldFun |
|
2806 |
! |
|
2807 |
||
2808 |
xoring:aBlock |
|
2809 |
"evaluate aBlock with function xoring" |
|
2810 |
||
2811 |
|fgPixel bgPixel oldFunction| |
|
2812 |
||
2813 |
fgPixel := (Black on:device) colorId. |
|
2814 |
bgPixel := (White on:device) colorId. |
|
2815 |
||
2816 |
gcId isNil ifTrue:[ |
|
2817 |
self initGC |
|
2818 |
]. |
|
2819 |
oldFunction := function. |
|
2820 |
device setForeground:(fgPixel bitXor:bgPixel) |
|
2821 |
background:bgPixel |
|
2822 |
in:gcId. |
|
2823 |
device setFunction:#xor in:gcId. |
|
2824 |
aBlock value. |
|
2825 |
paint := nil. "invalidate" |
|
2826 |
foreground := Black. |
|
2827 |
background := White. |
|
2828 |
device setForeground:fgPixel |
|
2829 |
background:bgPixel |
|
2830 |
in:gcId. |
|
2831 |
device setFunction:oldFunction in:gcId. |
|
2832 |
function := oldFunction |
|
2833 |
! ! |
|
2834 |
||
2835 |
!DeviceGraphicsContext methodsFor:'filling'! |
|
2836 |
||
2837 |
fillArcX:x y:y width:w height:h from:startAngle angle:angle |
|
2838 |
"draw a filled arc; apply transformation if nonNil" |
|
2839 |
||
784 | 2840 |
|pX pY rpX rpY nW nH| |
732 | 2841 |
|
2842 |
gcId isNil ifTrue:[ |
|
2843 |
self initGC |
|
2844 |
]. |
|
2845 |
transformation notNil ifTrue:[ |
|
2846 |
pX := transformation applyToX:x. |
|
2847 |
pY := transformation applyToY:y. |
|
2848 |
nW := transformation applyScaleX:w. |
|
2849 |
nH := transformation applyScaleY:h. |
|
2850 |
nW < 0 ifTrue:[ |
|
2851 |
nW := nW abs. |
|
2852 |
pX := pX - nW. |
|
2853 |
]. |
|
2854 |
nH < 0 ifTrue:[ |
|
2855 |
nH := nH abs. |
|
2856 |
pY := pY - nH. |
|
2857 |
]. |
|
2858 |
] ifFalse:[ |
|
2859 |
pX := x. |
|
2860 |
pY := y. |
|
2861 |
nW := w. |
|
2862 |
nH := h. |
|
2863 |
]. |
|
2864 |
||
2865 |
pX := pX rounded. |
|
2866 |
pY := pY rounded. |
|
2867 |
nW := nW rounded. |
|
2868 |
nH := nH rounded. |
|
2869 |
||
2870 |
device |
|
2871 |
fillArcX:pX |
|
2872 |
y:pY |
|
2873 |
width:nW |
|
2874 |
height:nH |
|
2875 |
from:startAngle |
|
2876 |
angle:angle |
|
2877 |
in:drawableId |
|
2878 |
with:gcId |
|
2879 |
||
784 | 2880 |
"/ rpX := pX rounded. |
2881 |
"/ rpY := pY rounded. |
|
2882 |
"/ nW := (nW + (rpX - pX)) rounded. |
|
2883 |
"/ nH := (nH + (rpY - pY)) rounded. |
|
2884 |
"/ |
|
2885 |
"/ device |
|
2886 |
"/ fillArcX:rpX |
|
2887 |
"/ y:rpY |
|
2888 |
"/ width:nW |
|
2889 |
"/ height:nH |
|
2890 |
"/ from:startAngle |
|
2891 |
"/ angle:angle |
|
2892 |
"/ in:drawableId |
|
2893 |
"/ with:gcId |
|
2894 |
||
732 | 2895 |
"Created: 8.5.1996 / 08:29:45 / cg" |
784 | 2896 |
"Modified: 4.6.1996 / 17:58:21 / cg" |
732 | 2897 |
! |
2898 |
||
2899 |
fillPolygon:aPolygon |
|
2900 |
"draw a filled polygon; apply transformation if nonNil" |
|
2901 |
||
2902 |
|newPolygon| |
|
2903 |
||
2904 |
gcId isNil ifTrue:[ |
|
2905 |
self initGC |
|
2906 |
]. |
|
2907 |
transformation notNil ifTrue:[ |
|
2908 |
newPolygon := aPolygon collect:[:point | transformation applyTo:point]. |
|
2909 |
] ifFalse:[ |
|
2910 |
newPolygon := aPolygon |
|
2911 |
]. |
|
2912 |
(newPolygon findFirst:[:p | |
|
2913 |
(p isPoint not |
|
2914 |
or:[(p x class ~~ SmallInteger) |
|
2915 |
or:[(p y class ~~ SmallInteger)]]) |
|
2916 |
]) ~~ 0 ifTrue:[ |
|
2917 |
newPolygon := newPolygon collect:[:p | p asPoint rounded] |
|
2918 |
]. |
|
2919 |
device |
|
2920 |
fillPolygon:newPolygon |
|
2921 |
in:drawableId |
|
2922 |
with:gcId |
|
2923 |
! |
|
2924 |
||
2925 |
fillRectangleX:x y:y width:w height:h |
|
2926 |
"draw a filled rectangle; apply transformation if nonNil" |
|
2927 |
||
784 | 2928 |
|pX pY rpX rpY nW nH| |
732 | 2929 |
|
2930 |
gcId isNil ifTrue:[ |
|
784 | 2931 |
self initGC |
732 | 2932 |
]. |
2933 |
transformation notNil ifTrue:[ |
|
784 | 2934 |
pX := transformation applyToX:x. |
2935 |
pY := transformation applyToY:y. |
|
2936 |
nW := transformation applyScaleX:w. |
|
2937 |
nH := transformation applyScaleY:h. |
|
2938 |
nW < 0 ifTrue:[ |
|
2939 |
nW := nW abs. |
|
2940 |
pX := pX - nW. |
|
2941 |
]. |
|
2942 |
nH < 0 ifTrue:[ |
|
2943 |
nH := nH abs. |
|
2944 |
pY := pY - nH. |
|
2945 |
]. |
|
732 | 2946 |
] ifFalse:[ |
784 | 2947 |
pX := x. |
2948 |
pY := y. |
|
2949 |
nW := w. |
|
2950 |
nH := h. |
|
732 | 2951 |
]. |
2952 |
pX := pX rounded. |
|
2953 |
pY := pY rounded. |
|
2954 |
nW := nW rounded. |
|
2955 |
nH := nH rounded. |
|
2956 |
||
2957 |
device |
|
784 | 2958 |
fillRectangleX:pX |
2959 |
y:pY |
|
2960 |
width:nW |
|
2961 |
height:nH |
|
2962 |
in:drawableId with:gcId |
|
2963 |
||
2964 |
"/ rpX := pX rounded. |
|
2965 |
"/ rpY := pY rounded. |
|
2966 |
"/ nW := (nW + (pX - rpX)) rounded. |
|
2967 |
"/ nH := (nH + (pY - rpY)) rounded. |
|
2968 |
"/ |
|
2969 |
"/ device |
|
2970 |
"/ fillRectangleX:rpX |
|
2971 |
"/ y:rpY |
|
2972 |
"/ width:nW |
|
2973 |
"/ height:nH |
|
2974 |
"/ in:drawableId with:gcId |
|
2975 |
||
2976 |
"Modified: 4.6.1996 / 17:58:49 / cg" |
|
732 | 2977 |
! ! |
2978 |
||
2979 |
!DeviceGraphicsContext methodsFor:'initialization'! |
|
2980 |
||
2981 |
createGC |
|
2982 |
"since we do not need a gc-object for the drawable until something is |
|
2983 |
really drawn, none is created. |
|
2984 |
This method is sent, when the first drawing happens" |
|
2985 |
||
2986 |
|fgId bgId p| |
|
2987 |
||
2988 |
gcId := device gcFor:drawableId. |
|
2989 |
||
2990 |
foreground isNil ifTrue:[foreground := Black]. |
|
2991 |
background isNil ifTrue:[background := White]. |
|
2992 |
||
2993 |
foreground isColor ifTrue:[ |
|
745 | 2994 |
"get device colors from the device indep. colors" |
2995 |
foreground := foreground on:device. |
|
2996 |
fgId := foreground colorId. |
|
2997 |
fgId isNil ifTrue:[ |
|
2998 |
(foreground grayIntensity >= 50) ifTrue:[ |
|
2999 |
fgId := device whitepixel |
|
3000 |
] ifFalse:[ |
|
3001 |
fgId := device blackpixel |
|
3002 |
] |
|
3003 |
]. |
|
732 | 3004 |
] ifFalse:[ |
745 | 3005 |
fgId := device blackpixel. |
732 | 3006 |
]. |
3007 |
||
3008 |
background isColor ifTrue:[ |
|
745 | 3009 |
background := background on:device. |
3010 |
bgId := background colorId. |
|
3011 |
bgId isNil ifTrue:[ |
|
3012 |
(background grayIntensity >= 50) ifTrue:[ |
|
3013 |
bgId := device whitepixel |
|
3014 |
] ifFalse:[ |
|
3015 |
bgId := device blackpixel |
|
3016 |
] |
|
3017 |
]. |
|
732 | 3018 |
] ifFalse:[ |
745 | 3019 |
bgId := device whitepixel |
732 | 3020 |
]. |
3021 |
||
3022 |
"now, this is something the device can work with ..." |
|
3023 |
device setForeground:fgId background:bgId in:gcId. |
|
3024 |
||
3025 |
"switch to paint" |
|
3026 |
p := paint. |
|
3027 |
paint := nil. |
|
3028 |
self paint:p. |
|
3029 |
||
3030 |
((lineWidth ~~ 0) |
|
3031 |
or:[(lineStyle ~~ #solid) |
|
3032 |
or:[(capStyle ~~ #butt) |
|
3033 |
or:[joinStyle ~~ #miter]]]) ifTrue:[ |
|
745 | 3034 |
device setLineWidth:lineWidth |
3035 |
style:lineStyle |
|
3036 |
cap:capStyle |
|
3037 |
join:joinStyle |
|
3038 |
in:gcId |
|
732 | 3039 |
]. |
3040 |
||
3041 |
mask notNil ifTrue:[ |
|
745 | 3042 |
(mask depth == 1) ifTrue:[ |
3043 |
device setBitmapMask:(mask id) in:gcId |
|
3044 |
] ifFalse:[ |
|
3045 |
device setPixmapMask:(mask id) in:gcId |
|
3046 |
]. |
|
3047 |
maskOrigin notNil ifTrue:[ |
|
3048 |
device setMaskOriginX:maskOrigin x y:maskOrigin y in:gcId |
|
3049 |
] |
|
732 | 3050 |
]. |
3051 |
(function ~~ #copy) ifTrue:[device setFunction:function in:gcId]. |
|
3052 |
||
3053 |
"defer the getting of a device font |
|
3054 |
- this is now done when the first drawstring occurs, |
|
3055 |
since many views (layout-views) will never draw strings and |
|
3056 |
therefore, the overhead of aquiring a font can be avoided. |
|
3057 |
" |
|
3058 |
||
3059 |
" |
|
3060 |
font := font on:device. |
|
3061 |
id := font fontId. |
|
3062 |
id notNil ifTrue:[ |
|
745 | 3063 |
device setFont:id in:gcId |
732 | 3064 |
] |
3065 |
" |
|
745 | 3066 |
|
3067 |
"Modified: 28.5.1996 / 20:45:24 / cg" |
|
732 | 3068 |
! |
3069 |
||
3070 |
destroy |
|
3071 |
"when the drawable is destroyed, the associated GC must be destroyed with it" |
|
3072 |
||
3073 |
gcId notNil ifTrue:[ |
|
3074 |
device destroyGC:gcId. |
|
3075 |
gcId := nil. |
|
3076 |
Lobby registerChange:self. |
|
3077 |
] |
|
3078 |
! |
|
3079 |
||
3080 |
initGC |
|
3081 |
"since we do not need a gc-object for the drawable until something is |
|
3082 |
really drawn, none is created. |
|
3083 |
This method is sent, when the first drawing happens" |
|
3084 |
||
3085 |
self createGC. |
|
3086 |
Lobby registerChange:self. |
|
3087 |
! |
|
3088 |
||
3089 |
initialize |
|
3090 |
"setup everything for later use; actual work is done in |
|
3091 |
initColors and initFont, which are usually redefined." |
|
3092 |
||
3093 |
"make certain Workstation is initialized - just a check - will vanish soon" |
|
3094 |
Display isNil ifTrue:[ |
|
3095 |
'DEVDRAW: Display not initialized when first DeviceGraphicsContext created' errorPrintNL. |
|
3096 |
Workstation initialize |
|
3097 |
]. |
|
3098 |
||
3099 |
super initialize. |
|
3100 |
||
3101 |
foreground := Black. |
|
3102 |
background := White. |
|
3103 |
! |
|
3104 |
||
3105 |
prepareForReinit |
|
3106 |
"kludge - clear drawableId and gcId |
|
3107 |
needed after snapin" |
|
3108 |
||
3109 |
gcId := nil. |
|
3110 |
drawableId := nil. |
|
3111 |
deviceFont := nil |
|
3112 |
! |
|
3113 |
||
3114 |
recreate |
|
3115 |
"sent after a snapin, reinit draw stuff for new device" |
|
3116 |
||
3117 |
gcId := nil. |
|
3118 |
foreground notNil ifTrue:[ |
|
3119 |
foreground := foreground on:device |
|
3120 |
]. |
|
3121 |
background notNil ifTrue:[ |
|
3122 |
background := background on:device |
|
3123 |
]. |
|
3124 |
paint notNil ifTrue:[ |
|
3125 |
paint := paint on:device |
|
3126 |
]. |
|
3127 |
bgPaint notNil ifTrue:[ |
|
3128 |
bgPaint := bgPaint on:device |
|
3129 |
] |
|
3130 |
! |
|
3131 |
||
3132 |
reinitialize |
|
3133 |
'reinit of ' errorPrint. self classNameWithArticle errorPrint. |
|
3134 |
' failed' errorPrintNL |
|
832
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
3135 |
! |
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
3136 |
|
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
3137 |
releaseGC |
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
3138 |
"destroy the associated GC - can be done to be nice to the |
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
3139 |
display if you know that you are done with a drawable." |
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
3140 |
|
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
3141 |
gcId notNil ifTrue:[ |
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
3142 |
device destroyGC:gcId. |
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
3143 |
gcId := nil. |
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
3144 |
Lobby registerChange:self. |
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
3145 |
] |
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
3146 |
|
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
3147 |
"Created: 11.6.1996 / 22:07:30 / cg" |
732 | 3148 |
! ! |
3149 |
||
3150 |
!DeviceGraphicsContext methodsFor:'instance release'! |
|
3151 |
||
3152 |
disposed |
|
3153 |
"some Drawable has been collected |
|
3154 |
- must release operating system resources" |
|
3155 |
||
3156 |
^ self subclassResponsibility |
|
3157 |
! ! |
|
3158 |
||
3159 |
!DeviceGraphicsContext methodsFor:'private'! |
|
3160 |
||
3161 |
setDevice:aDevice id:aDrawbleId gcId:aGCId |
|
3162 |
"private" |
|
3163 |
||
3164 |
device := aDevice. |
|
3165 |
gcId := aGCId. |
|
3166 |
drawableId := aDrawbleId |
|
3167 |
! |
|
3168 |
||
3169 |
setGCForPaint |
|
3170 |
"private; given a complex color (i.e. a pixmap or dithered color, |
|
3171 |
setup the GC to draw in this color. |
|
3172 |
A helper for paint and paint:on:" |
|
3173 |
||
832
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
3174 |
|dither map pixelId p fg bg vOrg ditherDepth deviceDepth| |
732 | 3175 |
|
3176 |
gcId notNil ifTrue:[ |
|
3177 |
(p := paint) isColor ifTrue:[ |
|
3178 |
paint := p := p on:device. |
|
3179 |
pixelId := p colorId. |
|
3180 |
pixelId notNil ifTrue:[ |
|
3181 |
" |
|
3182 |
a real (undithered) color |
|
3183 |
" |
|
3184 |
mask notNil ifTrue:[ |
|
3185 |
mask := nil. |
|
3186 |
device setBitmapMask:nil in:gcId |
|
3187 |
]. |
|
3188 |
(p ~~ foreground) ifTrue:[ |
|
3189 |
foreground := paint. |
|
3190 |
device setForeground:pixelId in:gcId |
|
3191 |
]. |
|
3192 |
^ self |
|
3193 |
]. |
|
3194 |
"a dithered color" |
|
3195 |
dither := paint ditherForm. |
|
3196 |
] ifFalse:[ |
|
3197 |
"mhmh - seems to be some kind of form ..." |
|
3198 |
paint := paint on:device. |
|
3199 |
dither := paint |
|
3200 |
]. |
|
3201 |
" |
|
3202 |
a dithered color or image |
|
3203 |
" |
|
3204 |
(ditherDepth := dither depth) == 1 ifTrue:[ |
|
3205 |
"a simple 0/1 bitmap" |
|
3206 |
map := dither colorMap. |
|
3207 |
"temporary (kludgy) fix for destroyed paint" |
|
3208 |
p := paint. |
|
3209 |
map isNil ifTrue:[ |
|
3210 |
fg := Color black. |
|
3211 |
bg := Color white. |
|
3212 |
] ifFalse:[ |
|
3213 |
fg := map at:2. |
|
3214 |
bg := map at:1. |
|
3215 |
]. |
|
3216 |
self foreground:fg background:bg. |
|
3217 |
paint := p |
|
3218 |
] ifFalse:[ |
|
832
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
3219 |
deviceDepth := device depth. |
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
3220 |
(ditherDepth ~~ deviceDepth) ifTrue:[ |
732 | 3221 |
dither := dither asFormOn:device. |
832
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
3222 |
ditherDepth := dither depth. |
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
3223 |
(dither isNil or:[ditherDepth ~~ deviceDepth]) ifTrue:[ |
732 | 3224 |
self error:'bad dither'. |
3225 |
^ self |
|
3226 |
] |
|
3227 |
] |
|
3228 |
]. |
|
3229 |
self mask:dither. |
|
3230 |
vOrg := self viewOrigin. |
|
3231 |
self setMaskOriginX:vOrg x negated y:vOrg y negated. |
|
3232 |
] |
|
3233 |
||
3234 |
"Created: 16.5.1996 / 15:35:51 / cg" |
|
832
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
3235 |
"Modified: 12.6.1996 / 12:49:07 / cg" |
732 | 3236 |
! ! |
3237 |
||
3238 |
!DeviceGraphicsContext methodsFor:'queries'! |
|
3239 |
||
3240 |
horizontalIntegerPixelPerMillimeter |
|
3241 |
"return the (rounded) number of pixels per millimeter" |
|
3242 |
||
3243 |
^ device horizontalPixelPerMillimeter rounded |
|
3244 |
! |
|
3245 |
||
3246 |
horizontalPixelPerInch |
|
3247 |
"return the number of horizontal pixels per inch of the display" |
|
3248 |
||
3249 |
^ device horizontalPixelPerMillimeter * 25.4 |
|
3250 |
! |
|
3251 |
||
3252 |
horizontalPixelPerMillimeter |
|
3253 |
"return the number of pixels per millimeter (not rounded)" |
|
3254 |
||
3255 |
^ device horizontalPixelPerMillimeter |
|
3256 |
! |
|
3257 |
||
3258 |
horizontalPixelPerMillimeter:millis |
|
3259 |
"return the number of pixels (not rounded) for millis millimeter" |
|
3260 |
||
3261 |
^ device horizontalPixelPerMillimeter * millis |
|
3262 |
! |
|
3263 |
||
784 | 3264 |
resolution |
3265 |
"return a point consisting of pixel-per-inch horizontally and vertically." |
|
3266 |
||
3267 |
^ device resolution |
|
3268 |
||
3269 |
"Created: 4.6.1996 / 15:23:55 / cg" |
|
3270 |
! |
|
3271 |
||
732 | 3272 |
verticalIntegerPixelPerMillimeter |
3273 |
"return the (rounded) number of pixels per millimeter" |
|
3274 |
||
3275 |
^ device verticalPixelPerMillimeter rounded |
|
3276 |
! |
|
3277 |
||
3278 |
verticalPixelPerInch |
|
3279 |
"return the number of vertical pixels per inch of the display" |
|
3280 |
||
3281 |
^ device verticalPixelPerMillimeter * 25.4 |
|
3282 |
! |
|
3283 |
||
3284 |
verticalPixelPerMillimeter |
|
3285 |
"return the number of pixels per millimeter (not rounded)" |
|
3286 |
||
3287 |
^ device verticalPixelPerMillimeter |
|
3288 |
! |
|
3289 |
||
3290 |
verticalPixelPerMillimeter:millis |
|
3291 |
"return the number of pixels (not rounded) for millis millimeter" |
|
3292 |
||
3293 |
^ device verticalPixelPerMillimeter * millis |
|
3294 |
! ! |
|
3295 |
||
3296 |
!DeviceGraphicsContext class methodsFor:'documentation'! |
|
3297 |
||
3298 |
version |
|
832
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
3299 |
^ '$Header: /cvs/stx/stx/libview/DeviceGraphicsContext.st,v 1.7 1996-06-12 11:04:34 cg Exp $' |
732 | 3300 |
! ! |
3301 |
DeviceGraphicsContext initialize! |