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