author | Claus Gittinger <cg@exept.de> |
Fri, 21 Jun 1996 13:32:40 +0200 | |
changeset 895 | 0d49372cded9 |
parent 868 | 65c93e5f6f8b |
child 902 | 7f5d81d377de |
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:[ |
|
868 | 832 |
'DEVGC: invalid bitmap copy - ignored' errorPrintNL. |
833 |
^ self |
|
732 | 834 |
]. |
835 |
||
836 |
gcId isNil ifTrue:[ |
|
868 | 837 |
self initGC |
732 | 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:[ |
|
868 | 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 |
|
732 | 861 |
] ifFalse:[ |
868 | 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 |
|
732 | 870 |
] |
868 | 871 |
|
872 |
"Modified: 15.6.1996 / 15:36:38 / cg" |
|
732 | 873 |
! |
874 |
||
875 |
copyPlaneFrom:aDrawable x:srcX y:srcY toX:dstX y:dstY width:w height:h |
|
876 |
"copy one plane from aDrawable into the receiver. 0's are drawn in |
|
877 |
background, while 1's are drawn with foreground color. |
|
878 |
The depth of aDrawable must (should) be 1. |
|
879 |
The drawable must have been allocated on the same device. |
|
880 |
All coordinates are in device coordinates." |
|
881 |
||
882 |
|id| |
|
883 |
||
884 |
id := aDrawable id. |
|
885 |
||
886 |
"temporary ... |
|
887 |
this fixes a problem after restart on another display, |
|
888 |
when a file-bitmap wasnt found. In this case, the id of the |
|
889 |
bitmap will be nil. This will be fixed soon. |
|
890 |
" |
|
891 |
(id isNil |
|
892 |
or:[aDrawable graphicsDevice ~~ device]) ifTrue:[ |
|
868 | 893 |
'DEVGC: invalid copyPlane - ignored' errorPrintNL. |
894 |
^ self |
|
732 | 895 |
]. |
896 |
||
897 |
gcId isNil ifTrue:[ |
|
868 | 898 |
self initGC |
732 | 899 |
]. |
900 |
||
901 |
device |
|
868 | 902 |
copyPlaneFromId:id |
903 |
x:srcX y:srcY |
|
904 |
to:drawableId |
|
905 |
x:dstX y:dstY |
|
906 |
width:w |
|
907 |
height:h |
|
908 |
with:gcId |
|
909 |
||
910 |
"Modified: 15.6.1996 / 15:36:42 / cg" |
|
732 | 911 |
! ! |
912 |
||
913 |
!DeviceGraphicsContext methodsFor:'copying'! |
|
914 |
||
915 |
postCopy |
|
916 |
"this may not be enough to allow copying of views ..." |
|
917 |
||
918 |
super postCopy. |
|
919 |
device := drawableId := gcId := nil. |
|
920 |
self recreate |
|
921 |
! ! |
|
922 |
||
923 |
!DeviceGraphicsContext methodsFor:'drawing'! |
|
924 |
||
925 |
displayArcX:x y:y width:w height:h from:startAngle angle:angle |
|
926 |
"draw an arc; apply transformation if nonNil" |
|
927 |
||
784 | 928 |
|pX pY rpX rpY nW nH| |
732 | 929 |
|
930 |
gcId isNil ifTrue:[ |
|
931 |
self initGC |
|
932 |
]. |
|
933 |
transformation notNil ifTrue:[ |
|
934 |
pX := transformation applyToX:x. |
|
935 |
pY := transformation applyToY:y. |
|
936 |
nW := transformation applyScaleX:w. |
|
937 |
nH := transformation applyScaleY:h. |
|
938 |
nW < 0 ifTrue:[ |
|
939 |
nW := nW abs. |
|
940 |
pX := pX - nW. |
|
941 |
]. |
|
942 |
nH < 0 ifTrue:[ |
|
943 |
nH := nH abs. |
|
944 |
pY := pY - nH. |
|
945 |
]. |
|
946 |
] ifFalse:[ |
|
947 |
pX := x. |
|
948 |
pY := y. |
|
949 |
nW := w. |
|
950 |
nH := h. |
|
951 |
]. |
|
952 |
||
953 |
pX := pX rounded. |
|
954 |
pY := pY rounded. |
|
955 |
nW := nW rounded. |
|
956 |
nH := nH rounded. |
|
957 |
||
958 |
device |
|
959 |
displayArcX:pX |
|
960 |
y:pY |
|
961 |
width:nW |
|
962 |
height:nH |
|
963 |
from:startAngle |
|
964 |
angle:angle |
|
965 |
in:drawableId |
|
966 |
with:gcId |
|
967 |
||
784 | 968 |
"/ rpX := pX rounded. |
969 |
"/ rpY := pY rounded. |
|
970 |
"/ nW := (nW + (rpX - pX)) rounded. |
|
971 |
"/ nH := (nH + (rpY - pY)) rounded. |
|
972 |
"/ |
|
973 |
"/ device |
|
974 |
"/ displayArcX:rpX |
|
975 |
"/ y:rpY |
|
976 |
"/ width:nW |
|
977 |
"/ height:nH |
|
978 |
"/ from:startAngle |
|
979 |
"/ angle:angle |
|
980 |
"/ in:drawableId |
|
981 |
"/ with:gcId |
|
982 |
||
732 | 983 |
"Created: 8.5.1996 / 08:31:30 / cg" |
784 | 984 |
"Modified: 4.6.1996 / 17:59:28 / cg" |
732 | 985 |
! |
986 |
||
987 |
displayForm:formToDraw x:x y:y |
|
988 |
"draw a form; if its a 1-plane bitmap, 1-bits are drawn in the |
|
989 |
current paint-color, leaving pixels with 0-bits unchanged |
|
990 |
(i.e. only 1-bits are drawn from the form). |
|
991 |
If its a deep form (i.e. a pixmap) the current paint |
|
992 |
settings are ignored and the form is drawn as-is. |
|
993 |
Care must be taken, that the paint color is correctly allocated |
|
994 |
(by sending #on: to the color) before doing so. |
|
995 |
Using functions other than #copy only makes sense if you are |
|
996 |
certain, that the colors are real colors (actually, only for |
|
997 |
noColor or allColor)." |
|
998 |
||
999 |
|realForm pX pY w h nW nH| |
|
1000 |
||
1001 |
realForm := formToDraw. |
|
1002 |
||
1003 |
transformation notNil ifTrue:[ |
|
1004 |
pX := transformation applyToX:x. |
|
1005 |
pY := transformation applyToY:y. |
|
1006 |
||
1007 |
transformation noScale ifFalse:[ |
|
1008 |
w := formToDraw width. |
|
1009 |
h := formToDraw height. |
|
1010 |
||
1011 |
nW := (transformation applyScaleX:w) rounded. |
|
1012 |
nH := (transformation applyScaleY:h) rounded. |
|
1013 |
||
1014 |
((nW ~= w) or:[nH ~= h]) ifTrue:[ |
|
1015 |
"/ |
|
1016 |
"/ hard case - someone is drawing forms with scaling in effect |
|
1017 |
"/ look if we have a scaled version in our pocket ... |
|
1018 |
"/ |
|
1019 |
realForm := nil. |
|
1020 |
CachedScaledForms notNil ifTrue:[ |
|
1021 |
(CachedScales at:formToDraw ifAbsent:nil) = transformation scale ifTrue:[ |
|
1022 |
realForm := CachedScaledForms at:formToDraw ifAbsent:nil. |
|
1023 |
] |
|
1024 |
]. |
|
1025 |
realForm isNil ifTrue:[ |
|
1026 |
"/ |
|
1027 |
"/ nope - must do the work ... |
|
1028 |
"/ |
|
1029 |
realForm := formToDraw magnifiedBy:(nW / w) @ (nH / h). |
|
1030 |
CachedScaledForms isNil ifTrue:[ |
|
1031 |
CachedScaledForms := WeakIdentityDictionary new. |
|
1032 |
CachedScales := WeakIdentityDictionary new. |
|
1033 |
]. |
|
1034 |
CachedScaledForms at:formToDraw put:realForm. |
|
1035 |
CachedScales at:formToDraw put:transformation scale. |
|
1036 |
] |
|
1037 |
] |
|
1038 |
] |
|
1039 |
] ifFalse:[ |
|
1040 |
pX := x. |
|
1041 |
pY := y. |
|
1042 |
]. |
|
1043 |
pX := pX rounded. |
|
1044 |
pY := pY rounded. |
|
1045 |
||
1046 |
self displayDeviceForm:realForm x:pX y:pY |
|
1047 |
||
1048 |
"Modified: 21.5.1996 / 21:15:44 / cg" |
|
1049 |
! |
|
1050 |
||
1051 |
displayLineFromX:x0 y:y0 toX:x1 y:y1 |
|
1052 |
"draw a line (with current paint-color); apply transformation if nonNil" |
|
1053 |
||
1054 |
|pX0 pY0 pX1 pY1 easy fgId bgId| |
|
1055 |
||
1056 |
gcId isNil ifTrue:[ |
|
1057 |
self initGC |
|
1058 |
]. |
|
1059 |
||
1060 |
lineStyle == #doubleDashed ifTrue:[ |
|
1061 |
" |
|
1062 |
if bgPaint or paint is not a real color, we have to do it the hard way ... |
|
1063 |
" |
|
1064 |
easy := true. |
|
1065 |
paint isColor ifFalse:[ |
|
1066 |
easy := false |
|
1067 |
] ifTrue:[ |
|
1068 |
fgId := paint colorId. |
|
1069 |
fgId isNil ifTrue:[ |
|
1070 |
easy := false |
|
1071 |
] |
|
1072 |
]. |
|
1073 |
bgPaint isColor ifFalse:[ |
|
1074 |
easy := false |
|
1075 |
] ifTrue:[ |
|
1076 |
bgId := bgPaint colorId. |
|
1077 |
bgId isNil ifTrue:[ |
|
1078 |
easy := false |
|
1079 |
] |
|
1080 |
]. |
|
1081 |
||
1082 |
easy ifTrue:[ |
|
1083 |
((foreground ~~ paint) or:[background ~~ bgPaint]) ifTrue:[ |
|
1084 |
device setForeground:fgId background:bgId in:gcId. |
|
1085 |
foreground := paint. |
|
1086 |
background := bgPaint. |
|
1087 |
]. |
|
1088 |
] ifFalse:[ |
|
1089 |
'DEVDRAW: cannot draw dashes with dithered colors' errorPrintNL |
|
1090 |
]. |
|
1091 |
]. |
|
1092 |
||
1093 |
transformation notNil ifTrue:[ |
|
1094 |
pX0 := transformation applyToX:x0. |
|
1095 |
pY0 := transformation applyToY:y0. |
|
1096 |
pX1 := transformation applyToX:x1. |
|
1097 |
pY1 := transformation applyToY:y1. |
|
1098 |
] ifFalse:[ |
|
1099 |
pX0 := x0. |
|
1100 |
pY0 := y0. |
|
1101 |
pX1 := x1. |
|
1102 |
pY1 := y1 |
|
1103 |
]. |
|
1104 |
||
1105 |
pX0 := pX0 rounded. |
|
1106 |
pY0 := pY0 rounded. |
|
1107 |
pX1 := pX1 rounded. |
|
1108 |
pY1 := pY1 rounded. |
|
1109 |
||
1110 |
device displayLineFromX:pX0 y:pY0 toX:pX1 y:pY1 in:drawableId with:gcId |
|
1111 |
||
1112 |
"Modified: 13.4.1996 / 20:31:19 / cg" |
|
1113 |
! |
|
1114 |
||
1115 |
displayOpaqueForm:formToDraw x:x y:y |
|
1116 |
"draw a form; if its a 1-plane bitmap, 1-bits are drawn in the |
|
1117 |
current paint-color and 0-bits in the bgPaint color. |
|
1118 |
If its a deep form (i.e. a pixmap) the current paint/bgPaint |
|
1119 |
settings are ignored and the form drawn as-is. |
|
1120 |
In the 1-plane case, special care must be taken if paint and/or bgPaint |
|
1121 |
dithered colors or patterns, since are that the colors are correctly allocated |
|
1122 |
(by sending #on: to the colors) before doing so. |
|
1123 |
If there is a transformation, the image is scaled as appropiate." |
|
1124 |
||
1125 |
|w h realForm pX pY nW nH| |
|
1126 |
||
1127 |
bgPaint isNil ifTrue:[ |
|
1128 |
"/ |
|
1129 |
"/ actually not an opaque draw |
|
1130 |
"/ |
|
1131 |
self displayForm:formToDraw x:x y:y. |
|
1132 |
^ self |
|
1133 |
]. |
|
1134 |
||
1135 |
realForm := formToDraw. |
|
1136 |
||
1137 |
transformation notNil ifTrue:[ |
|
1138 |
pX := transformation applyToX:x. |
|
1139 |
pY := transformation applyToY:y. |
|
1140 |
||
1141 |
transformation noScale ifFalse:[ |
|
1142 |
w := formToDraw width. |
|
1143 |
h := formToDraw height. |
|
1144 |
||
1145 |
nW := (transformation applyScaleX:w) rounded. |
|
1146 |
nH := (transformation applyScaleY:h) rounded. |
|
1147 |
||
1148 |
((nW ~= w) or:[nH ~= h]) ifTrue:[ |
|
1149 |
"/ |
|
1150 |
"/ hard case - someone is drawing forms with scaling in effect |
|
1151 |
"/ look if we have a scaled version in our pocket ... |
|
1152 |
"/ |
|
1153 |
realForm := nil. |
|
1154 |
CachedScaledForms notNil ifTrue:[ |
|
1155 |
(CachedScales at:formToDraw ifAbsent:nil) = transformation scale ifTrue:[ |
|
1156 |
realForm := CachedScaledForms at:formToDraw ifAbsent:nil. |
|
1157 |
] |
|
1158 |
]. |
|
1159 |
realForm isNil ifTrue:[ |
|
1160 |
"/ |
|
1161 |
"/ nope - must do the work ... |
|
1162 |
"/ |
|
1163 |
realForm := formToDraw magnifiedBy:(nW / w) @ (nH / h). |
|
1164 |
CachedScaledForms isNil ifTrue:[ |
|
1165 |
CachedScaledForms := WeakIdentityDictionary new. |
|
1166 |
CachedScales := WeakIdentityDictionary new. |
|
1167 |
]. |
|
1168 |
CachedScaledForms at:formToDraw put:realForm. |
|
1169 |
CachedScales at:formToDraw put:transformation scale. |
|
1170 |
] |
|
1171 |
] |
|
1172 |
] |
|
1173 |
] ifFalse:[ |
|
1174 |
pX := x. |
|
1175 |
pY := y. |
|
1176 |
]. |
|
1177 |
||
1178 |
pX := pX rounded. |
|
1179 |
pY := pY rounded. |
|
1180 |
||
1181 |
self displayDeviceOpaqueForm:realForm x:pX y:pY |
|
1182 |
||
1183 |
"Modified: 21.5.1996 / 21:15:54 / cg" |
|
1184 |
! |
|
1185 |
||
1186 |
displayOpaqueString:aString from:index1 to:index2 x:x y:y |
|
1187 |
"draw a substring at the coordinate x/y - draw foreground pixels in |
|
1188 |
paint-color and background pixels in bgPaint-color. |
|
1189 |
If the transformation involves scaling, |
|
1190 |
the fonts point-size is scaled as appropriate. |
|
1191 |
Assuming that device can only draw in device colors, we have to handle |
|
1192 |
the case where paint and/or bgPaint are dithered colors" |
|
1193 |
||
1194 |
|easy w h savedPaint fgId bgId |
|
1195 |
id pX pY fontUsed sz s| |
|
1196 |
||
1197 |
" |
|
1198 |
if backgroundPaint color is nil, we assume |
|
1199 |
this is a non-opaque draw |
|
1200 |
" |
|
1201 |
bgPaint isNil ifTrue:[ |
|
1202 |
self displayString:aString from:index1 to:index2 x:x y:y. |
|
1203 |
^ self |
|
1204 |
]. |
|
1205 |
||
1206 |
(aString isString not |
|
1207 |
or:[aString isText]) ifTrue:[ |
|
1208 |
" |
|
1209 |
hook for non-strings (i.e. attributed text) |
|
1210 |
that 'thing' should know how to display itself ... |
|
1211 |
" |
|
1212 |
aString displayOpaqueOn:self x:x y:y from:index1 to:index2. |
|
1213 |
^ self |
|
1214 |
]. |
|
1215 |
||
1216 |
gcId isNil ifTrue:[ |
|
1217 |
self initGC |
|
1218 |
]. |
|
1219 |
||
1220 |
fontUsed := font. |
|
1221 |
transformation notNil ifTrue:[ |
|
1222 |
pX := transformation applyToX:x. |
|
1223 |
pY := transformation applyToY:y. |
|
1224 |
transformation noScale ifFalse:[ |
|
1225 |
sz := font size. |
|
1226 |
sz isNil ifTrue:[ |
|
1227 |
"/ oops - not a real font; use original font |
|
1228 |
fontUsed := font |
|
1229 |
] ifFalse:[ |
|
1230 |
fontUsed := font size:(transformation applyScaleY:sz) rounded. |
|
1231 |
] |
|
1232 |
] |
|
1233 |
] ifFalse:[ |
|
1234 |
pX := x. |
|
1235 |
pY := y. |
|
1236 |
]. |
|
1237 |
pX := pX rounded. |
|
1238 |
pY := pY rounded. |
|
1239 |
||
1240 |
fontUsed := fontUsed on:device. |
|
1241 |
||
1242 |
id := fontUsed fontId. |
|
1243 |
id isNil ifTrue:[ |
|
1244 |
" |
|
1245 |
hook for alien fonts |
|
1246 |
that 'font' should know how to display the string ... |
|
1247 |
" |
|
1248 |
fontUsed displayOpaqueString:aString from:index1 to:index2 x:x y:y in:self. |
|
1249 |
^ self |
|
1250 |
]. |
|
1251 |
||
1252 |
s := aString. |
|
1253 |
s encoding ~~ font encoding ifTrue:[ |
|
1254 |
s := s encodeInto:(font encoding). |
|
1255 |
]. |
|
1256 |
||
1257 |
" |
|
1258 |
if bgPaint or paint is not a real Color, we have to do it the hard way ... |
|
1259 |
" |
|
1260 |
easy := true. |
|
1261 |
paint isColor ifFalse:[ |
|
1262 |
easy := false |
|
1263 |
] ifTrue:[ |
|
1264 |
fgId := paint colorId. |
|
1265 |
fgId isNil ifTrue:[ |
|
1266 |
easy := false |
|
1267 |
] |
|
1268 |
]. |
|
1269 |
bgPaint isColor ifFalse:[ |
|
1270 |
easy := false |
|
1271 |
] ifTrue:[ |
|
1272 |
bgId := bgPaint colorId. |
|
1273 |
bgId isNil ifTrue:[ |
|
1274 |
easy := false |
|
1275 |
] |
|
1276 |
]. |
|
1277 |
||
1278 |
easy ifTrue:[ |
|
1279 |
deviceFont ~~ fontUsed ifTrue:[ |
|
1280 |
device setFont:id in:gcId. |
|
1281 |
deviceFont := fontUsed |
|
1282 |
]. |
|
1283 |
||
1284 |
device setForeground:fgId background:bgId in:gcId. |
|
1285 |
foreground := paint. |
|
1286 |
background := bgPaint. |
|
1287 |
device displayOpaqueString:s |
|
1288 |
from:index1 to:index2 |
|
1289 |
x:pX y:pY |
|
1290 |
in:drawableId with:gcId. |
|
1291 |
^ self |
|
1292 |
]. |
|
1293 |
||
1294 |
w := fontUsed widthOf:s from:index1 to:index2. |
|
1295 |
h := fontUsed height. |
|
1296 |
||
1297 |
(fgId notNil and:[function == #copy]) ifTrue:[ |
|
1298 |
deviceFont ~~ fontUsed ifTrue:[ |
|
1299 |
device setFont:id in:gcId. |
|
1300 |
deviceFont := fontUsed |
|
1301 |
]. |
|
1302 |
" |
|
1303 |
only bg is dithered; fill with bg first ... |
|
1304 |
" |
|
1305 |
savedPaint := paint. |
|
1306 |
self paint:bgPaint. |
|
1307 |
self fillDeviceRectangleX:pX y:(pY - fontUsed ascent) width:w height:h. |
|
1308 |
self paint:savedPaint. |
|
1309 |
||
1310 |
" |
|
1311 |
then draw using fgPaint (which is a real color) |
|
1312 |
" |
|
1313 |
device displayString:s |
|
1314 |
from:index1 to:index2 |
|
1315 |
x:pX y:pY |
|
1316 |
in:drawableId with:gcId. |
|
1317 |
^ self |
|
1318 |
]. |
|
1319 |
||
832
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
1320 |
"/ the very hard case (fg-dither) |
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
1321 |
|
732 | 1322 |
self displayDeviceOpaqueString:s from:index1 to:index2 in:fontUsed x:pX y:pY. |
1323 |
||
832
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
1324 |
"Modified: 12.6.1996 / 12:36:33 / cg" |
732 | 1325 |
! |
1326 |
||
1327 |
displayOpaqueString:aString x:x y:y |
|
1328 |
"draw a string at the coordinate x/y - draw foreground pixels in paint-color, |
|
1329 |
background pixels in bgPaint color. If the transformation involves scaling, |
|
1330 |
the fonts point-size is scaled as appropriate. |
|
1331 |
Assuming that device can only draw in device colors, we have to handle |
|
1332 |
the case where paint and/or bgPaint are dithered colors or images." |
|
1333 |
||
1334 |
|id easy fgId bgId pX pY fontUsed sz s| |
|
1335 |
||
1336 |
" |
|
1337 |
if backgroundPaint color is nil, we assume |
|
1338 |
this is a non-opaque draw |
|
1339 |
" |
|
1340 |
bgPaint isNil ifTrue:[ |
|
1341 |
self displayString:aString x:x y:y. |
|
1342 |
^ self |
|
1343 |
]. |
|
1344 |
||
1345 |
(aString isString not |
|
1346 |
or:[aString isText]) ifTrue:[ |
|
1347 |
" |
|
1348 |
hook for non-strings (i.e. attributed text) |
|
1349 |
that 'thing' should know how to display itself ... |
|
1350 |
" |
|
1351 |
aString displayOpaqueOn:self x:x y:y. |
|
1352 |
^ self |
|
1353 |
]. |
|
1354 |
||
1355 |
" |
|
1356 |
if bgPaint or paint is not a real Color, we have to do it the hard way ... |
|
1357 |
" |
|
1358 |
easy := true. |
|
1359 |
paint isColor ifFalse:[ |
|
1360 |
easy := false |
|
1361 |
] ifTrue:[ |
|
1362 |
fgId := paint colorId. |
|
1363 |
fgId isNil ifTrue:[ |
|
1364 |
easy := false |
|
1365 |
] |
|
1366 |
]. |
|
1367 |
bgPaint isColor ifFalse:[ |
|
1368 |
easy := false |
|
1369 |
] ifTrue:[ |
|
1370 |
bgId := bgPaint colorId. |
|
1371 |
bgId isNil ifTrue:[ |
|
1372 |
easy := false |
|
1373 |
] |
|
1374 |
]. |
|
1375 |
easy ifFalse:[ |
|
1376 |
" |
|
1377 |
for the hard case, use the general drawing method |
|
1378 |
(no need for optimizations - its slow anyway) |
|
1379 |
" |
|
1380 |
self displayOpaqueString:aString |
|
1381 |
from:1 to:(aString size) |
|
1382 |
x:x y:y. |
|
1383 |
^ self |
|
1384 |
]. |
|
1385 |
||
1386 |
gcId isNil ifTrue:[ |
|
1387 |
self initGC |
|
1388 |
]. |
|
1389 |
||
1390 |
fontUsed := font. |
|
1391 |
transformation notNil ifTrue:[ |
|
1392 |
pX := transformation applyToX:x. |
|
1393 |
pY := transformation applyToY:y. |
|
1394 |
transformation noScale ifFalse:[ |
|
1395 |
sz := font size. |
|
1396 |
sz isNil ifTrue:[ |
|
1397 |
"/ oops - not a real font; use original font |
|
1398 |
fontUsed := font |
|
1399 |
] ifFalse:[ |
|
1400 |
fontUsed := font size:(transformation applyScaleY:sz) rounded. |
|
1401 |
] |
|
1402 |
] |
|
1403 |
] ifFalse:[ |
|
1404 |
pX := x. |
|
1405 |
pY := y. |
|
1406 |
]. |
|
1407 |
pX := pX rounded. |
|
1408 |
pY := pY rounded. |
|
1409 |
||
1410 |
fontUsed := fontUsed on:device. |
|
1411 |
||
1412 |
id := fontUsed fontId. |
|
1413 |
id isNil ifTrue:[ |
|
1414 |
" |
|
1415 |
hook for alien fonts |
|
1416 |
that 'font' should know how to display the string ... |
|
1417 |
" |
|
1418 |
fontUsed displayOpaqueString:aString from:1 to:(aString size) x:x y:y in:self. |
|
1419 |
^ self |
|
1420 |
]. |
|
1421 |
||
1422 |
s := aString. |
|
1423 |
s encoding ~~ font encoding ifTrue:[ |
|
1424 |
s := s encodeInto:(font encoding). |
|
1425 |
]. |
|
1426 |
||
1427 |
deviceFont ~~ fontUsed ifTrue:[ |
|
1428 |
device setFont:id in:gcId. |
|
1429 |
deviceFont := fontUsed |
|
1430 |
]. |
|
1431 |
||
1432 |
||
1433 |
device setForeground:fgId background:bgId in:gcId. |
|
1434 |
foreground := paint. |
|
1435 |
background := bgPaint. |
|
1436 |
device displayOpaqueString:s |
|
1437 |
x:pX y:pY |
|
1438 |
in:drawableId with:gcId. |
|
1439 |
||
1440 |
"Modified: 21.5.1996 / 21:16:17 / cg" |
|
1441 |
! |
|
1442 |
||
1443 |
displayPointX:x y:y |
|
1444 |
"draw a point (with current paint-color); apply transformation if nonNil" |
|
1445 |
||
1446 |
|pX pY| |
|
1447 |
||
1448 |
gcId isNil ifTrue:[ |
|
1449 |
self initGC |
|
1450 |
]. |
|
1451 |
transformation notNil ifTrue:[ |
|
1452 |
pX := transformation applyToX:x. |
|
1453 |
pY := transformation applyToY:y. |
|
1454 |
] ifFalse:[ |
|
1455 |
pX := x. |
|
1456 |
pY := y |
|
1457 |
]. |
|
1458 |
pX := pX rounded. |
|
1459 |
pY := pY rounded. |
|
1460 |
||
1461 |
device displayPointX:pX y:pY in:drawableId with:gcId |
|
1462 |
! |
|
1463 |
||
1464 |
displayPolygon:aPolygon |
|
1465 |
"draw (the outline of) a polygon (with current paint-color). |
|
1466 |
Apply transformation if nonNil" |
|
1467 |
||
1468 |
|newPolygon| |
|
1469 |
||
1470 |
gcId isNil ifTrue:[ |
|
1471 |
self initGC |
|
1472 |
]. |
|
1473 |
transformation notNil ifTrue:[ |
|
1474 |
newPolygon := aPolygon collect:[:point | transformation applyTo:point]. |
|
1475 |
] ifFalse:[ |
|
1476 |
newPolygon := aPolygon |
|
1477 |
]. |
|
1478 |
(newPolygon findFirst:[:p | |
|
1479 |
(p isPoint not |
|
1480 |
or:[(p x class ~~ SmallInteger) |
|
1481 |
or:[(p y class ~~ SmallInteger)]]) |
|
1482 |
]) ~~ 0 ifTrue:[ |
|
1483 |
newPolygon := newPolygon collect:[:p | p asPoint rounded] |
|
1484 |
]. |
|
1485 |
||
1486 |
device displayPolygon:newPolygon in:drawableId with:gcId |
|
1487 |
! |
|
1488 |
||
1489 |
displayRectangleX:x y:y width:w height:h |
|
1490 |
"draw a rectangle (with current paint-color). |
|
1491 |
If transformation is nonNil, drawing is in logical coordinates." |
|
1492 |
||
784 | 1493 |
|pX pY rpX rpY nW nH easy fgId bgId| |
732 | 1494 |
|
1495 |
gcId isNil ifTrue:[ |
|
1496 |
self initGC |
|
1497 |
]. |
|
1498 |
||
1499 |
lineStyle == #doubleDashed ifTrue:[ |
|
1500 |
" |
|
1501 |
if bgPaint or paint is not a real color, we have to do it the hard way ... |
|
1502 |
" |
|
1503 |
easy := true. |
|
1504 |
paint isColor ifFalse:[ |
|
1505 |
easy := false |
|
1506 |
] ifTrue:[ |
|
1507 |
fgId := paint colorId. |
|
1508 |
fgId isNil ifTrue:[ |
|
1509 |
easy := false |
|
1510 |
] |
|
1511 |
]. |
|
1512 |
bgPaint isColor ifFalse:[ |
|
1513 |
easy := false |
|
1514 |
] ifTrue:[ |
|
1515 |
bgId := bgPaint colorId. |
|
1516 |
bgId isNil ifTrue:[ |
|
1517 |
easy := false |
|
1518 |
] |
|
1519 |
]. |
|
1520 |
||
1521 |
easy ifTrue:[ |
|
1522 |
((foreground ~~ paint) or:[background ~~ bgPaint]) ifTrue:[ |
|
1523 |
device setForeground:fgId background:bgId in:gcId. |
|
1524 |
foreground := paint. |
|
1525 |
background := bgPaint. |
|
1526 |
]. |
|
1527 |
] ifFalse:[ |
|
1528 |
'DEVDRAW: cannot draw dashes with dithered colors' errorPrintNL |
|
1529 |
]. |
|
1530 |
]. |
|
1531 |
||
1532 |
transformation notNil ifTrue:[ |
|
1533 |
pX := transformation applyToX:x. |
|
1534 |
pY := transformation applyToY:y. |
|
1535 |
nW := transformation applyScaleX:w. |
|
1536 |
nH := transformation applyScaleY:h. |
|
1537 |
nW < 0 ifTrue:[ |
|
1538 |
nW := nW abs. |
|
1539 |
pX := pX - nW. |
|
1540 |
]. |
|
1541 |
nH < 0 ifTrue:[ |
|
1542 |
nH := nH abs. |
|
1543 |
pY := pY - nH. |
|
1544 |
]. |
|
1545 |
] ifFalse:[ |
|
1546 |
pX := x. |
|
1547 |
pY := y. |
|
1548 |
nW := w. |
|
1549 |
nH := h |
|
1550 |
]. |
|
1551 |
||
1552 |
pX := pX rounded. |
|
1553 |
pY := pY rounded. |
|
1554 |
nW := nW rounded. |
|
1555 |
nH := nH rounded. |
|
1556 |
||
1557 |
"I asked myself many times if we should draw w/h or (w-1)/(h-1) bits - |
|
1558 |
this one seems mathematically incorrect but allows to draw and fill |
|
1559 |
a rectangle using the same extents. |
|
1560 |
I'm not certain if is the right thing to do ... |
|
1561 |
" |
|
784 | 1562 |
device displayRectangleX:pX |
1563 |
y:pY |
|
1564 |
width:(nW - 1) |
|
1565 |
height:(nH - 1) |
|
1566 |
in:drawableId with:gcId |
|
1567 |
||
1568 |
"/ rpX := pX rounded. |
|
1569 |
"/ rpY := pY rounded. |
|
1570 |
"/ nW := (nW + (rpX - pX)) rounded. |
|
1571 |
"/ nH := (nH + (rpY - pY)) rounded. |
|
1572 |
"/ |
|
1573 |
"/ "I asked myself many times if we should draw w/h or (w-1)/(h-1) bits - |
|
1574 |
"/ this one seems mathematically incorrect but allows to draw and fill |
|
1575 |
"/ a rectangle using the same extents. |
|
1576 |
"/ I'm not certain if is the right thing to do ... |
|
1577 |
"/ " |
|
1578 |
"/ device displayRectangleX:rpX |
|
1579 |
"/ y:rpY |
|
1580 |
"/ width:(nW - 1) |
|
1581 |
"/ height:(nH - 1) |
|
1582 |
"/ in:drawableId with:gcId |
|
1583 |
||
1584 |
"Modified: 4.6.1996 / 18:00:03 / cg" |
|
732 | 1585 |
! |
1586 |
||
1587 |
displayString:aString from:index1 to:index2 x:x y:y |
|
1588 |
"draw a substring at the coordinate x/y - |
|
1589 |
draw foreground-pixels only (in current paint-color), |
|
1590 |
leaving background as-is. If the transformation involves scaling, |
|
1591 |
the fonts point-size is scaled as appropriate." |
|
1592 |
||
1593 |
|id pX pY fontUsed sz s| |
|
1594 |
||
1595 |
"hook for non-strings (i.e. attributed text)" |
|
1596 |
aString isString ifFalse:[ |
|
1597 |
^ aString displayOn:self x:x y:y from:index1 to:index2 |
|
1598 |
]. |
|
1599 |
||
1600 |
gcId isNil ifTrue:[ |
|
1601 |
self initGC |
|
1602 |
]. |
|
1603 |
||
1604 |
fontUsed := font. |
|
1605 |
transformation notNil ifTrue:[ |
|
1606 |
pX := transformation applyToX:x. |
|
1607 |
pY := transformation applyToY:y. |
|
1608 |
transformation noScale ifFalse:[ |
|
1609 |
sz := font size. |
|
1610 |
sz isNil ifTrue:[ |
|
1611 |
"/ oops - not a real font; use original font |
|
1612 |
fontUsed := font |
|
1613 |
] ifFalse:[ |
|
1614 |
fontUsed := font size:(transformation applyScaleY:sz) rounded. |
|
1615 |
] |
|
1616 |
] |
|
1617 |
] ifFalse:[ |
|
1618 |
pX := x. |
|
1619 |
pY := y. |
|
1620 |
]. |
|
1621 |
pX := pX rounded. |
|
1622 |
pY := pY rounded. |
|
1623 |
||
1624 |
fontUsed := fontUsed on:device. |
|
1625 |
||
1626 |
id := fontUsed fontId. |
|
1627 |
id isNil ifTrue:[ |
|
1628 |
"hook for alien fonts" |
|
1629 |
font displayString:aString from:index1 to:index2 x:x y:y in:self. |
|
1630 |
^ self |
|
1631 |
]. |
|
1632 |
||
1633 |
s := aString. |
|
1634 |
s encoding ~~ font encoding ifTrue:[ |
|
1635 |
s := s encodeInto:(font encoding). |
|
1636 |
]. |
|
1637 |
||
1638 |
deviceFont ~~ fontUsed ifTrue:[ |
|
1639 |
device setFont:id in:gcId. |
|
1640 |
deviceFont := fontUsed |
|
1641 |
]. |
|
1642 |
device displayString:s from:index1 to:index2 |
|
1643 |
x:pX y:pY in:drawableId with:gcId |
|
1644 |
||
1645 |
"Modified: 21.5.1996 / 21:16:24 / cg" |
|
1646 |
! |
|
1647 |
||
1648 |
displayString:aString x:x y:y |
|
1649 |
"draw a string at the coordinate x/y - |
|
1650 |
draw foreground-pixels only (in current paint-color), |
|
1651 |
leaving background as-is. If the transformation involves scaling, |
|
1652 |
the fonts point-size is scaled as appropriate." |
|
1653 |
||
1654 |
|id pX pY fontUsed sz s| |
|
1655 |
||
1656 |
"hook for non-strings (i.e. attributed text)" |
|
1657 |
(aString isString not |
|
1658 |
or:[aString isText]) ifTrue:[ |
|
1659 |
^ aString displayOn:self x:x y:y |
|
1660 |
]. |
|
1661 |
||
1662 |
gcId isNil ifTrue:[ |
|
1663 |
self initGC |
|
1664 |
]. |
|
1665 |
||
1666 |
fontUsed := font. |
|
1667 |
transformation notNil ifTrue:[ |
|
1668 |
pX := transformation applyToX:x. |
|
1669 |
pY := transformation applyToY:y. |
|
1670 |
transformation noScale ifFalse:[ |
|
1671 |
sz := font size. |
|
1672 |
sz isNil ifTrue:[ |
|
1673 |
"/ oops - not a real font; use original font |
|
1674 |
fontUsed := font |
|
1675 |
] ifFalse:[ |
|
1676 |
fontUsed := font size:(transformation applyScaleY:sz) rounded. |
|
1677 |
] |
|
1678 |
] |
|
1679 |
] ifFalse:[ |
|
1680 |
pX := x. |
|
1681 |
pY := y. |
|
1682 |
]. |
|
1683 |
pX := pX rounded. |
|
1684 |
pY := pY rounded. |
|
1685 |
||
1686 |
fontUsed := fontUsed on:device. |
|
1687 |
||
1688 |
id := fontUsed fontId. |
|
1689 |
id isNil ifTrue:[ |
|
1690 |
"hook for alien fonts" |
|
1691 |
fontUsed displayString:aString x:x y:y in:self |
|
1692 |
] ifFalse:[ |
|
1693 |
s := aString. |
|
1694 |
s encoding ~~ fontUsed encoding ifTrue:[ |
|
1695 |
s := s encodeInto:(fontUsed encoding). |
|
1696 |
]. |
|
1697 |
||
1698 |
deviceFont ~~ fontUsed ifTrue:[ |
|
1699 |
device setFont:id in:gcId. |
|
1700 |
deviceFont := fontUsed |
|
1701 |
]. |
|
1702 |
device displayString:s x:pX y:pY in:drawableId with:gcId |
|
1703 |
] |
|
1704 |
||
1705 |
"Modified: 21.5.1996 / 21:16:30 / cg" |
|
1706 |
! |
|
1707 |
||
1708 |
displayUnscaledForm:formToDraw x:x y:y |
|
1709 |
"draw a form; if its a 1-plane bitmap, 1-bits are drawn in the |
|
1710 |
current paint-color, leaving pixels with 0-bits unchanged |
|
1711 |
(i.e. only 1-bits are drawn from the form). |
|
1712 |
If its a deep form (i.e. a pixmap) the current paint |
|
1713 |
settings are ignored and the form is drawn as-is. |
|
1714 |
Care must be taken, that the paint color is correctly allocated |
|
1715 |
(by sending #on: to the color) before doing so. |
|
1716 |
Using functions other than #copy only makes sense if you are |
|
1717 |
certain, that the colors are real colors (actually, only for |
|
1718 |
noColor or allColor). |
|
1719 |
The origins coordinate is transformed, but the image itself is unscaled." |
|
1720 |
||
1721 |
|pX pY| |
|
1722 |
||
1723 |
transformation notNil ifTrue:[ |
|
1724 |
pX := transformation applyToX:x. |
|
1725 |
pY := transformation applyToY:y. |
|
1726 |
] ifFalse:[ |
|
1727 |
pX := x. |
|
1728 |
pY := y. |
|
1729 |
]. |
|
1730 |
pX := pX rounded. |
|
1731 |
pY := pY rounded. |
|
1732 |
||
1733 |
self displayDeviceForm:formToDraw x:pX y:pY |
|
1734 |
! |
|
1735 |
||
1736 |
displayUnscaledOpaqueForm:formToDraw x:x y:y |
|
1737 |
"draw a form; if its a 1-plane bitmap, 1-bits are drawn in the |
|
1738 |
current paint-color, 0 bits in background color. |
|
1739 |
If its a deep form (i.e. a pixmap) the current paint |
|
1740 |
settings are ignored and the form is drawn as-is (opaque). |
|
1741 |
The origins coordinate is transformed, but the image itself is unscaled." |
|
1742 |
||
1743 |
|pX pY| |
|
1744 |
||
1745 |
transformation notNil ifTrue:[ |
|
1746 |
pX := transformation applyToX:x. |
|
1747 |
pY := transformation applyToY:y. |
|
1748 |
] ifFalse:[ |
|
1749 |
pX := x. |
|
1750 |
pY := y. |
|
1751 |
]. |
|
1752 |
pX := pX rounded. |
|
1753 |
pY := pY rounded. |
|
1754 |
||
1755 |
self displayDeviceOpaqueForm:formToDraw x:pX y:pY |
|
1756 |
! |
|
1757 |
||
1758 |
displayUnscaledOpaqueString:aString from:index1 to:index2 x:x y:y |
|
1759 |
"draw a substring at the transformed coordinate x/y but do not scale the font. |
|
1760 |
Draw foreground pixels in paint-color, background pixels in bgPaint color." |
|
1761 |
||
1762 |
|pX pY| |
|
1763 |
||
1764 |
transformation notNil ifTrue:[ |
|
1765 |
pX := transformation applyToX:x. |
|
1766 |
pY := transformation applyToY:y. |
|
1767 |
] ifFalse:[ |
|
1768 |
pX := x. |
|
1769 |
pY := y. |
|
1770 |
]. |
|
1771 |
self displayDeviceOpaqueString:aString from:index1 to:index2 in:font x:pX y:pY |
|
1772 |
! |
|
1773 |
||
1774 |
displayUnscaledOpaqueString:aString x:x y:y |
|
1775 |
"draw a string at the transformed coordinate x/y but do not scale the font. |
|
1776 |
Draw foreground pixels in paint-color, background pixels in bgPaint color." |
|
1777 |
||
1778 |
|pX pY| |
|
1779 |
||
1780 |
transformation notNil ifTrue:[ |
|
1781 |
pX := transformation applyToX:x. |
|
1782 |
pY := transformation applyToY:y. |
|
1783 |
] ifFalse:[ |
|
1784 |
pX := x. |
|
1785 |
pY := y. |
|
1786 |
]. |
|
1787 |
self displayDeviceOpaqueString:aString from:1 to:(aString size) in:font x:pX y:pY |
|
1788 |
! |
|
1789 |
||
1790 |
displayUnscaledString:aString from:index1 to:index2 x:x y:y |
|
1791 |
"draw a substring at the transformed coordinate x/y but do not scale the font. |
|
1792 |
draw foreground-pixels only (in current paint-color), leaving background as-is." |
|
1793 |
||
1794 |
|pX pY| |
|
1795 |
||
1796 |
transformation notNil ifTrue:[ |
|
1797 |
pX := transformation applyToX:x. |
|
1798 |
pY := transformation applyToY:y. |
|
1799 |
] ifFalse:[ |
|
1800 |
pX := x. |
|
1801 |
pY := y. |
|
1802 |
]. |
|
1803 |
self displayDeviceString:aString from:index1 to:index2 in:font x:pX y:pY |
|
1804 |
! |
|
1805 |
||
1806 |
displayUnscaledString:aString x:x y:y |
|
1807 |
"draw a string at the transformed coordinate x/y but do not scale the font. |
|
1808 |
draw foreground-pixels only (in current paint-color), leaving background as-is." |
|
1809 |
||
1810 |
|pX pY| |
|
1811 |
||
1812 |
transformation notNil ifTrue:[ |
|
1813 |
pX := transformation applyToX:x. |
|
1814 |
pY := transformation applyToY:y. |
|
1815 |
] ifFalse:[ |
|
1816 |
pX := x. |
|
1817 |
pY := y. |
|
1818 |
]. |
|
1819 |
self displayDeviceString:aString from:1 to:(aString size) in:font x:pX y:pY |
|
1820 |
! ! |
|
1821 |
||
1822 |
!DeviceGraphicsContext methodsFor:'drawing in device coordinates'! |
|
1823 |
||
1824 |
displayDeviceForm:aForm x:x y:y |
|
1825 |
"draw a form; if its a 1-plane bitmap, 1-bits are drawn in the |
|
1826 |
current paint-color, leaving pixels with 0-bits unchanged |
|
1827 |
(i.e. only 1-bits are drawn from the form). |
|
1828 |
The form must have been allocated on the same device. |
|
1829 |
No transformation or scaling is done. |
|
1830 |
If its a deep form (i.e. a pixmap) the current paint |
|
1831 |
settings are ignored and the form is drawn as-is. |
|
1832 |
Care must be taken, that the paint color is correctly allocated |
|
1833 |
(by sending #on: to the color) before doing so. |
|
1834 |
Using functions other than #copy only makes sense if you are |
|
1835 |
certain, that the colors are real colors (actually, only for |
|
1836 |
noColor or allColor)." |
|
1837 |
||
1838 |
|id w h easy paintDither tmpForm |
|
895
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1839 |
fgId noColor allColor allBits pX pY |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1840 |
mask maskId| |
732 | 1841 |
|
1842 |
w := aForm width. |
|
1843 |
h := aForm height. |
|
1844 |
||
1845 |
pX := x rounded. |
|
1846 |
pY := y rounded. |
|
1847 |
||
1848 |
id := aForm id. |
|
1849 |
||
1850 |
"temporary ..." |
|
1851 |
(id isNil |
|
1852 |
or:[aForm graphicsDevice ~~ device]) ifTrue:[ |
|
768 | 1853 |
id := (aForm on:device) id. |
1854 |
id isNil ifTrue:[ |
|
868 | 1855 |
'DEVGC: invalid form draw - ignored' errorPrintNL. |
768 | 1856 |
^ self |
1857 |
]. |
|
732 | 1858 |
]. |
1859 |
gcId isNil ifTrue:[ |
|
768 | 1860 |
self initGC |
732 | 1861 |
]. |
1862 |
||
1863 |
" |
|
1864 |
a deep form ignores paint/bgPaint settings |
|
1865 |
" |
|
1866 |
(aForm depth ~~ 1) ifTrue:[ |
|
895
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1867 |
(mask := aForm mask) notNil ifTrue:[ |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1868 |
mask depth == 1 ifFalse:[ |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1869 |
'DEVGC: alpha channel not yet supported' errorPrintCR. |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1870 |
] ifTrue:[ |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1871 |
maskId := (mask on:device) id. |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1872 |
maskId notNil ifTrue:[ |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1873 |
" |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1874 |
create temp-form; |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1875 |
" |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1876 |
tmpForm := Form width:w height:h depth:device depth on:device. |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1877 |
tmpForm initGC. |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1878 |
|
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1879 |
" |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1880 |
fill tempform with image |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1881 |
" |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1882 |
device |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1883 |
copyFromId:id |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1884 |
x:0 y:0 |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1885 |
to:tmpForm id |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1886 |
x:0 y:0 |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1887 |
width:w |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1888 |
height:h |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1889 |
with:tmpForm gcId. |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1890 |
|
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1891 |
allColor := Color allColor. |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1892 |
allBits := allColor colorId. |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1893 |
|
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1894 |
" |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1895 |
stamp out mask in temp form |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1896 |
" |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1897 |
device setForeground:allBits background:0 in:tmpForm gcId. |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1898 |
device setFunction:#and in:tmpForm gcId. |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1899 |
device |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1900 |
copyPlaneFromId:maskId |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1901 |
x:0 y:0 |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1902 |
to:tmpForm id |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1903 |
x:0 y:0 |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1904 |
width:w |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1905 |
height:h |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1906 |
with:tmpForm gcId. |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1907 |
|
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1908 |
|
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1909 |
" |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1910 |
stamp out mask in destination |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1911 |
" |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1912 |
device setForeground:0 background:allBits in:gcId. |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1913 |
device setFunction:#and in:gcId. |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1914 |
device |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1915 |
copyPlaneFromId:maskId |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1916 |
x:0 y:0 |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1917 |
to:drawableId |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1918 |
x:pX y:pY |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1919 |
width:w |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1920 |
height:h |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1921 |
with:gcId. |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1922 |
"/ Delay waitForSeconds:3. |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1923 |
" |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1924 |
or-in tempform-bits ... |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1925 |
" |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1926 |
device setFunction:#or in:gcId. |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1927 |
device |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1928 |
copyFromId:tmpForm id |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1929 |
x:0 y:0 |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1930 |
to:drawableId |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1931 |
x:pX y:pY |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1932 |
width:w |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1933 |
height:h |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1934 |
with:gcId. |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1935 |
|
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1936 |
foreground notNil ifTrue:[ |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1937 |
self device setForeground:foreground colorId in:gcId. |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1938 |
]. |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1939 |
background notNil ifTrue:[ |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1940 |
self device setBackground:background colorId in:gcId. |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1941 |
]. |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1942 |
device setFunction:function in:gcId. |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1943 |
^ self |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1944 |
] |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1945 |
] |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1946 |
]. |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
1947 |
|
768 | 1948 |
device |
1949 |
copyFromId:id |
|
1950 |
x:0 y:0 |
|
1951 |
to:drawableId |
|
1952 |
x:pX y:pY |
|
1953 |
width:w |
|
1954 |
height:h |
|
1955 |
with:gcId. |
|
1956 |
^ self |
|
732 | 1957 |
]. |
1958 |
||
1959 |
" |
|
1960 |
the following code is somewhat complicated, since it has to deal |
|
1961 |
with dithered paint colors, which cannot be done directly on most |
|
1962 |
devices (actually, a test for the devices capabilities has to be added here) |
|
1963 |
(just assume drawing a bitmap with dithered paint color ... sigh) |
|
1964 |
" |
|
1965 |
||
1966 |
" |
|
1967 |
if paint is not a real color, we have to do it the hard way ... |
|
1968 |
" |
|
1969 |
easy := (function == #copy). |
|
1970 |
easy ifTrue:[ |
|
768 | 1971 |
paint isColor ifFalse:[ |
1972 |
paintDither := paint. |
|
1973 |
easy := false |
|
1974 |
] ifTrue:[ |
|
1975 |
paintDither := paint ditherForm. |
|
1976 |
paintDither notNil ifTrue:[ |
|
1977 |
easy := false. |
|
1978 |
] |
|
1979 |
]. |
|
732 | 1980 |
]. |
1981 |
||
1982 |
allColor := Color allColor. |
|
1983 |
allBits := allColor colorId. |
|
1984 |
||
1985 |
easy ifTrue:[ |
|
768 | 1986 |
" |
1987 |
paint is a real color |
|
1988 |
" |
|
1989 |
||
1990 |
" |
|
1991 |
if paint color is all-0 or all-1's, we can do it in one |
|
1992 |
operation ... |
|
1993 |
" |
|
1994 |
fgId := paint colorId. |
|
1995 |
||
1996 |
((fgId ~~ ((1 bitShift:device depth)-1)) |
|
1997 |
and:[fgId ~~ allBits]) ifTrue:[ |
|
1998 |
" |
|
1999 |
clear fg-bits ... |
|
2000 |
" |
|
2001 |
device setForeground:0 background:allBits in:gcId. |
|
2002 |
device setFunction:#and in:gcId. |
|
2003 |
device |
|
2004 |
copyPlaneFromId:id |
|
2005 |
x:0 y:0 |
|
2006 |
to:drawableId |
|
2007 |
x:pX y:pY |
|
2008 |
width:w |
|
2009 |
height:h |
|
2010 |
with:gcId. |
|
2011 |
]. |
|
2012 |
||
2013 |
fgId ~~ 0 ifTrue:[ |
|
2014 |
" |
|
2015 |
or-in fg-bits ... |
|
2016 |
" |
|
2017 |
device setForeground:fgId background:0 in:gcId. |
|
2018 |
device setFunction:#or in:gcId. |
|
2019 |
device |
|
2020 |
copyPlaneFromId:id |
|
2021 |
x:0 y:0 |
|
2022 |
to:drawableId |
|
2023 |
x:pX y:pY |
|
2024 |
width:w |
|
2025 |
height:h |
|
2026 |
with:gcId. |
|
2027 |
]. |
|
2028 |
" |
|
2029 |
flush foreground/background cache |
|
2030 |
" |
|
2031 |
foreground := nil. |
|
2032 |
background := nil. |
|
2033 |
device setFunction:function in:gcId. |
|
2034 |
^ self |
|
732 | 2035 |
]. |
2036 |
||
2037 |
||
2038 |
" |
|
2039 |
hard case; paint is a dithered color |
|
2040 |
" |
|
2041 |
||
2042 |
noColor := Color noColor. |
|
2043 |
||
2044 |
" |
|
2045 |
create temp-form; |
|
2046 |
" |
|
2047 |
tmpForm := Form width:w height:h depth:device depth on:device. |
|
2048 |
" |
|
2049 |
fill tempform |
|
2050 |
" |
|
2051 |
tmpForm paint:paint. |
|
2052 |
tmpForm fillRectangleX:0 y:0 width:w height:h. |
|
2053 |
" |
|
2054 |
stamp out background |
|
2055 |
" |
|
2056 |
tmpForm paint:allColor on:noColor. |
|
2057 |
tmpForm function:#and. |
|
2058 |
tmpForm displayOpaqueForm:aForm x:0 y:0. |
|
2059 |
" |
|
2060 |
stamp out foreground from destination |
|
2061 |
" |
|
2062 |
device setForeground:0 background:allBits in:gcId. |
|
2063 |
device setFunction:#and in:gcId. |
|
2064 |
device |
|
768 | 2065 |
copyPlaneFromId:id |
2066 |
x:0 y:0 |
|
2067 |
to:drawableId |
|
2068 |
x:pX y:pY |
|
2069 |
width:w |
|
2070 |
height:h |
|
2071 |
with:gcId. |
|
732 | 2072 |
" |
2073 |
or-in temp into destination |
|
2074 |
" |
|
2075 |
device setForeground:allBits background:0 in:gcId. |
|
2076 |
device setFunction:#or in:gcId. |
|
2077 |
||
2078 |
device |
|
768 | 2079 |
copyFromId:tmpForm id |
2080 |
x:0 y:0 |
|
2081 |
to:drawableId |
|
2082 |
x:pX y:pY |
|
2083 |
width:w |
|
2084 |
height:h |
|
2085 |
with:gcId. |
|
732 | 2086 |
" |
2087 |
flush foreground/background cache |
|
2088 |
" |
|
2089 |
foreground := nil. |
|
2090 |
background := nil. |
|
2091 |
device setFunction:function in:gcId. |
|
768 | 2092 |
|
895
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
2093 |
"Modified: 21.6.1996 / 13:26:10 / cg" |
732 | 2094 |
! |
2095 |
||
2096 |
displayDeviceLineFromX:x0 y:y0 toX:x1 y:y1 |
|
2097 |
"draw a line (with current paint-color) in device coordinate space. |
|
2098 |
This ignores any transformations. The coordinates must be integers." |
|
2099 |
||
2100 |
gcId isNil ifTrue:[ |
|
2101 |
self initGC |
|
2102 |
]. |
|
2103 |
device displayLineFromX:x0 y:y0 toX:x1 y:y1 in:drawableId with:gcId |
|
2104 |
! |
|
2105 |
||
2106 |
displayDeviceOpaqueForm:aForm x:x y:y |
|
2107 |
"draw a form; if its a 1-plane bitmap, 1-bits are drawn in the |
|
2108 |
current paint-color and 0-bits in the bgPaint color. |
|
2109 |
If its a deep form (i.e. a pixmap) the current paint/bgPaint |
|
2110 |
settings are ignored and the form drawn as-is. |
|
2111 |
In the 1-plane case, special care must be taken if paint and/or bgPaint |
|
2112 |
dithered colors or patterns, since are that the colors are correctly allocated (by sending #on: |
|
2113 |
to the colors) before doing so. |
|
2114 |
The form must have been allocated on the same device. |
|
2115 |
Drawing is in device coordinates; no scaling is done." |
|
2116 |
||
2117 |
|id w h easy savedPaint bgForm fgForm tmpForm |
|
2118 |
fgId bgId noColor allColor allBits dx dy |
|
2119 |
pX pY deviceDepth| |
|
2120 |
||
895
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
2121 |
" |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
2122 |
a deep form ignores paint/bgPaint settings |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
2123 |
and is always drawn opaque. |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
2124 |
" |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
2125 |
(aForm depth ~~ 1) ifTrue:[ |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
2126 |
device |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
2127 |
copyFromId:id |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
2128 |
x:0 y:0 |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
2129 |
to:drawableId |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
2130 |
x:pX y:pY |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
2131 |
width:w |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
2132 |
height:h |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
2133 |
with:gcId. |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
2134 |
^ self |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
2135 |
]. |
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
2136 |
|
732 | 2137 |
bgPaint isNil ifTrue:[ |
868 | 2138 |
self displayDeviceForm:aForm x:x y:y. |
2139 |
^ self |
|
732 | 2140 |
]. |
2141 |
||
2142 |
w := aForm width. |
|
2143 |
h := aForm height. |
|
2144 |
||
2145 |
pX := x rounded. |
|
2146 |
pY := y rounded. |
|
2147 |
||
2148 |
id := aForm id. |
|
2149 |
||
2150 |
"temporary ..." |
|
2151 |
(id isNil |
|
2152 |
or:[aForm graphicsDevice ~~ device]) ifTrue:[ |
|
868 | 2153 |
id := (aForm on:device) id. |
2154 |
id isNil ifTrue:[ |
|
2155 |
'DEVGC: invalid form draw - ignored' errorPrintNL. |
|
2156 |
^ self |
|
2157 |
]. |
|
732 | 2158 |
]. |
2159 |
||
2160 |
gcId isNil ifTrue:[ |
|
868 | 2161 |
self initGC |
732 | 2162 |
]. |
2163 |
||
2164 |
"the following code is somewhat complicated, since it has to deal |
|
2165 |
with dithered fg/bg colors, which cannot be done directly on most |
|
2166 |
devices (actually, a test for the devices capabilities has to be added here) |
|
2167 |
(just assume drawing a bitmap with dithered fg/bg colors ... sigh) |
|
2168 |
" |
|
2169 |
||
2170 |
" |
|
2171 |
if bgPaint or paint is not a real color, we have to do it the hard way ... |
|
2172 |
" |
|
2173 |
easy := true. |
|
2174 |
paint isColor ifFalse:[ |
|
868 | 2175 |
easy := false |
732 | 2176 |
] ifTrue:[ |
868 | 2177 |
fgId := paint colorId. |
2178 |
fgId isNil ifTrue:[ |
|
2179 |
easy := false |
|
2180 |
] |
|
732 | 2181 |
]. |
2182 |
bgPaint isColor ifFalse:[ |
|
868 | 2183 |
easy := false |
732 | 2184 |
] ifTrue:[ |
868 | 2185 |
bgId := bgPaint colorId. |
2186 |
bgId isNil ifTrue:[ |
|
2187 |
easy := false |
|
2188 |
] |
|
732 | 2189 |
]. |
2190 |
||
2191 |
easy ifTrue:[ |
|
868 | 2192 |
" |
2193 |
easy: both paint and bgPaint are real colors |
|
2194 |
" |
|
2195 |
((foreground ~~ paint) or:[background ~~ bgPaint]) ifTrue:[ |
|
2196 |
device setForeground:fgId background:bgId in:gcId. |
|
2197 |
foreground := paint. |
|
2198 |
background := bgPaint. |
|
2199 |
]. |
|
2200 |
device |
|
2201 |
copyPlaneFromId:id |
|
2202 |
x:0 y:0 |
|
2203 |
to:drawableId |
|
2204 |
x:pX y:pY |
|
2205 |
width:w |
|
2206 |
height:h |
|
2207 |
with:gcId. |
|
2208 |
^ self |
|
732 | 2209 |
]. |
2210 |
||
2211 |
" |
|
2212 |
hard case: paint and/or bgPaint are dithered or patterns |
|
2213 |
" |
|
2214 |
allColor := Color allColor. |
|
2215 |
allBits := allColor colorId. |
|
2216 |
deviceDepth := device depth. |
|
2217 |
||
2218 |
(fgId notNil and:[function == #copy]) ifTrue:[ |
|
868 | 2219 |
" |
2220 |
only bg is dithered; fill with bg first ... |
|
2221 |
" |
|
2222 |
savedPaint := paint. |
|
2223 |
self paint:bgPaint. |
|
2224 |
self fillDeviceRectangleX:pX y:pY width:w height:h. |
|
2225 |
self paint:savedPaint. |
|
2226 |
||
2227 |
" |
|
2228 |
if paint color is all-0 or all-1's, we can do it in one |
|
2229 |
operation ... |
|
2230 |
" |
|
2231 |
((fgId ~~ ((1 bitShift:deviceDepth)-1)) |
|
2232 |
and:[fgId ~~ allBits]) ifTrue:[ |
|
2233 |
" |
|
2234 |
clear fg-bits ... |
|
2235 |
" |
|
2236 |
device setForeground:0 background:allBits in:gcId. |
|
2237 |
device setFunction:#and in:gcId. |
|
2238 |
device |
|
2239 |
copyPlaneFromId:id |
|
2240 |
x:0 y:0 |
|
2241 |
to:drawableId |
|
2242 |
x:pX y:pY |
|
2243 |
width:w |
|
2244 |
height:h |
|
2245 |
with:gcId. |
|
2246 |
]. |
|
2247 |
||
2248 |
fgId ~~ 0 ifTrue:[ |
|
2249 |
" |
|
2250 |
or-in fg-bits ... |
|
2251 |
" |
|
2252 |
device setForeground:fgId background:0 in:gcId. |
|
2253 |
device setFunction:#or in:gcId. |
|
2254 |
device |
|
2255 |
copyPlaneFromId:id |
|
2256 |
x:0 y:0 |
|
2257 |
to:drawableId |
|
2258 |
x:pX y:pY |
|
2259 |
width:w |
|
2260 |
height:h |
|
2261 |
with:gcId. |
|
2262 |
]. |
|
2263 |
" |
|
2264 |
flush foreground/background cache |
|
2265 |
" |
|
2266 |
foreground := nil. |
|
2267 |
background := nil. |
|
2268 |
device setFunction:function in:gcId. |
|
2269 |
^ self |
|
732 | 2270 |
]. |
2271 |
||
2272 |
(bgId notNil and:[function == #copy]) ifTrue:[ |
|
868 | 2273 |
" |
2274 |
only fg is dithered; fill with fg first ... |
|
2275 |
" |
|
2276 |
self fillDeviceRectangleX:pX y:pY width:w height:h. |
|
2277 |
||
2278 |
" |
|
2279 |
if paint color is all-0 or all-1's, we can do it in one |
|
2280 |
operation ... |
|
2281 |
" |
|
2282 |
((bgId ~~ ((1 bitShift:deviceDepth)-1)) |
|
2283 |
and:[bgId ~~ allBits]) ifTrue:[ |
|
2284 |
" |
|
2285 |
clear bg-bits ... |
|
2286 |
" |
|
2287 |
device setForeground:allBits background:0 in:gcId. |
|
2288 |
device setFunction:#and in:gcId. |
|
2289 |
device |
|
2290 |
copyPlaneFromId:id |
|
2291 |
x:0 y:0 |
|
2292 |
to:drawableId |
|
2293 |
x:pX y:pY |
|
2294 |
width:w |
|
2295 |
height:h |
|
2296 |
with:gcId. |
|
2297 |
]. |
|
2298 |
||
2299 |
" |
|
2300 |
or-in bg-bits ... |
|
2301 |
" |
|
2302 |
bgId ~~ 0 ifTrue:[ |
|
2303 |
device setForeground:0 background:bgId in:gcId. |
|
2304 |
device setFunction:#or in:gcId. |
|
2305 |
device |
|
2306 |
copyPlaneFromId:id |
|
2307 |
x:0 y:0 |
|
2308 |
to:drawableId |
|
2309 |
x:pX y:pY |
|
2310 |
width:w |
|
2311 |
height:h |
|
2312 |
with:gcId. |
|
2313 |
]. |
|
2314 |
" |
|
2315 |
flush foreground/background cache |
|
2316 |
" |
|
2317 |
foreground := nil. |
|
2318 |
background := nil. |
|
2319 |
device setFunction:function in:gcId. |
|
2320 |
^ self |
|
732 | 2321 |
]. |
2322 |
||
2323 |
" |
|
2324 |
very hard case; both fg and bg are dithered colors |
|
2325 |
" |
|
2326 |
noColor := Color noColor. |
|
2327 |
||
2328 |
" |
|
2329 |
create temp-forms; |
|
2330 |
" |
|
2331 |
bgForm := Form width:w height:h depth:deviceDepth on:device. |
|
2332 |
fgForm := Form width:w height:h depth:deviceDepth on:device. |
|
2333 |
tmpForm := Form width:w height:h depth:deviceDepth on:device. |
|
2334 |
||
2335 |
" |
|
2336 |
fill |
|
2337 |
" |
|
2338 |
dx := dy := 0. |
|
2339 |
maskOrigin notNil ifTrue:[ |
|
868 | 2340 |
dx := maskOrigin x. |
2341 |
dy := maskOrigin y |
|
732 | 2342 |
]. |
2343 |
||
2344 |
bgForm paint:bgPaint. |
|
2345 |
bgForm setMaskOriginX:(x negated + dx) y:(y negated + dy). |
|
2346 |
bgForm fillRectangleX:0 y:0 width:w height:h. |
|
2347 |
fgForm paint:paint. |
|
2348 |
fgForm setMaskOriginX:(x negated + dx) y:(y negated + dy). |
|
2349 |
fgForm fillRectangleX:0 y:0 width:w height:h. |
|
2350 |
||
2351 |
" |
|
2352 |
stamp-out background |
|
2353 |
" |
|
2354 |
bgForm paint:noColor on:allColor. |
|
2355 |
bgForm function:#and. |
|
2356 |
bgForm displayOpaqueForm:aForm x:0 y:0. |
|
2357 |
||
2358 |
" |
|
2359 |
stamp-out foreground |
|
2360 |
" |
|
2361 |
fgForm paint:allColor on:noColor. |
|
2362 |
fgForm function:#and. |
|
2363 |
fgForm displayOpaqueForm:aForm x:0 y:0. |
|
2364 |
||
2365 |
" |
|
2366 |
clear tempform |
|
2367 |
" |
|
2368 |
tmpForm paint:noColor. |
|
2369 |
tmpForm fillRectangleX:0 y:0 width:w height:h. |
|
2370 |
||
2371 |
" |
|
2372 |
merge fg-temp and bg-temp into tmp |
|
2373 |
" |
|
2374 |
tmpForm function:#or. |
|
2375 |
tmpForm paint:noColor on:allColor. |
|
2376 |
tmpForm copyFrom:fgForm x:0 y:0 toX:0 y:0 width:w height:h. |
|
2377 |
tmpForm copyFrom:bgForm x:0 y:0 toX:0 y:0 width:w height:h. |
|
2378 |
||
2379 |
" |
|
2380 |
finally, draw it |
|
2381 |
" |
|
2382 |
device setForeground:0 background:allBits in:gcId. |
|
2383 |
device |
|
868 | 2384 |
copyFromId:tmpForm id |
2385 |
x:0 y:0 |
|
2386 |
to:drawableId |
|
2387 |
x:pX y:pY |
|
2388 |
width:w |
|
2389 |
height:h |
|
2390 |
with:gcId. |
|
732 | 2391 |
" |
2392 |
flush foreground/background cache |
|
2393 |
" |
|
2394 |
foreground := nil. |
|
2395 |
background := nil. |
|
868 | 2396 |
|
895
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
2397 |
"Modified: 21.6.1996 / 13:31:06 / cg" |
732 | 2398 |
! |
2399 |
||
2400 |
displayDeviceOpaqueString:aString from:index1 to:index2 in:font x:x y:y |
|
2401 |
"draw a substring at the coordinate x/y - draw foreground pixels in |
|
2402 |
paint-color and background pixels in bgPaint-color. |
|
2403 |
Assuming that device can only draw in device colors, we have to handle |
|
2404 |
the case where paint and/or bgPaint are dithered colors. |
|
2405 |
No translation or scaling is done." |
|
2406 |
||
2407 |
|easy w h savedPaint fgId bgId allColor allBits noColor |
|
2408 |
id bgForm fgForm tmpForm maskForm dx dy pX pY fontUsed s |
|
2409 |
deviceDepth| |
|
2410 |
||
2411 |
" |
|
2412 |
if backgroundPaint color is nil, we assume |
|
2413 |
this is a non-opaque draw |
|
2414 |
" |
|
2415 |
bgPaint isNil ifTrue:[ |
|
2416 |
self displayDeviceString:aString from:index1 to:index2 x:x y:y. |
|
2417 |
^ self |
|
2418 |
]. |
|
2419 |
||
2420 |
(aString isString not |
|
2421 |
or:[aString isText]) ifTrue:[ |
|
2422 |
" |
|
2423 |
hook for non-strings (i.e. attributed text) |
|
2424 |
that 'thing' should know how to display itself ... |
|
2425 |
" |
|
2426 |
aString displayOpaqueOn:self x:x y:y from:index1 to:index2. |
|
2427 |
^ self |
|
2428 |
]. |
|
2429 |
||
2430 |
gcId isNil ifTrue:[ |
|
2431 |
self initGC |
|
2432 |
]. |
|
2433 |
||
2434 |
pX := x rounded. |
|
2435 |
pY := y rounded. |
|
2436 |
||
2437 |
fontUsed := font on:device. |
|
2438 |
||
2439 |
id := fontUsed fontId. |
|
2440 |
id isNil ifTrue:[ |
|
2441 |
" |
|
2442 |
hook for alien fonts |
|
2443 |
that 'font' should know how to display the string ... |
|
2444 |
" |
|
2445 |
font displayOpaqueString:aString from:index1 to:index2 x:x y:y in:self. |
|
2446 |
^ self |
|
2447 |
]. |
|
2448 |
||
2449 |
s := aString. |
|
2450 |
s encoding ~~ font encoding ifTrue:[ |
|
2451 |
s := s encodeInto:(font encoding). |
|
2452 |
]. |
|
2453 |
||
2454 |
deviceFont ~~ fontUsed ifTrue:[ |
|
2455 |
device setFont:id in:gcId. |
|
2456 |
deviceFont := fontUsed |
|
2457 |
]. |
|
2458 |
||
2459 |
" |
|
2460 |
if bgPaint or paint is not a real Color, we have to do it the hard way ... |
|
2461 |
" |
|
2462 |
easy := true. |
|
2463 |
paint isColor ifFalse:[ |
|
2464 |
easy := false |
|
2465 |
] ifTrue:[ |
|
2466 |
fgId := paint colorId. |
|
2467 |
fgId isNil ifTrue:[ |
|
2468 |
easy := false |
|
2469 |
] |
|
2470 |
]. |
|
2471 |
bgPaint isColor ifFalse:[ |
|
2472 |
easy := false |
|
2473 |
] ifTrue:[ |
|
2474 |
bgId := bgPaint colorId. |
|
2475 |
bgId isNil ifTrue:[ |
|
2476 |
easy := false |
|
2477 |
] |
|
2478 |
]. |
|
2479 |
||
2480 |
easy ifTrue:[ |
|
2481 |
device setForeground:fgId background:bgId in:gcId. |
|
2482 |
foreground := paint. |
|
2483 |
background := bgPaint. |
|
2484 |
device displayOpaqueString:s |
|
2485 |
from:index1 to:index2 |
|
2486 |
x:pX y:pY |
|
2487 |
in:drawableId with:gcId. |
|
2488 |
^ self |
|
2489 |
]. |
|
2490 |
||
2491 |
w := fontUsed widthOf:s from:index1 to:index2. |
|
2492 |
h := fontUsed height. |
|
2493 |
||
2494 |
(fgId notNil and:[function == #copy]) ifTrue:[ |
|
2495 |
" |
|
2496 |
only bg is dithered; fill with bg first ... |
|
2497 |
" |
|
2498 |
savedPaint := paint. |
|
2499 |
self paint:bgPaint. |
|
2500 |
self fillRectangleX:pX y:(pY - fontUsed ascent) width:w height:h. |
|
2501 |
self paint:savedPaint. |
|
2502 |
||
2503 |
" |
|
2504 |
then draw using fgPaint (which is a real color) |
|
2505 |
" |
|
2506 |
device displayString:s |
|
2507 |
from:index1 to:index2 |
|
2508 |
x:pX y:pY |
|
2509 |
in:drawableId with:gcId. |
|
2510 |
^ self |
|
2511 |
]. |
|
2512 |
||
2513 |
allColor := Color allColor. |
|
2514 |
allBits := allColor colorId. |
|
2515 |
||
2516 |
deviceDepth := device depth. |
|
2517 |
||
2518 |
" |
|
2519 |
the code below is correct, but some (all?) implementations of the |
|
2520 |
X Window system seem to not support ALU-functions when drawing opaque strings. |
|
2521 |
Therefore we use the slower code below. |
|
2522 |
" |
|
2523 |
||
2524 |
"/ (bgId notNil and:[function == #copy]) ifTrue:[ |
|
2525 |
"/ " |
|
2526 |
"/ only fg is dithered; fill with fg first ... |
|
2527 |
"/ " |
|
2528 |
"/ self fillRectangleX:pX y:(pY - fontUsed ascent) width:w height:h. |
|
2529 |
"/ |
|
2530 |
"/ " |
|
2531 |
"/ if bgPaint color is all-0 or all-1's, we can do it in one |
|
2532 |
"/ operation ... |
|
2533 |
"/ " |
|
2534 |
"/ ((bgId ~~ ((1 bitShift:deviceDepth)-1)) |
|
2535 |
"/ and:[bgId ~~ allBits]) ifTrue:[ |
|
2536 |
"/ " |
|
2537 |
"/ clear bg bits ... |
|
2538 |
"/ " |
|
2539 |
"/ device setForeground:allBits background:0 in:gcId. |
|
2540 |
"/ device setFunction:#and in:gcId. |
|
2541 |
"/ device displayOpaqueString:s |
|
2542 |
"/ from:index1 to:index2 |
|
2543 |
"/ x:pX y:pY |
|
2544 |
"/ in:drawableId with:gcId. |
|
2545 |
"/ ]. |
|
2546 |
"/ |
|
2547 |
"/ " |
|
2548 |
"/ or-in bg bits ... |
|
2549 |
"/ " |
|
2550 |
"/ bgId ~~ 0 ifTrue:[ |
|
2551 |
"/ device setForeground:0 background:bgId in:gcId. |
|
2552 |
"/ device setFunction:#or in:gcId. |
|
2553 |
"/ device displayOpaqueString:s |
|
2554 |
"/ from:index1 to:index2 |
|
2555 |
"/ x:pX y:pY |
|
2556 |
"/ in:drawableId with:gcId. |
|
2557 |
"/ ]. |
|
2558 |
"/ " |
|
2559 |
"/ flush foreground/background cache |
|
2560 |
"/ " |
|
2561 |
"/ foreground := nil. |
|
2562 |
"/ background := nil. |
|
2563 |
"/ device setFunction:function in:gcId. |
|
2564 |
"/ ^ self |
|
2565 |
"/ ]. |
|
2566 |
||
768 | 2567 |
(bgId notNil and:[function == #copy]) ifTrue:[ |
2568 |
" |
|
2569 |
only fg is dithered; fill with bg first ... |
|
2570 |
" |
|
2571 |
device setForeground:bgId in:gcId. |
|
2572 |
device setFunction:#copy in:gcId. |
|
832
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
2573 |
device setBitmapMask:nil in:gcId. |
768 | 2574 |
self fillRectangleX:pX y:(pY - fontUsed ascent) width:w height:h. |
2575 |
||
832
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
2576 |
"/ draw fg dithered |
768 | 2577 |
(mask depth == 1) ifTrue:[ |
832
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
2578 |
device setBitmapMask:mask id in:gcId. |
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
2579 |
device setForeground:foreground colorId background:background colorId in:gcId. |
768 | 2580 |
] ifFalse:[ |
2581 |
device setPixmapMask:mask id in:gcId |
|
2582 |
]. |
|
2583 |
||
2584 |
device displayString:s |
|
2585 |
from:index1 to:index2 |
|
2586 |
x:pX y:pY |
|
2587 |
in:drawableId with:gcId. |
|
2588 |
^ self. |
|
2589 |
"/ |
|
2590 |
"/ " |
|
2591 |
"/ if bgPaint color is all-0 or all-1's, we can do it in one |
|
2592 |
"/ operation ... |
|
2593 |
"/ " |
|
2594 |
"/ ((bgId ~~ ((1 bitShift:deviceDepth)-1)) |
|
2595 |
"/ and:[bgId ~~ allBits]) ifTrue:[ |
|
2596 |
"/ " |
|
2597 |
"/ clear bg bits ... |
|
2598 |
"/ " |
|
2599 |
"/ device setForeground:allBits background:0 in:gcId. |
|
2600 |
"/ device setFunction:#and in:gcId. |
|
2601 |
"/ device displayOpaqueString:s |
|
2602 |
"/ from:index1 to:index2 |
|
2603 |
"/ x:pX y:pY |
|
2604 |
"/ in:drawableId with:gcId. |
|
2605 |
"/ ]. |
|
2606 |
"/ |
|
2607 |
"/ " |
|
2608 |
"/ or-in bg bits ... |
|
2609 |
"/ " |
|
2610 |
"/ bgId ~~ 0 ifTrue:[ |
|
2611 |
"/ device setForeground:0 background:bgId in:gcId. |
|
2612 |
"/ device setFunction:#or in:gcId. |
|
2613 |
"/ device displayOpaqueString:s |
|
2614 |
"/ from:index1 to:index2 |
|
2615 |
"/ x:pX y:pY |
|
2616 |
"/ in:drawableId with:gcId. |
|
2617 |
"/ ]. |
|
2618 |
"/ " |
|
2619 |
"/ flush foreground/background cache |
|
2620 |
"/ " |
|
2621 |
"/ foreground := nil. |
|
2622 |
"/ background := nil. |
|
2623 |
"/ device setFunction:function in:gcId. |
|
2624 |
"/ ^ self |
|
832
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
2625 |
]. |
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
2626 |
|
732 | 2627 |
" |
832
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
2628 |
very hard case, both fg and bg are dithered colors/images |
732 | 2629 |
" |
2630 |
noColor := Color noColor. |
|
832
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
2631 |
"/ 'hard: ' print. aString print. ' ' print. paint print. ' ' print. bgPaint printCR. |
732 | 2632 |
" |
2633 |
create temp-forms; |
|
2634 |
" |
|
2635 |
bgForm := Form width:w height:h depth:deviceDepth on:device. |
|
2636 |
fgForm := Form width:w height:h depth:deviceDepth on:device. |
|
2637 |
tmpForm := Form width:w height:h depth:deviceDepth on:device. |
|
2638 |
maskForm := Form width:w height:h depth:deviceDepth on:device. |
|
2639 |
||
2640 |
" |
|
2641 |
fill |
|
2642 |
" |
|
2643 |
dx := 0. |
|
2644 |
dy := fontUsed ascent. |
|
2645 |
maskOrigin notNil ifTrue:[ |
|
2646 |
dx := maskOrigin x. |
|
2647 |
dy := dy + maskOrigin y |
|
2648 |
]. |
|
2649 |
||
2650 |
bgForm paint:bgPaint. |
|
2651 |
bgForm setMaskOriginX:(pX negated + dx) y:(pY negated + dy). |
|
2652 |
bgForm fillRectangleX:0 y:0 width:w height:h. |
|
2653 |
||
2654 |
fgForm paint:paint. |
|
2655 |
fgForm setMaskOriginX:(pX negated + dx) y:(pY negated + dy). |
|
2656 |
fgForm fillRectangleX:0 y:0 width:w height:h. |
|
2657 |
||
2658 |
" |
|
2659 |
stamp-out background (have now bg-bits with fg=0 in bgForm) |
|
2660 |
" |
|
2661 |
bgForm font:fontUsed. |
|
2662 |
bgForm paint:noColor on:allColor. |
|
2663 |
bgForm function:#and. |
|
2664 |
bgForm displayString:s |
|
2665 |
from:index1 to:index2 |
|
2666 |
x:0 y:fontUsed ascent. |
|
2667 |
||
2668 |
" |
|
2669 |
stamp-out foreground |
|
2670 |
" |
|
2671 |
maskForm font:fontUsed. |
|
2672 |
maskForm paint:allColor on:noColor. |
|
2673 |
maskForm displayOpaqueString:s |
|
2674 |
from:index1 to:index2 |
|
2675 |
x:0 y:fontUsed ascent. |
|
2676 |
||
2677 |
fgForm function:#and. |
|
2678 |
fgForm copyFrom:maskForm x:0 y:0 toX:0 y:0 width:w height:h. |
|
2679 |
||
2680 |
" |
|
2681 |
clear tempform |
|
2682 |
" |
|
2683 |
tmpForm paint:noColor. |
|
2684 |
tmpForm fillRectangleX:0 y:0 width:w height:h. |
|
2685 |
||
2686 |
" |
|
2687 |
merge fg-temp and bg-temp into tmp |
|
2688 |
" |
|
2689 |
tmpForm function:#or. |
|
2690 |
tmpForm paint:noColor on:allColor. |
|
2691 |
tmpForm copyFrom:fgForm x:0 y:0 toX:0 y:0 width:w height:h. |
|
2692 |
tmpForm copyFrom:bgForm x:0 y:0 toX:0 y:0 width:w height:h. |
|
2693 |
" |
|
2694 |
finally, draw it |
|
2695 |
" |
|
2696 |
device setForeground:0 background:allBits in:gcId. |
|
2697 |
device |
|
2698 |
copyFromId:tmpForm id |
|
2699 |
x:0 y:0 |
|
2700 |
to:drawableId |
|
2701 |
x:pX y:pY-fontUsed ascent |
|
2702 |
width:w |
|
2703 |
height:h |
|
2704 |
with:gcId. |
|
2705 |
" |
|
2706 |
flush foreground/background cache |
|
2707 |
" |
|
2708 |
foreground := nil. |
|
2709 |
background := nil. |
|
2710 |
||
832
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
2711 |
"Modified: 12.6.1996 / 12:50:12 / cg" |
732 | 2712 |
! |
2713 |
||
2714 |
displayDeviceOpaqueString:aString from:index1 to:index2 x:x y:y |
|
2715 |
"draw a substring at the coordinate x/y - draw foreground pixels in |
|
2716 |
paint-color and background pixels in bgPaint-color. |
|
2717 |
Assuming that device can only draw in device colors, we have to handle |
|
2718 |
the case where paint and/or bgPaint are dithered colors. |
|
2719 |
No translation or scaling is done." |
|
2720 |
||
2721 |
self displayDeviceOpaqueString:aString from:index1 to:index2 in:font x:x y:y |
|
2722 |
! |
|
2723 |
||
2724 |
displayDeviceOpaqueString:aString x:x y:y |
|
2725 |
"draw a string at the coordinate x/y - draw foreground pixels in |
|
2726 |
paint-color and background pixels in bgPaint-color. |
|
2727 |
No translation or scaling is done" |
|
2728 |
||
2729 |
self displayDeviceOpaqueString:aString from:1 to:(aString size) in:font x:x y:y |
|
2730 |
! |
|
2731 |
||
2732 |
displayDeviceString:aString from:index1 to:index2 in:font x:x y:y |
|
2733 |
"draw a substring at the coordinate x/y - |
|
2734 |
draw foreground-pixels only (in current paint-color), leaving background as-is. |
|
2735 |
No translation or scaling is done" |
|
2736 |
||
2737 |
|id pX pY fontUsed s| |
|
2738 |
||
2739 |
" |
|
2740 |
hook for non-strings (i.e. attributed text) |
|
2741 |
" |
|
2742 |
(aString isString not |
|
2743 |
or:[aString isText]) ifTrue:[ |
|
2744 |
^ aString displayOn:self x:x y:y from:index1 to:index2 |
|
2745 |
]. |
|
2746 |
||
2747 |
gcId isNil ifTrue:[ |
|
2748 |
self initGC |
|
2749 |
]. |
|
2750 |
||
2751 |
pX := x rounded. |
|
2752 |
pY := y rounded. |
|
2753 |
||
2754 |
fontUsed := font on:device. |
|
2755 |
||
2756 |
id := fontUsed fontId. |
|
2757 |
id isNil ifTrue:[ |
|
2758 |
"hook for alien fonts" |
|
2759 |
font displayString:aString from:index1 to:index2 x:x y:y in:self |
|
2760 |
] ifFalse:[ |
|
2761 |
s := aString. |
|
2762 |
s encoding ~~ font encoding ifTrue:[ |
|
2763 |
s := s encodeInto:(font encoding). |
|
2764 |
]. |
|
2765 |
||
2766 |
deviceFont ~~ fontUsed ifTrue:[ |
|
2767 |
device setFont:id in:gcId. |
|
2768 |
deviceFont := fontUsed |
|
2769 |
]. |
|
2770 |
device displayString:s from:index1 to:index2 |
|
2771 |
x:pX y:pY in:drawableId with:gcId |
|
2772 |
] |
|
2773 |
||
2774 |
"Modified: 12.5.1996 / 17:49:22 / cg" |
|
2775 |
! |
|
2776 |
||
2777 |
displayDeviceString:aString from:index1 to:index2 x:x y:y |
|
2778 |
"draw a substring at the coordinate x/y - |
|
2779 |
draw foreground-pixels only (in current paint-color), leaving background as-is. |
|
2780 |
No translation or scaling is done" |
|
2781 |
||
2782 |
self displayDeviceString:aString from:index1 to:index2 in:font x:x y:y |
|
2783 |
! |
|
2784 |
||
2785 |
displayDeviceString:aString x:x y:y |
|
2786 |
"draw a string at the coordinate x/y - |
|
2787 |
draw foreground-pixels only (in current paint-color), leaving background as-is. |
|
2788 |
No translation or scaling is done" |
|
2789 |
||
2790 |
self displayDeviceString:aString from:1 to:(aString size) in:font x:x y:y |
|
2791 |
! |
|
2792 |
||
2793 |
fillDeviceRectangleX:x y:y width:w height:h |
|
2794 |
"draw a filled rectangle in device coordinate space. |
|
2795 |
This ignores any transformations. The coordinates must be integers." |
|
2796 |
||
2797 |
gcId isNil ifTrue:[ |
|
2798 |
self initGC |
|
2799 |
]. |
|
2800 |
device |
|
2801 |
fillRectangleX:x |
|
2802 |
y:y |
|
2803 |
width:w |
|
2804 |
height:h |
|
2805 |
in:drawableId with:gcId |
|
2806 |
! ! |
|
2807 |
||
2808 |
!DeviceGraphicsContext methodsFor:'evaluating in another context'! |
|
2809 |
||
2810 |
reverseDo:aBlock |
|
2811 |
"evaluate aBlock with foreground and background interchanged. |
|
2812 |
This can be reimplemented here in a faster way." |
|
2813 |
||
2814 |
|oldFg oldBg| |
|
2815 |
||
2816 |
oldFg := foreground on:device. |
|
2817 |
oldBg := background on:device. |
|
2818 |
self foreground:background background:foreground. |
|
2819 |
aBlock value. |
|
2820 |
self foreground:oldFg background:oldBg |
|
2821 |
! |
|
2822 |
||
2823 |
withBackground:fgColor do:aBlock |
|
2824 |
"evaluate aBlock with changed background." |
|
2825 |
||
2826 |
|oldBg| |
|
2827 |
||
2828 |
oldBg := background. |
|
2829 |
self background:fgColor. |
|
2830 |
aBlock value. |
|
2831 |
self background:oldBg |
|
2832 |
! |
|
2833 |
||
2834 |
withForeground:fgColor background:bgColor do:aBlock |
|
2835 |
"evaluate aBlock with changed foreground and background." |
|
2836 |
||
2837 |
|oldFg oldBg| |
|
2838 |
||
2839 |
oldFg := foreground. |
|
2840 |
oldBg := background. |
|
2841 |
self foreground:fgColor background:bgColor. |
|
2842 |
aBlock value. |
|
2843 |
self foreground:oldFg background:oldBg |
|
2844 |
! |
|
2845 |
||
2846 |
withForeground:fgColor background:bgColor function:aFunction do:aBlock |
|
2847 |
"evaluate aBlock with foreground, background and function" |
|
2848 |
||
2849 |
|oldFg oldBg oldFun| |
|
2850 |
||
2851 |
oldFg := foreground. |
|
2852 |
oldBg := background. |
|
2853 |
oldFun := function. |
|
2854 |
self foreground:fgColor background:bgColor function:aFunction. |
|
2855 |
aBlock value. |
|
2856 |
self foreground:oldFg background:oldBg function:oldFun |
|
2857 |
! |
|
2858 |
||
2859 |
withForeground:fgColor background:bgColor mask:aMask do:aBlock |
|
2860 |
"evaluate aBlock with foreground, background and mask" |
|
2861 |
||
2862 |
|oldFg oldBg oldMask| |
|
2863 |
||
2864 |
oldFg := foreground. |
|
2865 |
oldBg := background. |
|
2866 |
oldMask := mask. |
|
2867 |
self foreground:fgColor background:bgColor. |
|
2868 |
self mask:aMask. |
|
2869 |
aBlock value. |
|
2870 |
self foreground:oldFg background:oldBg. |
|
2871 |
self mask:oldMask |
|
2872 |
! |
|
2873 |
||
2874 |
withForeground:fgColor do:aBlock |
|
2875 |
"evaluate aBlock with changed foreground." |
|
2876 |
||
2877 |
|oldFg| |
|
2878 |
||
2879 |
oldFg := foreground. |
|
2880 |
self foreground:fgColor. |
|
2881 |
aBlock value. |
|
2882 |
self foreground:oldFg |
|
2883 |
! |
|
2884 |
||
2885 |
withForeground:fgColor function:aFunction do:aBlock |
|
2886 |
"evaluate aBlock with changed foreground and function." |
|
2887 |
||
2888 |
|oldFg oldFun| |
|
2889 |
||
2890 |
oldFg := foreground. |
|
2891 |
oldFun := function. |
|
2892 |
self foreground:fgColor background:background function:aFunction. |
|
2893 |
aBlock value. |
|
2894 |
self foreground:oldFg background:background function:oldFun |
|
2895 |
! |
|
2896 |
||
2897 |
xoring:aBlock |
|
2898 |
"evaluate aBlock with function xoring" |
|
2899 |
||
2900 |
|fgPixel bgPixel oldFunction| |
|
2901 |
||
2902 |
fgPixel := (Black on:device) colorId. |
|
2903 |
bgPixel := (White on:device) colorId. |
|
2904 |
||
2905 |
gcId isNil ifTrue:[ |
|
2906 |
self initGC |
|
2907 |
]. |
|
2908 |
oldFunction := function. |
|
2909 |
device setForeground:(fgPixel bitXor:bgPixel) |
|
2910 |
background:bgPixel |
|
2911 |
in:gcId. |
|
2912 |
device setFunction:#xor in:gcId. |
|
2913 |
aBlock value. |
|
2914 |
paint := nil. "invalidate" |
|
2915 |
foreground := Black. |
|
2916 |
background := White. |
|
2917 |
device setForeground:fgPixel |
|
2918 |
background:bgPixel |
|
2919 |
in:gcId. |
|
2920 |
device setFunction:oldFunction in:gcId. |
|
2921 |
function := oldFunction |
|
2922 |
! ! |
|
2923 |
||
2924 |
!DeviceGraphicsContext methodsFor:'filling'! |
|
2925 |
||
2926 |
fillArcX:x y:y width:w height:h from:startAngle angle:angle |
|
2927 |
"draw a filled arc; apply transformation if nonNil" |
|
2928 |
||
784 | 2929 |
|pX pY rpX rpY nW nH| |
732 | 2930 |
|
2931 |
gcId isNil ifTrue:[ |
|
2932 |
self initGC |
|
2933 |
]. |
|
2934 |
transformation notNil ifTrue:[ |
|
2935 |
pX := transformation applyToX:x. |
|
2936 |
pY := transformation applyToY:y. |
|
2937 |
nW := transformation applyScaleX:w. |
|
2938 |
nH := transformation applyScaleY:h. |
|
2939 |
nW < 0 ifTrue:[ |
|
2940 |
nW := nW abs. |
|
2941 |
pX := pX - nW. |
|
2942 |
]. |
|
2943 |
nH < 0 ifTrue:[ |
|
2944 |
nH := nH abs. |
|
2945 |
pY := pY - nH. |
|
2946 |
]. |
|
2947 |
] ifFalse:[ |
|
2948 |
pX := x. |
|
2949 |
pY := y. |
|
2950 |
nW := w. |
|
2951 |
nH := h. |
|
2952 |
]. |
|
2953 |
||
2954 |
pX := pX rounded. |
|
2955 |
pY := pY rounded. |
|
2956 |
nW := nW rounded. |
|
2957 |
nH := nH rounded. |
|
2958 |
||
2959 |
device |
|
2960 |
fillArcX:pX |
|
2961 |
y:pY |
|
2962 |
width:nW |
|
2963 |
height:nH |
|
2964 |
from:startAngle |
|
2965 |
angle:angle |
|
2966 |
in:drawableId |
|
2967 |
with:gcId |
|
2968 |
||
784 | 2969 |
"/ rpX := pX rounded. |
2970 |
"/ rpY := pY rounded. |
|
2971 |
"/ nW := (nW + (rpX - pX)) rounded. |
|
2972 |
"/ nH := (nH + (rpY - pY)) rounded. |
|
2973 |
"/ |
|
2974 |
"/ device |
|
2975 |
"/ fillArcX:rpX |
|
2976 |
"/ y:rpY |
|
2977 |
"/ width:nW |
|
2978 |
"/ height:nH |
|
2979 |
"/ from:startAngle |
|
2980 |
"/ angle:angle |
|
2981 |
"/ in:drawableId |
|
2982 |
"/ with:gcId |
|
2983 |
||
732 | 2984 |
"Created: 8.5.1996 / 08:29:45 / cg" |
784 | 2985 |
"Modified: 4.6.1996 / 17:58:21 / cg" |
732 | 2986 |
! |
2987 |
||
2988 |
fillPolygon:aPolygon |
|
2989 |
"draw a filled polygon; apply transformation if nonNil" |
|
2990 |
||
2991 |
|newPolygon| |
|
2992 |
||
2993 |
gcId isNil ifTrue:[ |
|
2994 |
self initGC |
|
2995 |
]. |
|
2996 |
transformation notNil ifTrue:[ |
|
2997 |
newPolygon := aPolygon collect:[:point | transformation applyTo:point]. |
|
2998 |
] ifFalse:[ |
|
2999 |
newPolygon := aPolygon |
|
3000 |
]. |
|
3001 |
(newPolygon findFirst:[:p | |
|
3002 |
(p isPoint not |
|
3003 |
or:[(p x class ~~ SmallInteger) |
|
3004 |
or:[(p y class ~~ SmallInteger)]]) |
|
3005 |
]) ~~ 0 ifTrue:[ |
|
3006 |
newPolygon := newPolygon collect:[:p | p asPoint rounded] |
|
3007 |
]. |
|
3008 |
device |
|
3009 |
fillPolygon:newPolygon |
|
3010 |
in:drawableId |
|
3011 |
with:gcId |
|
3012 |
! |
|
3013 |
||
3014 |
fillRectangleX:x y:y width:w height:h |
|
3015 |
"draw a filled rectangle; apply transformation if nonNil" |
|
3016 |
||
784 | 3017 |
|pX pY rpX rpY nW nH| |
732 | 3018 |
|
3019 |
gcId isNil ifTrue:[ |
|
784 | 3020 |
self initGC |
732 | 3021 |
]. |
3022 |
transformation notNil ifTrue:[ |
|
784 | 3023 |
pX := transformation applyToX:x. |
3024 |
pY := transformation applyToY:y. |
|
3025 |
nW := transformation applyScaleX:w. |
|
3026 |
nH := transformation applyScaleY:h. |
|
3027 |
nW < 0 ifTrue:[ |
|
3028 |
nW := nW abs. |
|
3029 |
pX := pX - nW. |
|
3030 |
]. |
|
3031 |
nH < 0 ifTrue:[ |
|
3032 |
nH := nH abs. |
|
3033 |
pY := pY - nH. |
|
3034 |
]. |
|
732 | 3035 |
] ifFalse:[ |
784 | 3036 |
pX := x. |
3037 |
pY := y. |
|
3038 |
nW := w. |
|
3039 |
nH := h. |
|
732 | 3040 |
]. |
3041 |
pX := pX rounded. |
|
3042 |
pY := pY rounded. |
|
3043 |
nW := nW rounded. |
|
3044 |
nH := nH rounded. |
|
3045 |
||
3046 |
device |
|
784 | 3047 |
fillRectangleX:pX |
3048 |
y:pY |
|
3049 |
width:nW |
|
3050 |
height:nH |
|
3051 |
in:drawableId with:gcId |
|
3052 |
||
3053 |
"/ rpX := pX rounded. |
|
3054 |
"/ rpY := pY rounded. |
|
3055 |
"/ nW := (nW + (pX - rpX)) rounded. |
|
3056 |
"/ nH := (nH + (pY - rpY)) rounded. |
|
3057 |
"/ |
|
3058 |
"/ device |
|
3059 |
"/ fillRectangleX:rpX |
|
3060 |
"/ y:rpY |
|
3061 |
"/ width:nW |
|
3062 |
"/ height:nH |
|
3063 |
"/ in:drawableId with:gcId |
|
3064 |
||
3065 |
"Modified: 4.6.1996 / 17:58:49 / cg" |
|
732 | 3066 |
! ! |
3067 |
||
3068 |
!DeviceGraphicsContext methodsFor:'initialization'! |
|
3069 |
||
3070 |
createGC |
|
3071 |
"since we do not need a gc-object for the drawable until something is |
|
3072 |
really drawn, none is created. |
|
3073 |
This method is sent, when the first drawing happens" |
|
3074 |
||
3075 |
|fgId bgId p| |
|
3076 |
||
3077 |
gcId := device gcFor:drawableId. |
|
3078 |
||
3079 |
foreground isNil ifTrue:[foreground := Black]. |
|
3080 |
background isNil ifTrue:[background := White]. |
|
3081 |
||
3082 |
foreground isColor ifTrue:[ |
|
745 | 3083 |
"get device colors from the device indep. colors" |
3084 |
foreground := foreground on:device. |
|
3085 |
fgId := foreground colorId. |
|
3086 |
fgId isNil ifTrue:[ |
|
3087 |
(foreground grayIntensity >= 50) ifTrue:[ |
|
3088 |
fgId := device whitepixel |
|
3089 |
] ifFalse:[ |
|
3090 |
fgId := device blackpixel |
|
3091 |
] |
|
3092 |
]. |
|
732 | 3093 |
] ifFalse:[ |
745 | 3094 |
fgId := device blackpixel. |
732 | 3095 |
]. |
3096 |
||
3097 |
background isColor ifTrue:[ |
|
745 | 3098 |
background := background on:device. |
3099 |
bgId := background colorId. |
|
3100 |
bgId isNil ifTrue:[ |
|
3101 |
(background grayIntensity >= 50) ifTrue:[ |
|
3102 |
bgId := device whitepixel |
|
3103 |
] ifFalse:[ |
|
3104 |
bgId := device blackpixel |
|
3105 |
] |
|
3106 |
]. |
|
732 | 3107 |
] ifFalse:[ |
745 | 3108 |
bgId := device whitepixel |
732 | 3109 |
]. |
3110 |
||
3111 |
"now, this is something the device can work with ..." |
|
3112 |
device setForeground:fgId background:bgId in:gcId. |
|
3113 |
||
3114 |
"switch to paint" |
|
3115 |
p := paint. |
|
3116 |
paint := nil. |
|
3117 |
self paint:p. |
|
3118 |
||
3119 |
((lineWidth ~~ 0) |
|
3120 |
or:[(lineStyle ~~ #solid) |
|
3121 |
or:[(capStyle ~~ #butt) |
|
3122 |
or:[joinStyle ~~ #miter]]]) ifTrue:[ |
|
745 | 3123 |
device setLineWidth:lineWidth |
3124 |
style:lineStyle |
|
3125 |
cap:capStyle |
|
3126 |
join:joinStyle |
|
3127 |
in:gcId |
|
732 | 3128 |
]. |
3129 |
||
3130 |
mask notNil ifTrue:[ |
|
745 | 3131 |
(mask depth == 1) ifTrue:[ |
3132 |
device setBitmapMask:(mask id) in:gcId |
|
3133 |
] ifFalse:[ |
|
3134 |
device setPixmapMask:(mask id) in:gcId |
|
3135 |
]. |
|
3136 |
maskOrigin notNil ifTrue:[ |
|
3137 |
device setMaskOriginX:maskOrigin x y:maskOrigin y in:gcId |
|
3138 |
] |
|
732 | 3139 |
]. |
3140 |
(function ~~ #copy) ifTrue:[device setFunction:function in:gcId]. |
|
3141 |
||
3142 |
"defer the getting of a device font |
|
3143 |
- this is now done when the first drawstring occurs, |
|
3144 |
since many views (layout-views) will never draw strings and |
|
3145 |
therefore, the overhead of aquiring a font can be avoided. |
|
3146 |
" |
|
3147 |
||
3148 |
" |
|
3149 |
font := font on:device. |
|
3150 |
id := font fontId. |
|
3151 |
id notNil ifTrue:[ |
|
745 | 3152 |
device setFont:id in:gcId |
732 | 3153 |
] |
3154 |
" |
|
745 | 3155 |
|
3156 |
"Modified: 28.5.1996 / 20:45:24 / cg" |
|
732 | 3157 |
! |
3158 |
||
3159 |
destroy |
|
3160 |
"when the drawable is destroyed, the associated GC must be destroyed with it" |
|
3161 |
||
3162 |
gcId notNil ifTrue:[ |
|
3163 |
device destroyGC:gcId. |
|
3164 |
gcId := nil. |
|
3165 |
Lobby registerChange:self. |
|
3166 |
] |
|
3167 |
! |
|
3168 |
||
3169 |
initGC |
|
3170 |
"since we do not need a gc-object for the drawable until something is |
|
3171 |
really drawn, none is created. |
|
3172 |
This method is sent, when the first drawing happens" |
|
3173 |
||
3174 |
self createGC. |
|
3175 |
Lobby registerChange:self. |
|
3176 |
! |
|
3177 |
||
3178 |
initialize |
|
3179 |
"setup everything for later use; actual work is done in |
|
3180 |
initColors and initFont, which are usually redefined." |
|
3181 |
||
3182 |
"make certain Workstation is initialized - just a check - will vanish soon" |
|
3183 |
Display isNil ifTrue:[ |
|
3184 |
'DEVDRAW: Display not initialized when first DeviceGraphicsContext created' errorPrintNL. |
|
3185 |
Workstation initialize |
|
3186 |
]. |
|
3187 |
||
3188 |
super initialize. |
|
3189 |
||
3190 |
foreground := Black. |
|
3191 |
background := White. |
|
3192 |
! |
|
3193 |
||
3194 |
prepareForReinit |
|
3195 |
"kludge - clear drawableId and gcId |
|
3196 |
needed after snapin" |
|
3197 |
||
3198 |
gcId := nil. |
|
3199 |
drawableId := nil. |
|
3200 |
deviceFont := nil |
|
3201 |
! |
|
3202 |
||
3203 |
recreate |
|
3204 |
"sent after a snapin, reinit draw stuff for new device" |
|
3205 |
||
3206 |
gcId := nil. |
|
3207 |
foreground notNil ifTrue:[ |
|
3208 |
foreground := foreground on:device |
|
3209 |
]. |
|
3210 |
background notNil ifTrue:[ |
|
3211 |
background := background on:device |
|
3212 |
]. |
|
3213 |
paint notNil ifTrue:[ |
|
3214 |
paint := paint on:device |
|
3215 |
]. |
|
3216 |
bgPaint notNil ifTrue:[ |
|
3217 |
bgPaint := bgPaint on:device |
|
3218 |
] |
|
3219 |
! |
|
3220 |
||
3221 |
reinitialize |
|
3222 |
'reinit of ' errorPrint. self classNameWithArticle errorPrint. |
|
3223 |
' failed' errorPrintNL |
|
832
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
3224 |
! |
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
3225 |
|
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
3226 |
releaseGC |
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
3227 |
"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
|
3228 |
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
|
3229 |
|
844 | 3230 |
foreground := background := paint := bgPaint := nil. |
832
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
3231 |
gcId notNil ifTrue:[ |
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
3232 |
device destroyGC:gcId. |
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
3233 |
gcId := nil. |
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
3234 |
Lobby registerChange:self. |
844 | 3235 |
]. |
832
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
3236 |
|
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
3237 |
"Created: 11.6.1996 / 22:07:30 / cg" |
844 | 3238 |
"Modified: 12.6.1996 / 20:52:34 / cg" |
732 | 3239 |
! ! |
3240 |
||
3241 |
!DeviceGraphicsContext methodsFor:'instance release'! |
|
3242 |
||
3243 |
disposed |
|
3244 |
"some Drawable has been collected |
|
3245 |
- must release operating system resources" |
|
3246 |
||
3247 |
^ self subclassResponsibility |
|
3248 |
! ! |
|
3249 |
||
3250 |
!DeviceGraphicsContext methodsFor:'private'! |
|
3251 |
||
3252 |
setDevice:aDevice id:aDrawbleId gcId:aGCId |
|
3253 |
"private" |
|
3254 |
||
3255 |
device := aDevice. |
|
3256 |
gcId := aGCId. |
|
3257 |
drawableId := aDrawbleId |
|
3258 |
! |
|
3259 |
||
3260 |
setGCForPaint |
|
3261 |
"private; given a complex color (i.e. a pixmap or dithered color, |
|
3262 |
setup the GC to draw in this color. |
|
3263 |
A helper for paint and paint:on:" |
|
3264 |
||
832
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
3265 |
|dither map pixelId p fg bg vOrg ditherDepth deviceDepth| |
732 | 3266 |
|
3267 |
gcId notNil ifTrue:[ |
|
3268 |
(p := paint) isColor ifTrue:[ |
|
3269 |
paint := p := p on:device. |
|
3270 |
pixelId := p colorId. |
|
3271 |
pixelId notNil ifTrue:[ |
|
3272 |
" |
|
3273 |
a real (undithered) color |
|
3274 |
" |
|
3275 |
mask notNil ifTrue:[ |
|
3276 |
mask := nil. |
|
3277 |
device setBitmapMask:nil in:gcId |
|
3278 |
]. |
|
3279 |
(p ~~ foreground) ifTrue:[ |
|
3280 |
foreground := paint. |
|
3281 |
device setForeground:pixelId in:gcId |
|
3282 |
]. |
|
3283 |
^ self |
|
3284 |
]. |
|
3285 |
"a dithered color" |
|
3286 |
dither := paint ditherForm. |
|
3287 |
] ifFalse:[ |
|
3288 |
"mhmh - seems to be some kind of form ..." |
|
3289 |
paint := paint on:device. |
|
3290 |
dither := paint |
|
3291 |
]. |
|
3292 |
" |
|
3293 |
a dithered color or image |
|
3294 |
" |
|
3295 |
(ditherDepth := dither depth) == 1 ifTrue:[ |
|
3296 |
"a simple 0/1 bitmap" |
|
3297 |
map := dither colorMap. |
|
3298 |
"temporary (kludgy) fix for destroyed paint" |
|
3299 |
p := paint. |
|
3300 |
map isNil ifTrue:[ |
|
3301 |
fg := Color black. |
|
3302 |
bg := Color white. |
|
3303 |
] ifFalse:[ |
|
3304 |
fg := map at:2. |
|
3305 |
bg := map at:1. |
|
3306 |
]. |
|
3307 |
self foreground:fg background:bg. |
|
3308 |
paint := p |
|
3309 |
] ifFalse:[ |
|
832
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
3310 |
deviceDepth := device depth. |
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
3311 |
(ditherDepth ~~ deviceDepth) ifTrue:[ |
732 | 3312 |
dither := dither asFormOn:device. |
832
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
3313 |
ditherDepth := dither depth. |
064890dcfabd
fixed opaque string draw with deep-dither
Claus Gittinger <cg@exept.de>
parents:
786
diff
changeset
|
3314 |
(dither isNil or:[ditherDepth ~~ deviceDepth]) ifTrue:[ |
732 | 3315 |
self error:'bad dither'. |
3316 |
^ self |
|
3317 |
] |
|
3318 |
] |
|
3319 |
]. |
|
3320 |
self mask:dither. |
|
3321 |
vOrg := self viewOrigin. |
|
3322 |
self setMaskOriginX:vOrg x negated y:vOrg y negated. |
|
3323 |
] |
|
3324 |
||
3325 |
"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
|
3326 |
"Modified: 12.6.1996 / 12:49:07 / cg" |
732 | 3327 |
! ! |
3328 |
||
3329 |
!DeviceGraphicsContext methodsFor:'queries'! |
|
3330 |
||
3331 |
horizontalIntegerPixelPerMillimeter |
|
3332 |
"return the (rounded) number of pixels per millimeter" |
|
3333 |
||
3334 |
^ device horizontalPixelPerMillimeter rounded |
|
3335 |
! |
|
3336 |
||
3337 |
horizontalPixelPerInch |
|
3338 |
"return the number of horizontal pixels per inch of the display" |
|
3339 |
||
3340 |
^ device horizontalPixelPerMillimeter * 25.4 |
|
3341 |
! |
|
3342 |
||
3343 |
horizontalPixelPerMillimeter |
|
3344 |
"return the number of pixels per millimeter (not rounded)" |
|
3345 |
||
3346 |
^ device horizontalPixelPerMillimeter |
|
3347 |
! |
|
3348 |
||
3349 |
horizontalPixelPerMillimeter:millis |
|
3350 |
"return the number of pixels (not rounded) for millis millimeter" |
|
3351 |
||
3352 |
^ device horizontalPixelPerMillimeter * millis |
|
3353 |
! |
|
3354 |
||
784 | 3355 |
resolution |
3356 |
"return a point consisting of pixel-per-inch horizontally and vertically." |
|
3357 |
||
3358 |
^ device resolution |
|
3359 |
||
3360 |
"Created: 4.6.1996 / 15:23:55 / cg" |
|
3361 |
! |
|
3362 |
||
732 | 3363 |
verticalIntegerPixelPerMillimeter |
3364 |
"return the (rounded) number of pixels per millimeter" |
|
3365 |
||
3366 |
^ device verticalPixelPerMillimeter rounded |
|
3367 |
! |
|
3368 |
||
3369 |
verticalPixelPerInch |
|
3370 |
"return the number of vertical pixels per inch of the display" |
|
3371 |
||
3372 |
^ device verticalPixelPerMillimeter * 25.4 |
|
3373 |
! |
|
3374 |
||
3375 |
verticalPixelPerMillimeter |
|
3376 |
"return the number of pixels per millimeter (not rounded)" |
|
3377 |
||
3378 |
^ device verticalPixelPerMillimeter |
|
3379 |
! |
|
3380 |
||
3381 |
verticalPixelPerMillimeter:millis |
|
3382 |
"return the number of pixels (not rounded) for millis millimeter" |
|
3383 |
||
3384 |
^ device verticalPixelPerMillimeter * millis |
|
3385 |
! ! |
|
3386 |
||
3387 |
!DeviceGraphicsContext class methodsFor:'documentation'! |
|
3388 |
||
3389 |
version |
|
895
0d49372cded9
if a deep image has a mask, care for it (stamp out & or-in)
Claus Gittinger <cg@exept.de>
parents:
868
diff
changeset
|
3390 |
^ '$Header: /cvs/stx/stx/libview/DeviceGraphicsContext.st,v 1.10 1996-06-21 11:32:40 cg Exp $' |
732 | 3391 |
! ! |
3392 |
DeviceGraphicsContext initialize! |