From 44c8e75ba92de8f003f193f1e80b374b3402419d Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Sun, 14 Jul 2013 11:16:32 +0000 Subject: [PATCH] support for @2x notation for wxBITMAP_TYPE_PNG (non-resource) on retina displays git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74511 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/osx/bitmap.h | 2 +- src/osx/core/bitmap.cpp | 29 +++++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/include/wx/osx/bitmap.h b/include/wx/osx/bitmap.h index d6d973aeda..271e320d24 100644 --- a/include/wx/osx/bitmap.h +++ b/include/wx/osx/bitmap.h @@ -116,7 +116,7 @@ public: wxBitmap(const wxSize& sz, int depth = -1) { (void)Create(sz, depth); } // Convert from wxImage: - wxBitmap(const wxImage& image, int depth = -1); + wxBitmap(const wxImage& image, int depth = -1, double scale = 1.0); // Convert from wxIcon wxBitmap(const wxIcon& icon) { CopyFromIcon(icon); } diff --git a/src/osx/core/bitmap.cpp b/src/osx/core/bitmap.cpp index ac0804d1f1..14e725b071 100644 --- a/src/osx/core/bitmap.cpp +++ b/src/osx/core/bitmap.cpp @@ -25,6 +25,8 @@ #include "wx/rawbmp.h" +#include "wx/filename.h" + IMPLEMENT_DYNAMIC_CLASS(wxBitmap, wxGDIObject) IMPLEMENT_DYNAMIC_CLASS(wxMask, wxObject) @@ -1235,10 +1237,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 +1291,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 +1301,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()) {