Applied patch [ 1407318 ] bitmap clipping / transparency mask (X11 port)

By Burkhard Fischer


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@36924 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart
2006-01-17 15:53:56 +00:00
parent a9d9e2f262
commit 2fb0cabbf9

View File

@@ -1170,49 +1170,72 @@ void wxWindowDC::DoDrawBitmap( const wxBitmap &bitmap,
WXPixmap mask = NULL; WXPixmap mask = NULL;
if (use_bitmap.GetMask()) mask = use_bitmap.GetMask()->GetBitmap(); if (use_bitmap.GetMask()) mask = use_bitmap.GetMask()->GetBitmap();
if (useMask && mask) bool setClipMask = false;
if (!m_currentClippingRegion.IsNull() || (useMask && mask))
{ {
WXPixmap new_mask = NULL; // XSetClipMask() call is necessary (because of clip region and/or transparent mask)
#if 0 setClipMask = true;
Pixmap new_pixmap = 0;
if (!m_currentClippingRegion.IsNull()) if (!m_currentClippingRegion.IsNull())
{ {
GdkColor col; // clipping necessary => create new_pixmap
new_mask = gdk_pixmap_new( wxGetRootWindow()->window, ww, hh, 1 ); Display *xdisplay = (Display*) m_display;
GdkGC *gc = gdk_gc_new( new_mask ); int xscreen = DefaultScreen( xdisplay );
col.pixel = 0; Window xroot = RootWindow( xdisplay, xscreen );
gdk_gc_set_foreground( gc, &col );
gdk_draw_rectangle( new_mask, gc, TRUE, 0, 0, ww, hh ); new_pixmap = XCreatePixmap( xdisplay, xroot, w, h, 1 );
col.pixel = 0; GC gc = XCreateGC( xdisplay, new_pixmap, 0, NULL );
gdk_gc_set_background( gc, &col );
col.pixel = 1; int bpp = wxTheApp->GetVisualInfo(m_display)->m_visualDepth;
gdk_gc_set_foreground( gc, &col ); if (bpp == 8)
gdk_gc_set_clip_region( gc, m_currentClippingRegion.GetRegion() ); XSetForeground( xdisplay, gc, WhitePixel(xdisplay,xscreen) );
gdk_gc_set_clip_origin( gc, -xx, -yy ); else
gdk_gc_set_fill( gc, GDK_OPAQUE_STIPPLED ); XSetForeground( xdisplay, gc, BlackPixel(xdisplay,xscreen) );
gdk_gc_set_stipple( gc, mask );
gdk_draw_rectangle( new_mask, gc, TRUE, 0, 0, ww, hh ); XSetFillStyle( xdisplay, gc, FillSolid );
gdk_gc_unref( gc ); XFillRectangle( xdisplay, new_pixmap, gc, 0, 0, w, h );
if (bpp == 8)
XSetForeground( xdisplay, gc, BlackPixel(xdisplay,xscreen) );
else
XSetForeground( xdisplay, gc, WhitePixel(xdisplay,xscreen) );
if (useMask && mask)
{
// transparent mask => call XSetStipple
XSetFillStyle( xdisplay, gc, FillStippled );
XSetTSOrigin( xdisplay, gc, 0, 0);
XSetStipple( xdisplay, gc, (Pixmap) mask);
} }
#endif
wxCoord clip_x, clip_y, clip_w, clip_h;
m_currentClippingRegion.GetBox(clip_x, clip_y, clip_w, clip_h);
XFillRectangle( xdisplay, new_pixmap, gc, clip_x-xx, clip_y-yy, clip_w, clip_h );
XFreeGC( xdisplay, gc );
}
if (is_mono) if (is_mono)
{ {
if (new_mask) if (new_pixmap)
XSetClipMask( (Display*) m_display, (GC) m_textGC, (Pixmap) new_mask ); XSetClipMask( (Display*) m_display, (GC) m_textGC, new_pixmap );
else else
XSetClipMask( (Display*) m_display, (GC) m_textGC, (Pixmap) mask ); XSetClipMask( (Display*) m_display, (GC) m_textGC, (Pixmap) mask );
XSetClipOrigin( (Display*) m_display, (GC) m_textGC, xx, yy ); XSetClipOrigin( (Display*) m_display, (GC) m_textGC, xx, yy );
} }
else else
{ {
if (new_mask) if (new_pixmap)
XSetClipMask( (Display*) m_display, (GC) m_penGC, (Pixmap) new_mask ); XSetClipMask( (Display*) m_display, (GC) m_penGC, new_pixmap );
else else
XSetClipMask( (Display*) m_display, (GC) m_penGC, (Pixmap) mask ); XSetClipMask( (Display*) m_display, (GC) m_penGC, (Pixmap) mask );
XSetClipOrigin( (Display*) m_display, (GC) m_penGC, xx, yy ); XSetClipOrigin( (Display*) m_display, (GC) m_penGC, xx, yy );
} }
if (new_mask) if (new_pixmap)
XFreePixmap( (Display*) m_display, (Pixmap) new_mask ); XFreePixmap( (Display*) m_display, new_pixmap );
} }
// Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For // Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For
@@ -1225,7 +1248,7 @@ void wxWindowDC::DoDrawBitmap( const wxBitmap &bitmap,
(GC) m_penGC, 0, 0, w, h, xx, yy ); (GC) m_penGC, 0, 0, w, h, xx, yy );
// remove mask again if any // remove mask again if any
if (useMask && mask) if (setClipMask)
{ {
if (is_mono) if (is_mono)
{ {