From 3370b763181bb865b041a963be93f2b719c20f4c Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Thu, 20 Sep 2018 21:53:22 +0200 Subject: [PATCH] Direct NSImage drawing --- include/wx/osx/cocoa/private.h | 4 ++++ src/osx/carbon/utilscocoa.mm | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/include/wx/osx/cocoa/private.h b/include/wx/osx/cocoa/private.h index c460861a20..2d231e63df 100644 --- a/include/wx/osx/cocoa/private.h +++ b/include/wx/osx/cocoa/private.h @@ -32,6 +32,10 @@ OSStatus WXDLLIMPEXP_CORE wxMacDrawCGImage( CGContextRef inContext, const CGRect * inBounds, CGImageRef inImage) ; +void WXDLLIMPEXP_CORE wxOSXDrawNSImage( + CGContextRef inContext, + const CGRect * inBounds, + WX_NSImage inImage) ; WX_NSImage WXDLLIMPEXP_CORE wxOSXGetSystemImage(const wxString& name); WX_NSImage WXDLLIMPEXP_CORE wxOSXGetNSImageFromCGImage( CGImageRef image, double scale = 1.0, bool isTemplate = false); WX_NSImage WXDLLIMPEXP_CORE wxOSXGetNSImageFromIconRef( WXHICON iconref ); diff --git a/src/osx/carbon/utilscocoa.mm b/src/osx/carbon/utilscocoa.mm index 9b0fc6baa9..2cde919b82 100644 --- a/src/osx/carbon/utilscocoa.mm +++ b/src/osx/carbon/utilscocoa.mm @@ -280,6 +280,30 @@ CGContextRef WXDLLIMPEXP_CORE wxOSXCreateBitmapContextFromNSImage( WX_NSImage ns return hbitmap; } +void WXDLLIMPEXP_CORE wxOSXDrawNSImage( + CGContextRef inContext, + const CGRect * inBounds, + WX_NSImage inImage) +{ + if (inImage != nil) + { + CGContextSaveGState(inContext); + CGContextTranslateCTM(inContext, inBounds->origin.x, inBounds->origin.y + inBounds->size.height); + CGRect r = *inBounds; + r.origin.x = r.origin.y = 0; + CGContextScaleCTM(inContext, 1, -1); + + NSGraphicsContext *previousContext = [NSGraphicsContext currentContext]; + NSGraphicsContext *nsGraphicsContext = [NSGraphicsContext graphicsContextWithGraphicsPort:inContext flipped:NO]; + [NSGraphicsContext setCurrentContext:nsGraphicsContext]; + [inImage drawInRect:NSRectFromCGRect(r) fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0]; + [NSGraphicsContext setCurrentContext:previousContext]; + + CGContextRestoreGState(inContext); + + } +} + double wxOSXGetMainScreenContentScaleFactor() { return [[NSScreen mainScreen] backingScaleFactor];