return DoBlit(destPt.x, destPt.y, sz.x, sz.y,
source, srcPt.x, srcPt.y, rop, useMask, srcPtMask.x, srcPtMask.y);
}
+
+ wxBitmap GetAsBitmap()
+ {
+ return DoGetAsBitmap();
+ }
#if wxUSE_SPLINES
// TODO: this API needs fixing (wxPointList, why (!const) "wxList *"?)
wxDC *source, wxCoord xsrc, wxCoord ysrc,
int rop = wxCOPY, bool useMask = false, wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord) = 0;
+ virtual wxBitmap DoGetAsBitmap() const { return wxNullBitmap; }
+
virtual void DoGetSize(int *width, int *height) const = 0;
virtual void DoGetSizeMM(int* width, int* height) const = 0;
wxWindow *GetWindow() const { return m_window; }
protected :
virtual void DoGetSize( int *width, int *height ) const;
+ virtual wxBitmap DoGetAsBitmap() const;
wxWindow *m_window;
#if wxMAC_USE_CORE_GRAPHICS
bool m_release;
{
wxCHECK_MSG( Ok(), false, wxT("wxGCDC(cg)::DoBlit - invalid DC") );
wxCHECK_MSG( source->Ok(), false, wxT("wxGCDC(cg)::DoBlit - invalid source DC") );
-
+
if ( logical_func == wxNO_OP )
return true;
+ else if ( logical_func != wxCOPY )
+ {
+ wxFAIL_MSG( wxT("Blitting is only supported with wxCOPY logical operation.") );
+ return false;
+ }
if (xsrcMask == -1 && ysrcMask == -1)
{
wxCoord wwdest = LogicalToDeviceXRel(width);
wxCoord hhdest = LogicalToDeviceYRel(height);
+ wxBitmap blit;
wxMemoryDC* memdc = wxDynamicCast(source,wxMemoryDC);
- if ( memdc && logical_func == wxCOPY )
+ if ( memdc )
{
- wxBitmap blit = memdc->GetSelectedBitmap();
+ blit = memdc->GetSelectedBitmap();
wxASSERT_MSG( blit.Ok() , wxT("Invalid bitmap for blitting") );
blit = wxNullBitmap;
}
}
-
- if ( blit.Ok() )
- {
- m_graphicContext->DrawBitmap( blit, xxdest , yydest , wwdest , hhdest );
+ }
+ else
+ {
+ wxWindowDC* windc = wxDynamicCast(source,wxWindowDC);
+ if (windc)
+ {
+ wxBitmap bmp;
+ bmp = windc->GetAsBitmap();
+ if (bmp.IsOk())
+ blit = bmp.GetSubBitmap( wxRect(xsrc, ysrc, width, height ) );
}
}
+
+ if ( blit.Ok() )
+ {
+ m_graphicContext->DrawBitmap( blit, xxdest , yydest , wwdest , hhdest );
+ }
else
{
- wxFAIL_MSG( wxT("Blitting is only supported from bitmap contexts, and only with wxCOPY logical operation.") );
+ wxFAIL_MSG( wxT("Cannot Blit. Unable to get contents of DC as bitmap.") );
return false;
}
#endif
#include "wx/graphics.h"
+#include "wx/rawbmp.h"
#include "wx/mac/private.h"
//-----------------------------------------------------------------------------
#endif
}
+wxBitmap wxWindowDC::DoGetAsBitmap() const
+{
+ ControlRef handle = (ControlRef) m_window->GetHandle();
+ if ( !handle )
+ return wxNullBitmap;
+
+ HIRect rect;
+ CGImageRef image;
+ CGContextRef context;
+ void* data;
+
+ size_t bytesPerRow;
+
+ HIViewCreateOffscreenImage( handle, 0, &rect, &image);
+
+ int width = rect.size.width;
+ int height = rect.size.height;
+
+ bytesPerRow = ( ( width * 8 * 4 + 7 ) / 8 );
+
+ data = calloc( 1, bytesPerRow * height );
+ context = CGBitmapContextCreate( data, width, height, 8, bytesPerRow, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaPremultipliedFirst );
+
+ CGContextDrawImage( context, rect, image );
+
+ unsigned char* buffer = (unsigned char*) data;
+ wxBitmap bmp = wxBitmap(width, height, 32);
+ wxAlphaPixelData pixData(bmp, wxPoint(0,0), wxSize(width, height));
+
+ pixData.UseAlpha();
+ wxAlphaPixelData::Iterator p(pixData);
+ for (int y=0; y<height; y++) {
+ wxAlphaPixelData::Iterator rowStart = p;
+ for (int x=0; x<width; x++) {
+ unsigned char a = buffer[3];
+ p.Red() = a; buffer++;
+ p.Green() = a; buffer++;
+ p.Blue() = a; buffer++;
+ p.Alpha() = a; buffer++;
+ ++p;
+ }
+ p = rowStart;
+ p.OffsetY(pixData, 1);
+ }
+
+ return bmp;
+}
+
/*
* wxClientDC
*/