From 887dd52f06a985ec0455e91f4b3d2b091a1b1c7b Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Mon, 18 Feb 2002 22:13:23 +0000 Subject: [PATCH] Added more wxRegion tests to erase sample. Implemented "clear now, paint later". Corrected colour-by-name lookup. Corrected DrawRectangle code which produced redraw garbage under wxX11. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@14297 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/x11/window.h | 7 +++++-- samples/erase/erase.cpp | 12 ++++++++++++ src/gtk/colour.cpp | 1 + src/gtk1/colour.cpp | 1 + src/x11/app.cpp | 16 +++++++++++----- src/x11/colour.cpp | 8 +++++++- src/x11/dcclient.cpp | 2 +- src/x11/window.cpp | 26 +++++++++++++++++++------- 8 files changed, 57 insertions(+), 16 deletions(-) diff --git a/include/wx/x11/window.h b/include/wx/x11/window.h index 29b646cafe..e7ef074f99 100644 --- a/include/wx/x11/window.h +++ b/include/wx/x11/window.h @@ -120,8 +120,11 @@ public: // arrange status bar, toolbar etc. virtual bool PreResize(); - // Generates paint events - void X11SendPaintEvents(); + // Generates paint events from m_updateRegion + void SendPaintEvents(); + + // Generates erase events from m_clearRegion + void SendEraseEvents(); // Clip to paint region? bool GetClipPaintRegion() { return m_clipPaintRegion; } diff --git a/samples/erase/erase.cpp b/samples/erase/erase.cpp index eeddaad927..f25a792739 100644 --- a/samples/erase/erase.cpp +++ b/samples/erase/erase.cpp @@ -188,6 +188,18 @@ void MyCanvas::OnPaint( wxPaintEvent &event ) dc.SetBrush( *wxRED_BRUSH ); dc.DrawRectangle( 100, 100, 200, 200 ); + + dc.DestroyClipingRegion(); + + dc.SetPen( *wxTRANSPARENT_PEN ); + + wxRegion strip( 110, 200, 30, 1 ); + wxRegionIterator it( strip ); + while (it) + { + dc.DrawRectangle( it.GetX(), it.GetY(), it.GetWidth(), it.GetHeight() ); + it ++; + } } void MyCanvas::OnEraseBackground( wxEraseEvent &event ) diff --git a/src/gtk/colour.cpp b/src/gtk/colour.cpp index 8ee81076b5..d4b9194145 100644 --- a/src/gtk/colour.cpp +++ b/src/gtk/colour.cpp @@ -158,6 +158,7 @@ void wxColour::InitFromName( const wxString &colourName ) else { m_refData = new wxColourRefData(); + if (!gdk_color_parse( colourName.mb_str(), &M_COLDATA->m_color )) { // VZ: asserts are good in general but this one is triggered by diff --git a/src/gtk1/colour.cpp b/src/gtk1/colour.cpp index 8ee81076b5..d4b9194145 100644 --- a/src/gtk1/colour.cpp +++ b/src/gtk1/colour.cpp @@ -158,6 +158,7 @@ void wxColour::InitFromName( const wxString &colourName ) else { m_refData = new wxColourRefData(); + if (!gdk_color_parse( colourName.mb_str(), &M_COLDATA->m_color )) { // VZ: asserts are good in general but this one is triggered by diff --git a/src/x11/app.cpp b/src/x11/app.cpp index 511b5fb034..d45ff95d4a 100644 --- a/src/x11/app.cpp +++ b/src/x11/app.cpp @@ -544,9 +544,12 @@ void wxApp::ProcessXEvent(WXEvent* _event) win->GetClearRegion().Union( event->xexpose.x, event->xexpose.y, event->xexpose.width, event->xexpose.height); - - // if (event->xexpose.count == 0) - // win->Update(); + + if (event->xexpose.count == 0) + { + // Only erase background, paint in idle time. + win->SendEraseEvents(); + } } return; @@ -565,8 +568,11 @@ void wxApp::ProcessXEvent(WXEvent* _event) win->GetClearRegion().Union( event->xgraphicsexpose.x, event->xgraphicsexpose.y, event->xgraphicsexpose.width, event->xgraphicsexpose.height); - // if (event->xgraphicsexpose.count == 0) - // win->Update(); + if (event->xgraphicsexpose.count == 0) + { + // Only erase background, paint in idle time. + win->SendEraseEvents(); + } } return; diff --git a/src/x11/colour.cpp b/src/x11/colour.cpp index cf8302dd51..f989be7f44 100644 --- a/src/x11/colour.cpp +++ b/src/x11/colour.cpp @@ -15,6 +15,7 @@ #endif #include "wx/gdicmn.h" +#include "wx/app.h" #include "wx/x11/private.h" @@ -154,6 +155,9 @@ void wxColour::InitFromName( const wxString &colourName ) else { m_refData = new wxColourRefData(); + + M_COLDATA->m_colormap = wxTheApp->GetMainColormap( wxGlobalDisplay() ); + if (!XParseColor( wxGlobalDisplay(), (Colormap) M_COLDATA->m_colormap, colourName.mb_str(), &M_COLDATA->m_color )) { // VZ: asserts are good in general but this one is triggered by @@ -234,7 +238,9 @@ unsigned char wxColour::Blue() const void wxColour::CalcPixel( WXColormap cmap ) { - if (!Ok()) return; + wxCHECK_RET( Ok(), wxT("invalid colour") ); + + wxCHECK_RET( cmap, wxT("invalid colormap") ); M_COLDATA->AllocColour( cmap ); } diff --git a/src/x11/dcclient.cpp b/src/x11/dcclient.cpp index 286375fa0e..68b68bf7b8 100644 --- a/src/x11/dcclient.cpp +++ b/src/x11/dcclient.cpp @@ -741,7 +741,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 ); } } diff --git a/src/x11/window.cpp b/src/x11/window.cpp index ed580bbb2e..0ddb715476 100644 --- a/src/x11/window.cpp +++ b/src/x11/window.cpp @@ -357,7 +357,7 @@ void wxWindowX11::DoCaptureMouse() return; } - wxLogDebug("Grabbed pointer"); + /// wxLogDebug("Grabbed pointer"); #if 0 res = XGrabButton(wxGlobalDisplay(), AnyButton, AnyModifier, @@ -416,7 +416,8 @@ void wxWindowX11::DoReleaseMouse() XUngrabKeyboard( wxGlobalDisplay(), CurrentTime ); #endif } - wxLogDebug("Ungrabbed pointer"); + + // wxLogDebug("Ungrabbed pointer"); m_winCaptured = FALSE; } @@ -940,8 +941,11 @@ void wxWindowX11::Update() { if (!m_updateRegion.IsEmpty()) { - // Actually send erase and paint events. - X11SendPaintEvents(); + // Actually send erase events. + SendEraseEvents(); + + // Actually send paint events. + SendPaintEvents(); } } @@ -953,12 +957,12 @@ void wxWindowX11::Clear() dc.Clear(); } -void wxWindowX11::X11SendPaintEvents() +void wxWindowX11::SendEraseEvents() { - m_clipPaintRegion = TRUE; - if (!m_clearRegion.IsEmpty()) { + m_clipPaintRegion = TRUE; + wxWindowDC dc( (wxWindow*)this ); dc.SetClippingRegion( m_clearRegion ); @@ -982,7 +986,15 @@ void wxWindowX11::X11SendPaintEvents() XFreeGC( xdisplay, xgc ); } m_clearRegion.Clear(); + + m_clipPaintRegion = FALSE; } +} + + +void wxWindowX11::SendPaintEvents() +{ + m_clipPaintRegion = TRUE; wxNcPaintEvent nc_paint_event( GetId() ); nc_paint_event.SetEventObject( this ); -- 2.45.2