From 9ba691fd6a0a243513c5b23320a4a4f17687c1fe Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Wed, 28 Feb 2007 21:42:09 +0000 Subject: [PATCH] Add an implementation of wxCairoContext::DrawBitmap git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@44582 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/generic/graphicc.cpp | 108 +++++++++++++++++++++++++++++++++++---- 1 file changed, 98 insertions(+), 10 deletions(-) diff --git a/src/generic/graphicc.cpp b/src/generic/graphicc.cpp index 0a447edbb2..a3a93aeb76 100755 --- a/src/generic/graphicc.cpp +++ b/src/generic/graphicc.cpp @@ -37,6 +37,7 @@ #endif #include "wx/graphics.h" +#include "wx/rawbmp.h" #if wxUSE_GRAPHICS_CONTEXT @@ -1145,20 +1146,107 @@ void wxCairoContext::PopState() void wxCairoContext::DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) { - /* - Bitmap* image = Bitmap::FromHBITMAP((HBITMAP)bmp.GetHBITMAP(),(HPALETTE)bmp.GetPalette()->GetHPALETTE()); - m_context->DrawImage(image,(REAL) x,(REAL) y,(REAL) w,(REAL) h) ; - delete image ; - */ + wxCHECK_RET( bmp.IsOk(), wxT("Invalid bitmap in wxCairoContext::DrawBitmap")); + + cairo_surface_t* surface; + int bw = bmp.GetWidth(); + int bh = bmp.GetHeight(); + wxBitmap bmpSource = bmp; // we need a non-const instance + + // Create a surface object and copy the bitmap pixel data to it. + if (bmpSource.HasAlpha() || bmpSource.GetMask()) + { + surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, bw, bh); + wxUint32* data = (wxUint32*)cairo_image_surface_get_data(surface); + wxAlphaPixelData pixData(bmpSource, wxPoint(0,0), wxSize(bw, bh)); + wxCHECK_RET( pixData, wxT("Failed to gain raw access to bitmap data.")); + + wxAlphaPixelData::Iterator p(pixData); + for (int y=0; yDrawImage(image,(REAL) x,(REAL) y,(REAL) w,(REAL) h) ; - delete image ; - */ + // An icon is a bitmap on wxGTK, so do this the easy way. When we want to + // start using the Cairo backend on other platforms then we may need to + // fiddle with this... + DrawBitmap(icon, x, y, w, h); }