X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a11672a469f036436838911c268cb2f8d5da5bf8..5e885a580a735716af33b47b0743b5fa04a0cb9f:/src/x11/bitmap.cpp diff --git a/src/x11/bitmap.cpp b/src/x11/bitmap.cpp index 6d4c558c3e..ad2ae57169 100644 --- a/src/x11/bitmap.cpp +++ b/src/x11/bitmap.cpp @@ -18,11 +18,25 @@ #include "wx/log.h" #include "wx/image.h" #include "wx/app.h" +#if wxUSE_NANOX +#include "wx/dcmemory.h" +#endif #include "wx/x11/private.h" +/* No point in using libXPM for NanoX */ +#if wxUSE_NANOX +#undef wxHAVE_LIB_XPM +#define wxHAVE_LIB_XPM 0 +#endif + +#if wxUSE_XPM #if wxHAVE_LIB_XPM - #include +#include +#else +#include "wx/xpmdecod.h" +#include "wx/wfstream.h" +#endif #endif #include @@ -65,6 +79,7 @@ wxMask::~wxMask() bool wxMask::Create( const wxBitmap& bitmap, const wxColour& colour ) { +#if !wxUSE_NANOX if (m_bitmap) { XFreePixmap( (Display*) m_display, (Pixmap) m_bitmap ); @@ -162,6 +177,10 @@ bool wxMask::Create( const wxBitmap& bitmap, XFreeGC( xdisplay, gc ); return TRUE; +#else + return FALSE; +#endif + // wxUSE_NANOX } bool wxMask::Create( const wxBitmap& bitmap, int paletteIndex ) @@ -178,6 +197,7 @@ bool wxMask::Create( const wxBitmap& bitmap, int paletteIndex ) bool wxMask::Create( const wxBitmap& bitmap ) { +#if !wxUSE_NANOX if (m_bitmap) { XFreePixmap( (Display*) m_display, (Pixmap) m_bitmap ); @@ -205,6 +225,10 @@ bool wxMask::Create( const wxBitmap& bitmap ) XFreeGC( (Display*) m_display, gc ); return TRUE; +#else + return FALSE; +#endif + // wxUSE_NANOX } //----------------------------------------------------------------------------- @@ -286,6 +310,13 @@ bool wxBitmap::Create( int width, int height, int depth ) M_BMPDATA->m_mask = (wxMask *) NULL; M_BMPDATA->m_width = width; M_BMPDATA->m_height = height; + +#if wxUSE_NANOX + M_BMPDATA->m_bitmap = (WXPixmap) GrNewPixmap(width, height, NULL); + M_BMPDATA->m_bpp = bpp; + + wxASSERT_MSG( M_BMPDATA->m_bitmap, wxT("Bitmap creation failed") ); +#else if (depth == 1) { M_BMPDATA->m_bitmap = (WXPixmap) XCreatePixmap( (Display*) M_BMPDATA->m_display, xroot, width, height, 1 ); @@ -302,12 +333,14 @@ bool wxBitmap::Create( int width, int height, int depth ) M_BMPDATA->m_bpp = depth; } - +#endif return Ok(); } bool wxBitmap::CreateFromXpm( const char **bits ) { +#if wxUSE_XPM +#if wxHAVE_LIB_XPM UnRef(); wxCHECK_MSG( bits != NULL, FALSE, wxT("invalid bitmap data") ) @@ -358,6 +391,7 @@ bool wxBitmap::CreateFromXpm( const char **bits ) M_BMPDATA->m_mask->SetBitmap( (WXPixmap) mask ); M_BMPDATA->m_mask->SetDisplay( xdisplay ); } + return TRUE; } else { @@ -365,12 +399,74 @@ bool wxBitmap::CreateFromXpm( const char **bits ) return FALSE; } - - return TRUE; +#else + wxXPMDecoder decoder; + wxImage image(decoder.ReadData(bits)); + if (image.Ok()) + return CreateFromImage(image); + else + return FALSE; +#endif +#endif + return FALSE; } bool wxBitmap::CreateFromImage( const wxImage& image, int depth ) { +#if wxUSE_NANOX + if (!image.Ok()) + { + wxASSERT_MSG(image.Ok(), "Invalid wxImage passed to wxBitmap::CreateFromImage."); + return FALSE; + } + + int w = image.GetWidth(); + int h = image.GetHeight(); + + if (!Create(w, h, depth)) + return FALSE; + + wxMemoryDC memDC; + memDC.SelectObject(*this); + + // Warning: this is very inefficient. + wxPen pen; + pen.SetStyle(wxSOLID); + pen.SetWidth(1); + + int i, j; + for (i = 0; i < w; i++) + { + for (j = 0; j < h; j++) + { + unsigned char red = image.GetRed(i, j); + unsigned char green = image.GetGreen(i, j); + unsigned char blue = image.GetBlue(i, j); + wxColour colour(red, green, blue); + + pen.SetColour(colour); + memDC.SetPen(pen); + memDC.DrawPoint(i, j); + +#if 0 + if (hasMask) + { + // scan the bitmap for the transparent colour and set the corresponding + // pixels in the mask to BLACK and the rest to WHITE + if (maskR == red && maskG == green && maskB == blue) + ::SetPixel(hMaskDC, i, j, PALETTERGB(0, 0, 0)); + else + ::SetPixel(hMaskDC, i, j, PALETTERGB(255, 255, 255)); + } +#endif + } + } + memDC.SelectObject(wxNullBitmap); + + return TRUE; +#else + // !wxUSE_NANOX + UnRef(); wxCHECK_MSG( image.Ok(), FALSE, wxT("invalid image") ) @@ -598,6 +694,9 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth ) GC gc = XCreateGC( xdisplay, (Pixmap) M_BMPDATA->m_pixmap, 0, NULL ); XPutImage( xdisplay, (Pixmap) M_BMPDATA->m_pixmap, gc, data_image, 0, 0, 0, 0, width, height ); +#ifdef __WXDEBUG__ + XSync(wxGlobalDisplay(), False); +#endif XDestroyImage( data_image ); XFreeGC( xdisplay, gc ); @@ -615,6 +714,8 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth ) } return TRUE; +#endif + // wxUSE_NANOX } static void wxCalcPrecAndShift( unsigned long mask, int *shift, int *prec ) @@ -648,7 +749,37 @@ wxImage wxBitmap::ConvertToImage() const Visual* xvisual = DefaultVisual( xdisplay, xscreen ); int bpp = DefaultDepth( xdisplay, xscreen ); + +#if wxUSE_NANOX + int w = image.GetWidth(); + int h = image.GetHeight(); + wxMemoryDC memDC; + memDC.SelectObject(*this); + + wxColour pixelCol; + + // Warning: this is very inefficient. + int i, j; + for (i = 0; i < w; i++) + { + for (j = 0; j < h; j++) + { + memDC.GetPixel(i, j, & pixelCol); + + // TODO: make wxColour accessors more efficient + // by inlining, if possible + image.SetRGB(i, j, + pixelCol.Red(), pixelCol.Green(), + pixelCol.Blue()); + } + } + memDC.SelectObject(wxNullBitmap); + + return image; + +#else + // !wxUSE_NANOX XImage *x_image = NULL; if (GetPixmap()) { @@ -801,8 +932,9 @@ wxImage wxBitmap::ConvertToImage() const XDestroyImage( x_image ); if (x_image_mask) XDestroyImage( x_image_mask ); - return image; +#endif + // wxUSE_NANOX } wxBitmap::wxBitmap( const wxBitmap& bmp ) @@ -817,6 +949,7 @@ wxBitmap::wxBitmap( const wxString &filename, int type ) wxBitmap::wxBitmap( const char bits[], int width, int height, int WXUNUSED(depth) ) { +#if !wxUSE_NANOX m_refData = new wxBitmapRefData(); M_BMPDATA->m_display = wxGlobalDisplay(); @@ -831,7 +964,7 @@ wxBitmap::wxBitmap( const char bits[], int width, int height, int WXUNUSED(depth M_BMPDATA->m_width = width; M_BMPDATA->m_height = height; M_BMPDATA->m_bpp = 1; - +#endif wxCHECK_RET( M_BMPDATA->m_bitmap, wxT("couldn't create bitmap") ); } @@ -970,6 +1103,8 @@ bool wxBitmap::LoadFile( const wxString &name, int type ) if (type == wxBITMAP_TYPE_XPM) { +#if wxUSE_XPM +#if wxHAVE_LIB_XPM m_refData = new wxBitmapRefData(); M_BMPDATA->m_display = wxGlobalDisplay(); @@ -1013,6 +1148,29 @@ bool wxBitmap::LoadFile( const wxString &name, int type ) return FALSE; } +#else +#if wxUSE_STREAMS + wxXPMDecoder decoder; + wxFileInputStream stream(name); + if (stream.Ok()) + { + wxImage image(decoder.ReadFile(stream)); + if (image.Ok()) + return CreateFromImage(image); + else + return FALSE; + } + else + return FALSE; +#else + return FALSE; +#endif + // wxUSE_STREAMS +#endif + // wxHAVE_LIB_XPM +#endif + // wxUSE_XPM + return FALSE; } else // try if wxImage can load it {