Removing non-native bitmap code, using common code for iOS and macOS
This commit is contained in:
committed by
Vadim Zeitlin
parent
bca583234e
commit
266f32493e
@@ -2764,6 +2764,7 @@ DECLARE_WXCOCOA_OBJC_CLASS(NSString);
|
|||||||
|
|
||||||
typedef WX_NSWindow WXWindow;
|
typedef WX_NSWindow WXWindow;
|
||||||
typedef WX_NSView WXWidget;
|
typedef WX_NSView WXWidget;
|
||||||
|
typedef WX_NSImage WXImage;
|
||||||
typedef WX_NSMenu WXHMENU;
|
typedef WX_NSMenu WXHMENU;
|
||||||
typedef WX_NSOpenGLPixelFormat WXGLPixelFormat;
|
typedef WX_NSOpenGLPixelFormat WXGLPixelFormat;
|
||||||
typedef WX_NSOpenGLContext WXGLContext;
|
typedef WX_NSOpenGLContext WXGLContext;
|
||||||
@@ -2771,6 +2772,7 @@ typedef WX_NSOpenGLContext WXGLContext;
|
|||||||
#elif wxOSX_USE_IPHONE
|
#elif wxOSX_USE_IPHONE
|
||||||
|
|
||||||
DECLARE_WXCOCOA_OBJC_CLASS(UIWindow);
|
DECLARE_WXCOCOA_OBJC_CLASS(UIWindow);
|
||||||
|
DECLARE_WXCOCOA_OBJC_CLASS(UImage);
|
||||||
DECLARE_WXCOCOA_OBJC_CLASS(UIView);
|
DECLARE_WXCOCOA_OBJC_CLASS(UIView);
|
||||||
DECLARE_WXCOCOA_OBJC_CLASS(UIFont);
|
DECLARE_WXCOCOA_OBJC_CLASS(UIFont);
|
||||||
DECLARE_WXCOCOA_OBJC_CLASS(UIImage);
|
DECLARE_WXCOCOA_OBJC_CLASS(UIImage);
|
||||||
@@ -2781,6 +2783,7 @@ DECLARE_WXCOCOA_OBJC_CLASS(UIWebView);
|
|||||||
|
|
||||||
typedef WX_UIWindow WXWindow;
|
typedef WX_UIWindow WXWindow;
|
||||||
typedef WX_UIView WXWidget;
|
typedef WX_UIView WXWidget;
|
||||||
|
typedef WX_UIImage WXImage;
|
||||||
typedef WX_EAGLContext WXGLContext;
|
typedef WX_EAGLContext WXGLContext;
|
||||||
typedef WX_NSString WXGLPixelFormat;
|
typedef WX_NSString WXGLPixelFormat;
|
||||||
typedef WX_UIWebView OSXWebViewPtr;
|
typedef WX_UIWebView OSXWebViewPtr;
|
||||||
|
@@ -118,7 +118,7 @@ public:
|
|||||||
|
|
||||||
// creates an bitmap from the native image format
|
// creates an bitmap from the native image format
|
||||||
wxBitmap(CGImageRef image, double scale = 1.0);
|
wxBitmap(CGImageRef image, double scale = 1.0);
|
||||||
wxBitmap(WX_NSImage image);
|
wxBitmap(WXImage image);
|
||||||
wxBitmap(CGContextRef bitmapcontext);
|
wxBitmap(CGContextRef bitmapcontext);
|
||||||
|
|
||||||
// Create a bitmap compatible with the given DC
|
// Create a bitmap compatible with the given DC
|
||||||
@@ -147,7 +147,7 @@ public:
|
|||||||
|
|
||||||
virtual bool Create(const void* data, wxBitmapType type, int width, int height, int depth = 1);
|
virtual bool Create(const void* data, wxBitmapType type, int width, int height, int depth = 1);
|
||||||
bool Create( CGImageRef image, double scale = 1.0 );
|
bool Create( CGImageRef image, double scale = 1.0 );
|
||||||
bool Create( WX_NSImage image );
|
bool Create( WXImage image );
|
||||||
bool Create( CGContextRef bitmapcontext);
|
bool Create( CGContextRef bitmapcontext);
|
||||||
|
|
||||||
// Create a bitmap compatible with the given DC, inheriting its magnification factor
|
// Create a bitmap compatible with the given DC, inheriting its magnification factor
|
||||||
@@ -207,13 +207,16 @@ public:
|
|||||||
// returns a CGImageRef which must released after usage with CGImageRelease
|
// returns a CGImageRef which must released after usage with CGImageRelease
|
||||||
CGImageRef CreateCGImage() const ;
|
CGImageRef CreateCGImage() const ;
|
||||||
|
|
||||||
|
WXImage GetImage() const;
|
||||||
#if wxOSX_USE_COCOA
|
#if wxOSX_USE_COCOA
|
||||||
// returns an autoreleased version of the image
|
// returns an autoreleased version of the image
|
||||||
WX_NSImage GetNSImage() const;
|
WX_NSImage GetNSImage() const
|
||||||
|
{ return GetImage(); }
|
||||||
#endif
|
#endif
|
||||||
#if wxOSX_USE_IPHONE
|
#if wxOSX_USE_IPHONE
|
||||||
// returns an autoreleased version of the image
|
// returns an autoreleased version of the image
|
||||||
WX_UIImage GetUIImage() const;
|
WX_UIImage GetUIImage() const
|
||||||
|
{ return GetImage(); }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if WXWIN_COMPATIBILITY_3_0
|
#if WXWIN_COMPATIBILITY_3_0
|
||||||
|
@@ -41,10 +41,6 @@ WX_NSImage WXDLLIMPEXP_CORE wxOSXGetNSImageFromCGImage( CGImageRef image, double
|
|||||||
WX_NSImage WXDLLIMPEXP_CORE wxOSXGetNSImageFromIconRef( WXHICON iconref );
|
WX_NSImage WXDLLIMPEXP_CORE wxOSXGetNSImageFromIconRef( WXHICON iconref );
|
||||||
WX_NSImage WXDLLIMPEXP_CORE wxOSXGetIconForType(OSType type );
|
WX_NSImage WXDLLIMPEXP_CORE wxOSXGetIconForType(OSType type );
|
||||||
void WXDLLIMPEXP_CORE wxOSXSetImageSize(WX_NSImage image, CGFloat width, CGFloat height);
|
void WXDLLIMPEXP_CORE wxOSXSetImageSize(WX_NSImage image, CGFloat width, CGFloat height);
|
||||||
CGSize WXDLLIMPEXP_CORE wxOSXGetImageSize(WX_NSImage image);
|
|
||||||
CGImageRef WXDLLIMPEXP_CORE wxOSXCreateCGImageFromNSImage( WX_NSImage nsimage, double *scale = NULL );
|
|
||||||
CGImageRef WXDLLIMPEXP_CORE wxOSXGetCGImageFromNSImage( WX_NSImage nsimage, CGRect* r, CGContextRef cg);
|
|
||||||
CGContextRef WXDLLIMPEXP_CORE wxOSXCreateBitmapContextFromNSImage( WX_NSImage nsimage, bool *isTemplate = NULL);
|
|
||||||
|
|
||||||
wxBitmap WXDLLIMPEXP_CORE wxOSXCreateSystemBitmap(const wxString& id, const wxString &client, const wxSize& size);
|
wxBitmap WXDLLIMPEXP_CORE wxOSXCreateSystemBitmap(const wxString& id, const wxString &client, const wxSize& size);
|
||||||
WXWindow WXDLLIMPEXP_CORE wxOSXGetMainWindow();
|
WXWindow WXDLLIMPEXP_CORE wxOSXGetMainWindow();
|
||||||
|
@@ -114,6 +114,15 @@ WXDLLIMPEXP_CORE CGColorSpaceRef wxMacGetGenericRGBColorSpace(void);
|
|||||||
|
|
||||||
WXDLLIMPEXP_CORE double wxOSXGetMainScreenContentScaleFactor();
|
WXDLLIMPEXP_CORE double wxOSXGetMainScreenContentScaleFactor();
|
||||||
|
|
||||||
|
// UI
|
||||||
|
|
||||||
|
CGSize WXDLLIMPEXP_CORE wxOSXGetImageSize(WXImage image);
|
||||||
|
CGImageRef WXDLLIMPEXP_CORE wxOSXCreateCGImageFromImage( WXImage nsimage, double *scale = NULL );
|
||||||
|
CGImageRef WXDLLIMPEXP_CORE wxOSXGetCGImageFromImage( WXImage nsimage, CGRect* r, CGContextRef cg);
|
||||||
|
CGContextRef WXDLLIMPEXP_CORE wxOSXCreateBitmapContextFromImage( WXImage nsimage, bool *isTemplate = NULL);
|
||||||
|
WXImage WXDLLIMPEXP_CORE wxOSXGetImageFromCGImage( CGImageRef image, double scale = 1.0, bool isTemplate = false);
|
||||||
|
|
||||||
|
|
||||||
class wxWindowMac;
|
class wxWindowMac;
|
||||||
// to
|
// to
|
||||||
extern wxWindow* g_MacLastWindow;
|
extern wxWindow* g_MacLastWindow;
|
||||||
|
@@ -165,11 +165,6 @@ WXWindow wxOSXGetKeyWindow()
|
|||||||
|
|
||||||
#if wxOSX_USE_IPHONE
|
#if wxOSX_USE_IPHONE
|
||||||
|
|
||||||
WX_UIImage wxOSXGetUIImageFromCGImage( CGImageRef image )
|
|
||||||
{
|
|
||||||
return [UIImage imageWithCGImage:image];
|
|
||||||
}
|
|
||||||
|
|
||||||
wxBitmap wxOSXCreateSystemBitmap(const wxString& name, const wxString &client, const wxSize& size)
|
wxBitmap wxOSXCreateSystemBitmap(const wxString& name, const wxString &client, const wxSize& size)
|
||||||
{
|
{
|
||||||
#if 1
|
#if 1
|
||||||
@@ -181,29 +176,11 @@ wxBitmap wxOSXCreateSystemBitmap(const wxString& name, const wxString &client, c
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
double wxOSXGetMainScreenContentScaleFactor()
|
|
||||||
{
|
|
||||||
double scale;
|
|
||||||
|
|
||||||
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 40000
|
|
||||||
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
|
|
||||||
{
|
|
||||||
scale=[[UIScreen mainScreen] scale];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
scale=1.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if wxOSX_USE_COCOA
|
#if wxOSX_USE_COCOA
|
||||||
|
|
||||||
WX_NSImage wxOSXGetSystemImage(const wxString& name)
|
WXImage wxOSXGetSystemImage(const wxString& name)
|
||||||
{
|
{
|
||||||
wxCFStringRef cfname(name);
|
wxCFStringRef cfname(name);
|
||||||
NSImage* nsimage = [NSImage imageNamed:cfname.AsNSString()];
|
NSImage* nsimage = [NSImage imageNamed:cfname.AsNSString()];
|
||||||
@@ -222,38 +199,47 @@ wxBitmap wxOSXCreateSystemBitmap(const wxString& name, const wxString &client, c
|
|||||||
return wxNullBitmap;
|
return wxNullBitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
WX_NSImage wxOSXGetNSImageFromCGImage( CGImageRef image, double scaleFactor, bool isTemplate )
|
#endif
|
||||||
|
|
||||||
|
WXImage wxOSXGetImageFromCGImage( CGImageRef image, double scaleFactor, bool isTemplate )
|
||||||
{
|
{
|
||||||
NSRect imageRect = NSMakeRect(0.0, 0.0, 0.0, 0.0);
|
#if wxOSX_USE_COCOA
|
||||||
|
NSSize sz;
|
||||||
// Get the image dimensions.
|
sz.height = CGImageGetHeight(image)/scaleFactor;
|
||||||
imageRect.size.height = CGImageGetHeight(image)/scaleFactor;
|
sz.width = CGImageGetWidth(image)/scaleFactor;
|
||||||
imageRect.size.width = CGImageGetWidth(image)/scaleFactor;
|
NSImage* newImage = [[NSImage alloc] initWithCGImage:image size:sz];
|
||||||
|
|
||||||
NSImage* newImage = [[NSImage alloc] initWithCGImage:image size:imageRect.size];
|
|
||||||
|
|
||||||
[newImage setTemplate:isTemplate];
|
[newImage setTemplate:isTemplate];
|
||||||
|
|
||||||
[newImage autorelease];
|
[newImage autorelease];
|
||||||
return( newImage );
|
return( newImage );
|
||||||
|
#else
|
||||||
|
return [UIImage imageWithCGImage:image scale:scaleFactor orientation:UIImageOrientationUp];
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
WX_NSImage WXDLLIMPEXP_CORE wxOSXGetNSImageFromIconRef( WXHICON iconref )
|
#if wxOSX_USE_ICONREF
|
||||||
|
WXImage WXDLLIMPEXP_CORE wxOSXGetNSImageFromIconRef( WXHICON iconref )
|
||||||
{
|
{
|
||||||
NSImage *newImage = [[NSImage alloc] initWithIconRef:iconref];
|
NSImage *newImage = [[NSImage alloc] initWithIconRef:iconref];
|
||||||
[newImage autorelease];
|
[newImage autorelease];
|
||||||
return( newImage );
|
return( newImage );
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
CGImageRef WXDLLIMPEXP_CORE wxOSXGetCGImageFromNSImage( WX_NSImage nsimage, CGRect* r, CGContextRef cg)
|
CGImageRef WXDLLIMPEXP_CORE wxOSXGetCGImageFromImage( WXImage nsimage, CGRect* r, CGContextRef cg)
|
||||||
{
|
{
|
||||||
|
#if wxOSX_USE_COCOA
|
||||||
NSRect nsRect = NSRectFromCGRect(*r);
|
NSRect nsRect = NSRectFromCGRect(*r);
|
||||||
return [nsimage CGImageForProposedRect:&nsRect
|
return [nsimage CGImageForProposedRect:&nsRect
|
||||||
context:[NSGraphicsContext graphicsContextWithGraphicsPort:cg flipped:YES]
|
context:[NSGraphicsContext graphicsContextWithGraphicsPort:cg flipped:YES]
|
||||||
hints:nil];
|
hints:nil];
|
||||||
|
#else
|
||||||
|
return [nsimage CGImage];
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
CGContextRef WXDLLIMPEXP_CORE wxOSXCreateBitmapContextFromNSImage( WX_NSImage nsimage, bool *isTemplate)
|
CGContextRef WXDLLIMPEXP_CORE wxOSXCreateBitmapContextFromImage( WXImage nsimage, bool *isTemplate)
|
||||||
{
|
{
|
||||||
// based on http://www.mail-archive.com/cocoa-dev@lists.apple.com/msg18065.html
|
// based on http://www.mail-archive.com/cocoa-dev@lists.apple.com/msg18065.html
|
||||||
|
|
||||||
@@ -261,13 +247,18 @@ CGContextRef WXDLLIMPEXP_CORE wxOSXCreateBitmapContextFromNSImage( WX_NSImage ns
|
|||||||
if (nsimage != nil)
|
if (nsimage != nil)
|
||||||
{
|
{
|
||||||
double scale = wxOSXGetMainScreenContentScaleFactor();
|
double scale = wxOSXGetMainScreenContentScaleFactor();
|
||||||
|
|
||||||
|
#if wxOSX_USE_COCOA
|
||||||
NSSize imageSize = [nsimage size];
|
NSSize imageSize = [nsimage size];
|
||||||
|
#else
|
||||||
|
CGSize imageSize = [nsimage size];
|
||||||
|
#endif
|
||||||
|
|
||||||
hbitmap = CGBitmapContextCreate(NULL, imageSize.width*scale, imageSize.height*scale, 8, 0, wxMacGetGenericRGBColorSpace(), kCGImageAlphaPremultipliedFirst);
|
hbitmap = CGBitmapContextCreate(NULL, imageSize.width*scale, imageSize.height*scale, 8, 0, wxMacGetGenericRGBColorSpace(), kCGImageAlphaPremultipliedFirst);
|
||||||
CGContextScaleCTM( hbitmap, scale, scale );
|
CGContextScaleCTM( hbitmap, scale, scale );
|
||||||
CGContextClearRect(hbitmap,CGRectMake(0, 0, imageSize.width, imageSize.height));
|
CGContextClearRect(hbitmap,CGRectMake(0, 0, imageSize.width, imageSize.height));
|
||||||
|
|
||||||
|
#if wxOSX_USE_COCOA
|
||||||
NSGraphicsContext *previousContext = [NSGraphicsContext currentContext];
|
NSGraphicsContext *previousContext = [NSGraphicsContext currentContext];
|
||||||
NSGraphicsContext *nsGraphicsContext = [NSGraphicsContext graphicsContextWithGraphicsPort:hbitmap flipped:NO];
|
NSGraphicsContext *nsGraphicsContext = [NSGraphicsContext graphicsContextWithGraphicsPort:hbitmap flipped:NO];
|
||||||
[NSGraphicsContext setCurrentContext:nsGraphicsContext];
|
[NSGraphicsContext setCurrentContext:nsGraphicsContext];
|
||||||
@@ -276,6 +267,10 @@ CGContextRef WXDLLIMPEXP_CORE wxOSXCreateBitmapContextFromNSImage( WX_NSImage ns
|
|||||||
|
|
||||||
if (isTemplate)
|
if (isTemplate)
|
||||||
*isTemplate = [nsimage isTemplate];
|
*isTemplate = [nsimage isTemplate];
|
||||||
|
#else
|
||||||
|
wxUnusedVar(isTemplate);
|
||||||
|
CGContextDrawImage(hbitmap,CGRectMake(0, 0, imageSize.width, imageSize.height),[nsimage CGImage]);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
return hbitmap;
|
return hbitmap;
|
||||||
}
|
}
|
||||||
@@ -283,7 +278,7 @@ CGContextRef WXDLLIMPEXP_CORE wxOSXCreateBitmapContextFromNSImage( WX_NSImage ns
|
|||||||
void WXDLLIMPEXP_CORE wxOSXDrawNSImage(
|
void WXDLLIMPEXP_CORE wxOSXDrawNSImage(
|
||||||
CGContextRef inContext,
|
CGContextRef inContext,
|
||||||
const CGRect * inBounds,
|
const CGRect * inBounds,
|
||||||
WX_NSImage inImage)
|
WXImage inImage)
|
||||||
{
|
{
|
||||||
if (inImage != nil)
|
if (inImage != nil)
|
||||||
{
|
{
|
||||||
@@ -293,12 +288,15 @@ void WXDLLIMPEXP_CORE wxOSXDrawNSImage(
|
|||||||
r.origin.x = r.origin.y = 0;
|
r.origin.x = r.origin.y = 0;
|
||||||
CGContextScaleCTM(inContext, 1, -1);
|
CGContextScaleCTM(inContext, 1, -1);
|
||||||
|
|
||||||
NSGraphicsContext *previousContext = [NSGraphicsContext currentContext];
|
#if wxOSX_USE_COCOA
|
||||||
|
NSGraphicsContext *previousContext = [NSGraphicsContext currentContext];
|
||||||
NSGraphicsContext *nsGraphicsContext = [NSGraphicsContext graphicsContextWithGraphicsPort:inContext flipped:NO];
|
NSGraphicsContext *nsGraphicsContext = [NSGraphicsContext graphicsContextWithGraphicsPort:inContext flipped:NO];
|
||||||
[NSGraphicsContext setCurrentContext:nsGraphicsContext];
|
[NSGraphicsContext setCurrentContext:nsGraphicsContext];
|
||||||
[inImage drawInRect:NSRectFromCGRect(r) fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
|
[inImage drawInRect:NSRectFromCGRect(r) fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
|
||||||
[NSGraphicsContext setCurrentContext:previousContext];
|
[NSGraphicsContext setCurrentContext:previousContext];
|
||||||
|
#else
|
||||||
|
CGContextDrawImage(inContext, *inBounds, [inImage CGImage]);
|
||||||
|
#endif
|
||||||
CGContextRestoreGState(inContext);
|
CGContextRestoreGState(inContext);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -306,30 +304,50 @@ void WXDLLIMPEXP_CORE wxOSXDrawNSImage(
|
|||||||
|
|
||||||
double wxOSXGetMainScreenContentScaleFactor()
|
double wxOSXGetMainScreenContentScaleFactor()
|
||||||
{
|
{
|
||||||
|
#if wxOSX_USE_COCOA
|
||||||
return [[NSScreen mainScreen] backingScaleFactor];
|
return [[NSScreen mainScreen] backingScaleFactor];
|
||||||
|
#else
|
||||||
|
return [[UIScreen mainScreen] scale];
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
WX_NSImage wxOSXGetIconForType(OSType type )
|
WXImage wxOSXGetIconForType(OSType type )
|
||||||
{
|
{
|
||||||
|
#if wxOSX_USE_COCOA
|
||||||
return [[NSWorkspace sharedWorkspace] iconForFileType: NSFileTypeForHFSTypeCode(type)];
|
return [[NSWorkspace sharedWorkspace] iconForFileType: NSFileTypeForHFSTypeCode(type)];
|
||||||
|
#else
|
||||||
|
return NULL;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxOSXSetImageSize(WX_NSImage image, CGFloat width, CGFloat height)
|
void wxOSXSetImageSize(WXImage image, CGFloat width, CGFloat height)
|
||||||
{
|
{
|
||||||
|
#if wxOSX_USE_COCOA
|
||||||
[image setSize:NSMakeSize(width, height)];
|
[image setSize:NSMakeSize(width, height)];
|
||||||
|
#else
|
||||||
|
// TODO
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
CGSize wxOSXGetImageSize(WX_NSImage image)
|
CGSize wxOSXGetImageSize(WXImage image)
|
||||||
{
|
{
|
||||||
|
#if wxOSX_USE_COCOA
|
||||||
return NSSizeToCGSize([image size]);
|
return NSSizeToCGSize([image size]);
|
||||||
|
#else
|
||||||
|
return [image size];
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
CGImageRef wxOSXCreateCGImageFromNSImage( WX_NSImage nsimage, double *scaleptr )
|
CGImageRef wxOSXCreateCGImageFromImage( WXImage nsimage, double *scaleptr )
|
||||||
{
|
{
|
||||||
CGImageRef image = NULL;
|
CGImageRef image = NULL;
|
||||||
if (nsimage != nil)
|
if (nsimage != nil)
|
||||||
{
|
{
|
||||||
|
#if wxOSX_USE_COCOA
|
||||||
image = [nsimage CGImageForProposedRect:nil context:nil hints:nil];
|
image = [nsimage CGImageForProposedRect:nil context:nil hints:nil];
|
||||||
|
#else
|
||||||
|
image = [nsimage CGImage];
|
||||||
|
#endif
|
||||||
CFRetain(image);
|
CFRetain(image);
|
||||||
if ( scaleptr )
|
if ( scaleptr )
|
||||||
*scaleptr = CGImageGetWidth(image)/[nsimage size].width;
|
*scaleptr = CGImageGetWidth(image)/[nsimage size].width;
|
||||||
@@ -343,6 +361,8 @@ CGImageRef wxOSXCreateCGImageFromNSImage( WX_NSImage nsimage, double *scaleptr )
|
|||||||
|
|
||||||
// copied from cursor.mm
|
// copied from cursor.mm
|
||||||
|
|
||||||
|
#if wxOSX_USE_COCOA
|
||||||
|
|
||||||
static NSCursor* wxGetStockCursor( short sIndex )
|
static NSCursor* wxGetStockCursor( short sIndex )
|
||||||
{
|
{
|
||||||
ClassicCursor* pCursor = &gMacCursors[sIndex];
|
ClassicCursor* pCursor = &gMacCursors[sIndex];
|
||||||
@@ -560,6 +580,7 @@ void wxMacCocoaShowCursor()
|
|||||||
{
|
{
|
||||||
[NSCursor unhide];
|
[NSCursor unhide];
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
//---------------------------------------------------------
|
//---------------------------------------------------------
|
||||||
// helper functions for NSString<->wxString conversion
|
// helper functions for NSString<->wxString conversion
|
||||||
@@ -588,6 +609,8 @@ NSString* wxNSStringWithWxString(const wxString &wxstring)
|
|||||||
// appearance in effect
|
// appearance in effect
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#if wxOSX_USE_COCOA
|
||||||
|
|
||||||
wxOSXEffectiveAppearanceSetter::wxOSXEffectiveAppearanceSetter()
|
wxOSXEffectiveAppearanceSetter::wxOSXEffectiveAppearanceSetter()
|
||||||
{
|
{
|
||||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14
|
||||||
|
@@ -49,7 +49,7 @@ public:
|
|||||||
wxBitmapRefData(int width , int height , int depth, double logicalscale = 1.0);
|
wxBitmapRefData(int width , int height , int depth, double logicalscale = 1.0);
|
||||||
wxBitmapRefData(CGContextRef context);
|
wxBitmapRefData(CGContextRef context);
|
||||||
wxBitmapRefData(CGImageRef image, double scale);
|
wxBitmapRefData(CGImageRef image, double scale);
|
||||||
wxBitmapRefData(WX_NSImage image);
|
wxBitmapRefData(WXImage image);
|
||||||
wxBitmapRefData();
|
wxBitmapRefData();
|
||||||
wxBitmapRefData(const wxBitmapRefData &tocopy);
|
wxBitmapRefData(const wxBitmapRefData &tocopy);
|
||||||
|
|
||||||
@@ -59,24 +59,12 @@ public:
|
|||||||
|
|
||||||
void Free();
|
void Free();
|
||||||
|
|
||||||
#if wxOSX_BITMAP_NATIVE_ACCESS
|
|
||||||
int GetWidth() const;
|
int GetWidth() const;
|
||||||
int GetHeight() const;
|
int GetHeight() const;
|
||||||
int GetDepth() const;
|
int GetDepth() const;
|
||||||
int GetBytesPerRow() const;
|
int GetBytesPerRow() const;
|
||||||
bool HasAlpha() const;
|
bool HasAlpha() const;
|
||||||
WX_NSImage GetNSImage() const;
|
WXImage GetImage() const;
|
||||||
#else
|
|
||||||
void SetWidth( int width ) { m_width = width; }
|
|
||||||
void SetHeight( int height ) { m_height = height; }
|
|
||||||
void SetDepth( int depth ) { m_depth = depth; }
|
|
||||||
|
|
||||||
int GetWidth() const { return m_width; }
|
|
||||||
int GetHeight() const { return m_height; }
|
|
||||||
int GetDepth() const { return m_depth; }
|
|
||||||
int GetBytesPerRow() const { return m_bytesPerRow; }
|
|
||||||
bool HasAlpha() const { return m_hasAlpha; }
|
|
||||||
#endif
|
|
||||||
double GetScaleFactor() const { return m_scaleFactor; }
|
double GetScaleFactor() const { return m_scaleFactor; }
|
||||||
|
|
||||||
const void *GetRawAccess() const;
|
const void *GetRawAccess() const;
|
||||||
@@ -119,24 +107,14 @@ private :
|
|||||||
bool Create(int width , int height , int depth, double logicalscale);
|
bool Create(int width , int height , int depth, double logicalscale);
|
||||||
bool Create( CGImageRef image, double scale );
|
bool Create( CGImageRef image, double scale );
|
||||||
bool Create( CGContextRef bitmapcontext);
|
bool Create( CGContextRef bitmapcontext);
|
||||||
bool Create( WX_NSImage image);
|
bool Create( WXImage image);
|
||||||
void Init();
|
void Init();
|
||||||
|
|
||||||
void EnsureBitmapExists() const;
|
void EnsureBitmapExists() const;
|
||||||
|
|
||||||
void FreeDerivedRepresentations();
|
void FreeDerivedRepresentations();
|
||||||
|
|
||||||
#if !wxOSX_BITMAP_NATIVE_ACCESS
|
WXImage m_nsImage;
|
||||||
int m_width;
|
|
||||||
int m_height;
|
|
||||||
int m_bytesPerRow;
|
|
||||||
int m_depth;
|
|
||||||
bool m_hasAlpha;
|
|
||||||
wxMemoryBuffer m_memBuf;
|
|
||||||
bool m_ok;
|
|
||||||
#else
|
|
||||||
WX_NSImage m_nsImage;
|
|
||||||
#endif
|
|
||||||
int m_rawAccessCount;
|
int m_rawAccessCount;
|
||||||
mutable CGImageRef m_cgImageRef;
|
mutable CGImageRef m_cgImageRef;
|
||||||
bool m_isTemplate;
|
bool m_isTemplate;
|
||||||
@@ -155,7 +133,7 @@ private :
|
|||||||
static const int kBestByteAlignement = 16;
|
static const int kBestByteAlignement = 16;
|
||||||
static const int kMaskBytesPerPixel = 1;
|
static const int kMaskBytesPerPixel = 1;
|
||||||
|
|
||||||
static int GetBestBytesPerRow( int rawBytes )
|
static size_t GetBestBytesPerRow( size_t rawBytes )
|
||||||
{
|
{
|
||||||
return (((rawBytes)+kBestByteAlignement-1) & ~(kBestByteAlignement-1) );
|
return (((rawBytes)+kBestByteAlignement-1) & ~(kBestByteAlignement-1) );
|
||||||
}
|
}
|
||||||
@@ -176,15 +154,7 @@ CGImageRef wxMacCreateCGImageFromBitmap( const wxBitmap& bitmap )
|
|||||||
|
|
||||||
void wxBitmapRefData::Init()
|
void wxBitmapRefData::Init()
|
||||||
{
|
{
|
||||||
#if !wxOSX_BITMAP_NATIVE_ACCESS
|
|
||||||
m_width = 0 ;
|
|
||||||
m_height = 0 ;
|
|
||||||
m_depth = 0 ;
|
|
||||||
m_bytesPerRow = 0;
|
|
||||||
m_hasAlpha = false;
|
|
||||||
#else
|
|
||||||
m_nsImage = NULL;
|
m_nsImage = NULL;
|
||||||
#endif
|
|
||||||
m_bitmapMask = NULL ;
|
m_bitmapMask = NULL ;
|
||||||
m_cgImageRef = NULL ;
|
m_cgImageRef = NULL ;
|
||||||
m_isTemplate = false;
|
m_isTemplate = false;
|
||||||
@@ -238,7 +208,7 @@ wxBitmapRefData::wxBitmapRefData(CGImageRef image, double scale)
|
|||||||
Create( image, scale );
|
Create( image, scale );
|
||||||
}
|
}
|
||||||
|
|
||||||
wxBitmapRefData::wxBitmapRefData(WX_NSImage image)
|
wxBitmapRefData::wxBitmapRefData(WXImage image)
|
||||||
{
|
{
|
||||||
Init();
|
Init();
|
||||||
Create( image );
|
Create( image );
|
||||||
@@ -249,12 +219,12 @@ void wxBitmapRefData::EnsureBitmapExists() const
|
|||||||
if ( ! m_hBitmap && m_nsImage)
|
if ( ! m_hBitmap && m_nsImage)
|
||||||
{
|
{
|
||||||
wxBitmapRefData* t = const_cast<wxBitmapRefData*>(this);
|
wxBitmapRefData* t = const_cast<wxBitmapRefData*>(this);
|
||||||
t->m_hBitmap = wxOSXCreateBitmapContextFromNSImage(m_nsImage, &t->m_isTemplate);
|
t->m_hBitmap = wxOSXCreateBitmapContextFromImage(m_nsImage, &t->m_isTemplate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool wxBitmapRefData::Create( WX_NSImage image )
|
bool wxBitmapRefData::Create( WXImage image )
|
||||||
{
|
{
|
||||||
m_nsImage = image;
|
m_nsImage = image;
|
||||||
|
|
||||||
@@ -267,51 +237,34 @@ bool wxBitmapRefData::Create( WX_NSImage image )
|
|||||||
|
|
||||||
bool wxBitmapRefData::Create(CGImageRef image, double scale)
|
bool wxBitmapRefData::Create(CGImageRef image, double scale)
|
||||||
{
|
{
|
||||||
if ( image != NULL )
|
if (image != NULL)
|
||||||
{
|
{
|
||||||
#if wxOSX_BITMAP_NATIVE_ACCESS
|
size_t m_width = CGImageGetWidth(image);
|
||||||
int m_width, m_height, m_depth, m_bytesPerRow;
|
size_t m_height = CGImageGetHeight(image);
|
||||||
#endif
|
|
||||||
m_width = CGImageGetWidth(image);
|
|
||||||
m_height = CGImageGetHeight(image);
|
|
||||||
m_depth = 32;
|
|
||||||
m_hBitmap = NULL;
|
m_hBitmap = NULL;
|
||||||
m_scaleFactor = scale;
|
m_scaleFactor = scale;
|
||||||
|
|
||||||
m_bytesPerRow = GetBestBytesPerRow( m_width * 4 ) ;
|
size_t m_bytesPerRow = GetBestBytesPerRow(m_width * 4);
|
||||||
#if !wxOSX_BITMAP_NATIVE_ACCESS
|
void* data = NULL;
|
||||||
size_t size = m_bytesPerRow * m_height ;
|
|
||||||
void* data = m_memBuf.GetWriteBuf( size ) ;
|
|
||||||
if ( data != NULL )
|
|
||||||
{
|
|
||||||
memset( data , 0 , size ) ;
|
|
||||||
m_memBuf.UngetWriteBuf( size ) ;
|
|
||||||
#else
|
|
||||||
void* data = NULL;
|
|
||||||
#endif
|
|
||||||
CGImageAlphaInfo alpha = CGImageGetAlphaInfo(image);
|
|
||||||
if ( alpha == kCGImageAlphaNone || alpha == kCGImageAlphaNoneSkipFirst || alpha == kCGImageAlphaNoneSkipLast )
|
|
||||||
{
|
|
||||||
m_hBitmap = CGBitmapContextCreate((char*) data, m_width, m_height, 8, m_bytesPerRow, wxMacGetGenericRGBColorSpace(), kCGImageAlphaNoneSkipFirst );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
#if !wxOSX_BITMAP_NATIVE_ACCESS
|
|
||||||
m_hasAlpha = true;
|
|
||||||
#endif
|
|
||||||
m_hBitmap = CGBitmapContextCreate((char*) data, m_width, m_height, 8, m_bytesPerRow, wxMacGetGenericRGBColorSpace(), kCGImageAlphaPremultipliedFirst );
|
|
||||||
}
|
|
||||||
CGRect rect = CGRectMake(0,0,m_width,m_height);
|
|
||||||
CGContextDrawImage(m_hBitmap, rect, image);
|
|
||||||
|
|
||||||
wxASSERT_MSG( m_hBitmap , wxT("Unable to create CGBitmapContext context") ) ;
|
CGImageAlphaInfo alpha = CGImageGetAlphaInfo(image);
|
||||||
CGContextTranslateCTM( m_hBitmap, 0, m_height );
|
if (alpha == kCGImageAlphaNone || alpha == kCGImageAlphaNoneSkipFirst || alpha == kCGImageAlphaNoneSkipLast)
|
||||||
CGContextScaleCTM( m_hBitmap, 1*m_scaleFactor, -1*m_scaleFactor );
|
{
|
||||||
#if !wxOSX_BITMAP_NATIVE_ACCESS
|
m_hBitmap = CGBitmapContextCreate((char*)data, m_width, m_height, 8, m_bytesPerRow, wxMacGetGenericRGBColorSpace(), kCGImageAlphaNoneSkipFirst);
|
||||||
} /* data != NULL */
|
}
|
||||||
#endif
|
else
|
||||||
|
{
|
||||||
|
m_hBitmap = CGBitmapContextCreate((char*)data, m_width, m_height, 8, m_bytesPerRow, wxMacGetGenericRGBColorSpace(), kCGImageAlphaPremultipliedFirst);
|
||||||
|
}
|
||||||
|
CGRect rect = CGRectMake(0, 0, m_width, m_height);
|
||||||
|
CGContextDrawImage(m_hBitmap, rect, image);
|
||||||
|
|
||||||
|
wxASSERT_MSG(m_hBitmap, wxT("Unable to create CGBitmapContext context"));
|
||||||
|
CGContextTranslateCTM(m_hBitmap, 0, m_height);
|
||||||
|
CGContextScaleCTM(m_hBitmap, 1 * m_scaleFactor, -1 * m_scaleFactor);
|
||||||
}
|
}
|
||||||
return IsOk() ;
|
return IsOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxBitmapRefData::Create(CGContextRef context)
|
bool wxBitmapRefData::Create(CGContextRef context)
|
||||||
@@ -319,94 +272,47 @@ bool wxBitmapRefData::Create(CGContextRef context)
|
|||||||
if ( context != NULL && CGBitmapContextGetData(context) )
|
if ( context != NULL && CGBitmapContextGetData(context) )
|
||||||
{
|
{
|
||||||
m_hBitmap = context;
|
m_hBitmap = context;
|
||||||
#if !wxOSX_BITMAP_NATIVE_ACCESS
|
|
||||||
m_bytesPerRow = CGBitmapContextGetBytesPerRow(context);
|
|
||||||
m_width = CGBitmapContextGetWidth(context);
|
|
||||||
m_height = CGBitmapContextGetHeight(context);
|
|
||||||
m_depth = CGBitmapContextGetBitsPerPixel(context) ;
|
|
||||||
#endif
|
|
||||||
// our own contexts conform to this, always.
|
// our own contexts conform to this, always.
|
||||||
wxASSERT( GetDepth() == 32 );
|
wxASSERT( GetDepth() == 32 );
|
||||||
|
|
||||||
#if !wxOSX_BITMAP_NATIVE_ACCESS
|
|
||||||
size_t size = GetBytesPerRow() * GetHeight() ;
|
|
||||||
void* data = m_memBuf.GetWriteBuf( size ) ;
|
|
||||||
|
|
||||||
memcpy( data , CGBitmapContextGetData(context) , size ) ;
|
|
||||||
m_memBuf.UngetWriteBuf( size ) ;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// determine content scale
|
// determine content scale
|
||||||
CGRect userrect = CGRectMake(0, 0, 10, 10);
|
CGRect userrect = CGRectMake(0, 0, 10, 10);
|
||||||
CGRect devicerect;
|
CGRect devicerect;
|
||||||
devicerect = CGContextConvertRectToDeviceSpace(context, userrect);
|
devicerect = CGContextConvertRectToDeviceSpace(context, userrect);
|
||||||
m_scaleFactor = devicerect.size.height / userrect.size.height;
|
m_scaleFactor = devicerect.size.height / userrect.size.height;
|
||||||
|
|
||||||
CGImageAlphaInfo alpha = CGBitmapContextGetAlphaInfo(context);
|
|
||||||
|
|
||||||
if ( alpha == kCGImageAlphaNone || alpha == kCGImageAlphaNoneSkipFirst || alpha == kCGImageAlphaNoneSkipLast )
|
|
||||||
{
|
|
||||||
// no alpha
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
#if !wxOSX_BITMAP_NATIVE_ACCESS
|
|
||||||
m_hasAlpha = true;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return IsOk() ;
|
return IsOk() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxBitmapRefData::Create( int w , int h , int d, double logicalscale )
|
bool wxBitmapRefData::Create(int w, int h, int d, double logicalscale)
|
||||||
{
|
{
|
||||||
#if wxOSX_BITMAP_NATIVE_ACCESS
|
size_t m_width = wxMax(1, w);
|
||||||
int m_width, m_height, m_depth, m_bytesPerRow;
|
size_t m_height = wxMax(1, h);
|
||||||
#endif
|
|
||||||
m_width = wxMax(1, w);
|
|
||||||
m_height = wxMax(1, h);
|
|
||||||
m_depth = d ;
|
|
||||||
m_scaleFactor = logicalscale;
|
|
||||||
m_hBitmap = NULL ;
|
|
||||||
|
|
||||||
m_bytesPerRow = GetBestBytesPerRow( m_width * 4 ) ;
|
int m_scaleFactor = logicalscale;
|
||||||
#if !wxOSX_BITMAP_NATIVE_ACCESS
|
m_hBitmap = NULL;
|
||||||
size_t size = m_bytesPerRow * m_height ;
|
|
||||||
void* data = m_memBuf.GetWriteBuf( size ) ;
|
size_t m_bytesPerRow = GetBestBytesPerRow(m_width * 4);
|
||||||
if ( data != NULL )
|
void* data = NULL;
|
||||||
{
|
m_hBitmap = CGBitmapContextCreate((char*)data, m_width, m_height, 8, m_bytesPerRow, wxMacGetGenericRGBColorSpace(), kCGImageAlphaNoneSkipFirst);
|
||||||
memset( data , 0 , size ) ;
|
wxASSERT_MSG(m_hBitmap, wxT("Unable to create CGBitmapContext context"));
|
||||||
m_memBuf.UngetWriteBuf( size ) ;
|
CGContextTranslateCTM(m_hBitmap, 0, m_height);
|
||||||
#else
|
CGContextScaleCTM(m_hBitmap, 1 * GetScaleFactor(), -1 * GetScaleFactor());
|
||||||
void* data = NULL;
|
|
||||||
#endif
|
return IsOk();
|
||||||
m_hBitmap = CGBitmapContextCreate((char*) data, m_width, m_height, 8, m_bytesPerRow, wxMacGetGenericRGBColorSpace(), kCGImageAlphaNoneSkipFirst );
|
|
||||||
wxASSERT_MSG( m_hBitmap , wxT("Unable to create CGBitmapContext context") ) ;
|
|
||||||
CGContextTranslateCTM( m_hBitmap, 0, m_height );
|
|
||||||
CGContextScaleCTM( m_hBitmap, 1*GetScaleFactor(), -1*GetScaleFactor() );
|
|
||||||
#if !wxOSX_BITMAP_NATIVE_ACCESS
|
|
||||||
} /* data != NULL */
|
|
||||||
#endif
|
|
||||||
return IsOk() ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxBitmapRefData::IsOk() const
|
bool wxBitmapRefData::IsOk() const
|
||||||
{
|
{
|
||||||
return ( m_hBitmap.get() != NULL
|
return (m_hBitmap.get() != NULL || m_nsImage != NULL);
|
||||||
#if wxOSX_BITMAP_NATIVE_ACCESS
|
|
||||||
|| m_nsImage != NULL
|
|
||||||
#endif
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if wxOSX_BITMAP_NATIVE_ACCESS
|
|
||||||
|
|
||||||
int wxBitmapRefData::GetWidth() const
|
int wxBitmapRefData::GetWidth() const
|
||||||
{
|
{
|
||||||
wxCHECK_MSG( IsOk() , 0 , "Invalid Bitmap");
|
wxCHECK_MSG( IsOk() , 0 , "Invalid Bitmap");
|
||||||
|
|
||||||
if ( m_hBitmap )
|
if ( m_hBitmap )
|
||||||
return CGBitmapContextGetWidth(m_hBitmap);
|
return (int) CGBitmapContextGetWidth(m_hBitmap);
|
||||||
else
|
else
|
||||||
return (int) wxOSXGetImageSize(m_nsImage).width;
|
return (int) wxOSXGetImageSize(m_nsImage).width;
|
||||||
}
|
}
|
||||||
@@ -416,7 +322,7 @@ int wxBitmapRefData::GetHeight() const
|
|||||||
wxCHECK_MSG( IsOk() , 0 , "Invalid Bitmap");
|
wxCHECK_MSG( IsOk() , 0 , "Invalid Bitmap");
|
||||||
|
|
||||||
if ( m_hBitmap )
|
if ( m_hBitmap )
|
||||||
return CGBitmapContextGetHeight(m_hBitmap);
|
return (int) CGBitmapContextGetHeight(m_hBitmap);
|
||||||
else
|
else
|
||||||
return (int) wxOSXGetImageSize(m_nsImage).height;
|
return (int) wxOSXGetImageSize(m_nsImage).height;
|
||||||
}
|
}
|
||||||
@@ -426,7 +332,7 @@ int wxBitmapRefData::GetDepth() const
|
|||||||
wxCHECK_MSG( IsOk() , 0 , "Invalid Bitmap");
|
wxCHECK_MSG( IsOk() , 0 , "Invalid Bitmap");
|
||||||
|
|
||||||
if ( m_hBitmap )
|
if ( m_hBitmap )
|
||||||
return CGBitmapContextGetBitsPerPixel(m_hBitmap);
|
return (int) CGBitmapContextGetBitsPerPixel(m_hBitmap);
|
||||||
else
|
else
|
||||||
return 32; // a bitmap converted from an nsimage would have this depth
|
return 32; // a bitmap converted from an nsimage would have this depth
|
||||||
}
|
}
|
||||||
@@ -435,9 +341,9 @@ int wxBitmapRefData::GetBytesPerRow() const
|
|||||||
wxCHECK_MSG( IsOk() , 0 , "Invalid Bitmap");
|
wxCHECK_MSG( IsOk() , 0 , "Invalid Bitmap");
|
||||||
|
|
||||||
if ( m_hBitmap )
|
if ( m_hBitmap )
|
||||||
return CGBitmapContextGetBytesPerRow(m_hBitmap);
|
return (int) CGBitmapContextGetBytesPerRow(m_hBitmap);
|
||||||
else
|
else
|
||||||
return GetBestBytesPerRow( GetWidth() * 4);
|
return (int) GetBestBytesPerRow( GetWidth() * 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxBitmapRefData::HasAlpha() const
|
bool wxBitmapRefData::HasAlpha() const
|
||||||
@@ -455,22 +361,19 @@ bool wxBitmapRefData::HasAlpha() const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WX_NSImage wxBitmapRefData::GetNSImage() const
|
WXImage wxBitmapRefData::GetImage() const
|
||||||
{
|
{
|
||||||
wxCHECK_MSG( IsOk() , 0 , "Invalid Bitmap");
|
wxCHECK_MSG( IsOk() , 0 , "Invalid Bitmap");
|
||||||
|
|
||||||
if ( !m_nsImage )
|
if ( !m_nsImage )
|
||||||
{
|
{
|
||||||
wxCFRef< CGImageRef > cgimage(CreateCGImage());
|
wxCFRef< CGImageRef > cgimage(CreateCGImage());
|
||||||
return wxOSXGetNSImageFromCGImage( cgimage, GetScaleFactor(), IsTemplate() );
|
return wxOSXGetImageFromCGImage( cgimage, GetScaleFactor(), IsTemplate() );
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_nsImage;
|
return m_nsImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void wxBitmapRefData::UseAlpha( bool use )
|
void wxBitmapRefData::UseAlpha( bool use )
|
||||||
{
|
{
|
||||||
wxCHECK_RET( IsOk() , wxT("invalid bitmap") ) ;
|
wxCHECK_RET( IsOk() , wxT("invalid bitmap") ) ;
|
||||||
@@ -478,16 +381,10 @@ void wxBitmapRefData::UseAlpha( bool use )
|
|||||||
if ( HasAlpha() == use )
|
if ( HasAlpha() == use )
|
||||||
return ;
|
return ;
|
||||||
|
|
||||||
#if !wxOSX_BITMAP_NATIVE_ACCESS
|
CGContextRef hBitmap = CGBitmapContextCreate(NULL, GetWidth(), GetHeight(), 8, GetBytesPerRow(), wxMacGetGenericRGBColorSpace(), use ? kCGImageAlphaPremultipliedFirst : kCGImageAlphaNoneSkipFirst );
|
||||||
m_hasAlpha = use ;
|
|
||||||
void *data = m_memBuf.GetData();
|
|
||||||
#else
|
|
||||||
void *data = NULL;
|
|
||||||
#endif
|
|
||||||
CGContextRef hBitmap = CGBitmapContextCreate(data, GetWidth(), GetHeight(), 8, GetBytesPerRow(), wxMacGetGenericRGBColorSpace(), use ? kCGImageAlphaPremultipliedFirst : kCGImageAlphaNoneSkipFirst );
|
|
||||||
#if wxOSX_BITMAP_NATIVE_ACCESS
|
|
||||||
memcpy(CGBitmapContextGetData(hBitmap),CGBitmapContextGetData(m_hBitmap),GetBytesPerRow()*GetHeight());
|
memcpy(CGBitmapContextGetData(hBitmap),CGBitmapContextGetData(m_hBitmap),GetBytesPerRow()*GetHeight());
|
||||||
#endif
|
|
||||||
wxASSERT_MSG( hBitmap , wxT("Unable to create CGBitmapContext context") ) ;
|
wxASSERT_MSG( hBitmap , wxT("Unable to create CGBitmapContext context") ) ;
|
||||||
CGContextTranslateCTM( hBitmap, 0, GetHeight() );
|
CGContextTranslateCTM( hBitmap, 0, GetHeight() );
|
||||||
CGContextScaleCTM( hBitmap, GetScaleFactor(), -GetScaleFactor() );
|
CGContextScaleCTM( hBitmap, GetScaleFactor(), -GetScaleFactor() );
|
||||||
@@ -501,11 +398,7 @@ const void *wxBitmapRefData::GetRawAccess() const
|
|||||||
|
|
||||||
EnsureBitmapExists();
|
EnsureBitmapExists();
|
||||||
|
|
||||||
#if !wxOSX_BITMAP_NATIVE_ACCESS
|
|
||||||
return m_memBuf.GetData() ;
|
|
||||||
#else
|
|
||||||
return CGBitmapContextGetData(m_hBitmap);
|
return CGBitmapContextGetData(m_hBitmap);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void *wxBitmapRefData::GetRawAccess()
|
void *wxBitmapRefData::GetRawAccess()
|
||||||
@@ -773,7 +666,7 @@ CGImageRef wxBitmapRefData::CreateCGImage() const
|
|||||||
{
|
{
|
||||||
if (m_nsImage)
|
if (m_nsImage)
|
||||||
{
|
{
|
||||||
image = wxOSXCreateCGImageFromNSImage(m_nsImage);
|
image = wxOSXCreateCGImageFromImage(m_nsImage);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -957,27 +850,7 @@ wxBitmapRefData::~wxBitmapRefData()
|
|||||||
|
|
||||||
bool wxBitmap::CopyFromIcon(const wxIcon& icon)
|
bool wxBitmap::CopyFromIcon(const wxIcon& icon)
|
||||||
{
|
{
|
||||||
#if wxOSX_BITMAP_NATIVE_ACCESS
|
return Create( icon.GetImage() );
|
||||||
return Create( icon.GetNSImage() );
|
|
||||||
#else
|
|
||||||
int w = icon.GetWidth() ;
|
|
||||||
int h = icon.GetHeight() ;
|
|
||||||
|
|
||||||
if ( Create( w, h ) )
|
|
||||||
{
|
|
||||||
// Assume 32 bpp icon has transparency values
|
|
||||||
UseAlpha(icon.GetDepth() == 32);
|
|
||||||
|
|
||||||
wxMemoryDC dc ;
|
|
||||||
dc.SelectObject( *this ) ;
|
|
||||||
dc.DrawIcon( icon , 0 , 0 ) ;
|
|
||||||
dc.SelectObject( wxNullBitmap ) ;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits)
|
wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits)
|
||||||
@@ -1109,14 +982,12 @@ IconRef wxBitmap::CreateIconRef() const
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if wxOSX_USE_COCOA
|
wxBitmap::wxBitmap(WXImage image)
|
||||||
|
|
||||||
wxBitmap::wxBitmap(WX_NSImage image)
|
|
||||||
{
|
{
|
||||||
(void)Create(image);
|
(void)Create(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxBitmap::Create(WX_NSImage image)
|
bool wxBitmap::Create(WXImage image)
|
||||||
{
|
{
|
||||||
UnRef();
|
UnRef();
|
||||||
|
|
||||||
@@ -1139,22 +1010,11 @@ bool wxBitmap::Create(CGContextRef bitmapcontext)
|
|||||||
return GetBitmapData()->IsOk() ;
|
return GetBitmapData()->IsOk() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
WX_NSImage wxBitmap::GetNSImage() const
|
WXImage wxBitmap::GetImage() const
|
||||||
{
|
{
|
||||||
return GetBitmapData()->GetNSImage();
|
return GetBitmapData()->GetImage();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if wxOSX_USE_IPHONE
|
|
||||||
|
|
||||||
WX_UIImage wxBitmap::GetUIImage() const
|
|
||||||
{
|
|
||||||
wxCFRef< CGImageRef > cgimage(CreateCGImage());
|
|
||||||
return wxOSXGetUIImageFromCGImage( cgimage );
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
wxBitmap wxBitmap::GetSubBitmap(const wxRect &rect) const
|
wxBitmap wxBitmap::GetSubBitmap(const wxRect &rect) const
|
||||||
{
|
{
|
||||||
wxCHECK_MSG( IsOk() &&
|
wxCHECK_MSG( IsOk() &&
|
||||||
|
Reference in New Issue
Block a user