diff --git a/include/wx/cocoa/dc.h b/include/wx/cocoa/dc.h index dd4b3fdbe5..f7f46012ce 100644 --- a/include/wx/cocoa/dc.h +++ b/include/wx/cocoa/dc.h @@ -56,6 +56,10 @@ protected: void CocoaApplyTransformations(); float m_cocoaHeight; bool m_cocoaFlipped; +// Blitting + virtual bool CocoaDoBlitOnFocusedDC(wxCoord xdest, wxCoord ydest, + wxCoord width, wxCoord height, wxCoord xsrc, wxCoord ysrc, + int logicalFunc, bool useMask, wxCoord xsrcMask, wxCoord ysrcMask); //------------------------------------------------------------------------- // Implementation //------------------------------------------------------------------------- diff --git a/include/wx/cocoa/dcmemory.h b/include/wx/cocoa/dcmemory.h index d6ca56d864..a81f980166 100644 --- a/include/wx/cocoa/dcmemory.h +++ b/include/wx/cocoa/dcmemory.h @@ -29,6 +29,10 @@ protected: // DC stack virtual bool CocoaLockFocus(); virtual bool CocoaUnlockFocus(); +// Blitting + virtual bool CocoaDoBlitOnFocusedDC(wxCoord xdest, wxCoord ydest, + wxCoord width, wxCoord height, wxCoord xsrc, wxCoord ysrc, + int logicalFunc, bool useMask, wxCoord xsrcMask, wxCoord ysrcMask); }; #endif // __WX_COCOA_DCMEMORY_H__ diff --git a/src/cocoa/dc.mm b/src/cocoa/dc.mm index 2d230c92b3..6d887caf95 100644 --- a/src/cocoa/dc.mm +++ b/src/cocoa/dc.mm @@ -447,6 +447,16 @@ void wxDC::DoCrossHair(wxCoord x, wxCoord y) bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, wxDC *source, wxCoord xsrc, wxCoord ysrc, int rop, bool useMask , wxCoord xsrcMask, wxCoord ysrcMask) +{ + if(!CocoaTakeFocus()) return false; + if(!source) return false; + return source->CocoaDoBlitOnFocusedDC(xdest,ydest,width,height, + xsrc, ysrc, rop, useMask, xsrcMask, ysrcMask); +} + +bool wxDC::CocoaDoBlitOnFocusedDC(wxCoord xdest, wxCoord ydest, + wxCoord width, wxCoord height, wxCoord xsrc, wxCoord ysrc, + int logicalFunc, bool useMask, wxCoord xsrcMask, wxCoord ysrcMask) { return false; } diff --git a/src/cocoa/dcmemory.mm b/src/cocoa/dcmemory.mm index e097fea9a5..02efda166f 100644 --- a/src/cocoa/dcmemory.mm +++ b/src/cocoa/dcmemory.mm @@ -10,8 +10,11 @@ ///////////////////////////////////////////////////////////////////////////// #include "wx/dcmemory.h" +#include "wx/log.h" #import +#import +#import //----------------------------------------------------------------------------- // wxMemoryDC @@ -77,3 +80,41 @@ void wxMemoryDC::DoGetSize( int *width, int *height ) const *height = m_selectedBitmap.GetHeight(); } +bool wxMemoryDC::CocoaDoBlitOnFocusedDC(wxCoord xdest, wxCoord ydest, + wxCoord width, wxCoord height, wxCoord xsrc, wxCoord ysrc, + int logicalFunc, bool useMask, wxCoord xsrcMask, wxCoord ysrcMask) +{ + if(!m_selectedBitmap.Ok()) + return false; + + NSAffineTransform *transform = [NSAffineTransform transform]; + [transform translateXBy:xdest yBy:ydest]; + + NSAffineTransform *flipTransform = [NSAffineTransform transform]; + /* x' = 1x + 0y + 0 + y' = 0x + -1y + window's height + */ + NSAffineTransformStruct matrix = { + 1, 0 + , 0, -1 + , 0, height + }; + [flipTransform setTransformStruct: matrix]; + + NSGraphicsContext *context = [NSGraphicsContext currentContext]; + [context saveGraphicsState]; + [transform concat]; + [flipTransform concat]; + + wxLogDebug("[m_cocoaNSImage isFlipped]=%d", [m_cocoaNSImage isFlipped]); + [m_cocoaNSImage drawAtPoint: NSMakePoint(0,0) + fromRect: NSMakeRect(xsrc, + m_selectedBitmap.GetHeight()-height-ysrc, + width, height) + operation: NSCompositeCopy // FIXME: raster ops + fraction: 1.0]; + + [context restoreGraphicsState]; + return false; +} +