From e1208c3103734c8581c9854c344b97323e381897 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Sat, 4 Mar 2000 16:23:26 +0000 Subject: [PATCH] Lotta stuff for drawing etc. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@6436 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/dcclient.h | 1 + include/wx/gtk/gdiobj.h | 2 + include/wx/gtk/region.h | 28 ++++--- include/wx/gtk1/dcclient.h | 1 + include/wx/gtk1/gdiobj.h | 2 + include/wx/gtk1/region.h | 28 ++++--- samples/drawing/drawing.cpp | 50 +++++++----- src/generic/listctrl.cpp | 2 +- src/gtk/brush.cpp | 12 ++- src/gtk/dcclient.cpp | 152 +++++++++++++++++++++--------------- src/gtk/dcscreen.cpp | 2 + src/gtk/region.cpp | 135 ++++++++++++++++++++++++++------ src/gtk1/brush.cpp | 12 ++- src/gtk1/dcclient.cpp | 152 +++++++++++++++++++++--------------- src/gtk1/dcscreen.cpp | 2 + src/gtk1/region.cpp | 135 ++++++++++++++++++++++++++------ 16 files changed, 478 insertions(+), 238 deletions(-) diff --git a/include/wx/gtk/dcclient.h b/include/wx/gtk/dcclient.h index a70c424edb..374999e853 100644 --- a/include/wx/gtk/dcclient.h +++ b/include/wx/gtk/dcclient.h @@ -115,6 +115,7 @@ public: GdkGC *m_bgGC; GdkColormap *m_cmap; bool m_isMemDC; + bool m_isScreenDC; wxWindow *m_owner; wxRegion m_currentClippingRegion; wxRegion m_paintClippingRegion; diff --git a/include/wx/gtk/gdiobj.h b/include/wx/gtk/gdiobj.h index 23e4077cc7..12153a1025 100644 --- a/include/wx/gtk/gdiobj.h +++ b/include/wx/gtk/gdiobj.h @@ -26,6 +26,8 @@ public: virtual bool GetVisible() { return m_visible; } virtual void SetVisible( bool visible ) { m_visible = visible; } + bool IsNull() const { return (m_refData == 0); } + protected: bool m_visible; /* can a pointer to this object be safely taken? * - only if created within FindOrCreate... */ diff --git a/include/wx/gtk/region.h b/include/wx/gtk/region.h index ff139cb0f5..7369192305 100644 --- a/include/wx/gtk/region.h +++ b/include/wx/gtk/region.h @@ -30,16 +30,19 @@ class wxRegion; enum wxRegionContain { - wxOutRegion = 0, wxPartRegion = 1, wxInRegion = 2 + wxOutRegion = 0, + wxPartRegion = 1, + wxInRegion = 2 }; // So far, for internal use only -enum wxRegionOp { -wxRGN_AND, // Creates the intersection of the two combined regions. -wxRGN_COPY, // Creates a copy of the region identified by hrgnSrc1. -wxRGN_DIFF, // Combines the parts of hrgnSrc1 that are not part of hrgnSrc2. -wxRGN_OR, // Creates the union of two combined regions. -wxRGN_XOR // Creates the union of two combined regions except for any overlapping areas. +enum wxRegionOp +{ + wxRGN_AND, // Creates the intersection of the two combined regions. + wxRGN_COPY, // Creates a copy of the region identified by hrgnSrc1. + wxRGN_DIFF, // Combines the parts of hrgnSrc1 that are not part of hrgnSrc2. + wxRGN_OR, // Creates the union of two combined regions. + wxRGN_XOR // Creates the union of two combined regions except for any overlapping areas. }; //----------------------------------------------------------------------------- @@ -48,10 +51,7 @@ wxRGN_XOR // Creates the union of two combined regions except for any class wxRegion : public wxGDIObject { - DECLARE_DYNAMIC_CLASS(wxRegion); - - public: - +public: wxRegion( wxCoord x, wxCoord y, wxCoord w, wxCoord h ); wxRegion( const wxPoint& topLeft, const wxPoint& bottomRight ); wxRegion( const wxRect& rect ); @@ -95,10 +95,12 @@ class wxRegion : public wxGDIObject wxRegionContain Contains(const wxPoint& pt) const; wxRegionContain Contains(const wxRect& rect) const; - public: - +public: wxList *GetRectList() const; GdkRegion *GetRegion() const; + +private: + DECLARE_DYNAMIC_CLASS(wxRegion); }; class wxRegionIterator: public wxObject diff --git a/include/wx/gtk1/dcclient.h b/include/wx/gtk1/dcclient.h index a70c424edb..374999e853 100644 --- a/include/wx/gtk1/dcclient.h +++ b/include/wx/gtk1/dcclient.h @@ -115,6 +115,7 @@ public: GdkGC *m_bgGC; GdkColormap *m_cmap; bool m_isMemDC; + bool m_isScreenDC; wxWindow *m_owner; wxRegion m_currentClippingRegion; wxRegion m_paintClippingRegion; diff --git a/include/wx/gtk1/gdiobj.h b/include/wx/gtk1/gdiobj.h index 23e4077cc7..12153a1025 100644 --- a/include/wx/gtk1/gdiobj.h +++ b/include/wx/gtk1/gdiobj.h @@ -26,6 +26,8 @@ public: virtual bool GetVisible() { return m_visible; } virtual void SetVisible( bool visible ) { m_visible = visible; } + bool IsNull() const { return (m_refData == 0); } + protected: bool m_visible; /* can a pointer to this object be safely taken? * - only if created within FindOrCreate... */ diff --git a/include/wx/gtk1/region.h b/include/wx/gtk1/region.h index ff139cb0f5..7369192305 100644 --- a/include/wx/gtk1/region.h +++ b/include/wx/gtk1/region.h @@ -30,16 +30,19 @@ class wxRegion; enum wxRegionContain { - wxOutRegion = 0, wxPartRegion = 1, wxInRegion = 2 + wxOutRegion = 0, + wxPartRegion = 1, + wxInRegion = 2 }; // So far, for internal use only -enum wxRegionOp { -wxRGN_AND, // Creates the intersection of the two combined regions. -wxRGN_COPY, // Creates a copy of the region identified by hrgnSrc1. -wxRGN_DIFF, // Combines the parts of hrgnSrc1 that are not part of hrgnSrc2. -wxRGN_OR, // Creates the union of two combined regions. -wxRGN_XOR // Creates the union of two combined regions except for any overlapping areas. +enum wxRegionOp +{ + wxRGN_AND, // Creates the intersection of the two combined regions. + wxRGN_COPY, // Creates a copy of the region identified by hrgnSrc1. + wxRGN_DIFF, // Combines the parts of hrgnSrc1 that are not part of hrgnSrc2. + wxRGN_OR, // Creates the union of two combined regions. + wxRGN_XOR // Creates the union of two combined regions except for any overlapping areas. }; //----------------------------------------------------------------------------- @@ -48,10 +51,7 @@ wxRGN_XOR // Creates the union of two combined regions except for any class wxRegion : public wxGDIObject { - DECLARE_DYNAMIC_CLASS(wxRegion); - - public: - +public: wxRegion( wxCoord x, wxCoord y, wxCoord w, wxCoord h ); wxRegion( const wxPoint& topLeft, const wxPoint& bottomRight ); wxRegion( const wxRect& rect ); @@ -95,10 +95,12 @@ class wxRegion : public wxGDIObject wxRegionContain Contains(const wxPoint& pt) const; wxRegionContain Contains(const wxRect& rect) const; - public: - +public: wxList *GetRectList() const; GdkRegion *GetRegion() const; + +private: + DECLARE_DYNAMIC_CLASS(wxRegion); }; class wxRegionIterator: public wxObject diff --git a/samples/drawing/drawing.cpp b/samples/drawing/drawing.cpp index 0f1cf27ffd..7e6f40b2cb 100644 --- a/samples/drawing/drawing.cpp +++ b/samples/drawing/drawing.cpp @@ -73,6 +73,7 @@ static wxBitmap gs_bmpNoMask, gs_bmpMask, gs_bmpWithMask, gs_bmp4, + gs_bmp4_mono, gs_bmp36; // ---------------------------------------------------------------------------- @@ -243,9 +244,12 @@ bool MyApp::LoadImages() wxString path = pathList.FindValidPath("pat4.bmp"); if ( !path ) return FALSE; + /* 4 colour bitmap */ gs_bmp4.LoadFile(path, wxBITMAP_TYPE_BMP); - wxMask* mask4 = new wxMask(gs_bmp4, *wxBLACK); - gs_bmp4.SetMask(mask4); + /* turn into mono-bitmap */ + gs_bmp4_mono.LoadFile(path, wxBITMAP_TYPE_BMP); + wxMask* mask4 = new wxMask(gs_bmp4_mono, *wxBLACK); + gs_bmp4_mono.SetMask(mask4); path = pathList.FindValidPath("pat36.bmp"); if ( !path ) @@ -325,20 +329,21 @@ MyCanvas::MyCanvas( MyFrame *parent ) : wxScrolledWindow( parent ) m_std_icon = wxTheApp->GetStdIcon(wxICON_INFORMATION); } -//draw a polygon and an overlapping rectangle -//is transparent is 1, the fill pattern are made transparent -//is transparent is 2, the fill pattern are made transparent but inversed -//is transparent is 0 the text for and background color will be used to represent/map -//the colors of the monochrome bitmap pixels to the fillpattern +// Draw a polygon and an overlapping rectangle +// If transparent is 1, the fill pattern is made transparent. +// If transparent is 2, the fill pattern is made transparent but inversed +// If is transparent is 0 the text for and background color will be used to represent/map +// the colors of the monochrome bitmap pixels to the fillpattern // -//i miss_used the the menu items for setting so called back and fore ground color -//just to show how the those colors do influence the fillpatterns -//just play with those, -//and with the code -//variations are endless using other logical functions +// I abused the the menu items for setting so called back and fore ground color +// just to show how the those colors do influence the fillpatterns just play +// with those, and with the code variations are endless using other logical +// functions. + void MyCanvas::DrawTestPoly( int x, int y,wxDC &dc,int transparent ) { - wxBrush* brush4 = new wxBrush(gs_bmp4); + wxBrush* brush4 = new wxBrush(gs_bmp4); + wxBrush* brush4_mono = new wxBrush(gs_bmp4_mono); wxBrush* brush36 = new wxBrush(gs_bmp36); wxPoint todraw[5]; @@ -369,20 +374,24 @@ void MyCanvas::DrawTestPoly( int x, int y,wxDC &dc,int transparent ) { case 0: { + dc.SetLogicalFunction(wxCOPY); + dc.SetPen( wxPen( "black", 4, wxSOLID) ); dc.SetBrush( *brush4 ); - dc.SetTextForeground(*wxGREEN); - dc.SetTextBackground(m_owner->m_colourForeground); - dc.SetLogicalFunction(wxCOPY); dc.DrawPolygon(5,todraw,0,0,wxWINDING_RULE); - //don't understand hwo but the outline is also depending on logicalfunction dc.SetPen( wxPen( "red", 4, wxSOLID) ); dc.SetBrush( *brush36 ); dc.SetTextForeground(*wxCYAN); dc.SetTextBackground(m_owner->m_colourBackground); - dc.SetLogicalFunction(wxCOPY); dc.DrawRectangle( x+10, y+10, 200, 200 ); + + dc.SetPen( wxPen( "green", 4, wxSOLID) ); + dc.SetBrush( *brush4_mono ); + dc.SetTextForeground(*wxCYAN); + dc.SetTextBackground(m_owner->m_colourBackground); + dc.DrawRectangle( x+50, y+50, 200, 200 ); + dc.SetBrush(wxNullBrush); dc.SetPen(wxNullPen); break; @@ -523,6 +532,7 @@ void MyCanvas::DrawTestPoly( int x, int y,wxDC &dc,int transparent ) } delete brush4; + delete brush4_mono; delete brush36; } @@ -943,7 +953,7 @@ void MyCanvas::OnPaint(wxPaintEvent &WXUNUSED(event)) } } -// dc.Clear(); + dc.Clear(); if ( m_owner->m_textureBackground) { dc.SetPen(*wxMEDIUM_GREY_PEN); @@ -974,8 +984,10 @@ void MyCanvas::OnPaint(wxPaintEvent &WXUNUSED(event)) case Show_Polygons: DrawTestPoly( 0, 100, dc, 0 ); +/* DrawTestPoly( 33, 500, dc, 1 ); DrawTestPoly( 43, 1000, dc, 2 ); +*/ break; case Show_Mask: diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index 573cdd5007..e1928cc532 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -2657,7 +2657,7 @@ void wxListMainWindow::CalculatePositions() if (y+lineSpacing-6 >= clientHeight) // -6 for earlier "line breaking" { m_currentVisibleLines = 0; - y = 5; + y = 2; x += maxWidth+6; entireWidth += maxWidth+6; maxWidth = 0; diff --git a/src/gtk/brush.cpp b/src/gtk/brush.cpp index ca0987080c..b58261b95c 100644 --- a/src/gtk/brush.cpp +++ b/src/gtk/brush.cpp @@ -66,15 +66,13 @@ wxBrush::wxBrush( const wxBitmap &stippleBitmap ) { m_refData = new wxBrushRefData(); M_BRUSHDATA->m_colour = *wxBLACK; + M_BRUSHDATA->m_stipple = stippleBitmap; + if (M_BRUSHDATA->m_stipple.GetMask()) - { - M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE; - } - else - { - M_BRUSHDATA->m_style = wxSTIPPLE; - } + M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE; + else + M_BRUSHDATA->m_style = wxSTIPPLE; if (wxTheBrushList) wxTheBrushList->AddBrush( this ); } diff --git a/src/gtk/dcclient.cpp b/src/gtk/dcclient.cpp index 153341d175..465a33f868 100644 --- a/src/gtk/dcclient.cpp +++ b/src/gtk/dcclient.cpp @@ -28,7 +28,7 @@ // local defines //----------------------------------------------------------------------------- -#define USE_PAINT_REGION 0 +#define USE_PAINT_REGION 1 //----------------------------------------------------------------------------- // local data @@ -110,6 +110,8 @@ void gdk_draw_bitmap (GdkDrawable *drawable, // Implement Pool of Graphic contexts. Creating them takes too much time. //----------------------------------------------------------------------------- +#define GC_POOL_SIZE 200 + enum wxPoolGCType { wxGC_ERROR = 0, @@ -130,16 +132,16 @@ struct wxGC bool m_used; }; -static wxGC wxGCPool[200]; +static wxGC wxGCPool[GC_POOL_SIZE]; static void wxInitGCPool() { - memset( wxGCPool, 0, 200*sizeof(wxGC) ); + memset( wxGCPool, 0, GC_POOL_SIZE*sizeof(wxGC) ); } static void wxCleanUpGCPool() { - for (int i = 0; i < 200; i++) + for (int i = 0; i < GC_POOL_SIZE; i++) { if (wxGCPool[i].m_gc) gdk_gc_unref( wxGCPool[i].m_gc ); @@ -148,7 +150,7 @@ static void wxCleanUpGCPool() static GdkGC* wxGetPoolGC( GdkWindow *window, wxPoolGCType type ) { - for (int i = 0; i < 200; i++) + for (int i = 0; i < GC_POOL_SIZE; i++) { if (!wxGCPool[i].m_gc) { @@ -171,7 +173,7 @@ static GdkGC* wxGetPoolGC( GdkWindow *window, wxPoolGCType type ) static void wxFreePoolGC( GdkGC *gc ) { - for (int i = 0; i < 200; i++) + for (int i = 0; i < GC_POOL_SIZE; i++) { if (wxGCPool[i].m_gc == gc) { @@ -197,6 +199,7 @@ wxWindowDC::wxWindowDC() m_bgGC = (GdkGC *) NULL; m_cmap = (GdkColormap *) NULL; m_isMemDC = FALSE; + m_isScreenDC = FALSE; m_owner = (wxWindow *)NULL; } @@ -209,6 +212,7 @@ wxWindowDC::wxWindowDC( wxWindow *window ) m_cmap = (GdkColormap *) NULL; m_owner = (wxWindow *)NULL; m_isMemDC = FALSE; + m_isScreenDC = FALSE; m_font = window->GetFont(); wxASSERT_MSG( window, wxT("DC needs a window") ); @@ -524,26 +528,42 @@ void wxWindowDC::DoDrawPolygon( int n, wxPoint points[], wxCoord xoffset, wxCoor if (m_window) { - if ((m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) && (m_brush.GetStipple()->GetMask())) - gdk_draw_polygon (m_window, m_textGC, TRUE, gdkpoints, n); - else + if (m_brush.GetStyle() != wxTRANSPARENT) { - if ((m_brush.GetStyle() != wxTRANSPARENT)) - gdk_draw_polygon (m_window, m_brushGC, TRUE, gdkpoints, n); + if ((m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) && (m_brush.GetStipple()->GetMask())) + { + gdk_gc_set_ts_origin( m_textGC, + m_deviceOriginX % m_brush.GetStipple()->GetWidth(), + m_deviceOriginY % m_brush.GetStipple()->GetHeight() ); + gdk_draw_polygon( m_window, m_textGC, TRUE, gdkpoints, n ); + gdk_gc_set_ts_origin( m_textGC, 0, 0 ); + } else + if (m_brush.GetStyle() == wxSTIPPLE) + { + gdk_gc_set_ts_origin( m_brushGC, + m_deviceOriginX % m_brush.GetStipple()->GetWidth(), + m_deviceOriginY % m_brush.GetStipple()->GetHeight() ); + gdk_draw_polygon( m_window, m_brushGC, TRUE, gdkpoints, n ); + gdk_gc_set_ts_origin( m_brushGC, 0, 0 ); + } + else + { + gdk_draw_polygon( m_window, m_brushGC, TRUE, gdkpoints, n ); + } } - } - // To do: Fillstyle + // To do: Fillstyle - if ((m_pen.GetStyle() != wxTRANSPARENT) && m_window) - { - for (i = 0 ; i < n ; i++) + if (m_pen.GetStyle() != wxTRANSPARENT) { - gdk_draw_line( m_window, m_penGC, - gdkpoints[i%n].x, - gdkpoints[i%n].y, - gdkpoints[(i+1)%n].x, - gdkpoints[(i+1)%n].y); + for (i = 0 ; i < n ; i++) + { + gdk_draw_line( m_window, m_penGC, + gdkpoints[i%n].x, + gdkpoints[i%n].y, + gdkpoints[(i+1)%n].x, + gdkpoints[(i+1)%n].y); + } } } @@ -568,19 +588,32 @@ void wxWindowDC::DoDrawRectangle( wxCoord x, wxCoord y, wxCoord width, wxCoord h if (m_window) { - if ((m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) && (m_brush.GetStipple()->GetMask())) - { - gdk_draw_rectangle( m_window, m_textGC, TRUE, xx, yy, ww, hh ); - gdk_draw_rectangle( m_window, m_penGC, FALSE, xx, yy, ww-1, hh-1 ); - } - else + if (m_brush.GetStyle() != wxTRANSPARENT) { - if (m_brush.GetStyle() != wxTRANSPARENT) + if ((m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) && (m_brush.GetStipple()->GetMask())) + { + gdk_gc_set_ts_origin( m_textGC, + m_deviceOriginX % m_brush.GetStipple()->GetWidth(), + m_deviceOriginY % m_brush.GetStipple()->GetHeight() ); + gdk_draw_rectangle( m_window, m_textGC, TRUE, xx, yy, ww, hh ); + gdk_gc_set_ts_origin( m_textGC, 0, 0 ); + } + else if (m_brush.GetStyle() == wxSTIPPLE) + { + gdk_gc_set_ts_origin( m_brushGC, + m_deviceOriginX % m_brush.GetStipple()->GetWidth(), + m_deviceOriginY % m_brush.GetStipple()->GetHeight() ); gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx, yy, ww, hh ); - - if (m_pen.GetStyle() != wxTRANSPARENT) - gdk_draw_rectangle( m_window, m_penGC, FALSE, xx, yy, ww-1, hh-1 ); + gdk_gc_set_ts_origin( m_brushGC, 0, 0 ); + } + else + { + gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx, yy, ww, hh ); + } } + + if (m_pen.GetStyle() != wxTRANSPARENT) + gdk_draw_rectangle( m_window, m_penGC, FALSE, xx, yy, ww-1, hh-1 ); } CalcBoundingBox( x, y ); @@ -717,7 +750,7 @@ void wxWindowDC::DoDrawBitmap( const wxBitmap &bitmap, int hh = YLOG2DEVREL(h); /* compare to current clipping region */ - if (!m_currentClippingRegion.IsEmpty()) + if (!m_currentClippingRegion.IsNull()) { wxRegion tmp( xx,yy,ww,hh ); tmp.Intersect( m_currentClippingRegion ); @@ -748,7 +781,7 @@ void wxWindowDC::DoDrawBitmap( const wxBitmap &bitmap, if (useMask && mask) { GdkBitmap *new_mask = (GdkBitmap*) NULL; - if (!m_currentClippingRegion.IsEmpty()) + if (!m_currentClippingRegion.IsNull()) { GdkColor col; new_mask = gdk_pixmap_new( wxRootWindow->window, ww, hh, 1 ); @@ -810,14 +843,14 @@ void wxWindowDC::DoDrawBitmap( const wxBitmap &bitmap, { gdk_gc_set_clip_mask( m_textGC, (GdkBitmap *) NULL ); gdk_gc_set_clip_origin( m_textGC, 0, 0 ); - if (!m_currentClippingRegion.IsEmpty()) + if (!m_currentClippingRegion.IsNull()) gdk_gc_set_clip_region( m_textGC, m_currentClippingRegion.GetRegion() ); } else { gdk_gc_set_clip_mask( m_penGC, (GdkBitmap *) NULL ); gdk_gc_set_clip_origin( m_penGC, 0, 0 ); - if (!m_currentClippingRegion.IsEmpty()) + if (!m_currentClippingRegion.IsNull()) gdk_gc_set_clip_region( m_penGC, m_currentClippingRegion.GetRegion() ); } } @@ -896,7 +929,7 @@ bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord he wxCoord hh = YLOG2DEVREL(height); /* compare to current clipping region */ - if (!m_currentClippingRegion.IsEmpty()) + if (!m_currentClippingRegion.IsNull()) { wxRegion tmp( xx,yy,ww,hh ); tmp.Intersect( m_currentClippingRegion ); @@ -941,7 +974,7 @@ bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord he if (useMask && mask) { GdkBitmap *new_mask = (GdkBitmap*) NULL; - if (!m_currentClippingRegion.IsEmpty()) + if (!m_currentClippingRegion.IsNull()) { GdkColor col; new_mask = gdk_pixmap_new( wxRootWindow->window, bm_ww, bm_hh, 1 ); @@ -996,14 +1029,14 @@ bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord he { gdk_gc_set_clip_mask( m_textGC, (GdkBitmap *) NULL ); gdk_gc_set_clip_origin( m_textGC, 0, 0 ); - if (!m_currentClippingRegion.IsEmpty()) + if (!m_currentClippingRegion.IsNull()) gdk_gc_set_clip_region( m_textGC, m_currentClippingRegion.GetRegion() ); } else { gdk_gc_set_clip_mask( m_penGC, (GdkBitmap *) NULL ); gdk_gc_set_clip_origin( m_penGC, 0, 0 ); - if (!m_currentClippingRegion.IsEmpty()) + if (!m_currentClippingRegion.IsNull()) gdk_gc_set_clip_region( m_penGC, m_currentClippingRegion.GetRegion() ); } } @@ -1027,18 +1060,14 @@ bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord he wxBitmap bitmap( width, height ); - /* We have to use the srcDC's GC as it might be a - wxScreenDC and we only have the GDK_INCLUDE_INFERIORS - flag set there. */ - - if (srcDC->GetWindow() == GDK_ROOT_PARENT()) + if (srcDC->m_isScreenDC) gdk_gc_set_subwindow( m_penGC, GDK_INCLUDE_INFERIORS ); - gdk_window_copy_area( bitmap.GetPixmap(), srcDC->m_penGC, 0, 0, + gdk_window_copy_area( bitmap.GetPixmap(), m_penGC, 0, 0, srcDC->GetWindow(), xsrc, ysrc, width, height ); - if (srcDC->GetWindow() == GDK_ROOT_PARENT()) + if (srcDC->m_isScreenDC) gdk_gc_set_subwindow( m_penGC, GDK_CLIP_BY_CHILDREN ); /* scale image */ @@ -1059,14 +1088,14 @@ bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord he { /* No scaling and not a memory dc with a mask either */ - if (srcDC->GetWindow() == GDK_ROOT_PARENT()) + if (srcDC->m_isScreenDC) gdk_gc_set_subwindow( m_penGC, GDK_INCLUDE_INFERIORS ); gdk_window_copy_area( m_window, m_penGC, xx, yy, srcDC->GetWindow(), xsrc, ysrc, width, height ); - if (srcDC->GetWindow() == GDK_ROOT_PARENT()) + if (srcDC->m_isScreenDC) gdk_gc_set_subwindow( m_penGC, GDK_CLIP_BY_CHILDREN ); } } @@ -1474,8 +1503,8 @@ void wxWindowDC::SetBrush( const wxBrush &brush ) if ((m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) && (m_brush.GetStipple()->GetMask())) { - gdk_gc_set_fill( m_textGC, GDK_OPAQUE_STIPPLED); - gdk_gc_set_stipple( m_textGC, m_brush.GetStipple()->GetMask()->GetBitmap() ); + gdk_gc_set_fill( m_textGC, GDK_OPAQUE_STIPPLED); + gdk_gc_set_stipple( m_textGC, m_brush.GetStipple()->GetMask()->GetBitmap() ); } if (IS_HATCH(m_brush.GetStyle())) @@ -1650,13 +1679,13 @@ void wxWindowDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoo rect.width = XLOG2DEVREL(width); rect.height = YLOG2DEVREL(height); - if (!m_currentClippingRegion.IsEmpty()) + if (!m_currentClippingRegion.IsNull()) m_currentClippingRegion.Intersect( rect ); else m_currentClippingRegion.Union( rect ); #if USE_PAINT_REGION - if (!m_paintClippingRegion.IsEmpty()) + if (!m_paintClippingRegion.IsNull()) m_currentClippingRegion.Intersect( m_paintClippingRegion ); #endif @@ -1683,13 +1712,13 @@ void wxWindowDC::DoSetClippingRegionAsRegion( const wxRegion ®ion ) if (!m_window) return; - if (!m_currentClippingRegion.IsEmpty()) + if (!m_currentClippingRegion.IsNull()) m_currentClippingRegion.Intersect( region ); else m_currentClippingRegion.Union( region ); #if USE_PAINT_REGION - if (!m_paintClippingRegion.IsEmpty()) + if (!m_paintClippingRegion.IsNull()) m_currentClippingRegion.Intersect( m_paintClippingRegion ); #endif @@ -1960,16 +1989,13 @@ wxPaintDC::wxPaintDC( wxWindow *win ) : wxWindowDC( win ) { #if USE_PAINT_REGION - if (!win->GetUpdateRegion().IsEmpty()) - { - m_paintClippingRegion = win->GetUpdateRegion(); - m_currentClippingRegion.Union( m_paintClippingRegion ); + m_paintClippingRegion = win->GetUpdateRegion(); + m_currentClippingRegion.Union( m_paintClippingRegion ); - gdk_gc_set_clip_region( m_penGC, m_paintClippingRegion.GetRegion() ); - gdk_gc_set_clip_region( m_brushGC, m_paintClippingRegion.GetRegion() ); - gdk_gc_set_clip_region( m_textGC, m_paintClippingRegion.GetRegion() ); - gdk_gc_set_clip_region( m_bgGC, m_paintClippingRegion.GetRegion() ); - } + gdk_gc_set_clip_region( m_penGC, m_paintClippingRegion.GetRegion() ); + gdk_gc_set_clip_region( m_brushGC, m_paintClippingRegion.GetRegion() ); + gdk_gc_set_clip_region( m_textGC, m_paintClippingRegion.GetRegion() ); + gdk_gc_set_clip_region( m_bgGC, m_paintClippingRegion.GetRegion() ); #endif } diff --git a/src/gtk/dcscreen.cpp b/src/gtk/dcscreen.cpp index 825cd2b2de..51a09f4806 100644 --- a/src/gtk/dcscreen.cpp +++ b/src/gtk/dcscreen.cpp @@ -38,6 +38,8 @@ wxScreenDC::wxScreenDC() m_cmap = gdk_colormap_get_system(); m_window = GDK_ROOT_PARENT(); + m_isScreenDC = TRUE; + SetUpDC(); gdk_gc_set_subwindow( m_penGC, GDK_INCLUDE_INFERIORS ); diff --git a/src/gtk/region.cpp b/src/gtk/region.cpp index edb6b766d9..8af2c03eee 100644 --- a/src/gtk/region.cpp +++ b/src/gtk/region.cpp @@ -94,20 +94,11 @@ wxRegion::wxRegion( const wxRect& rect ) g_rect.height = rect.height; M_REGIONDATA->m_region = gdk_region_union_with_rect( reg, &g_rect ); gdk_region_destroy( reg ); - - wxNode *node = M_REGIONDATA->m_rects.First(); - while (node) - { - wxRect *r = (wxRect*)node->Data(); - M_REGIONDATA->m_rects.Append( (wxObject*) new wxRect(r->x,r->y,r->width,r->height) ); - node = node->Next(); - } + M_REGIONDATA->m_rects.Append( (wxObject*) new wxRect(rect.x,rect.y,rect.width,rect.height) ); } wxRegion::wxRegion() { - m_refData = new wxRegionRefData(); - M_REGIONDATA->m_region = gdk_region_new(); } wxRegion::~wxRegion() @@ -127,8 +118,6 @@ bool wxRegion::operator != ( const wxRegion& region ) void wxRegion::Clear() { UnRef(); - m_refData = new wxRegionRefData(); - M_REGIONDATA->m_region = gdk_region_new(); } bool wxRegion::Union( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) @@ -138,29 +127,41 @@ bool wxRegion::Union( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) rect.y = y; rect.width = width; rect.height = height; - GdkRegion *reg = gdk_region_union_with_rect( M_REGIONDATA->m_region, &rect ); - gdk_region_destroy( M_REGIONDATA->m_region ); - M_REGIONDATA->m_region = reg; + if (!m_refData) + { + m_refData = new wxRegionRefData(); + GdkRegion *reg = gdk_region_new(); + M_REGIONDATA->m_region = gdk_region_union_with_rect( reg, &rect ); + gdk_region_destroy( reg ); + } + else + { + GdkRegion *reg = gdk_region_union_with_rect( M_REGIONDATA->m_region, &rect ); + gdk_region_destroy( M_REGIONDATA->m_region ); + M_REGIONDATA->m_region = reg; + } + M_REGIONDATA->m_rects.Append( (wxObject*) new wxRect(x,y,width,height) ); + return TRUE; } bool wxRegion::Union( const wxRect& rect ) { - GdkRectangle g_rect; - g_rect.x = rect.x; - g_rect.y = rect.y; - g_rect.width = rect.width; - g_rect.height = rect.height; - GdkRegion *reg = gdk_region_union_with_rect( M_REGIONDATA->m_region, &g_rect ); - gdk_region_destroy( M_REGIONDATA->m_region ); - M_REGIONDATA->m_region = reg; - M_REGIONDATA->m_rects.Append( (wxObject*) new wxRect(rect.x,rect.y,rect.width,rect.height) ); - return TRUE; + return Union( rect.x, rect.y, rect.width, rect.height ); } bool wxRegion::Union( const wxRegion& region ) { + if (region.IsNull()) + return FALSE; + + if (!m_refData) + { + m_refData = new wxRegionRefData(); + M_REGIONDATA->m_region = gdk_region_new(); + } + GdkRegion *reg = gdk_regions_union( M_REGIONDATA->m_region, region.GetRegion() ); gdk_region_destroy( M_REGIONDATA->m_region ); M_REGIONDATA->m_region = reg; @@ -178,6 +179,12 @@ bool wxRegion::Union( const wxRegion& region ) bool wxRegion::Intersect( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) { + if (!m_refData) + { + m_refData = new wxRegionRefData(); + M_REGIONDATA->m_region = gdk_region_new(); + } + wxRegion reg( x, y, width, height ); Intersect( reg ); return TRUE; @@ -185,6 +192,12 @@ bool wxRegion::Intersect( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) bool wxRegion::Intersect( const wxRect& rect ) { + if (!m_refData) + { + m_refData = new wxRegionRefData(); + M_REGIONDATA->m_region = gdk_region_new(); + } + wxRegion reg( rect ); Intersect( reg ); return TRUE; @@ -192,6 +205,16 @@ bool wxRegion::Intersect( const wxRect& rect ) bool wxRegion::Intersect( const wxRegion& region ) { + if (region.IsNull()) + return FALSE; + + if (!m_refData) + { + m_refData = new wxRegionRefData(); + M_REGIONDATA->m_region = gdk_region_new(); + return TRUE; + } + GdkRegion *reg = gdk_regions_intersect( M_REGIONDATA->m_region, region.GetRegion() ); gdk_region_destroy( M_REGIONDATA->m_region ); M_REGIONDATA->m_region = reg; @@ -200,6 +223,12 @@ bool wxRegion::Intersect( const wxRegion& region ) bool wxRegion::Subtract( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) { + if (!m_refData) + { + m_refData = new wxRegionRefData(); + M_REGIONDATA->m_region = gdk_region_new(); + } + wxRegion reg( x, y, width, height ); Subtract( reg ); return TRUE; @@ -207,6 +236,12 @@ bool wxRegion::Subtract( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) bool wxRegion::Subtract( const wxRect& rect ) { + if (!m_refData) + { + m_refData = new wxRegionRefData(); + M_REGIONDATA->m_region = gdk_region_new(); + } + wxRegion reg( rect ); Subtract( reg ); return TRUE; @@ -214,6 +249,15 @@ bool wxRegion::Subtract( const wxRect& rect ) bool wxRegion::Subtract( const wxRegion& region ) { + if (region.IsNull()) + return FALSE; + + if (!m_refData) + { + m_refData = new wxRegionRefData(); + M_REGIONDATA->m_region = gdk_region_new(); + } + GdkRegion *reg = gdk_regions_subtract( M_REGIONDATA->m_region, region.GetRegion() ); gdk_region_destroy( M_REGIONDATA->m_region ); M_REGIONDATA->m_region = reg; @@ -222,6 +266,12 @@ bool wxRegion::Subtract( const wxRegion& region ) bool wxRegion::Xor( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) { + if (!m_refData) + { + m_refData = new wxRegionRefData(); + M_REGIONDATA->m_region = gdk_region_new(); + } + wxRegion reg( x, y, width, height ); Xor( reg ); return TRUE; @@ -229,6 +279,12 @@ bool wxRegion::Xor( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) bool wxRegion::Xor( const wxRect& rect ) { + if (!m_refData) + { + m_refData = new wxRegionRefData(); + M_REGIONDATA->m_region = gdk_region_new(); + } + wxRegion reg( rect ); Xor( reg ); return TRUE; @@ -236,6 +292,15 @@ bool wxRegion::Xor( const wxRect& rect ) bool wxRegion::Xor( const wxRegion& region ) { + if (region.IsNull()) + return NULL; + + if (!m_refData) + { + m_refData = new wxRegionRefData(); + M_REGIONDATA->m_region = gdk_region_new(); + } + GdkRegion *reg = gdk_regions_xor( M_REGIONDATA->m_region, region.GetRegion() ); gdk_region_destroy( M_REGIONDATA->m_region ); M_REGIONDATA->m_region = reg; @@ -251,12 +316,15 @@ bool wxRegion::Xor( const wxRegion& region ) return TRUE; } -void wxRegion::GetBox( wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h ) const +void wxRegion::GetBox( wxCoord &x, wxCoord &y, wxCoord &w, wxCoord &h ) const { x = 0; y = 0; w = -1; h = -1; + if (m_refData) + return; + GdkRectangle rect; gdk_region_get_clipbox( M_REGIONDATA->m_region, &rect ); x = rect.x; @@ -277,11 +345,17 @@ wxRect wxRegion::GetBox() const bool wxRegion::Empty() const { + if (!m_refData) + return TRUE; + return gdk_region_empty( M_REGIONDATA->m_region ); } wxRegionContain wxRegion::Contains( wxCoord x, wxCoord y ) const { + if (!m_refData) + return wxOutRegion; + if (gdk_region_point_in( M_REGIONDATA->m_region, x, y )) return wxInRegion; else @@ -290,6 +364,9 @@ wxRegionContain wxRegion::Contains( wxCoord x, wxCoord y ) const wxRegionContain wxRegion::Contains( wxCoord x, wxCoord y, wxCoord w, wxCoord h ) const { + if (!m_refData) + return wxOutRegion; + GdkRectangle rect; rect.x = x; rect.y = y; @@ -317,11 +394,17 @@ wxRegionContain wxRegion::Contains(const wxRect& rect) const GdkRegion *wxRegion::GetRegion() const { + if (!m_refData) + return (GdkRegion*) NULL; + return M_REGIONDATA->m_region; } wxList *wxRegion::GetRectList() const { + if (!m_refData) + return (wxList*) NULL; + return &(M_REGIONDATA->m_rects); } diff --git a/src/gtk1/brush.cpp b/src/gtk1/brush.cpp index ca0987080c..b58261b95c 100644 --- a/src/gtk1/brush.cpp +++ b/src/gtk1/brush.cpp @@ -66,15 +66,13 @@ wxBrush::wxBrush( const wxBitmap &stippleBitmap ) { m_refData = new wxBrushRefData(); M_BRUSHDATA->m_colour = *wxBLACK; + M_BRUSHDATA->m_stipple = stippleBitmap; + if (M_BRUSHDATA->m_stipple.GetMask()) - { - M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE; - } - else - { - M_BRUSHDATA->m_style = wxSTIPPLE; - } + M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE; + else + M_BRUSHDATA->m_style = wxSTIPPLE; if (wxTheBrushList) wxTheBrushList->AddBrush( this ); } diff --git a/src/gtk1/dcclient.cpp b/src/gtk1/dcclient.cpp index 153341d175..465a33f868 100644 --- a/src/gtk1/dcclient.cpp +++ b/src/gtk1/dcclient.cpp @@ -28,7 +28,7 @@ // local defines //----------------------------------------------------------------------------- -#define USE_PAINT_REGION 0 +#define USE_PAINT_REGION 1 //----------------------------------------------------------------------------- // local data @@ -110,6 +110,8 @@ void gdk_draw_bitmap (GdkDrawable *drawable, // Implement Pool of Graphic contexts. Creating them takes too much time. //----------------------------------------------------------------------------- +#define GC_POOL_SIZE 200 + enum wxPoolGCType { wxGC_ERROR = 0, @@ -130,16 +132,16 @@ struct wxGC bool m_used; }; -static wxGC wxGCPool[200]; +static wxGC wxGCPool[GC_POOL_SIZE]; static void wxInitGCPool() { - memset( wxGCPool, 0, 200*sizeof(wxGC) ); + memset( wxGCPool, 0, GC_POOL_SIZE*sizeof(wxGC) ); } static void wxCleanUpGCPool() { - for (int i = 0; i < 200; i++) + for (int i = 0; i < GC_POOL_SIZE; i++) { if (wxGCPool[i].m_gc) gdk_gc_unref( wxGCPool[i].m_gc ); @@ -148,7 +150,7 @@ static void wxCleanUpGCPool() static GdkGC* wxGetPoolGC( GdkWindow *window, wxPoolGCType type ) { - for (int i = 0; i < 200; i++) + for (int i = 0; i < GC_POOL_SIZE; i++) { if (!wxGCPool[i].m_gc) { @@ -171,7 +173,7 @@ static GdkGC* wxGetPoolGC( GdkWindow *window, wxPoolGCType type ) static void wxFreePoolGC( GdkGC *gc ) { - for (int i = 0; i < 200; i++) + for (int i = 0; i < GC_POOL_SIZE; i++) { if (wxGCPool[i].m_gc == gc) { @@ -197,6 +199,7 @@ wxWindowDC::wxWindowDC() m_bgGC = (GdkGC *) NULL; m_cmap = (GdkColormap *) NULL; m_isMemDC = FALSE; + m_isScreenDC = FALSE; m_owner = (wxWindow *)NULL; } @@ -209,6 +212,7 @@ wxWindowDC::wxWindowDC( wxWindow *window ) m_cmap = (GdkColormap *) NULL; m_owner = (wxWindow *)NULL; m_isMemDC = FALSE; + m_isScreenDC = FALSE; m_font = window->GetFont(); wxASSERT_MSG( window, wxT("DC needs a window") ); @@ -524,26 +528,42 @@ void wxWindowDC::DoDrawPolygon( int n, wxPoint points[], wxCoord xoffset, wxCoor if (m_window) { - if ((m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) && (m_brush.GetStipple()->GetMask())) - gdk_draw_polygon (m_window, m_textGC, TRUE, gdkpoints, n); - else + if (m_brush.GetStyle() != wxTRANSPARENT) { - if ((m_brush.GetStyle() != wxTRANSPARENT)) - gdk_draw_polygon (m_window, m_brushGC, TRUE, gdkpoints, n); + if ((m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) && (m_brush.GetStipple()->GetMask())) + { + gdk_gc_set_ts_origin( m_textGC, + m_deviceOriginX % m_brush.GetStipple()->GetWidth(), + m_deviceOriginY % m_brush.GetStipple()->GetHeight() ); + gdk_draw_polygon( m_window, m_textGC, TRUE, gdkpoints, n ); + gdk_gc_set_ts_origin( m_textGC, 0, 0 ); + } else + if (m_brush.GetStyle() == wxSTIPPLE) + { + gdk_gc_set_ts_origin( m_brushGC, + m_deviceOriginX % m_brush.GetStipple()->GetWidth(), + m_deviceOriginY % m_brush.GetStipple()->GetHeight() ); + gdk_draw_polygon( m_window, m_brushGC, TRUE, gdkpoints, n ); + gdk_gc_set_ts_origin( m_brushGC, 0, 0 ); + } + else + { + gdk_draw_polygon( m_window, m_brushGC, TRUE, gdkpoints, n ); + } } - } - // To do: Fillstyle + // To do: Fillstyle - if ((m_pen.GetStyle() != wxTRANSPARENT) && m_window) - { - for (i = 0 ; i < n ; i++) + if (m_pen.GetStyle() != wxTRANSPARENT) { - gdk_draw_line( m_window, m_penGC, - gdkpoints[i%n].x, - gdkpoints[i%n].y, - gdkpoints[(i+1)%n].x, - gdkpoints[(i+1)%n].y); + for (i = 0 ; i < n ; i++) + { + gdk_draw_line( m_window, m_penGC, + gdkpoints[i%n].x, + gdkpoints[i%n].y, + gdkpoints[(i+1)%n].x, + gdkpoints[(i+1)%n].y); + } } } @@ -568,19 +588,32 @@ void wxWindowDC::DoDrawRectangle( wxCoord x, wxCoord y, wxCoord width, wxCoord h if (m_window) { - if ((m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) && (m_brush.GetStipple()->GetMask())) - { - gdk_draw_rectangle( m_window, m_textGC, TRUE, xx, yy, ww, hh ); - gdk_draw_rectangle( m_window, m_penGC, FALSE, xx, yy, ww-1, hh-1 ); - } - else + if (m_brush.GetStyle() != wxTRANSPARENT) { - if (m_brush.GetStyle() != wxTRANSPARENT) + if ((m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) && (m_brush.GetStipple()->GetMask())) + { + gdk_gc_set_ts_origin( m_textGC, + m_deviceOriginX % m_brush.GetStipple()->GetWidth(), + m_deviceOriginY % m_brush.GetStipple()->GetHeight() ); + gdk_draw_rectangle( m_window, m_textGC, TRUE, xx, yy, ww, hh ); + gdk_gc_set_ts_origin( m_textGC, 0, 0 ); + } + else if (m_brush.GetStyle() == wxSTIPPLE) + { + gdk_gc_set_ts_origin( m_brushGC, + m_deviceOriginX % m_brush.GetStipple()->GetWidth(), + m_deviceOriginY % m_brush.GetStipple()->GetHeight() ); gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx, yy, ww, hh ); - - if (m_pen.GetStyle() != wxTRANSPARENT) - gdk_draw_rectangle( m_window, m_penGC, FALSE, xx, yy, ww-1, hh-1 ); + gdk_gc_set_ts_origin( m_brushGC, 0, 0 ); + } + else + { + gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx, yy, ww, hh ); + } } + + if (m_pen.GetStyle() != wxTRANSPARENT) + gdk_draw_rectangle( m_window, m_penGC, FALSE, xx, yy, ww-1, hh-1 ); } CalcBoundingBox( x, y ); @@ -717,7 +750,7 @@ void wxWindowDC::DoDrawBitmap( const wxBitmap &bitmap, int hh = YLOG2DEVREL(h); /* compare to current clipping region */ - if (!m_currentClippingRegion.IsEmpty()) + if (!m_currentClippingRegion.IsNull()) { wxRegion tmp( xx,yy,ww,hh ); tmp.Intersect( m_currentClippingRegion ); @@ -748,7 +781,7 @@ void wxWindowDC::DoDrawBitmap( const wxBitmap &bitmap, if (useMask && mask) { GdkBitmap *new_mask = (GdkBitmap*) NULL; - if (!m_currentClippingRegion.IsEmpty()) + if (!m_currentClippingRegion.IsNull()) { GdkColor col; new_mask = gdk_pixmap_new( wxRootWindow->window, ww, hh, 1 ); @@ -810,14 +843,14 @@ void wxWindowDC::DoDrawBitmap( const wxBitmap &bitmap, { gdk_gc_set_clip_mask( m_textGC, (GdkBitmap *) NULL ); gdk_gc_set_clip_origin( m_textGC, 0, 0 ); - if (!m_currentClippingRegion.IsEmpty()) + if (!m_currentClippingRegion.IsNull()) gdk_gc_set_clip_region( m_textGC, m_currentClippingRegion.GetRegion() ); } else { gdk_gc_set_clip_mask( m_penGC, (GdkBitmap *) NULL ); gdk_gc_set_clip_origin( m_penGC, 0, 0 ); - if (!m_currentClippingRegion.IsEmpty()) + if (!m_currentClippingRegion.IsNull()) gdk_gc_set_clip_region( m_penGC, m_currentClippingRegion.GetRegion() ); } } @@ -896,7 +929,7 @@ bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord he wxCoord hh = YLOG2DEVREL(height); /* compare to current clipping region */ - if (!m_currentClippingRegion.IsEmpty()) + if (!m_currentClippingRegion.IsNull()) { wxRegion tmp( xx,yy,ww,hh ); tmp.Intersect( m_currentClippingRegion ); @@ -941,7 +974,7 @@ bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord he if (useMask && mask) { GdkBitmap *new_mask = (GdkBitmap*) NULL; - if (!m_currentClippingRegion.IsEmpty()) + if (!m_currentClippingRegion.IsNull()) { GdkColor col; new_mask = gdk_pixmap_new( wxRootWindow->window, bm_ww, bm_hh, 1 ); @@ -996,14 +1029,14 @@ bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord he { gdk_gc_set_clip_mask( m_textGC, (GdkBitmap *) NULL ); gdk_gc_set_clip_origin( m_textGC, 0, 0 ); - if (!m_currentClippingRegion.IsEmpty()) + if (!m_currentClippingRegion.IsNull()) gdk_gc_set_clip_region( m_textGC, m_currentClippingRegion.GetRegion() ); } else { gdk_gc_set_clip_mask( m_penGC, (GdkBitmap *) NULL ); gdk_gc_set_clip_origin( m_penGC, 0, 0 ); - if (!m_currentClippingRegion.IsEmpty()) + if (!m_currentClippingRegion.IsNull()) gdk_gc_set_clip_region( m_penGC, m_currentClippingRegion.GetRegion() ); } } @@ -1027,18 +1060,14 @@ bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord he wxBitmap bitmap( width, height ); - /* We have to use the srcDC's GC as it might be a - wxScreenDC and we only have the GDK_INCLUDE_INFERIORS - flag set there. */ - - if (srcDC->GetWindow() == GDK_ROOT_PARENT()) + if (srcDC->m_isScreenDC) gdk_gc_set_subwindow( m_penGC, GDK_INCLUDE_INFERIORS ); - gdk_window_copy_area( bitmap.GetPixmap(), srcDC->m_penGC, 0, 0, + gdk_window_copy_area( bitmap.GetPixmap(), m_penGC, 0, 0, srcDC->GetWindow(), xsrc, ysrc, width, height ); - if (srcDC->GetWindow() == GDK_ROOT_PARENT()) + if (srcDC->m_isScreenDC) gdk_gc_set_subwindow( m_penGC, GDK_CLIP_BY_CHILDREN ); /* scale image */ @@ -1059,14 +1088,14 @@ bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord he { /* No scaling and not a memory dc with a mask either */ - if (srcDC->GetWindow() == GDK_ROOT_PARENT()) + if (srcDC->m_isScreenDC) gdk_gc_set_subwindow( m_penGC, GDK_INCLUDE_INFERIORS ); gdk_window_copy_area( m_window, m_penGC, xx, yy, srcDC->GetWindow(), xsrc, ysrc, width, height ); - if (srcDC->GetWindow() == GDK_ROOT_PARENT()) + if (srcDC->m_isScreenDC) gdk_gc_set_subwindow( m_penGC, GDK_CLIP_BY_CHILDREN ); } } @@ -1474,8 +1503,8 @@ void wxWindowDC::SetBrush( const wxBrush &brush ) if ((m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) && (m_brush.GetStipple()->GetMask())) { - gdk_gc_set_fill( m_textGC, GDK_OPAQUE_STIPPLED); - gdk_gc_set_stipple( m_textGC, m_brush.GetStipple()->GetMask()->GetBitmap() ); + gdk_gc_set_fill( m_textGC, GDK_OPAQUE_STIPPLED); + gdk_gc_set_stipple( m_textGC, m_brush.GetStipple()->GetMask()->GetBitmap() ); } if (IS_HATCH(m_brush.GetStyle())) @@ -1650,13 +1679,13 @@ void wxWindowDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoo rect.width = XLOG2DEVREL(width); rect.height = YLOG2DEVREL(height); - if (!m_currentClippingRegion.IsEmpty()) + if (!m_currentClippingRegion.IsNull()) m_currentClippingRegion.Intersect( rect ); else m_currentClippingRegion.Union( rect ); #if USE_PAINT_REGION - if (!m_paintClippingRegion.IsEmpty()) + if (!m_paintClippingRegion.IsNull()) m_currentClippingRegion.Intersect( m_paintClippingRegion ); #endif @@ -1683,13 +1712,13 @@ void wxWindowDC::DoSetClippingRegionAsRegion( const wxRegion ®ion ) if (!m_window) return; - if (!m_currentClippingRegion.IsEmpty()) + if (!m_currentClippingRegion.IsNull()) m_currentClippingRegion.Intersect( region ); else m_currentClippingRegion.Union( region ); #if USE_PAINT_REGION - if (!m_paintClippingRegion.IsEmpty()) + if (!m_paintClippingRegion.IsNull()) m_currentClippingRegion.Intersect( m_paintClippingRegion ); #endif @@ -1960,16 +1989,13 @@ wxPaintDC::wxPaintDC( wxWindow *win ) : wxWindowDC( win ) { #if USE_PAINT_REGION - if (!win->GetUpdateRegion().IsEmpty()) - { - m_paintClippingRegion = win->GetUpdateRegion(); - m_currentClippingRegion.Union( m_paintClippingRegion ); + m_paintClippingRegion = win->GetUpdateRegion(); + m_currentClippingRegion.Union( m_paintClippingRegion ); - gdk_gc_set_clip_region( m_penGC, m_paintClippingRegion.GetRegion() ); - gdk_gc_set_clip_region( m_brushGC, m_paintClippingRegion.GetRegion() ); - gdk_gc_set_clip_region( m_textGC, m_paintClippingRegion.GetRegion() ); - gdk_gc_set_clip_region( m_bgGC, m_paintClippingRegion.GetRegion() ); - } + gdk_gc_set_clip_region( m_penGC, m_paintClippingRegion.GetRegion() ); + gdk_gc_set_clip_region( m_brushGC, m_paintClippingRegion.GetRegion() ); + gdk_gc_set_clip_region( m_textGC, m_paintClippingRegion.GetRegion() ); + gdk_gc_set_clip_region( m_bgGC, m_paintClippingRegion.GetRegion() ); #endif } diff --git a/src/gtk1/dcscreen.cpp b/src/gtk1/dcscreen.cpp index 825cd2b2de..51a09f4806 100644 --- a/src/gtk1/dcscreen.cpp +++ b/src/gtk1/dcscreen.cpp @@ -38,6 +38,8 @@ wxScreenDC::wxScreenDC() m_cmap = gdk_colormap_get_system(); m_window = GDK_ROOT_PARENT(); + m_isScreenDC = TRUE; + SetUpDC(); gdk_gc_set_subwindow( m_penGC, GDK_INCLUDE_INFERIORS ); diff --git a/src/gtk1/region.cpp b/src/gtk1/region.cpp index edb6b766d9..8af2c03eee 100644 --- a/src/gtk1/region.cpp +++ b/src/gtk1/region.cpp @@ -94,20 +94,11 @@ wxRegion::wxRegion( const wxRect& rect ) g_rect.height = rect.height; M_REGIONDATA->m_region = gdk_region_union_with_rect( reg, &g_rect ); gdk_region_destroy( reg ); - - wxNode *node = M_REGIONDATA->m_rects.First(); - while (node) - { - wxRect *r = (wxRect*)node->Data(); - M_REGIONDATA->m_rects.Append( (wxObject*) new wxRect(r->x,r->y,r->width,r->height) ); - node = node->Next(); - } + M_REGIONDATA->m_rects.Append( (wxObject*) new wxRect(rect.x,rect.y,rect.width,rect.height) ); } wxRegion::wxRegion() { - m_refData = new wxRegionRefData(); - M_REGIONDATA->m_region = gdk_region_new(); } wxRegion::~wxRegion() @@ -127,8 +118,6 @@ bool wxRegion::operator != ( const wxRegion& region ) void wxRegion::Clear() { UnRef(); - m_refData = new wxRegionRefData(); - M_REGIONDATA->m_region = gdk_region_new(); } bool wxRegion::Union( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) @@ -138,29 +127,41 @@ bool wxRegion::Union( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) rect.y = y; rect.width = width; rect.height = height; - GdkRegion *reg = gdk_region_union_with_rect( M_REGIONDATA->m_region, &rect ); - gdk_region_destroy( M_REGIONDATA->m_region ); - M_REGIONDATA->m_region = reg; + if (!m_refData) + { + m_refData = new wxRegionRefData(); + GdkRegion *reg = gdk_region_new(); + M_REGIONDATA->m_region = gdk_region_union_with_rect( reg, &rect ); + gdk_region_destroy( reg ); + } + else + { + GdkRegion *reg = gdk_region_union_with_rect( M_REGIONDATA->m_region, &rect ); + gdk_region_destroy( M_REGIONDATA->m_region ); + M_REGIONDATA->m_region = reg; + } + M_REGIONDATA->m_rects.Append( (wxObject*) new wxRect(x,y,width,height) ); + return TRUE; } bool wxRegion::Union( const wxRect& rect ) { - GdkRectangle g_rect; - g_rect.x = rect.x; - g_rect.y = rect.y; - g_rect.width = rect.width; - g_rect.height = rect.height; - GdkRegion *reg = gdk_region_union_with_rect( M_REGIONDATA->m_region, &g_rect ); - gdk_region_destroy( M_REGIONDATA->m_region ); - M_REGIONDATA->m_region = reg; - M_REGIONDATA->m_rects.Append( (wxObject*) new wxRect(rect.x,rect.y,rect.width,rect.height) ); - return TRUE; + return Union( rect.x, rect.y, rect.width, rect.height ); } bool wxRegion::Union( const wxRegion& region ) { + if (region.IsNull()) + return FALSE; + + if (!m_refData) + { + m_refData = new wxRegionRefData(); + M_REGIONDATA->m_region = gdk_region_new(); + } + GdkRegion *reg = gdk_regions_union( M_REGIONDATA->m_region, region.GetRegion() ); gdk_region_destroy( M_REGIONDATA->m_region ); M_REGIONDATA->m_region = reg; @@ -178,6 +179,12 @@ bool wxRegion::Union( const wxRegion& region ) bool wxRegion::Intersect( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) { + if (!m_refData) + { + m_refData = new wxRegionRefData(); + M_REGIONDATA->m_region = gdk_region_new(); + } + wxRegion reg( x, y, width, height ); Intersect( reg ); return TRUE; @@ -185,6 +192,12 @@ bool wxRegion::Intersect( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) bool wxRegion::Intersect( const wxRect& rect ) { + if (!m_refData) + { + m_refData = new wxRegionRefData(); + M_REGIONDATA->m_region = gdk_region_new(); + } + wxRegion reg( rect ); Intersect( reg ); return TRUE; @@ -192,6 +205,16 @@ bool wxRegion::Intersect( const wxRect& rect ) bool wxRegion::Intersect( const wxRegion& region ) { + if (region.IsNull()) + return FALSE; + + if (!m_refData) + { + m_refData = new wxRegionRefData(); + M_REGIONDATA->m_region = gdk_region_new(); + return TRUE; + } + GdkRegion *reg = gdk_regions_intersect( M_REGIONDATA->m_region, region.GetRegion() ); gdk_region_destroy( M_REGIONDATA->m_region ); M_REGIONDATA->m_region = reg; @@ -200,6 +223,12 @@ bool wxRegion::Intersect( const wxRegion& region ) bool wxRegion::Subtract( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) { + if (!m_refData) + { + m_refData = new wxRegionRefData(); + M_REGIONDATA->m_region = gdk_region_new(); + } + wxRegion reg( x, y, width, height ); Subtract( reg ); return TRUE; @@ -207,6 +236,12 @@ bool wxRegion::Subtract( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) bool wxRegion::Subtract( const wxRect& rect ) { + if (!m_refData) + { + m_refData = new wxRegionRefData(); + M_REGIONDATA->m_region = gdk_region_new(); + } + wxRegion reg( rect ); Subtract( reg ); return TRUE; @@ -214,6 +249,15 @@ bool wxRegion::Subtract( const wxRect& rect ) bool wxRegion::Subtract( const wxRegion& region ) { + if (region.IsNull()) + return FALSE; + + if (!m_refData) + { + m_refData = new wxRegionRefData(); + M_REGIONDATA->m_region = gdk_region_new(); + } + GdkRegion *reg = gdk_regions_subtract( M_REGIONDATA->m_region, region.GetRegion() ); gdk_region_destroy( M_REGIONDATA->m_region ); M_REGIONDATA->m_region = reg; @@ -222,6 +266,12 @@ bool wxRegion::Subtract( const wxRegion& region ) bool wxRegion::Xor( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) { + if (!m_refData) + { + m_refData = new wxRegionRefData(); + M_REGIONDATA->m_region = gdk_region_new(); + } + wxRegion reg( x, y, width, height ); Xor( reg ); return TRUE; @@ -229,6 +279,12 @@ bool wxRegion::Xor( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) bool wxRegion::Xor( const wxRect& rect ) { + if (!m_refData) + { + m_refData = new wxRegionRefData(); + M_REGIONDATA->m_region = gdk_region_new(); + } + wxRegion reg( rect ); Xor( reg ); return TRUE; @@ -236,6 +292,15 @@ bool wxRegion::Xor( const wxRect& rect ) bool wxRegion::Xor( const wxRegion& region ) { + if (region.IsNull()) + return NULL; + + if (!m_refData) + { + m_refData = new wxRegionRefData(); + M_REGIONDATA->m_region = gdk_region_new(); + } + GdkRegion *reg = gdk_regions_xor( M_REGIONDATA->m_region, region.GetRegion() ); gdk_region_destroy( M_REGIONDATA->m_region ); M_REGIONDATA->m_region = reg; @@ -251,12 +316,15 @@ bool wxRegion::Xor( const wxRegion& region ) return TRUE; } -void wxRegion::GetBox( wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h ) const +void wxRegion::GetBox( wxCoord &x, wxCoord &y, wxCoord &w, wxCoord &h ) const { x = 0; y = 0; w = -1; h = -1; + if (m_refData) + return; + GdkRectangle rect; gdk_region_get_clipbox( M_REGIONDATA->m_region, &rect ); x = rect.x; @@ -277,11 +345,17 @@ wxRect wxRegion::GetBox() const bool wxRegion::Empty() const { + if (!m_refData) + return TRUE; + return gdk_region_empty( M_REGIONDATA->m_region ); } wxRegionContain wxRegion::Contains( wxCoord x, wxCoord y ) const { + if (!m_refData) + return wxOutRegion; + if (gdk_region_point_in( M_REGIONDATA->m_region, x, y )) return wxInRegion; else @@ -290,6 +364,9 @@ wxRegionContain wxRegion::Contains( wxCoord x, wxCoord y ) const wxRegionContain wxRegion::Contains( wxCoord x, wxCoord y, wxCoord w, wxCoord h ) const { + if (!m_refData) + return wxOutRegion; + GdkRectangle rect; rect.x = x; rect.y = y; @@ -317,11 +394,17 @@ wxRegionContain wxRegion::Contains(const wxRect& rect) const GdkRegion *wxRegion::GetRegion() const { + if (!m_refData) + return (GdkRegion*) NULL; + return M_REGIONDATA->m_region; } wxList *wxRegion::GetRectList() const { + if (!m_refData) + return (wxList*) NULL; + return &(M_REGIONDATA->m_rects); } -- 2.45.2