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
This commit is contained in:
Stefan Csomor 2013-07-14 11:16:32 +00:00
parent 330d01ae47
commit 44c8e75ba9
2 changed files with 26 additions and 5 deletions

View File

@ -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); }

View File

@ -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())
{