Add support for template NSImages to wxBitmap
wxBitmap uses CGImage instead of NSImage internally and the conversion looses NSImage metadata. In particular, it looses the "template" attribute, which is set for files ending with "Template" and loaded trough wxArtProvider. This change makes it easy to use template images with native controls such as the toolbar. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_3_0_BRANCH@78017 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -32,9 +32,9 @@ OSStatus WXDLLIMPEXP_CORE wxMacDrawCGImage(
|
||||
CGContextRef inContext,
|
||||
const CGRect * inBounds,
|
||||
CGImageRef inImage) ;
|
||||
WX_NSImage WXDLLIMPEXP_CORE wxOSXGetNSImageFromCGImage( CGImageRef image, double scale = 1.0 );
|
||||
WX_NSImage WXDLLIMPEXP_CORE wxOSXGetNSImageFromCGImage( CGImageRef image, double scale = 1.0, bool isTemplate = false);
|
||||
CGImageRef WXDLLIMPEXP_CORE wxOSXCreateCGImageFromNSImage( WX_NSImage nsimage, double *scale = NULL );
|
||||
CGContextRef WXDLLIMPEXP_CORE wxOSXCreateBitmapContextFromNSImage( WX_NSImage nsimage);
|
||||
CGContextRef WXDLLIMPEXP_CORE wxOSXCreateBitmapContextFromNSImage( WX_NSImage nsimage, bool *isTemplate = NULL);
|
||||
|
||||
wxBitmap WXDLLIMPEXP_CORE wxOSXCreateSystemBitmap(const wxString& id, const wxString &client, const wxSize& size);
|
||||
WXWindow WXDLLIMPEXP_CORE wxOSXGetMainWindow();
|
||||
|
@@ -418,7 +418,7 @@ wxBitmap wxOSXCreateSystemBitmap(const wxString& name, const wxString &WXUNUSED(
|
||||
}
|
||||
|
||||
// From "Cocoa Drawing Guide:Working with Images"
|
||||
WX_NSImage wxOSXGetNSImageFromCGImage( CGImageRef image, double scaleFactor )
|
||||
WX_NSImage wxOSXGetNSImageFromCGImage( CGImageRef image, double scaleFactor, bool isTemplate )
|
||||
{
|
||||
NSRect imageRect = NSMakeRect(0.0, 0.0, 0.0, 0.0);
|
||||
|
||||
@@ -435,6 +435,8 @@ WX_NSImage wxOSXGetNSImageFromCGImage( CGImageRef image, double scaleFactor )
|
||||
CGContextDrawImage( imageContext, *(CGRect*)&imageRect, image );
|
||||
[newImage unlockFocus];
|
||||
|
||||
[newImage setTemplate:isTemplate];
|
||||
|
||||
/*
|
||||
// Create a bitmap rep from the image...
|
||||
NSBitmapImageRep *bitmapRep = [[NSBitmapImageRep alloc] initWithCGImage:cgImage];
|
||||
@@ -447,7 +449,7 @@ WX_NSImage wxOSXGetNSImageFromCGImage( CGImageRef image, double scaleFactor )
|
||||
return( newImage );
|
||||
}
|
||||
|
||||
CGContextRef WXDLLIMPEXP_CORE wxOSXCreateBitmapContextFromNSImage( WX_NSImage nsimage)
|
||||
CGContextRef WXDLLIMPEXP_CORE wxOSXCreateBitmapContextFromNSImage( WX_NSImage nsimage, bool *isTemplate)
|
||||
{
|
||||
// based on http://www.mail-archive.com/cocoa-dev@lists.apple.com/msg18065.html
|
||||
|
||||
@@ -469,6 +471,9 @@ CGContextRef WXDLLIMPEXP_CORE wxOSXCreateBitmapContextFromNSImage( WX_NSImage ns
|
||||
NSRectFill(NSMakeRect(0.0, 0.0, imageSize.width, imageSize.height));
|
||||
[nsimage drawAtPoint:NSZeroPoint fromRect:NSZeroRect operation:NSCompositeCopy fraction:1.0];
|
||||
[NSGraphicsContext setCurrentContext:previousContext];
|
||||
|
||||
if (isTemplate)
|
||||
*isTemplate = [nsimage isTemplate];
|
||||
}
|
||||
return hbitmap;
|
||||
}
|
||||
|
@@ -86,6 +86,9 @@ public:
|
||||
bool HasAlpha() const { return m_hasAlpha; }
|
||||
void UseAlpha( bool useAlpha );
|
||||
|
||||
bool IsTemplate() const { return m_isTemplate; }
|
||||
void SetTemplate(bool is) { m_isTemplate = is; }
|
||||
|
||||
public:
|
||||
#if wxUSE_PALETTE
|
||||
wxPalette m_bitmapPalette;
|
||||
@@ -126,6 +129,7 @@ public:
|
||||
int m_rawAccessCount;
|
||||
bool m_ok;
|
||||
mutable CGImageRef m_cgImageRef;
|
||||
bool m_isTemplate;
|
||||
|
||||
#ifndef __WXOSX_IPHONE__
|
||||
IconRef m_iconRef;
|
||||
@@ -240,6 +244,7 @@ void wxBitmapRefData::Init()
|
||||
m_ok = false ;
|
||||
m_bitmapMask = NULL ;
|
||||
m_cgImageRef = NULL ;
|
||||
m_isTemplate = false;
|
||||
|
||||
#ifndef __WXOSX_IPHONE__
|
||||
m_iconRef = NULL ;
|
||||
@@ -1078,7 +1083,11 @@ wxBitmap::wxBitmap(WX_NSImage image)
|
||||
|
||||
bool wxBitmap::Create(WX_NSImage image)
|
||||
{
|
||||
return Create(wxOSXCreateBitmapContextFromNSImage(image));
|
||||
bool isTemplate;
|
||||
if (!Create(wxOSXCreateBitmapContextFromNSImage(image, &isTemplate)))
|
||||
return false;
|
||||
M_BITMAPDATA->SetTemplate(isTemplate);
|
||||
return true;
|
||||
}
|
||||
|
||||
wxBitmap::wxBitmap(CGContextRef bitmapcontext)
|
||||
@@ -1098,7 +1107,7 @@ bool wxBitmap::Create(CGContextRef bitmapcontext)
|
||||
WX_NSImage wxBitmap::GetNSImage() const
|
||||
{
|
||||
wxCFRef< CGImageRef > cgimage(CreateCGImage());
|
||||
return wxOSXGetNSImageFromCGImage( cgimage, GetScaleFactor() );
|
||||
return wxOSXGetNSImageFromCGImage( cgimage, GetScaleFactor(), M_BITMAPDATA->IsTemplate() );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user