--- a/DeviceGraphicsContext.st Sat Apr 12 12:37:00 1997 +0200
+++ b/DeviceGraphicsContext.st Sat Apr 12 12:50:17 1997 +0200
@@ -1104,7 +1104,8 @@
!
displayForm:formToDraw x:x y:y
- "draw a form; if its a 1-plane bitmap, 1-bits are drawn in the
+ "draw a form or image non opaque;
+ if its a 1-plane bitmap, 1-bits are drawn in the
current paint-color, leaving pixels with 0-bits unchanged
(i.e. only 1-bits are drawn from the form).
If its a deep form (i.e. a pixmap) the current paint
@@ -1120,51 +1121,49 @@
realForm := formToDraw.
transformation notNil ifTrue:[
- pX := transformation applyToX:x.
- pY := transformation applyToY:y.
-
- transformation noScale ifFalse:[
- w := formToDraw width.
- h := formToDraw height.
-
- nW := (transformation applyScaleX:w) rounded.
- nH := (transformation applyScaleY:h) rounded.
-
- ((nW ~= w) or:[nH ~= h]) ifTrue:[
- "/
- "/ hard case - someone is drawing forms with scaling in effect
- "/ look if we have a scaled version in our pocket ...
- "/
- realForm := nil.
- CachedScaledForms notNil ifTrue:[
- (CachedScales at:formToDraw ifAbsent:nil) = transformation scale ifTrue:[
- realForm := CachedScaledForms at:formToDraw ifAbsent:nil.
- ]
- ].
- realForm isNil ifTrue:[
- "/
- "/ nope - must do the work ...
- "/
- realForm := formToDraw magnifiedBy:(nW / w) @ (nH / h).
- CachedScaledForms isNil ifTrue:[
- CachedScaledForms := WeakIdentityDictionary new.
- CachedScales := WeakIdentityDictionary new.
- ].
- CachedScaledForms at:formToDraw put:realForm.
- CachedScales at:formToDraw put:transformation scale.
- ]
- ]
- ]
+ pX := transformation applyToX:x.
+ pY := transformation applyToY:y.
+
+ transformation noScale ifFalse:[
+ w := formToDraw width.
+ h := formToDraw height.
+
+ nW := (transformation applyScaleX:w) rounded.
+ nH := (transformation applyScaleY:h) rounded.
+
+ ((nW ~= w) or:[nH ~= h]) ifTrue:[
+ "/
+ "/ hard case - someone is drawing forms with scaling in effect
+ "/ look if we have a scaled version in our pocket ...
+ "/
+ realForm := nil.
+ CachedScaledForms notNil ifTrue:[
+ (CachedScales at:formToDraw ifAbsent:nil) = transformation scale ifTrue:[
+ realForm := CachedScaledForms at:formToDraw ifAbsent:nil.
+ ]
+ ].
+ realForm isNil ifTrue:[
+ "/
+ "/ nope - must do the work ...
+ "/
+ realForm := formToDraw magnifiedBy:(nW / w) @ (nH / h).
+ CachedScaledForms isNil ifTrue:[
+ CachedScaledForms := WeakIdentityDictionary new.
+ CachedScales := WeakIdentityDictionary new.
+ ].
+ CachedScaledForms at:formToDraw put:realForm.
+ CachedScales at:formToDraw put:transformation scale.
+ ]
+ ]
+ ]
] ifFalse:[
- pX := x.
- pY := y.
+ pX := x.
+ pY := y.
].
- pX := pX rounded.
- pY := pY rounded.
self displayDeviceForm:realForm x:pX y:pY
- "Modified: 21.5.1996 / 21:15:44 / cg"
+ "Modified: 12.4.1997 / 12:47:29 / cg"
!
displayLineFromX:x0 y:y0 toX:x1 y:y1
@@ -1232,7 +1231,8 @@
!
displayOpaqueForm:formToDraw x:x y:y
- "draw a form; if its a 1-plane bitmap, 1-bits are drawn in the
+ "draw a form or image opaque;
+ if its a 1-plane bitmap, 1-bits are drawn in the
current paint-color and 0-bits in the bgPaint color.
If its a deep form (i.e. a pixmap) the current paint/bgPaint
settings are ignored and the form drawn as-is.
@@ -1244,62 +1244,59 @@
|w h realForm pX pY nW nH|
bgPaint isNil ifTrue:[
- "/
- "/ actually not an opaque draw
- "/
- self displayForm:formToDraw x:x y:y.
- ^ self
+ "/
+ "/ actually not an opaque draw
+ "/
+ self displayForm:formToDraw x:x y:y.
+ ^ self
].
realForm := formToDraw.
transformation notNil ifTrue:[
- pX := transformation applyToX:x.
- pY := transformation applyToY:y.
-
- transformation noScale ifFalse:[
- w := formToDraw width.
- h := formToDraw height.
-
- nW := (transformation applyScaleX:w) rounded.
- nH := (transformation applyScaleY:h) rounded.
-
- ((nW ~= w) or:[nH ~= h]) ifTrue:[
- "/
- "/ hard case - someone is drawing forms with scaling in effect
- "/ look if we have a scaled version in our pocket ...
- "/
- realForm := nil.
- CachedScaledForms notNil ifTrue:[
- (CachedScales at:formToDraw ifAbsent:nil) = transformation scale ifTrue:[
- realForm := CachedScaledForms at:formToDraw ifAbsent:nil.
- ]
- ].
- realForm isNil ifTrue:[
- "/
- "/ nope - must do the work ...
- "/
- realForm := formToDraw magnifiedBy:(nW / w) @ (nH / h).
- CachedScaledForms isNil ifTrue:[
- CachedScaledForms := WeakIdentityDictionary new.
- CachedScales := WeakIdentityDictionary new.
- ].
- CachedScaledForms at:formToDraw put:realForm.
- CachedScales at:formToDraw put:transformation scale.
- ]
- ]
- ]
+ pX := transformation applyToX:x.
+ pY := transformation applyToY:y.
+
+ transformation noScale ifFalse:[
+ w := formToDraw width.
+ h := formToDraw height.
+
+ nW := (transformation applyScaleX:w) rounded.
+ nH := (transformation applyScaleY:h) rounded.
+
+ ((nW ~= w) or:[nH ~= h]) ifTrue:[
+ "/
+ "/ hard case - someone is drawing forms with scaling in effect
+ "/ look if we have a scaled version in our pocket ...
+ "/
+ realForm := nil.
+ CachedScaledForms notNil ifTrue:[
+ (CachedScales at:formToDraw ifAbsent:nil) = transformation scale ifTrue:[
+ realForm := CachedScaledForms at:formToDraw ifAbsent:nil.
+ ]
+ ].
+ realForm isNil ifTrue:[
+ "/
+ "/ nope - must do the work ...
+ "/
+ realForm := formToDraw magnifiedBy:(nW / w) @ (nH / h).
+ CachedScaledForms isNil ifTrue:[
+ CachedScaledForms := WeakIdentityDictionary new.
+ CachedScales := WeakIdentityDictionary new.
+ ].
+ CachedScaledForms at:formToDraw put:realForm.
+ CachedScales at:formToDraw put:transformation scale.
+ ]
+ ]
+ ]
] ifFalse:[
- pX := x.
- pY := y.
+ pX := x.
+ pY := y.
].
- pX := pX rounded.
- pY := pY rounded.
-
self displayDeviceOpaqueForm:realForm x:pX y:pY
- "Modified: 21.5.1996 / 21:15:54 / cg"
+ "Modified: 12.4.1997 / 12:49:02 / cg"
!
displayOpaqueString:aString from:index1 to:index2 x:x y:y
@@ -1809,7 +1806,8 @@
!
displayUnscaledForm:formToDraw x:x y:y
- "draw a form; if its a 1-plane bitmap, 1-bits are drawn in the
+ "draw a form or image non opaque and unscaled;
+ if its a 1-plane bitmap, 1-bits are drawn in the
current paint-color, leaving pixels with 0-bits unchanged
(i.e. only 1-bits are drawn from the form).
If its a deep form (i.e. a pixmap) the current paint
@@ -1824,20 +1822,21 @@
|pX pY|
transformation notNil ifTrue:[
- pX := transformation applyToX:x.
- pY := transformation applyToY:y.
+ pX := transformation applyToX:x.
+ pY := transformation applyToY:y.
] ifFalse:[
- pX := x.
- pY := y.
+ pX := x.
+ pY := y.
].
- pX := pX rounded.
- pY := pY rounded.
self displayDeviceForm:formToDraw x:pX y:pY
+
+ "Modified: 12.4.1997 / 12:48:04 / cg"
!
displayUnscaledOpaqueForm:formToDraw x:x y:y
- "draw a form; if its a 1-plane bitmap, 1-bits are drawn in the
+ "draw a form or image opaque and unscaled;
+ if its a 1-plane bitmap, 1-bits are drawn in the
current paint-color, 0 bits in background color.
If its a deep form (i.e. a pixmap) the current paint
settings are ignored and the form is drawn as-is (opaque).
@@ -1846,16 +1845,16 @@
|pX pY|
transformation notNil ifTrue:[
- pX := transformation applyToX:x.
- pY := transformation applyToY:y.
+ pX := transformation applyToX:x.
+ pY := transformation applyToY:y.
] ifFalse:[
- pX := x.
- pY := y.
+ pX := x.
+ pY := y.
].
- pX := pX rounded.
- pY := pY rounded.
self displayDeviceOpaqueForm:formToDraw x:pX y:pY
+
+ "Modified: 12.4.1997 / 12:49:21 / cg"
!
displayUnscaledOpaqueString:aString from:index1 to:index2 x:x y:y
@@ -1925,13 +1924,17 @@
!DeviceGraphicsContext methodsFor:'drawing in device coordinates'!
displayDeviceForm:aForm x:x y:y
- "draw a form; if its a 1-plane bitmap, 1-bits are drawn in the
+ "draw a form or image non opaque (i.e. only foreground color is drawn);
+ If its a 1-plane bitmap, 1-bits are drawn in the
current paint-color, leaving pixels with 0-bits unchanged
(i.e. only 1-bits are drawn from the form).
- The form must have been allocated on the same device.
+ If its a deep form (i.e. a pixmap) the current paint
+ settings are ignored and the form is drawn as-is;
+ however, the mask is applied if present.
+
+ The form should must have been allocated on the same device,
+ otherwise its converted here, which slows down the draw.
No transformation or scaling is done.
- If its a deep form (i.e. a pixmap) the current paint
- settings are ignored and the form is drawn as-is.
Care must be taken, that the paint color is correctly allocated
(by sending #on: to the color) before doing so.
Using functions other than #copy only makes sense if you are
@@ -1973,102 +1976,142 @@
deviceMask := mask asFormOn:device.
maskId := deviceMask id.
maskId notNil ifTrue:[
- "
- create temp-form;
- "
- tmpForm := Form width:w height:h depth:device depth on:device.
- tmpForm initGC.
- tmpId := tmpForm id.
- tmpGCId := tmpForm gcId.
-
- "
- fill tempform with image
- "
- aForm depth == 1 ifTrue:[
- (colorMap := aForm colorMap) notNil ifTrue:[
- device
- setForeground:((colorMap at:2) on:device) colorId
- background:((colorMap at:1) on:device) colorId
- in:tmpGCId.
- ].
+ allColor := Color allColor.
+ allBits := allColor colorId.
+
+ aForm maskedPixelsAre0 ifTrue:[
+ "/ can do it without a temporary pixmap:
+ "/ or-in the form into the inverse stamped-out area
+ "/ of the destination.
+ "/ Oring is of course only possible if we know that
+ "/ masked pixels are already zero in the form.
+
+ "/ stamp out using mask
+ device setForeground:0 background:allBits in:gcId.
+ device setFunction:#and in:gcId.
device
- copyPlaneFromPixmapId:id
+ copyPlaneFromPixmapId:maskId
x:0
y:0
+ gc:(deviceMask gcId)
+ to:drawableId
+ x:pX
+ y:pY
gc:gcId
- to:tmpId
- x:0
- y:0
- gc:tmpGCId
width:w
height:h.
- ] ifFalse:[
+ "/ or-in the form
+ device setFunction:#or in:gcId.
device
copyFromPixmapId:id
x:0
y:0
+ gc:(deviceForm gcId)
+ to:drawableId
+ x:pX
+ y:pY
gc:gcId
+ width:w
+ height:h.
+
+ ] ifFalse:[
+ "/ must do it slow, using a temporary form ..
+
+ "
+ create temp-form;
+ "
+ tmpForm := Form width:w height:h depth:device depth on:device.
+ tmpForm initGC.
+ tmpId := tmpForm id.
+ tmpGCId := tmpForm gcId.
+
+ "
+ fill tempform with image
+ "
+ aForm depth == 1 ifTrue:[
+ (colorMap := aForm colorMap) notNil ifTrue:[
+ device
+ setForeground:((colorMap at:2) on:device) colorId
+ background:((colorMap at:1) on:device) colorId
+ in:tmpGCId.
+ ].
+ device
+ copyPlaneFromPixmapId:id
+ x:0
+ y:0
+ gc:gcId
+ to:tmpId
+ x:0
+ y:0
+ gc:tmpGCId
+ width:w
+ height:h.
+ ] ifFalse:[
+ device
+ copyFromPixmapId:id
+ x:0
+ y:0
+ gc:gcId
+ to:tmpId
+ x:0
+ y:0
+ gc:tmpGCId
+ width:w
+ height:h.
+ ].
+
+ "
+ stamp out mask in temp form
+ "
+ device setForeground:allBits background:0 in:tmpForm gcId.
+ device setFunction:#and in:tmpForm gcId.
+ device
+ copyPlaneFromPixmapId:maskId
+ x:0
+ y:0
+ gc:(deviceMask gcId)
to:tmpId
x:0
y:0
gc:tmpGCId
width:w
height:h.
+
+ "
+ stamp out mask in destination
+ "
+ device setForeground:0 background:allBits in:gcId.
+ device setFunction:#and in:gcId.
+ device
+ copyPlaneFromPixmapId:maskId
+ x:0
+ y:0
+ gc:(deviceMask gcId)
+ to:drawableId
+ x:pX
+ y:pY
+ gc:gcId
+ width:w
+ height:h.
+
+ "
+ or-in tempform-bits ...
+ "
+ device setFunction:#or in:gcId.
+ device
+ copyFromPixmapId:tmpId
+ x:0
+ y:0
+ gc:tmpGCId
+ to:drawableId
+ x:pX
+ y:pY
+ gc:gcId
+ width:w
+ height:h.
].
- allColor := Color allColor.
- allBits := allColor colorId.
-
- "
- stamp out mask in temp form
- "
- device setForeground:allBits background:0 in:tmpForm gcId.
- device setFunction:#and in:tmpForm gcId.
- device
- copyPlaneFromPixmapId:maskId
- x:0
- y:0
- gc:(deviceMask gcId)
- to:tmpId
- x:0
- y:0
- gc:tmpGCId
- width:w
- height:h.
-
- "
- stamp out mask in destination
- "
- device setForeground:0 background:allBits in:gcId.
- device setFunction:#and in:gcId.
- device
- copyPlaneFromPixmapId:maskId
- x:0
- y:0
- gc:(deviceMask gcId)
- to:drawableId
- x:pX
- y:pY
- gc:gcId
- width:w
- height:h.
-
- "
- or-in tempform-bits ...
- "
- device setFunction:#or in:gcId.
- device
- copyFromPixmapId:tmpId
- x:0
- y:0
- gc:tmpGCId
- to:drawableId
- x:pX
- y:pY
- gc:gcId
- width:w
- height:h.
-
+ "/ restore GC
foreground notNil ifTrue:[
device setForeground:foreground colorId in:gcId.
].
@@ -2279,7 +2322,7 @@
background := nil.
device setFunction:function in:gcId.
- "Modified: 1.4.1997 / 20:00:12 / cg"
+ "Modified: 12.4.1997 / 12:46:41 / cg"
!
displayDeviceLineFromX:x0 y:y0 toX:x1 y:y1
@@ -2293,26 +2336,23 @@
!
displayDeviceOpaqueForm:aForm x:x y:y
- "draw a form; if its a 1-plane bitmap, 1-bits are drawn in the
+ "draw a form or image opaque (i.e. both fg and bg is drawn);
+ If its a 1-plane bitmap, 1-bits are drawn in the
current paint-color and 0-bits in the bgPaint color.
If its a deep form (i.e. a pixmap) the current paint/bgPaint
settings are ignored and the form drawn as-is.
+ Any mask is ignored.
In the 1-plane case, special care must be taken if paint and/or bgPaint
dithered colors or patterns, since are that the colors are correctly allocated (by sending #on:
to the colors) before doing so.
- The form must have been allocated on the same device.
+ The form should have been allocated on the same device; otherwise,
+ its converted here, which slows down the draw.
Drawing is in device coordinates; no scaling is done."
|id w h easy savedPaint bgForm fgForm tmpForm
fgId bgId noColor allColor allBits dx dy
pX pY deviceDepth deviceForm|
- w := aForm width.
- h := aForm height.
-
- pX := x rounded.
- pY := y rounded.
-
deviceForm := aForm asFormOn:device.
id := deviceForm id.
@@ -2331,6 +2371,12 @@
self initGC
].
+ w := aForm width.
+ h := aForm height.
+
+ pX := x rounded.
+ pY := y rounded.
+
"
a deep form ignores paint/bgPaint settings
and is always drawn opaque.
@@ -2608,7 +2654,7 @@
foreground := nil.
background := nil.
- "Modified: 18.1.1997 / 17:13:35 / cg"
+ "Modified: 12.4.1997 / 12:43:09 / cg"
!
displayDeviceOpaqueString:aString from:index1 to:index2 in:font x:x y:y
@@ -3603,6 +3649,6 @@
!DeviceGraphicsContext class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libview/DeviceGraphicsContext.st,v 1.35 1997-04-02 18:15:21 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libview/DeviceGraphicsContext.st,v 1.36 1997-04-12 10:50:17 cg Exp $'
! !
DeviceGraphicsContext initialize!