only use native NSImage dimension

This commit is contained in:
Stefan Csomor
2018-09-10 21:20:35 +02:00
committed by Vadim Zeitlin
parent 84f68aa764
commit 148732993a
3 changed files with 9 additions and 15 deletions

View File

@@ -37,6 +37,7 @@ 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 wxOSXCreateCGImageFromNSImage( WX_NSImage nsimage, double *scale = NULL );
CGImageRef WXDLLIMPEXP_CORE wxOSXGetCGImageFromNSImage( WX_NSImage nsimage, CGRect* r, CGContextRef cg); CGImageRef WXDLLIMPEXP_CORE wxOSXGetCGImageFromNSImage( WX_NSImage nsimage, CGRect* r, CGContextRef cg);
CGContextRef WXDLLIMPEXP_CORE wxOSXCreateBitmapContextFromNSImage( WX_NSImage nsimage, bool *isTemplate = NULL); CGContextRef WXDLLIMPEXP_CORE wxOSXCreateBitmapContextFromNSImage( WX_NSImage nsimage, bool *isTemplate = NULL);

View File

@@ -42,11 +42,8 @@ public:
virtual bool IsOk() const wxOVERRIDE { return m_nsImage != NULL; } virtual bool IsOk() const wxOVERRIDE { return m_nsImage != NULL; }
virtual void Free(); virtual void Free();
void SetWidth( int width ) { m_width = width; } int GetWidth() const { return (int) wxOSXGetImageSize(m_nsImage).width; }
void SetHeight( int height ) { m_height = height; } int GetHeight() const { return (int) wxOSXGetImageSize(m_nsImage).height; }
int GetWidth() const { return m_width; }
int GetHeight() const { return m_height; }
WX_NSImage GetNSImage() const; WX_NSImage GetNSImage() const;
@@ -55,9 +52,6 @@ private:
void Create( NSImage* icon, int desiredWidth, int desiredHeight ); void Create( NSImage* icon, int desiredWidth, int desiredHeight );
NSImage* m_nsImage; NSImage* m_nsImage;
int m_width;
int m_height;
// We can (easily) copy m_iconRef so we don't implement the copy ctor. // We can (easily) copy m_iconRef so we don't implement the copy ctor.
wxDECLARE_NO_COPY_CLASS(wxIconRefData); wxDECLARE_NO_COPY_CLASS(wxIconRefData);
}; };
@@ -78,24 +72,18 @@ wxIconRefData::wxIconRefData( WXHICON iconref, int desiredWidth, int desiredHeig
ReleaseIconRef(iconref); ReleaseIconRef(iconref);
} }
void wxIconRefData::Create( NSImage* icon, int desiredWidth, int desiredHeight ) void wxIconRefData::Create( NSImage* icon, int WXUNUSED(desiredWidth), int WXUNUSED(desiredHeight) )
{ {
if ( icon ) if ( icon )
{ {
m_nsImage = icon; m_nsImage = icon;
wxMacCocoaRetain(icon); wxMacCocoaRetain(icon);
} }
// Standard sizes
SetWidth( desiredWidth == -1 ? 32 : desiredWidth ) ;
SetHeight( desiredHeight == -1 ? 32 : desiredHeight ) ;
} }
void wxIconRefData::Init() void wxIconRefData::Init()
{ {
m_nsImage = NULL; m_nsImage = NULL;
m_width =
m_height = 0;
} }
void wxIconRefData::Free() void wxIconRefData::Free()

View File

@@ -297,6 +297,11 @@ void wxOSXSetImageSize(WX_NSImage image, CGFloat width, CGFloat height)
[image setSize:NSMakeSize(width, height)]; [image setSize:NSMakeSize(width, height)];
} }
CGSize wxOSXGetImageSize(WX_NSImage image)
{
return NSSizeToCGSize([image size]);
}
CGImageRef wxOSXCreateCGImageFromNSImage( WX_NSImage nsimage, double *scaleptr ) CGImageRef wxOSXCreateCGImageFromNSImage( WX_NSImage nsimage, double *scaleptr )
{ {
// 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