porting dcscreen blit from 2.8

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56132 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2008-10-06 19:48:52 +00:00
parent 52cefafe7e
commit 4fcb208a4f
7 changed files with 292 additions and 2 deletions

View File

@@ -16,6 +16,7 @@
#include "wx/osx/private.h"
#include "wx/graphics.h"
#include "wx/osx/private/glgrab.h"
IMPLEMENT_ABSTRACT_CLASS(wxScreenDCImpl, wxWindowDCImpl)
@@ -57,3 +58,37 @@ wxScreenDCImpl::~wxScreenDCImpl()
DisposeWindow((WindowRef) m_overlayWindow );
#endif
}
wxBitmap wxScreenDCImpl::DoGetAsBitmap(const wxRect *subrect) const
{
CGRect srcRect = CGRectMake(0, 0, m_width, m_height);
if (subrect)
{
srcRect.origin.x = subrect->GetX();
srcRect.origin.y = subrect->GetY();
srcRect.size.width = subrect->GetWidth();
srcRect.size.height = subrect->GetHeight();
}
wxBitmap bmp = wxBitmap(srcRect.size.width, srcRect.size.height, 32);
CGContextRef context = (CGContextRef)bmp.GetHBITMAP();
CGContextSaveGState(context);
CGContextTranslateCTM( context, 0, m_height );
CGContextScaleCTM( context, 1, -1 );
if ( subrect )
srcRect = CGRectOffset( srcRect, -subrect->x, -subrect->y ) ;
CGImageRef image = grabViaOpenGL(kCGNullDirectDisplay, srcRect);
wxASSERT_MSG(image, wxT("wxScreenDC::GetAsBitmap - unable to get screenshot."));
CGContextDrawImage(context, srcRect, image);
CGContextRestoreGState(context);
return bmp;
}