X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/6db34764d7ba8ea3c221b3e302d26071af944f6e..0c8b041f147ff9bb6ce38f0e2da1fd82f6484523:/src/gtk1/bitmap.cpp diff --git a/src/gtk1/bitmap.cpp b/src/gtk1/bitmap.cpp index ea76fd0e34..df7af69140 100644 --- a/src/gtk1/bitmap.cpp +++ b/src/gtk1/bitmap.cpp @@ -16,13 +16,14 @@ #include "wx/defs.h" -#include "wx/palette.h" #include "wx/bitmap.h" +#include "wx/palette.h" #include "wx/icon.h" #include "wx/filefn.h" #include "wx/image.h" #include "wx/dcmemory.h" #include "wx/app.h" +#include "wx/rawbmp.h" #ifdef __WXGTK20__ // need this to get gdk_image_new_bitmap() @@ -39,7 +40,7 @@ #include #endif // GTK+ 2.0/1.2 -#include +#include "wx/math.h" extern void gdk_wx_draw_bitmap (GdkDrawable *drawable, GdkGC *gc, @@ -306,7 +307,7 @@ bool wxBitmap::Create( int width, int height, int depth ) if (depth == -1) depth = visual->depth; - wxCHECK_MSG( (depth == visual->depth) || (depth == 1), FALSE, + wxCHECK_MSG( (depth == visual->depth) || (depth == 1) || (depth == 32), FALSE, wxT("invalid bitmap depth") ) m_refData = new wxBitmapRefData(); @@ -318,6 +319,14 @@ bool wxBitmap::Create( int width, int height, int depth ) M_BMPDATA->m_bitmap = gdk_pixmap_new( wxGetRootWindow()->window, width, height, 1 ); M_BMPDATA->m_bpp = 1; } +#ifdef __WXGTK20__ + else if (depth == 32) + { + M_BMPDATA->m_pixbuf = gdk_pixbuf_new( GDK_COLORSPACE_RGB, true, + 8, width, height); + M_BMPDATA->m_bpp = 32; + } +#endif else { M_BMPDATA->m_pixmap = gdk_pixmap_new( wxGetRootWindow()->window, width, height, depth ); @@ -1153,12 +1162,12 @@ wxImage wxBitmap::ConvertToImage() const } wxBitmap::wxBitmap( const wxBitmap& bmp ) - : wxGDIObject() + : wxBitmapBase() { Ref( bmp ); } -wxBitmap::wxBitmap( const wxString &filename, int type ) +wxBitmap::wxBitmap( const wxString &filename, wxBitmapType type ) { LoadFile( filename, type ); } @@ -1324,7 +1333,7 @@ wxBitmap wxBitmap::GetSubBitmap( const wxRect& rect) const return ret; } -bool wxBitmap::SaveFile( const wxString &name, int type, wxPalette *WXUNUSED(palette) ) +bool wxBitmap::SaveFile( const wxString &name, wxBitmapType type, const wxPalette *WXUNUSED(palette) ) const { wxCHECK_MSG( Ok(), FALSE, wxT("invalid bitmap") ); @@ -1337,7 +1346,7 @@ bool wxBitmap::SaveFile( const wxString &name, int type, wxPalette *WXUNUSED(pal return FALSE; } -bool wxBitmap::LoadFile( const wxString &name, int type ) +bool wxBitmap::LoadFile( const wxString &name, wxBitmapType type ) { UnRef(); @@ -1390,6 +1399,11 @@ wxPalette *wxBitmap::GetPalette() const return M_BMPDATA->m_palette; } +void wxBitmap::SetPalette(const wxPalette& WXUNUSED(palette)) +{ + // TODO +} + void wxBitmap::SetHeight( int height ) { if (!m_refData) @@ -1444,9 +1458,11 @@ GdkPixmap *wxBitmap::GetPixmap() const // create the pixmap on the fly if we use Pixbuf representation: if (HasPixbuf() && !HasPixmap()) { + delete M_BMPDATA->m_mask; + M_BMPDATA->m_mask = new wxMask(); gdk_pixbuf_render_pixmap_and_mask(M_BMPDATA->m_pixbuf, &M_BMPDATA->m_pixmap, - NULL /*mask*/, + &M_BMPDATA->m_mask->m_bitmap, 128 /*threshold*/); } #endif // __WXGTK20__ @@ -1549,3 +1565,84 @@ void wxBitmap::PurgeOtherRepresentations(wxBitmap::Representation keep) } #endif // __WXGTK20__ + +void *wxBitmap::GetRawData(wxPixelDataBase& data, int bpp) +{ +#ifdef __WXGTK20__ + if (bpp != 32) + return NULL; + + GdkPixbuf *pixbuf = GetPixbuf(); + if (!pixbuf) + return NULL; + +#if 0 + if (gdk_pixbuf_get_has_alpha( pixbuf )) + wxPrintf( wxT("Has alpha\n") ); + else + wxPrintf( wxT("No alpha.\n") ); +#endif + + data.m_height = gdk_pixbuf_get_height( pixbuf ); + data.m_width = gdk_pixbuf_get_width( pixbuf ); + data.m_stride = gdk_pixbuf_get_rowstride( pixbuf ); + + return gdk_pixbuf_get_pixels( pixbuf ); +#else + return NULL; +#endif +} + +void wxBitmap::UngetRawData(wxPixelDataBase& data) +{ +} + + +bool wxBitmap::HasAlpha() const +{ +#ifdef __WXGTK20__ + return HasPixbuf(); +#else + return false; +#endif +} + +void wxBitmap::UseAlpha() +{ +#ifdef __WXGTK20__ + GetPixbuf(); +#endif +} + +//----------------------------------------------------------------------------- +// wxBitmapHandler +//----------------------------------------------------------------------------- + +IMPLEMENT_DYNAMIC_CLASS(wxBitmapHandler,wxBitmapHandlerBase) + +wxBitmapHandler::~wxBitmapHandler() +{ +} + +bool wxBitmapHandler::Create(wxBitmap *bitmap, void *data, long type, int width, int height, int depth) +{ + return FALSE; +} + +bool wxBitmapHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long flags, + int desiredWidth, int desiredHeight) +{ + return FALSE; +} + +bool wxBitmapHandler::SaveFile(const wxBitmap *bitmap, const wxString& name, int type, const wxPalette *palette) +{ + return FALSE; +} + +/* static */ void wxBitmap::InitStandardHandlers() +{ + // TODO: Insert handler based on GdkPixbufs handler later +} + +