X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c944835aaad14d090837aae9a14d78c08f7df512..71a09c3579dd5cb4cd8fa7fdc143561cbff74e12:/src/osx/core/bitmap.cpp?ds=sidebyside diff --git a/src/osx/core/bitmap.cpp b/src/osx/core/bitmap.cpp index bf31f8a00c..8ee6127b11 100644 --- a/src/osx/core/bitmap.cpp +++ b/src/osx/core/bitmap.cpp @@ -4,7 +4,6 @@ // Author: Stefan Csomor // Modified by: // Created: 1998-01-01 -// RCS-ID: $Id$ // Copyright: (c) Stefan Csomor // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -25,6 +24,8 @@ #include "wx/rawbmp.h" +#include "wx/filename.h" + IMPLEMENT_DYNAMIC_CLASS(wxBitmap, wxGDIObject) IMPLEMENT_DYNAMIC_CLASS(wxMask, wxObject) @@ -1235,10 +1236,29 @@ bool wxBitmap::LoadFile(const wxString& filename, wxBitmapType type) else { #if wxUSE_IMAGE - wxImage loadimage(filename, type); + double scale = 1.0; + wxString fname = filename; + + if ( type == wxBITMAP_TYPE_PNG ) + { + if ( wxOSXGetMainScreenContentScaleFactor() > 1.9 ) + { + wxFileName fn(filename); + fn.MakeAbsolute(); + fn.SetName(fn.GetName()+"@2x"); + + if ( fn.Exists() ) + { + fname = fn.GetFullPath(); + scale = 2.0; + } + } + } + + wxImage loadimage(fname, type); if (loadimage.IsOk()) { - *this = loadimage; + *this = wxBitmap(loadimage,-1,scale); return true; } @@ -1270,7 +1290,7 @@ bool wxBitmap::Create(const void* data, wxBitmapType type, int width, int height #if wxUSE_IMAGE -wxBitmap::wxBitmap(const wxImage& image, int depth) +wxBitmap::wxBitmap(const wxImage& image, int depth, double scale) { wxCHECK_RET( image.IsOk(), wxT("invalid image") ); @@ -1280,7 +1300,7 @@ wxBitmap::wxBitmap(const wxImage& image, int depth) wxBitmapRefData* bitmapRefData; - m_refData = bitmapRefData = new wxBitmapRefData( width , height , depth ) ; + m_refData = bitmapRefData = new wxBitmapRefData( width/scale, height/scale, depth, scale) ; if ( bitmapRefData->IsOk()) { @@ -1851,9 +1871,23 @@ bool wxBundleResourceHandler::LoadFile(wxBitmap *bitmap, { wxString ext = GetExtension().Lower(); wxCFStringRef resname(name); + wxCFStringRef resname2x(name+"@2x"); wxCFStringRef restype(ext); + double scale = 1.0; + + wxCFRef imageURL; + + if ( wxOSXGetMainScreenContentScaleFactor() > 1.9 ) + { + imageURL.reset(CFBundleCopyResourceURL(CFBundleGetMainBundle(), resname2x, restype, NULL)); + scale = 2.0; + } - wxCFRef imageURL(CFBundleCopyResourceURL(CFBundleGetMainBundle(), resname, restype, NULL)); + if ( imageURL.get() == NULL ) + { + imageURL.reset(CFBundleCopyResourceURL(CFBundleGetMainBundle(), resname, restype, NULL)); + scale = 1.0; + } if ( imageURL.get() != NULL ) { @@ -1869,7 +1903,7 @@ bool wxBundleResourceHandler::LoadFile(wxBitmap *bitmap, kCGRenderingIntentDefault); if ( image != NULL ) { - bitmap->Create(image); + bitmap->Create(image,scale); CGImageRelease(image); } }