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