From: Paul Cornett Date: Mon, 17 Dec 2007 06:30:25 +0000 (+0000) Subject: create hatch bitmaps on demand, and dispose of them at termination X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/f7732fa59a48ada168c88ccd004eca3c848d8a05 create hatch bitmaps on demand, and dispose of them at termination git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@50759 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/gtk/dcclient.cpp b/src/gtk/dcclient.cpp index 7278c64129..1d2280dd4f 100644 --- a/src/gtk/dcclient.cpp +++ b/src/gtk/dcclient.cpp @@ -52,14 +52,11 @@ #include "horiz.xbm" #include "verti.xbm" #include "cross.xbm" -#define num_hatches 6 #define IS_15_PIX_HATCH(s) ((s)==wxCROSSDIAG_HATCH || (s)==wxHORIZONTAL_HATCH || (s)==wxVERTICAL_HATCH) #define IS_16_PIX_HATCH(s) ((s)!=wxCROSSDIAG_HATCH && (s)!=wxHORIZONTAL_HATCH && (s)!=wxVERTICAL_HATCH) - -static GdkPixmap *hatches[num_hatches]; -static GdkPixmap **hatch_bitmap = (GdkPixmap **) NULL; +static GdkPixmap* hatches[wxLAST_HATCH - wxFIRST_HATCH + 1]; extern GtkWidget *wxGetRootWindow(); @@ -78,6 +75,37 @@ static inline double dmin(double a, double b) { return a < b ? a : b; } static inline double DegToRad(double deg) { return (deg * M_PI) / 180.0; } +static GdkPixmap* GetHatch(int style) +{ + wxASSERT(style >= wxFIRST_HATCH && style <= wxLAST_HATCH); + const int i = style - wxFIRST_HATCH; + if (hatches[i] == NULL) + { + switch (style) + { + case wxBDIAGONAL_HATCH: + hatches[i] = gdk_bitmap_create_from_data(NULL, bdiag_bits, bdiag_width, bdiag_height); + break; + case wxCROSSDIAG_HATCH: + hatches[i] = gdk_bitmap_create_from_data(NULL, cdiag_bits, cdiag_width, cdiag_height); + break; + case wxCROSS_HATCH: + hatches[i] = gdk_bitmap_create_from_data(NULL, cross_bits, cross_width, cross_height); + break; + case wxFDIAGONAL_HATCH: + hatches[i] = gdk_bitmap_create_from_data(NULL, fdiag_bits, fdiag_width, fdiag_height); + break; + case wxHORIZONTAL_HATCH: + hatches[i] = gdk_bitmap_create_from_data(NULL, horiz_bits, horiz_width, horiz_height); + break; + case wxVERTICAL_HATCH: + hatches[i] = gdk_bitmap_create_from_data(NULL, verti_bits, verti_width, verti_height); + break; + } + } + return hatches[i]; +} + //----------------------------------------------------------------------------- // temporary implementation of the missing GDK function //----------------------------------------------------------------------------- @@ -424,17 +452,6 @@ void wxWindowDCImpl::SetUpDC( bool isMemDC ) gdk_gc_set_clip_rectangle( m_brushGC, (GdkRectangle *) NULL ); gdk_gc_set_clip_rectangle( m_textGC, (GdkRectangle *) NULL ); gdk_gc_set_clip_rectangle( m_bgGC, (GdkRectangle *) NULL ); - - if (!hatch_bitmap) - { - hatch_bitmap = hatches; - hatch_bitmap[0] = gdk_bitmap_create_from_data( (GdkWindow *) NULL, bdiag_bits, bdiag_width, bdiag_height ); - hatch_bitmap[1] = gdk_bitmap_create_from_data( (GdkWindow *) NULL, cdiag_bits, cdiag_width, cdiag_height ); - hatch_bitmap[2] = gdk_bitmap_create_from_data( (GdkWindow *) NULL, fdiag_bits, fdiag_width, fdiag_height ); - hatch_bitmap[3] = gdk_bitmap_create_from_data( (GdkWindow *) NULL, cross_bits, cross_width, cross_height ); - hatch_bitmap[4] = gdk_bitmap_create_from_data( (GdkWindow *) NULL, horiz_bits, horiz_width, horiz_height ); - hatch_bitmap[5] = gdk_bitmap_create_from_data( (GdkWindow *) NULL, verti_bits, verti_width, verti_height ); - } } void wxWindowDCImpl::DoGetSize( int* width, int* height ) const @@ -2085,8 +2102,7 @@ void wxWindowDCImpl::SetBrush( const wxBrush &brush ) if (m_brush.IsHatch()) { gdk_gc_set_fill( m_brushGC, GDK_STIPPLED ); - int num = m_brush.GetStyle() - wxBDIAGONAL_HATCH; - gdk_gc_set_stipple( m_brushGC, hatches[num] ); + gdk_gc_set_stipple(m_brushGC, GetHatch(m_brush.GetStyle())); } } @@ -2130,8 +2146,7 @@ void wxWindowDCImpl::SetBackground( const wxBrush &brush ) if (m_backgroundBrush.IsHatch()) { gdk_gc_set_fill( m_bgGC, GDK_STIPPLED ); - int num = m_backgroundBrush.GetStyle() - wxBDIAGONAL_HATCH; - gdk_gc_set_stipple( m_bgGC, hatches[num] ); + gdk_gc_set_stipple(m_bgGC, GetHatch(m_backgroundBrush.GetStyle())); } } @@ -2535,4 +2550,10 @@ bool wxDCModule::OnInit() void wxDCModule::OnExit() { wxCleanUpGCPool(); + + for (int i = wxLAST_HATCH - wxFIRST_HATCH; i--; ) + { + if (hatches[i]) + g_object_unref(hatches[i]); + } }