Direct NSImage drawing

This commit is contained in:
Stefan Csomor 2018-09-20 21:53:22 +02:00 committed by Vadim Zeitlin
parent ee8132fea9
commit 3370b76318
2 changed files with 28 additions and 0 deletions

View File

@ -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 );

View File

@ -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];