X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d90c9596c1476f4bb1c728dc0169ef16f4d622d4..7b28e0ede49ca78e05df6bc6af2d2d8c508f8455:/src/gtk/dcclient.cpp?ds=inline diff --git a/src/gtk/dcclient.cpp b/src/gtk/dcclient.cpp index 802358014e..d67e3cc0c0 100644 --- a/src/gtk/dcclient.cpp +++ b/src/gtk/dcclient.cpp @@ -191,7 +191,7 @@ static void wxInitGCPool() // If we cannot malloc, then fail with error // when debug is enabled. If debug is not enabled, // the problem will eventually get caught - // in wxGetPoolGC. + // in wxGetPoolGC. wxFAIL_MSG( wxT("Cannot allocate GC pool") ); return; } @@ -237,13 +237,13 @@ static GdkGC* wxGetPoolGC( GdkWindow *window, wxPoolGCType type ) // We did not find an available GC. // We need to grow the GC pool. pptr = (wxGC *)realloc(wxGCPool, - (wxGCPoolSize + GC_POOL_ALLOC_SIZE)*sizeof(wxGC)); + (wxGCPoolSize + GC_POOL_ALLOC_SIZE)*sizeof(wxGC)); if (pptr != NULL) { // Initialize newly allocated pool. wxGCPool = pptr; - memset(&wxGCPool[wxGCPoolSize], 0, - GC_POOL_ALLOC_SIZE*sizeof(wxGC)); + memset(&wxGCPool[wxGCPoolSize], 0, + GC_POOL_ALLOC_SIZE*sizeof(wxGC)); // Initialize entry we will return. wxGCPool[wxGCPoolSize].m_gc = gdk_gc_new( window ); @@ -773,6 +773,7 @@ void wxWindowDC::DoDrawPolygon( int n, wxPoint points[], wxCoord xoffset, wxCoor if (m_pen.GetStyle() != wxTRANSPARENT) { +/* for (i = 0 ; i < n ; i++) { gdk_draw_line( m_window, m_penGC, @@ -781,6 +782,9 @@ void wxWindowDC::DoDrawPolygon( int n, wxPoint points[], wxCoord xoffset, wxCoor gdkpoints[(i+1)%n].x, gdkpoints[(i+1)%n].y); } +*/ + gdk_draw_polygon( m_window, m_penGC, FALSE, gdkpoints, n ); + } } @@ -1270,11 +1274,14 @@ bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest, wxCoord bm_width = memDC->m_selected.GetWidth(); wxCoord bm_height = memDC->m_selected.GetHeight(); - // get clip coords - wxRegion tmp( xx,yy,ww,hh ); - tmp.Intersect( m_currentClippingRegion ); - wxCoord cx,cy,cw,ch; - tmp.GetBox(cx,cy,cw,ch); + // Get clip coords for the bitmap. If we don't + // use wxBitmap::Rescale(), which can clip the + // bitmap, these are the same as the original + // coordinates + wxCoord cx = xx; + wxCoord cy = yy; + wxCoord cw = ww; + wxCoord ch = hh; // interpret userscale of src too double xsc,ysc; @@ -1285,16 +1292,23 @@ bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest, wxCoord bm_ww = XLOG2DEVREL( bm_width ); wxCoord bm_hh = YLOG2DEVREL( bm_height ); - // scale bitmap if required + // Scale bitmap if required wxBitmap use_bitmap; - if ((bm_width != bm_ww) || (bm_height != bm_hh)) { - use_bitmap = memDC->m_selected.Rescale(cx-xx,cy-yy,cw,ch,bm_ww,bm_hh); + // This indicates that the blitting code below will get + // a clipped bitmap and therefore needs to move the origin + // accordingly + wxRegion tmp( xx,yy,ww,hh ); + tmp.Intersect( m_currentClippingRegion ); + tmp.GetBox(cx,cy,cw,ch); + + // Scale and clipped bitmap + use_bitmap = memDC->m_selected.Rescale(cx-xx,cy-yy,cw,ch,bm_ww,bm_hh); } else { - // FIXME: use cx,cy,cw,ch here, too? + // Don't scale bitmap use_bitmap = memDC->m_selected; } @@ -1463,7 +1477,7 @@ void wxWindowDC::DoDrawText( const wxString &text, wxCoord x, wxCoord y ) int w,h; - if (abs(m_scaleY - 1.0) < 0.00001) + if (fabs(m_scaleY - 1.0) < 0.00001) { // If there is a user or actually any scale applied to // the device context, scale the font. @@ -2317,6 +2331,25 @@ int wxWindowDC::GetDepth() const IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxClientDC) +// Limit the paint region to the window size. Sometimes +// the paint region is too big, and this risks X11 errors +static void wxLimitRegionToSize(wxRegion& region, const wxSize& sz) +{ + wxRect originalRect = region.GetBox(); + wxRect rect(originalRect); + if (rect.width + rect.x > sz.x) + rect.width = sz.x - rect.x; + if (rect.height + rect.y > sz.y) + rect.height = sz.y - rect.y; + if (rect != originalRect) + { + region = wxRegion(rect); + wxLogTrace(wxT("painting"), wxT("Limiting region from %d, %d, %d, %d to %d, %d, %d, %d\n"), + originalRect.x, originalRect.y, originalRect.width, originalRect.height, + rect.x, rect.y, rect.width, rect.height); + } +} + wxPaintDC::wxPaintDC( wxWindow *win ) : wxClientDC( win ) { @@ -2324,21 +2357,23 @@ wxPaintDC::wxPaintDC( wxWindow *win ) if (!win->m_clipPaintRegion) return; + wxSize sz = win->GetSize(); m_paintClippingRegion = win->GetUpdateRegion(); + wxLimitRegionToSize(m_paintClippingRegion, sz); + GdkRegion *region = m_paintClippingRegion.GetRegion(); if ( region ) { - m_paintClippingRegion = win->GetUpdateRegion(); - GdkRegion *region = m_paintClippingRegion.GetRegion(); - if ( region ) - { - m_currentClippingRegion.Union( m_paintClippingRegion ); + m_currentClippingRegion.Union( m_paintClippingRegion ); + wxLimitRegionToSize(m_currentClippingRegion, sz); - gdk_gc_set_clip_region( m_penGC, region ); - gdk_gc_set_clip_region( m_brushGC, region ); - gdk_gc_set_clip_region( m_textGC, region ); - gdk_gc_set_clip_region( m_bgGC, region ); - } + if (sz.x <= 0 || sz.y <= 0) + return ; + + gdk_gc_set_clip_region( m_penGC, region ); + gdk_gc_set_clip_region( m_brushGC, region ); + gdk_gc_set_clip_region( m_textGC, region ); + gdk_gc_set_clip_region( m_bgGC, region ); } #endif // USE_PAINT_REGION }