X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3cd0b8c5b5a320bba065c4da306be3687d144157..cd560c961a09a8ae80b9c32856e195ed784cc547:/src/x11/dcclient.cpp?ds=sidebyside diff --git a/src/x11/dcclient.cpp b/src/x11/dcclient.cpp index 44b06b29b7..04c54e565e 100644 --- a/src/x11/dcclient.cpp +++ b/src/x11/dcclient.cpp @@ -225,7 +225,6 @@ void wxWindowDC::SetUpDC() m_textGC = (WXGC*) wxGetPoolGC( (Window) m_window, wxTEXT_SCREEN ); m_bgGC = (WXGC*) wxGetPoolGC( (Window) m_window, wxBG_SCREEN ); } -#if 0 else if (m_isMemDC && (((wxMemoryDC*)this)->m_selected.GetDepth() == 1)) { @@ -234,7 +233,6 @@ void wxWindowDC::SetUpDC() m_textGC = (WXGC*) wxGetPoolGC( (Window) m_window, wxTEXT_MONO ); m_bgGC = (WXGC*) wxGetPoolGC( (Window) m_window, wxBG_MONO ); } -#endif else { m_penGC = (WXGC*) wxGetPoolGC( (Window) m_window, wxPEN_COLOUR ); @@ -257,6 +255,11 @@ void wxWindowDC::SetUpDC() XSetFillStyle( (Display*) m_display, (GC) m_textGC, FillSolid ); +#if wxUSE_NANOX + // By default, draw transparently + GrSetGCUseBackground((GC) m_textGC, FALSE); +#endif + /* m_penGC */ m_pen.GetColour().CalcPixel( m_cmap ); XSetForeground( (Display*) m_display, (GC) m_penGC, m_pen.GetColour().GetPixel() ); @@ -290,13 +293,16 @@ void wxWindowDC::SetUpDC() if (!hatch_bitmap) { + int xscreen = DefaultScreen( (Display*) m_display ); + Window xroot = RootWindow( (Display*) m_display, xscreen ); + hatch_bitmap = hatches; - hatch_bitmap[0] = XCreateBitmapFromData( (Display*) m_display, None, bdiag_bits, bdiag_width, bdiag_height ); - hatch_bitmap[1] = XCreateBitmapFromData( (Display*) m_display, None, cdiag_bits, cdiag_width, cdiag_height ); - hatch_bitmap[2] = XCreateBitmapFromData( (Display*) m_display, None, fdiag_bits, fdiag_width, fdiag_height ); - hatch_bitmap[3] = XCreateBitmapFromData( (Display*) m_display, None, cross_bits, cross_width, cross_height ); - hatch_bitmap[4] = XCreateBitmapFromData( (Display*) m_display, None, horiz_bits, horiz_width, horiz_height ); - hatch_bitmap[5] = XCreateBitmapFromData( (Display*) m_display, None, verti_bits, verti_width, verti_height ); + hatch_bitmap[0] = XCreateBitmapFromData( (Display*) m_display, xroot, bdiag_bits, bdiag_width, bdiag_height ); + hatch_bitmap[1] = XCreateBitmapFromData( (Display*) m_display, xroot, cdiag_bits, cdiag_width, cdiag_height ); + hatch_bitmap[2] = XCreateBitmapFromData( (Display*) m_display, xroot, fdiag_bits, fdiag_width, fdiag_height ); + hatch_bitmap[3] = XCreateBitmapFromData( (Display*) m_display, xroot, cross_bits, cross_width, cross_height ); + hatch_bitmap[4] = XCreateBitmapFromData( (Display*) m_display, xroot, horiz_bits, horiz_width, horiz_height ); + hatch_bitmap[5] = XCreateBitmapFromData( (Display*) m_display, xroot, verti_bits, verti_width, verti_height ); } } @@ -740,7 +746,7 @@ void wxWindowDC::DoDrawRectangle( wxCoord x, wxCoord y, wxCoord width, wxCoord h if (m_pen.GetStyle () != wxTRANSPARENT) { XDrawRectangle( (Display*) m_display, (Window) m_window, - (GC) m_penGC, xx, yy, ww, hh ); + (GC) m_penGC, xx, yy, ww-1, hh-1 ); } } @@ -834,6 +840,7 @@ void wxWindowDC::DoDrawIcon( const wxIcon &icon, wxCoord x, wxCoord y) { } +#if wxUSE_NANOX void wxWindowDC::DoDrawBitmap( const wxBitmap &bitmap, wxCoord x, wxCoord y, bool useMask ) @@ -842,7 +849,125 @@ void wxWindowDC::DoDrawBitmap( const wxBitmap &bitmap, wxCHECK_RET( bitmap.Ok(), wxT("invalid bitmap") ); + bool is_mono = (bitmap.GetBitmap() != NULL); + + /* scale/translate size and position */ + int xx = XLOG2DEV(x); + int yy = YLOG2DEV(y); + + int w = bitmap.GetWidth(); + int h = bitmap.GetHeight(); + + CalcBoundingBox( x, y ); + CalcBoundingBox( x + w, y + h ); + + if (!m_window) return; + + int ww = XLOG2DEVREL(w); + int hh = YLOG2DEVREL(h); + + /* compare to current clipping region */ + if (!m_currentClippingRegion.IsNull()) + { + wxRegion tmp( xx,yy,ww,hh ); + tmp.Intersect( m_currentClippingRegion ); + if (tmp.IsEmpty()) + return; + } + + /* scale bitmap if required */ + wxBitmap use_bitmap; + if ((w != ww) || (h != hh)) + { + wxImage image( bitmap ); + image.Rescale( ww, hh ); +#if 0 + if (is_mono) + use_bitmap = image.ConvertToMonoBitmap(255,255,255); + else +#endif + use_bitmap = image.ConvertToBitmap(); + } + else + { + use_bitmap = bitmap; + } + + /* apply mask if any */ + WXPixmap mask = NULL; + if (use_bitmap.GetMask()) + mask = use_bitmap.GetMask()->GetBitmap(); + + if (useMask && mask) + { + Pixmap pixmap = (Pixmap) use_bitmap.GetPixmap() ; + Pixmap maskPixmap = (Pixmap) use_bitmap.GetMask()->GetBitmap() ; + Pixmap bufPixmap = GrNewPixmap(w, h, 0); + GC gc = GrNewGC(); + GrSetGCUseBackground(gc, FALSE); + GrSetGCMode(gc, GR_MODE_COPY); + + // This code assumes that background and foreground + // colours are used in ROPs, like in MSW. + // Not sure if this is true. + + // Copy destination to buffer. + // In DoBlit, we need this step because Blit has + // a ROP argument. Here, we don't need it. + // In DoBlit, we may be able to eliminate this step + // if we check if the rop = copy #if 0 + GrCopyArea(bufPixmap, gc, 0, 0, w, h, (Window) m_window, + 0, 0, GR_MODE_COPY); +#endif + + // Copy src to buffer using selected raster op (none selected + // in DrawBitmap, so just use Gxcopy) + GrCopyArea(bufPixmap, gc, 0, 0, w, h, pixmap, + 0, 0, GR_MODE_COPY); + + // Set masked area in buffer to BLACK (pixel value 0) + GrSetGCBackground(gc, WHITE); + GrSetGCForeground(gc, BLACK); + GrCopyArea(bufPixmap, gc, 0, 0, w, h, maskPixmap, + 0, 0, GR_MODE_AND); + + // set unmasked area in dest to BLACK + GrSetGCBackground(gc, BLACK); + GrSetGCForeground(gc, WHITE); + GrCopyArea((Window) m_window, gc, xx, yy, w, h, maskPixmap, + 0, 0, GR_MODE_AND); + + // OR buffer to dest + GrCopyArea((Window) m_window, gc, xx, yy, w, h, bufPixmap, + 0, 0, GR_MODE_OR); + + GrDestroyGC(gc); + GrDestroyWindow(bufPixmap); + } + else + XCopyArea( (Display*) m_display, (Pixmap) use_bitmap.GetPixmap(), (Window) m_window, + (GC) m_penGC, 0, 0, w, h, xx, yy ); + + /* remove mask again if any */ + if (useMask && mask) + { + if (!m_currentClippingRegion.IsNull()) + XSetRegion( (Display*) m_display, (GC) m_penGC, (Region) m_currentClippingRegion.GetX11Region() ); + } +} + +#else + +// Normal X11 +void wxWindowDC::DoDrawBitmap( const wxBitmap &bitmap, + wxCoord x, wxCoord y, + bool useMask ) +{ + wxCHECK_RET( Ok(), wxT("invalid window dc") ); + + wxCHECK_RET( bitmap.Ok(), wxT("invalid bitmap") ); + bool is_mono = (bitmap.GetBitmap() != NULL); /* scale/translate size and position */ @@ -875,9 +1000,11 @@ void wxWindowDC::DoDrawBitmap( const wxBitmap &bitmap, { wxImage image( bitmap ); image.Rescale( ww, hh ); +#if 0 if (is_mono) use_bitmap = image.ConvertToMonoBitmap(255,255,255); else +#endif use_bitmap = image.ConvertToBitmap(); } else @@ -886,12 +1013,13 @@ void wxWindowDC::DoDrawBitmap( const wxBitmap &bitmap, } /* apply mask if any */ - GdkBitmap *mask = (GdkBitmap *) NULL; + WXPixmap mask = NULL; if (use_bitmap.GetMask()) mask = use_bitmap.GetMask()->GetBitmap(); - + { if (useMask && mask) { - GdkBitmap *new_mask = (GdkBitmap*) NULL; + WXPixmap new_mask = NULL; +#if 0 if (!m_currentClippingRegion.IsNull()) { GdkColor col; @@ -911,54 +1039,59 @@ void wxWindowDC::DoDrawBitmap( const wxBitmap &bitmap, gdk_draw_rectangle( new_mask, gc, TRUE, 0, 0, ww, hh ); gdk_gc_unref( gc ); } - +#endif if (is_mono) { if (new_mask) - gdk_gc_set_clip_mask( m_textGC, new_mask ); + XSetClipMask( (Display*) m_display, (GC) m_textGC, (Pixmap) new_mask ); else - gdk_gc_set_clip_mask( m_textGC, mask ); - gdk_gc_set_clip_origin( m_textGC, xx, yy ); + XSetClipMask( (Display*) m_display, (GC) m_textGC, (Pixmap) mask ); + XSetClipOrigin( (Display*) m_display, (GC) m_textGC, xx, yy ); } else { if (new_mask) - gdk_gc_set_clip_mask( m_penGC, new_mask ); + XSetClipMask( (Display*) m_display, (GC) m_penGC, (Pixmap) new_mask ); else - gdk_gc_set_clip_mask( m_penGC, mask ); - gdk_gc_set_clip_origin( m_penGC, xx, yy ); + XSetClipMask( (Display*) m_display, (GC) m_penGC, (Pixmap) mask ); + XSetClipOrigin( (Display*) m_display, (GC) m_penGC, xx, yy ); } + if (new_mask) - gdk_bitmap_unref( new_mask ); + XFreePixmap( (Display*) m_display, (Pixmap) new_mask ); } + } /* Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For drawing a mono-bitmap (XBitmap) we use the current text GC */ if (is_mono) - gdk_wx_draw_bitmap( m_window, m_textGC, use_bitmap.GetBitmap(), 0, 0, xx, yy, -1, -1 ); + XCopyPlane( (Display*) m_display, (Pixmap) use_bitmap.GetBitmap(), (Window) m_window, + (GC) m_textGC, 0, 0, w, h, xx, yy, 1 ); else - gdk_draw_pixmap( m_window, m_penGC, use_bitmap.GetPixmap(), 0, 0, xx, yy, -1, -1 ); + XCopyArea( (Display*) m_display, (Pixmap) use_bitmap.GetPixmap(), (Window) m_window, + (GC) m_penGC, 0, 0, w, h, xx, yy ); /* remove mask again if any */ if (useMask && mask) { if (is_mono) { - gdk_gc_set_clip_mask( m_textGC, (GdkBitmap *) NULL ); - gdk_gc_set_clip_origin( m_textGC, 0, 0 ); + XSetClipMask( (Display*) m_display, (GC) m_textGC, None ); + XSetClipOrigin( (Display*) m_display, (GC) m_textGC, 0, 0 ); if (!m_currentClippingRegion.IsNull()) - gdk_gc_set_clip_region( m_textGC, m_currentClippingRegion.GetRegion() ); + XSetRegion( (Display*) m_display, (GC) m_textGC, (Region) m_currentClippingRegion.GetX11Region() ); } else { - gdk_gc_set_clip_mask( m_penGC, (GdkBitmap *) NULL ); - gdk_gc_set_clip_origin( m_penGC, 0, 0 ); + XSetClipMask( (Display*) m_display, (GC) m_penGC, None ); + XSetClipOrigin( (Display*) m_display, (GC) m_penGC, 0, 0 ); if (!m_currentClippingRegion.IsNull()) - gdk_gc_set_clip_region( m_penGC, m_currentClippingRegion.GetRegion() ); + XSetRegion( (Display*) m_display, (GC) m_penGC, (Region) m_currentClippingRegion.GetX11Region() ); } } -#endif } +#endif + // wxUSE_NANOX/!wxUSE_NANOX bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, wxDC *source, wxCoord xsrc, wxCoord ysrc, int rop, bool useMask, @@ -990,7 +1123,7 @@ bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord he { xsrcMask = xsrc; ysrcMask = ysrc; } - + #if 0 if (srcDC->m_isMemDC) { @@ -1239,16 +1372,18 @@ void wxWindowDC::DoDrawText( const wxString &text, wxCoord x, wxCoord y ) #endif XSetFont( (Display*) m_display, (GC) m_textGC, xfont->fid ); +#if !wxUSE_NANOX if ((xfont->min_byte1 == 0) && (xfont->max_byte1 == 0)) - { +#endif + { XDrawString( (Display*) m_display, (Window) m_window, - (GC) m_textGC, x, y, text.c_str(), text.Len() ); - } + (GC) m_textGC, x, y + XFontStructGetAscent(xfont), text.c_str(), text.Len() ); + } #if 0 if (m_font.GetUnderlined()) { - wxCoord ul_y = y + font->ascent; + wxCoord ul_y = y + XFontStructGetAscent(font); if (font->descent > 0) ul_y++; gdk_draw_line( m_window, m_textGC, x, ul_y, x + width, ul_y); } @@ -1284,7 +1419,7 @@ void wxWindowDC::DoGetTextExtent( const wxString &string, wxCoord *width, wxCoor int direction, ascent, descent2; XCharStruct overall; - XTextExtents( xfont, string.c_str(), string.Len(), &direction, + XTextExtents( xfont, (char*) string.c_str(), string.Len(), &direction, &ascent, &descent2, &overall); if (width) @@ -1524,14 +1659,14 @@ void wxWindowDC::SetBrush( const wxBrush &brush ) else { XSetFillStyle( (Display*) m_display, (GC) m_brushGC, FillStippled ); -// XSetStipple( (Display*) m_display, (GC) m_brushGC, (Pixmap) m_brush.GetStipple()->GetBitmap() ); + XSetStipple( (Display*) m_display, (GC) m_brushGC, (Pixmap) m_brush.GetStipple()->GetBitmap() ); } } if ((m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) && (m_brush.GetStipple()->GetMask())) { XSetFillStyle( (Display*) m_display, (GC) m_textGC, FillOpaqueStippled ); -// XSetStipple( (Display*) m_display, (GC) m_textGC, (Pixmap) m_brush.GetStipple()->GetMask()->GetBitmap() ); + XSetStipple( (Display*) m_display, (GC) m_textGC, (Pixmap) m_brush.GetStipple()->GetMask()->GetBitmap() ); } if (IS_HATCH(m_brush.GetStyle())) @@ -1575,7 +1710,7 @@ void wxWindowDC::SetBackground( const wxBrush &brush ) else { XSetFillStyle( (Display*) m_display, (GC) m_bgGC, FillStippled ); -// XSetStipple( (Display*) m_display, (GC) m_bgGC, (Pixmap) m_backgroundBrush.GetStipple()->GetBitmap() ); + XSetStipple( (Display*) m_display, (GC) m_bgGC, (Pixmap) m_backgroundBrush.GetStipple()->GetBitmap() ); } } @@ -1706,6 +1841,10 @@ void wxWindowDC::SetBackgroundMode( int mode ) m_backgroundMode = mode; +#if wxUSE_NANOX + GrSetGCUseBackground((GC) m_textGC, mode == wxTRANSPARENT ? FALSE : TRUE); +#endif + if (!m_window) return; // CMB 21/7/98: fill style of cross-hatch brushes is affected by @@ -1916,6 +2055,13 @@ wxClientDC::wxClientDC( wxWindow *win ) : wxWindowDC( win ) { wxCHECK_RET( win, _T("NULL window in wxClientDC::wxClientDC") ); + +#ifdef __WXUNIVERSAL__ + wxPoint ptOrigin = win->GetClientAreaOrigin(); + SetDeviceOrigin(ptOrigin.x, ptOrigin.y); + wxSize size = win->GetClientSize(); + SetClippingRegion(wxPoint(0, 0), size); +#endif // __WXUNIVERSAL__ } void wxClientDC::DoGetSize(int *width, int *height) const