#FEATURE by cg
authorClaus Gittinger <cg@exept.de>
Thu, 31 Aug 2017 21:41:03 +0200
changeset 8154 065b15ce117a
parent 8153 45bf33d4e1a3
child 8155 5da09f4eaf56
#FEATURE by cg class: DeviceGraphicsContext changed: #displayDeviceOpaqueForm:x:y: images are always drawn with their own color; only form bitmaps may be drawn with paint+bgPaint
DeviceGraphicsContext.st
--- a/DeviceGraphicsContext.st	Thu Aug 31 21:39:58 2017 +0200
+++ b/DeviceGraphicsContext.st	Thu Aug 31 21:41:03 2017 +0200
@@ -1,5 +1,3 @@
-"{ Encoding: utf8 }"
-
 "
  COPYRIGHT (c) 1992 by Claus Gittinger
 	      All Rights Reserved
@@ -1336,11 +1334,16 @@
 !
 
 displayOpaqueForm:formToDraw x:x y:y
-    "draw a form or image opaque;
-     if it's a 1-plane bitmap, 1-bits are drawn in the
-     current paint-color and 0-bits in the bgPaint color.
-     If it's a deep form (i.e. a pixmap) the current paint/bgPaint
-     settings are ignored and the form drawn as-is.
+    "draw a form or image opaque.
+     Somewhat backward compatible hacky:
+     
+     if it's a 1-plane form, 
+        1-bits are drawn in the current paint-color and 
+        0-bits in the bgPaint color.
+     
+     If it's a deep form (i.e. a pixmap) or an image,
+     the current paint/bgPaint settings are ignored and the image is drawn as-is.
+
      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.
@@ -1407,7 +1410,7 @@
     self displayDeviceOpaqueForm:realForm x:pX y:pY
 
     "Modified: / 12-04-1997 / 12:49:02 / cg"
-    "Modified (comment): / 13-02-2017 / 20:00:17 / cg"
+    "Modified (comment): / 31-08-2017 / 19:28:22 / cg"
 !
 
 displayOpaqueString:aString from:index1 to:index2 x:x y:y
@@ -2492,13 +2495,17 @@
     device displayLineFromX:x0 y:y0 toX:x1 y:y1 in:drawableId with:gcId
 !
 
-displayDeviceOpaqueForm:aForm x:x y:y
-    "draw a form or image opaque (i.e. both fg and bg is drawn);
-     If it's a 1-plane bitmap, 1-bits are drawn in the
-     current paint-color and 0-bits in the bgPaint color.
-     If it's a deep form (i.e. a pixmap) the current paint/bgPaint
-     settings are ignored and the form drawn as-is.
-     Any mask is ignored.
+displayDeviceOpaqueForm:aFormOrImage x:x y:y
+    "draw a form or image opaque (i.e. both fg and bg is drawn)
+     Somewhat backward compatible hacky:
+
+     if it's a 1-plane form, 
+        1-bits are drawn in the current paint-color and 
+        0-bits in the bgPaint color.
+
+     If it's a deep form (i.e. a pixmap) or an image,
+     the current paint/bgPaint settings are ignored and the image is drawn as-is.
+
      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.
@@ -2511,12 +2518,11 @@
      pX pY deviceDepth deviceForm deviceFormGCId map savForeground savBackground
      paintClr bgPaintClr|
 
-    deviceForm := aForm asFormOn:device.
+    deviceForm := aFormOrImage asFormOn:device.
     id := deviceForm drawableId.
 
     "temporary ..."
-    (id isNil
-     or:[aForm graphicsDevice ~~ device]) ifTrue:[
+    (id isNil or:[aFormOrImage graphicsDevice ~~ device]) ifTrue:[
         deviceForm := deviceForm asFormOn:device.
         id := deviceForm drawableId.
         id isNil ifTrue:[
@@ -2530,8 +2536,8 @@
     ].
     deviceFormGCId := deviceForm initGC.
 
-    w := aForm width.
-    h := aForm height.
+    w := aFormOrImage width.
+    h := aFormOrImage height.
 
     pX := x rounded.
     pY := y rounded.
@@ -2540,7 +2546,7 @@
      a deep form ignores paint/bgPaint settings
      and is always drawn opaque.
     "
-    (aForm depth ~~ 1) ifTrue:[
+    (aFormOrImage depth ~~ 1) ifTrue:[
         device
             copyFromPixmapId:id
             x:0 y:0 gc:deviceFormGCId
@@ -2552,17 +2558,24 @@
 
     paintClr := paint.
     bgPaintClr := bgPaint.
-    
-    map := aForm colorMap.
-    map notNil ifTrue:[
-        paintClr := map at:2.
-        bgPaintClr := map at:1.
+
+    "/ images are always drawn with its own colors
+    aFormOrImage isImage ifTrue:[
+        paintClr := aFormOrImage colorFromValue:1.
+        bgPaintClr := aFormOrImage colorFromValue:0.
+    ] ifFalse:[
+        "/ a form is drawn in the current paint/bgPaint, 
+        "/ it has an explicit colormap
+        map := aFormOrImage colorMap.
+        map notNil ifTrue:[
+            paintClr := map at:2.
+            bgPaintClr := map at:1.
+        ].
     ].
 
     "/ if no bgPaint is set, this is a non-opaque draw
-
     bgPaintClr isNil ifTrue:[
-        self displayDeviceForm:aForm x:x y:y.
+        self displayDeviceForm:aFormOrImage x:x y:y.
         ^ self
     ].
 
@@ -2607,7 +2620,9 @@
             to:drawableId x:pX y:pY gc:gcId
             width:w height:h.
 
-        device setForegroundColor:foreground backgroundColor:background in:gcId.
+        "/ restore    
+        foreground notNil ifTrue:[ device setForegroundColor:foreground in:gcId ].
+        background notNil ifTrue:[ device setBackgroundColor:background in:gcId ].
         ^ self
     ].
 
@@ -2823,7 +2838,7 @@
     foreground := nil.
     background := nil.
 
-    "Modified: / 15-03-2017 / 12:58:01 / cg"
+    "Modified: / 31-08-2017 / 19:35:55 / cg"
 !
 
 displayDeviceOpaqueString:aStringArg from:index1 to:index2 in:fontArg x:x y:y