diff src/w32term.c @ 48345:44c0f878e8b9

(x_draw_image_foreground, x_draw_image_glyph_string) (w32_draw_image_foreground_1): Handle image masks. (x_draw_image_glyph_string): Don't BitBlt transparently.
author Jason Rumney <jasonr@gnu.org>
date Fri, 15 Nov 2002 18:55:19 +0000
parents 01e253345507
children 9fde360ca455
line wrap: on
line diff
--- a/src/w32term.c	Fri Nov 15 18:51:53 2002 +0000
+++ b/src/w32term.c	Fri Nov 15 18:55:19 2002 +0000
@@ -3888,58 +3888,40 @@
 
   if (s->img->pixmap)
     {
-#if 0 /* TODO: image mask */
+      HDC compat_hdc = CreateCompatibleDC (s->hdc);
+      HBRUSH fg_brush = CreateSolidBrush (s->gc->foreground);
+      HBRUSH orig_brush = SelectObject (s->hdc, fg_brush);
+      HGDIOBJ orig_obj = SelectObject (compat_hdc, s->img->pixmap);
+      SetBkColor (compat_hdc, RGB (255, 255, 255));
+      SetTextColor (s->hdc, RGB (0, 0, 0));
+      x_set_glyph_string_clipping (s);
+
       if (s->img->mask)
 	{
-	  /* We can't set both a clip mask and use XSetClipRectangles
-	     because the latter also sets a clip mask.  We also can't
-	     trust on the shape extension to be available
-	     (XShapeCombineRegion).  So, compute the rectangle to draw
-	     manually.  */
-	  unsigned long mask = (GCClipMask | GCClipXOrigin | GCClipYOrigin
-				| GCFunction);
-	  XGCValues xgcv;
-	  XRectangle clip_rect, image_rect, r;
-
-	  xgcv.clip_mask = s->img->mask;
-	  xgcv.clip_x_origin = x;
-	  xgcv.clip_y_origin = y;
-	  xgcv.function = GXcopy;
-	  XChangeGC (s->display, s->gc, mask, &xgcv);
-
-	  w32_get_glyph_string_clip_rect (s, &clip_rect);
-	  image_rect.x = x;
-	  image_rect.y = y;
-	  image_rect.width = s->img->width;
-	  image_rect.height = s->img->height;
-	  if (IntersectRect (&r, &clip_rect, &image_rect))
-	    XCopyArea (s->display, s->img->pixmap, s->window, s->gc,
-		       r.x - x, r.y - y, r.width, r.height, r.x, r.y);
+	  HDC mask_dc = CreateCompatibleDC (s->hdc);
+	  HGDIOBJ mask_orig_obj = SelectObject (mask_dc, s->img->mask);
+
+	  SetTextColor (s->hdc, RGB (255, 255, 255));
+	  SetBkColor (s->hdc, RGB (0, 0, 0));
+
+	  BitBlt (s->hdc, x, y, s->img->width, s->img->height,
+		  compat_hdc, 0, 0, 0x990066);
+	  BitBlt (s->hdc, x, y, s->img->width, s->img->height,
+		  mask_dc, 0, 0, SRCAND);
+	  BitBlt (s->hdc, x, y, s->img->width, s->img->height,
+		  compat_hdc, 0, 0, 0x990066);
+
+	  SelectObject (mask_dc, mask_orig_obj);
+	  DeleteDC (mask_dc);
 	}
       else
-#endif
 	{
-          HDC compat_hdc = CreateCompatibleDC (s->hdc);
-          HBRUSH fg_brush = CreateSolidBrush (s->gc->foreground);
-          HBRUSH orig_brush = SelectObject (s->hdc, fg_brush);
-          HGDIOBJ orig_obj = SelectObject (compat_hdc, s->img->pixmap);
-          x_set_glyph_string_clipping (s);
-
-          SetTextColor (s->hdc, s->gc->foreground);
-          SetBkColor (s->hdc, s->gc->background);
-#if 0 /* From w32bdf.c (which is from Meadow).  */
+	  SetTextColor (s->hdc, s->gc->foreground);
+	  SetBkColor (s->hdc, s->gc->background);
+
           BitBlt (s->hdc, x, y, s->img->width, s->img->height,
-                  compat_hdc, 0, 0, SRCCOPY);
-          BitBlt (s->hdc, x, y, s->img->width, s->img->height,
-                  compat_hdc, 0, 0, 0xB8074A);
-#else
-          BitBlt (s->hdc, x, y, s->img->width, s->img->height,
-                  compat_hdc, 0, 0, 0xE20746);
-#endif
-          SelectObject (s->hdc, orig_brush);
-          DeleteObject (fg_brush);
-	  SelectObject (compat_hdc, orig_obj);
-          DeleteDC (compat_hdc);
+                  compat_hdc, 0, 0, NOTSRCCOPY);
+	  /* Meadow uses 0xE20746, previously SRCCOPY and 0xB8074A.  */
 
 	  /* When the image has a mask, we can expect that at
 	     least part of a mouse highlight or a block cursor will
@@ -3954,8 +3936,13 @@
 	      w32_draw_rectangle (s->hdc, s->gc, x - r, y - r ,
 				  s->img->width + r*2 - 1, s->img->height + r*2 - 1);
 	    }
-          w32_set_clip_rectangle (s->hdc, NULL);
 	}
+
+      w32_set_clip_rectangle (s->hdc, NULL);
+      SelectObject (s->hdc, orig_brush);
+      DeleteObject (fg_brush);
+      SelectObject (compat_hdc, orig_obj);
+      DeleteDC (compat_hdc);
     }
   else
     w32_draw_rectangle (s->hdc, s->gc, x, y, s->img->width -1,
@@ -4040,51 +4027,35 @@
 
   if (s->img->pixmap)
     {
-#if 0 /* TODO: image mask */
+      HDC compat_hdc = CreateCompatibleDC (hdc);
+      HBRUSH fg_brush = CreateSolidBrush (s->gc->foreground);
+      HBRUSH orig_brush = SelectObject (hdc, fg_brush);
+      HGDIOBJ orig_obj = SelectObject (compat_hdc, s->img->pixmap);
+
       if (s->img->mask)
 	{
-	  /* We can't set both a clip mask and use XSetClipRectangles
-	     because the latter also sets a clip mask.  We also can't
-	     trust on the shape extension to be available
-	     (XShapeCombineRegion).  So, compute the rectangle to draw
-	     manually.  */
-	  unsigned long mask = (GCClipMask | GCClipXOrigin | GCClipYOrigin
-				| GCFunction);
-	  XGCValues xgcv;
-
-	  xgcv.clip_mask = s->img->mask;
-	  xgcv.clip_x_origin = x;
-	  xgcv.clip_y_origin = y;
-	  xgcv.function = GXcopy;
-	  XChangeGC (s->display, s->gc, mask, &xgcv);
-
-	  XCopyArea (s->display, s->img->pixmap, pixmap, s->gc,
-		     0, 0, s->img->width, s->img->height, x, y);
-	  XSetClipMask (s->display, s->gc, None);
+	  HDC mask_dc = CreateCompatibleDC (hdc);
+	  HGDIOBJ mask_orig_obj = SelectObject (mask_dc, s->img->mask);
+
+	  SetTextColor (hdc, RGB (0, 0, 0));
+	  SetBkColor (hdc, RGB (255, 255, 255));
+	  BitBlt (hdc, x, y, s->img->width, s->img->height,
+		  compat_hdc, 0, 0, SRCINVERT);
+	  BitBlt (hdc, x, y, s->img->width, s->img->height,
+		  mask_dc, 0, 0, SRCAND);
+	  BitBlt (hdc, x, y, s->img->width, s->img->height,
+		  compat_hdc, 0, 0, SRCINVERT);
+
+	  SelectObject (mask_dc, mask_orig_obj);
+	  DeleteDC (mask_dc);
 	}
       else
-#endif
 	{
-          HDC compat_hdc = CreateCompatibleDC (hdc);
-          HBRUSH fg_brush = CreateSolidBrush (s->gc->foreground);
-          HBRUSH orig_brush = SelectObject (hdc, fg_brush);
-          HGDIOBJ orig_obj = SelectObject (compat_hdc, s->img->pixmap);
-
-          SetTextColor (hdc, s->gc->foreground);
-          SetBkColor (hdc, s->gc->background);
-#if 0 /* From w32bdf.c (which is from Meadow).  */
+	  SetTextColor (hdc, s->gc->foreground);
+	  SetBkColor (hdc, s->gc->background);
+
           BitBlt (hdc, x, y, s->img->width, s->img->height,
-                  compat_hdc, 0, 0, SRCCOPY);
-          BitBlt (hdc, x, y, s->img->width, s->img->height,
-                  compat_hdc, 0, 0, 0xB8074A);
-#else
-          BitBlt (hdc, x, y, s->img->width, s->img->height,
-                  compat_hdc, 0, 0, 0xE20746);
-#endif
-          SelectObject (hdc, orig_brush);
-          DeleteObject (fg_brush);
-	  SelectObject (compat_hdc, orig_obj);
-          DeleteDC (compat_hdc);
+                  compat_hdc, 0, 0, NOTSRCCOPY);
 
 	  /* When the image has a mask, we can expect that at
 	     least part of a mouse highlight or a block cursor will
@@ -4096,10 +4067,15 @@
 	    {
 	      int r = s->img->relief;
 	      if (r < 0) r = -r;
-	      w32_draw_rectangle (s->hdc, s->gc, x - r, y - r ,
+	      w32_draw_rectangle (hdc, s->gc, x - r, y - r ,
 				  s->img->width + r*2 - 1, s->img->height + r*2 - 1);
 	    }
 	}
+
+      SelectObject (hdc, orig_brush);
+      DeleteObject (fg_brush);
+      SelectObject (compat_hdc, orig_obj);
+      DeleteDC (compat_hdc);
     }
   else
     w32_draw_rectangle (hdc, s->gc, x, y, s->img->width - 1,
@@ -4165,9 +4141,7 @@
   if (height > s->img->height
       || s->img->hmargin
       || s->img->vmargin
-#if 0 /* TODO: image mask */
       || s->img->mask
-#endif
       || s->img->pixmap == 0
       || s->width != s->background_width)
     {
@@ -4177,7 +4151,7 @@
 	x = s->x;
 
       y = s->y + box_line_vwidth;
-#if 0 /* TODO: image mask */
+#if 0 /* TODO: figure out if we need to do this on Windows.  */
       if (s->img->mask)
 	{
 	  /* Create a pixmap as large as the glyph string.  Fill it
@@ -4235,15 +4209,9 @@
 
         SetTextColor (s->hdc, s->gc->foreground);
         SetBkColor (s->hdc, s->gc->background);
-#if 0 /* From w32bdf.c (which is from Meadow).  */
         BitBlt (s->hdc, s->x, s->y, s->background_width, s->height,
                 compat_hdc, 0, 0, SRCCOPY);
-        BitBlt (s->hdc, s->x, s->y, s->background_width, s->height,
-                compat_hdc, 0, 0, 0xB8074A);
-#else
-        BitBlt (s->hdc, s->x, s->y, s->background_width, s->height,
-                compat_hdc, 0, 0, 0xE20746);
-#endif
+
         SelectObject (s->hdc, orig_brush);
         DeleteObject (fg_brush);
         SelectObject (compat_hdc, orig_obj);
@@ -6586,7 +6554,6 @@
 	    }
 	}
     }
-
 #if 0 /* TODO: mouse cursor */
   XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), cursor);
 #endif