X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d76fe38b29803642f9b70c1457c25dbc1640f63e..6342bd1ab36c1957684c00d408d09fba65d33db6:/src/gtk/bitmap.cpp diff --git a/src/gtk/bitmap.cpp b/src/gtk/bitmap.cpp index bbde889014..ed3595f860 100644 --- a/src/gtk/bitmap.cpp +++ b/src/gtk/bitmap.cpp @@ -20,6 +20,16 @@ #include #include +extern void gdk_wx_draw_bitmap (GdkDrawable *drawable, + GdkGC *gc, + GdkDrawable *src, + gint xsrc, + gint ysrc, + gint xdest, + gint ydest, + gint width, + gint height); + //----------------------------------------------------------------------------- // data //----------------------------------------------------------------------------- @@ -92,20 +102,22 @@ bool wxMask::Create( const wxBitmap& bitmap, unsigned char green = colour.Green(); unsigned char blue = colour.Blue(); - GdkVisual *visual = gdk_visual_get_system(); + GdkVisual *visual = gdk_window_get_visual( wxRootWindow->window ); + wxASSERT( visual ); + int bpp = visual->depth; if ((bpp == 16) && (visual->red_mask != 0xf800)) bpp = 15; if (bpp == 15) { red = red & 0xf8; - blue = blue & 0xf8; green = green & 0xf8; + blue = blue & 0xf8; } if (bpp == 16) { red = red & 0xf8; - blue = blue & 0xfc; - green = green & 0xf8; + green = green & 0xfc; + blue = blue & 0xf8; } color.red = 0; @@ -178,7 +190,7 @@ bool wxMask::Create( const wxBitmap& bitmap ) GdkGC *gc = gdk_gc_new( m_bitmap ); - gdk_draw_bitmap( m_bitmap, gc, bitmap.GetBitmap(), 0, 0, 0, 0, bitmap.GetWidth(), bitmap.GetHeight() ); + gdk_wx_draw_bitmap( m_bitmap, gc, bitmap.GetBitmap(), 0, 0, 0, 0, bitmap.GetWidth(), bitmap.GetHeight() ); gdk_gc_unref( gc ); @@ -241,12 +253,24 @@ wxBitmap::wxBitmap() wxBitmap::wxBitmap( int width, int height, int depth ) { - wxCHECK_RET( (width > 0) && (height > 0), wxT("invalid bitmap size") ) + Create( width, height, depth ); - if (depth == -1) depth = gdk_window_get_visual( wxRootWindow->window )->depth; + if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this); +} - wxCHECK_RET( (depth == gdk_window_get_visual( wxRootWindow->window )->depth) || - (depth == 1), wxT("invalid bitmap depth") ) +bool wxBitmap::Create( int width, int height, int depth ) +{ + UnRef(); + + wxCHECK_MSG( (width > 0) && (height > 0), FALSE, wxT("invalid bitmap size") ) + + GdkVisual *visual = gdk_window_get_visual( wxRootWindow->window ); + wxASSERT( visual ); + + if (depth == -1) depth = visual->depth; + + wxCHECK_MSG( (depth == visual->depth) || + (depth == 1), FALSE, wxT("invalid bitmap depth") ) m_refData = new wxBitmapRefData(); M_BMPDATA->m_mask = (wxMask *) NULL; @@ -260,16 +284,18 @@ wxBitmap::wxBitmap( int width, int height, int depth ) else { M_BMPDATA->m_pixmap = gdk_pixmap_new( wxRootWindow->window, width, height, depth ); - M_BMPDATA->m_bpp = gdk_window_get_visual( wxRootWindow->window )->depth; + M_BMPDATA->m_bpp = visual->depth; } - if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this); + return Ok(); } - bool wxBitmap::CreateFromXpm( const char **bits ) { wxCHECK_MSG( bits != NULL, FALSE, wxT("invalid bitmap data") ) + GdkVisual *visual = gdk_window_get_visual( wxRootWindow->window ); + wxASSERT( visual ); + m_refData = new wxBitmapRefData(); GdkBitmap *mask = (GdkBitmap*) NULL; @@ -286,7 +312,8 @@ bool wxBitmap::CreateFromXpm( const char **bits ) gdk_window_get_size( M_BMPDATA->m_pixmap, &(M_BMPDATA->m_width), &(M_BMPDATA->m_height) ); - M_BMPDATA->m_bpp = gdk_window_get_visual( wxRootWindow->window )->depth; // ? + M_BMPDATA->m_bpp = visual->depth; // ? + if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this); return TRUE; @@ -334,12 +361,12 @@ wxBitmap& wxBitmap::operator = ( const wxBitmap& bmp ) return *this; } -bool wxBitmap::operator == ( const wxBitmap& bmp ) +bool wxBitmap::operator == ( const wxBitmap& bmp ) const { return m_refData == bmp.m_refData; } -bool wxBitmap::operator != ( const wxBitmap& bmp ) +bool wxBitmap::operator != ( const wxBitmap& bmp ) const { return m_refData != bmp.m_refData; } @@ -405,7 +432,7 @@ wxBitmap wxBitmap::GetSubBitmap( const wxRect& rect) const else { GdkGC *gc = gdk_gc_new( ret.GetBitmap() ); - gdk_draw_bitmap( ret.GetBitmap(), gc, GetBitmap(), rect.x, rect.y, 0, 0, rect.width, rect.height ); + gdk_wx_draw_bitmap( ret.GetBitmap(), gc, GetBitmap(), rect.x, rect.y, 0, 0, rect.width, rect.height ); gdk_gc_destroy( gc ); } @@ -415,7 +442,7 @@ wxBitmap wxBitmap::GetSubBitmap( const wxRect& rect) const mask->m_bitmap = gdk_pixmap_new( wxRootWindow->window, rect.width, rect.height, 1 ); GdkGC *gc = gdk_gc_new( mask->m_bitmap ); - gdk_draw_bitmap( mask->m_bitmap, gc, M_BMPDATA->m_mask->m_bitmap, 0, 0, rect.x, rect.y, rect.width, rect.height ); + gdk_wx_draw_bitmap( mask->m_bitmap, gc, M_BMPDATA->m_mask->m_bitmap, 0, 0, rect.x, rect.y, rect.width, rect.height ); gdk_gc_destroy( gc ); ret.SetMask( mask ); @@ -443,6 +470,9 @@ bool wxBitmap::LoadFile( const wxString &name, int type ) if (!wxFileExists(name)) return FALSE; + GdkVisual *visual = gdk_window_get_visual( wxRootWindow->window ); + wxASSERT( visual ); + if (type == wxBITMAP_TYPE_XPM) { m_refData = new wxBitmapRefData(); @@ -458,7 +488,8 @@ bool wxBitmap::LoadFile( const wxString &name, int type ) } gdk_window_get_size( M_BMPDATA->m_pixmap, &(M_BMPDATA->m_width), &(M_BMPDATA->m_height) ); - M_BMPDATA->m_bpp = gdk_window_get_visual( wxRootWindow->window )->depth; + + M_BMPDATA->m_bpp = visual->depth; } else // try if wxImage can load it {