Added wxDC::GetAsBitmap, and implemented wxWindowDC::DoGetAsBitmap on OS X, in order to restore the ability to blit the contents of those DCs.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@42604 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -314,6 +314,11 @@ public:
|
|||||||
source, srcPt.x, srcPt.y, rop, useMask, srcPtMask.x, srcPtMask.y);
|
source, srcPt.x, srcPt.y, rop, useMask, srcPtMask.x, srcPtMask.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxBitmap GetAsBitmap()
|
||||||
|
{
|
||||||
|
return DoGetAsBitmap();
|
||||||
|
}
|
||||||
|
|
||||||
#if wxUSE_SPLINES
|
#if wxUSE_SPLINES
|
||||||
// TODO: this API needs fixing (wxPointList, why (!const) "wxList *"?)
|
// TODO: this API needs fixing (wxPointList, why (!const) "wxList *"?)
|
||||||
void DrawSpline(wxCoord x1, wxCoord y1,
|
void DrawSpline(wxCoord x1, wxCoord y1,
|
||||||
@@ -712,6 +717,8 @@ protected:
|
|||||||
wxDC *source, wxCoord xsrc, wxCoord ysrc,
|
wxDC *source, wxCoord xsrc, wxCoord ysrc,
|
||||||
int rop = wxCOPY, bool useMask = false, wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord) = 0;
|
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 DoGetSize(int *width, int *height) const = 0;
|
||||||
virtual void DoGetSizeMM(int* width, int* height) const = 0;
|
virtual void DoGetSizeMM(int* width, int* height) const = 0;
|
||||||
|
|
||||||
|
@@ -35,6 +35,7 @@ class WXDLLEXPORT wxWindowDC: public wxDC
|
|||||||
wxWindow *GetWindow() const { return m_window; }
|
wxWindow *GetWindow() const { return m_window; }
|
||||||
protected :
|
protected :
|
||||||
virtual void DoGetSize( int *width, int *height ) const;
|
virtual void DoGetSize( int *width, int *height ) const;
|
||||||
|
virtual wxBitmap DoGetAsBitmap() const;
|
||||||
wxWindow *m_window;
|
wxWindow *m_window;
|
||||||
#if wxMAC_USE_CORE_GRAPHICS
|
#if wxMAC_USE_CORE_GRAPHICS
|
||||||
bool m_release;
|
bool m_release;
|
||||||
|
@@ -857,6 +857,11 @@ bool wxGCDC::DoBlit(
|
|||||||
|
|
||||||
if ( logical_func == wxNO_OP )
|
if ( logical_func == wxNO_OP )
|
||||||
return true;
|
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)
|
if (xsrcMask == -1 && ysrcMask == -1)
|
||||||
{
|
{
|
||||||
@@ -874,10 +879,11 @@ bool wxGCDC::DoBlit(
|
|||||||
wxCoord wwdest = LogicalToDeviceXRel(width);
|
wxCoord wwdest = LogicalToDeviceXRel(width);
|
||||||
wxCoord hhdest = LogicalToDeviceYRel(height);
|
wxCoord hhdest = LogicalToDeviceYRel(height);
|
||||||
|
|
||||||
|
wxBitmap blit;
|
||||||
wxMemoryDC* memdc = wxDynamicCast(source,wxMemoryDC);
|
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") );
|
wxASSERT_MSG( blit.Ok() , wxT("Invalid bitmap for blitting") );
|
||||||
|
|
||||||
@@ -908,15 +914,26 @@ bool wxGCDC::DoBlit(
|
|||||||
blit = wxNullBitmap;
|
blit = wxNullBitmap;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( blit.Ok() )
|
|
||||||
{
|
|
||||||
m_graphicContext->DrawBitmap( blit, xxdest , yydest , wwdest , hhdest );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
wxFAIL_MSG( wxT("Blitting is only supported from bitmap contexts, and only with wxCOPY logical operation.") );
|
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("Cannot Blit. Unable to get contents of DC as bitmap.") );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -24,6 +24,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "wx/graphics.h"
|
#include "wx/graphics.h"
|
||||||
|
#include "wx/rawbmp.h"
|
||||||
#include "wx/mac/private.h"
|
#include "wx/mac/private.h"
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -187,6 +188,54 @@ void wxWindowDC::DoGetSize( int* width, int* height ) const
|
|||||||
#endif
|
#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
|
* wxClientDC
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user