X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/77ff2d2639049a0bd8d64d87fbe27694354b7097..520e470fdd0daef09c77938db642e4583933c90d:/src/gtk/bitmap.cpp diff --git a/src/gtk/bitmap.cpp b/src/gtk/bitmap.cpp index 6f3e9146fb..07519ea19f 100644 --- a/src/gtk/bitmap.cpp +++ b/src/gtk/bitmap.cpp @@ -16,8 +16,13 @@ #include "wx/icon.h" #include "gdk/gdkprivate.h" -#ifdef USE_GDK_IMLIB +#ifdef wxUSE_GDK_IMLIB + #include "../gdk_imlib/gdk_imlib.h" +#include "gdk/gdkx.h" // GDK_DISPLAY +#include +#include + #endif //----------------------------------------------------------------------------- @@ -28,7 +33,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxMask,wxObject) wxMask::wxMask(void) { - m_bitmap = NULL; + m_bitmap = (GdkBitmap *) NULL; } wxMask::wxMask( const wxBitmap& WXUNUSED(bitmap), const wxColour& WXUNUSED(colour) ) @@ -45,7 +50,7 @@ wxMask::wxMask( const wxBitmap& WXUNUSED(bitmap) ) wxMask::~wxMask(void) { -#ifdef USE_GDK_IMLIB +#ifdef wxUSE_GDK_IMLIB // do not delete the mask, gdk_imlib does it for you #else if (m_bitmap) gdk_bitmap_unref( m_bitmap ); @@ -75,7 +80,7 @@ class wxBitmapRefData: public wxObjectRefData int m_width; int m_height; int m_bpp; -#ifdef USE_GDK_IMLIB +#ifdef wxUSE_GDK_IMLIB GdkImlibImage *m_image; #endif wxPalette *m_palette; @@ -83,21 +88,21 @@ class wxBitmapRefData: public wxObjectRefData wxBitmapRefData::wxBitmapRefData(void) { - m_pixmap = NULL; - m_bitmap = NULL; - m_mask = NULL; + m_pixmap = (GdkPixmap *) NULL; + m_bitmap = (GdkBitmap *) NULL; + m_mask = (wxMask *) NULL; m_width = 0; m_height = 0; m_bpp = 0; - m_palette = NULL; -#ifdef USE_GDK_IMLIB - m_image = NULL; + m_palette = (wxPalette *) NULL; +#ifdef wxUSE_GDK_IMLIB + m_image = (GdkImlibImage *) NULL; #endif } wxBitmapRefData::~wxBitmapRefData(void) { -#ifdef USE_GDK_IMLIB +#ifdef wxUSE_GDK_IMLIB if (m_pixmap) gdk_imlib_free_pixmap( m_pixmap ); if (m_image) gdk_imlib_kill_image( m_image ); #else @@ -122,7 +127,7 @@ wxBitmap::wxBitmap(void) wxBitmap::wxBitmap( int width, int height, int depth ) { m_refData = new wxBitmapRefData(); - M_BMPDATA->m_mask = NULL; + M_BMPDATA->m_mask = (wxMask *) NULL; M_BMPDATA->m_pixmap = gdk_pixmap_new( (GdkWindow*) &gdk_root_parent, width, height, depth ); M_BMPDATA->m_width = width; @@ -136,7 +141,7 @@ wxBitmap::wxBitmap( char **bits ) { m_refData = new wxBitmapRefData(); -#ifndef USE_GDK_IMLIB +#ifndef wxUSE_GDK_IMLIB GdkBitmap *mask = NULL; @@ -189,7 +194,7 @@ wxBitmap::wxBitmap( const char bits[], int width, int height, int WXUNUSED(depth { m_refData = new wxBitmapRefData(); - M_BMPDATA->m_mask = NULL; + M_BMPDATA->m_mask = (wxMask *) NULL; M_BMPDATA->m_bitmap = gdk_bitmap_create_from_data( (GdkWindow*) &gdk_root_parent, (gchar *) bits, width, height ); M_BMPDATA->m_width = width; @@ -223,67 +228,108 @@ bool wxBitmap::operator != ( const wxBitmap& bmp ) bool wxBitmap::Ok(void) const { - return m_refData != NULL; + return (m_refData != NULL); } int wxBitmap::GetHeight(void) const { - if (!Ok()) return 0; + if (!Ok()) + { + wxFAIL_MSG( "invalid bitmap" ); + return -1; + } + return M_BMPDATA->m_height; } int wxBitmap::GetWidth(void) const { - if (!Ok()) return 0; + if (!Ok()) + { + wxFAIL_MSG( "invalid bitmap" ); + return -1; + } + return M_BMPDATA->m_width; } int wxBitmap::GetDepth(void) const { - if (!Ok()) return 0; + if (!Ok()) + { + wxFAIL_MSG( "invalid bitmap" ); + return -1; + } + return M_BMPDATA->m_bpp; } void wxBitmap::SetHeight( int height ) { if (!Ok()) return; + + wxFAIL_MSG( "wxBitmap::SetHeight not implemented" ); + M_BMPDATA->m_height = height; } void wxBitmap::SetWidth( int width ) { if (!Ok()) return; + + wxFAIL_MSG( "wxBitmap::SetWidth not implemented" ); + M_BMPDATA->m_width = width; } void wxBitmap::SetDepth( int depth ) { if (!Ok()) return; + + wxFAIL_MSG( "wxBitmap::SetDepth not implemented" ); + M_BMPDATA->m_bpp = depth; } wxMask *wxBitmap::GetMask(void) const { - if (!Ok()) return NULL; + if (!Ok()) + { + wxFAIL_MSG( "invalid bitmap" ); + return (wxMask *) NULL; + } return M_BMPDATA->m_mask; } void wxBitmap::SetMask( wxMask *mask ) { - if (!Ok()) return; + if (!Ok()) + { + wxFAIL_MSG( "invalid bitmap" ); + return; + } if (M_BMPDATA->m_mask) delete M_BMPDATA->m_mask; + M_BMPDATA->m_mask = mask; } void wxBitmap::Resize( int height, int width ) { - if (!Ok()) return; + if (!Ok()) + { + wxFAIL_MSG( "invalid bitmap" ); + return; + } -#ifdef USE_GDK_IMLIB +#ifdef wxUSE_GDK_IMLIB - if (M_BMPDATA->m_bitmap) return; // not supported for bitmaps + if (M_BMPDATA->m_bitmap) + { + wxFAIL_MSG( "wxBitmap::Resize not supported for mono-bitmaps" ); + return; + } if (!M_BMPDATA->m_image) RecreateImage(); @@ -298,20 +344,38 @@ void wxBitmap::Resize( int height, int width ) Render(); +#else + + wxFAIL_MSG( "wxBitmap::Resize not implemented without GdkImlib" ); + #endif } bool wxBitmap::SaveFile( const wxString &name, int WXUNUSED(type), wxPalette *WXUNUSED(palette) ) { -#ifdef USE_GDK_IMLIB + if (!Ok()) + { + wxFAIL_MSG( "invalid bitmap" ); + return FALSE; + } + +#ifdef wxUSE_GDK_IMLIB - if (!Ok()) return FALSE; + if (M_BMPDATA->m_bitmap) + { + wxFAIL_MSG( "wxBitmap::SaveFile not supported for mono-bitmaps" ); + return FALSE; + } if (!M_BMPDATA->m_image) RecreateImage(); - return gdk_imlib_save_image( M_BMPDATA->m_image, WXSTRINGCAST name, NULL ); + return gdk_imlib_save_image( M_BMPDATA->m_image, WXSTRINGCAST name, (GdkImlibSaveInfo *) NULL ); +#else + + wxFAIL_MSG( "wxBitmap::SaveFile not implemented without GdkImlib" ); + #endif return FALSE; @@ -319,7 +383,7 @@ bool wxBitmap::SaveFile( const wxString &name, int WXUNUSED(type), bool wxBitmap::LoadFile( const wxString &name, int WXUNUSED(type) ) { -#ifdef USE_GDK_IMLIB +#ifdef wxUSE_GDK_IMLIB UnRef(); m_refData = new wxBitmapRefData(); @@ -338,6 +402,11 @@ bool wxBitmap::LoadFile( const wxString &name, int WXUNUSED(type) ) M_BMPDATA->m_bpp = 24; // ? return TRUE; + +#else + + wxFAIL_MSG( "wxBitmap::LoadFile not implemented without GdkImlib" ); + #endif return FALSE; @@ -345,48 +414,134 @@ bool wxBitmap::LoadFile( const wxString &name, int WXUNUSED(type) ) wxPalette *wxBitmap::GetPalette(void) const { - if (!Ok()) return NULL; + if (!Ok()) return (wxPalette *) NULL; return M_BMPDATA->m_palette; } GdkPixmap *wxBitmap::GetPixmap(void) const { - if (!Ok()) return NULL; + if (!Ok()) + { + wxFAIL_MSG( "invalid bitmap" ); + return (GdkPixmap *) NULL; + } + +// if (!M_BMPDATA->m_image) RecreateImage(); + return M_BMPDATA->m_pixmap; } GdkBitmap *wxBitmap::GetBitmap(void) const { - if (!Ok()) return NULL; + if (!Ok()) + { + wxFAIL_MSG( "invalid bitmap" ); + return (GdkBitmap *) NULL; + } return M_BMPDATA->m_bitmap; } void wxBitmap::DestroyImage(void) { - if (!Ok()) return; + if (!Ok()) + { + wxFAIL_MSG( "invalid bitmap" ); + return; + } if (M_BMPDATA->m_image) { gdk_imlib_destroy_image( M_BMPDATA->m_image ); - M_BMPDATA->m_image = NULL; + M_BMPDATA->m_image = (GdkImlibImage *) NULL; } } void wxBitmap::RecreateImage(void) { + if (!Ok()) + { + wxFAIL_MSG( "invalid bitmap" ); + return; + } + +#ifdef wxUSE_GDK_IMLIB + + DestroyImage(); + + wxCHECK_RET( M_BMPDATA->m_pixmap != NULL, "invalid bitmap" ); + + long size = (long)(M_BMPDATA->m_width)*(long)(M_BMPDATA->m_height)*(long)3; + unsigned char *data = new unsigned char[size]; + for (long i = 0; i < size; i++) data[i] = 100; + + GdkImage *image = gdk_image_get( M_BMPDATA->m_pixmap, 0, 0, M_BMPDATA->m_width, M_BMPDATA->m_height ); + + long pos = 0; + for (int j = 0; j < M_BMPDATA->m_height; j++) + { + for (int i = 0; i < M_BMPDATA->m_width; i++) + { + XColor xcol; + xcol.pixel = gdk_image_get_pixel( image, i, j ); + Colormap cm = ((GdkColormapPrivate*)gdk_imlib_get_colormap())->xcolormap; + XQueryColor( gdk_display, cm, &xcol ); + + data[pos] = xcol.red; + data[pos+1] = xcol.green; + data[pos+2] = xcol.blue; + pos += 3; + } + } + + wxCHECK_RET( M_BMPDATA->m_pixmap != NULL, "invalid bitmap" ); + + M_BMPDATA->m_image = gdk_imlib_create_image_from_data( + data, (unsigned char*)NULL, M_BMPDATA->m_width, M_BMPDATA->m_height ); + + delete[] data; + + gdk_image_destroy( image ); + + Render(); + +#else + + wxFAIL_MSG( "wxBitmap::RecreateImage not implemented without GdkImlib" ); + +#endif } void wxBitmap::Render(void) { - if (!Ok()) return; + if (!Ok()) + { + wxFAIL_MSG( "invalid bitmap" ); + return; + } -#ifdef USE_GDK_IMLIB +#ifdef wxUSE_GDK_IMLIB + if (!M_BMPDATA->m_image) RecreateImage(); + + if (M_BMPDATA->m_pixmap) + { + gdk_imlib_free_pixmap( M_BMPDATA->m_pixmap ); + M_BMPDATA->m_pixmap = (GdkPixmap*) NULL; + } + if (M_BMPDATA->m_mask) + { + delete M_BMPDATA->m_mask; + M_BMPDATA->m_mask = (wxMask*) NULL; + } + gdk_imlib_render( M_BMPDATA->m_image, M_BMPDATA->m_image->rgb_width, M_BMPDATA->m_image->rgb_height ); M_BMPDATA->m_width = M_BMPDATA->m_image->rgb_width; M_BMPDATA->m_height = M_BMPDATA->m_image->rgb_height; M_BMPDATA->m_pixmap = gdk_imlib_move_image( M_BMPDATA->m_image ); + + wxCHECK_RET( M_BMPDATA->m_pixmap != NULL, "pixmap rendering failed" ) + GdkBitmap *mask = gdk_imlib_move_mask( M_BMPDATA->m_image ); if (mask) { @@ -394,6 +549,10 @@ void wxBitmap::Render(void) M_BMPDATA->m_mask->m_bitmap = mask; } +#else + + wxFAIL_MSG( "wxBitmap::Render not implemented without GdkImlib" ); + #endif }