friend class WXDLLIMPEXP_FWD_CORE wxIcon;
friend class WXDLLIMPEXP_FWD_CORE wxCursor;
public:
+ wxBitmapRefData(int width , int height , int depth, double logicalscale);
wxBitmapRefData(int width , int height , int depth);
wxBitmapRefData(CGImageRef image);
wxBitmapRefData();
int GetWidth() const { return m_width; }
int GetHeight() const { return m_height; }
int GetDepth() const { return m_depth; }
-
+ double GetScaleFactor() const { return m_scaleFactor; }
void *GetRawAccess() const;
void *BeginRawAccess();
void EndRawAccess();
int GetBytesPerRow() const { return m_bytesPerRow; }
private :
bool Create(int width , int height , int depth);
+ bool Create(int width , int height , int depth, double logicalScale);
bool Create( CGImageRef image );
void Init();
#endif
CGContextRef m_hBitmap;
+ double m_scaleFactor;
};
m_rawAccessCount = 0 ;
m_hasAlpha = false;
+ m_scaleFactor = 1.0;
}
wxBitmapRefData::wxBitmapRefData(const wxBitmapRefData &tocopy) : wxGDIRefData()
{
Init();
- Create(tocopy.m_width, tocopy.m_height, tocopy.m_depth);
+ Create(tocopy.m_width, tocopy.m_height, tocopy.m_depth, tocopy.m_scaleFactor);
if (tocopy.m_bitmapMask)
m_bitmapMask = new wxMask(*tocopy.m_bitmapMask);
Create( w , h , d ) ;
}
+wxBitmapRefData::wxBitmapRefData(int w , int h , int d, double logicalscale)
+{
+ Init() ;
+ Create( w , h , d, logicalscale ) ;
+}
+
wxBitmapRefData::wxBitmapRefData(CGImageRef image)
{
Init();
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, -1 );
+ CGContextScaleCTM( m_hBitmap, 1*m_scaleFactor, -1*m_scaleFactor );
} /* data != NULL */
m_ok = ( m_hBitmap != NULL ) ;
return m_ok ;
}
+bool wxBitmapRefData::Create( int w , int h , int d, double logicalScale )
+{
+ m_scaleFactor = logicalScale;
+ return Create(w*logicalScale,h*logicalScale,d);
+}
+
void wxBitmapRefData::UseAlpha( bool use )
{
if ( m_hasAlpha == use )
m_hBitmap = CGBitmapContextCreate((char*) m_memBuf.GetData(), m_width, m_height, 8, m_bytesPerRow, wxMacGetGenericRGBColorSpace(), m_hasAlpha ? kCGImageAlphaPremultipliedFirst : kCGImageAlphaNoneSkipFirst );
wxASSERT_MSG( m_hBitmap , wxT("Unable to create CGBitmapContext context") ) ;
CGContextTranslateCTM( m_hBitmap, 0, m_height );
- CGContextScaleCTM( m_hBitmap, 1, -1 );
+ CGContextScaleCTM( m_hBitmap, 1*m_scaleFactor, -1*m_scaleFactor );
}
void *wxBitmapRefData::GetRawAccess() const
(void) Create(data, type, width, height, depth);
}
-wxBitmap::wxBitmap(int width, int height, const wxDC& WXUNUSED(dc))
+wxBitmap::wxBitmap(int width, int height, const wxDC& dc)
{
- (void) Create(width, height);
+ (void)Create(width, height, dc);
}
wxBitmap::wxBitmap(const wxString& filename, wxBitmapType type)
(rect.y+rect.height <= GetHeight()),
wxNullBitmap, wxT("invalid bitmap or bitmap region") );
- wxBitmap ret( rect.width, rect.height, GetDepth() );
+ wxBitmap ret;
+ double scale = GetScaleFactor();
+ ret.CreateScaled( rect.width, rect.height, GetDepth(), scale );
wxASSERT_MSG( ret.IsOk(), wxT("GetSubBitmap error") );
- int destwidth = rect.width ;
- int destheight = rect.height ;
+ int destwidth = rect.width*scale ;
+ int destheight = rect.height*scale ;
{
unsigned char *sourcedata = (unsigned char*) GetRawAccess() ;
{
int sourcelinesize = GetBitmapData()->GetBytesPerRow() ;
int destlinesize = ret.GetBitmapData()->GetBytesPerRow() ;
- unsigned char *source = sourcedata + rect.x * 4 + rect.y * sourcelinesize ;
+ unsigned char *source = sourcedata + int(rect.x * scale * 4 + rect.y *scale * sourcelinesize) ;
unsigned char *dest = destdata ;
for (int yy = 0; yy < destheight; ++yy, source += sourcelinesize , dest += destlinesize)
return M_BITMAPDATA->IsOk() ;
}
+bool wxBitmap::Create(int w, int h, const wxDC& dc)
+{
+ double factor = dc.GetContentScaleFactor();
+ return CreateScaled(w,h,wxBITMAP_SCREEN_DEPTH, factor);
+}
+
+bool wxBitmap::CreateScaled(int w, int h, int d, double logicalScale)
+{
+ UnRef();
+
+ if ( d < 0 )
+ d = wxDisplayDepth() ;
+
+ m_refData = new wxBitmapRefData( w , h , d, logicalScale );
+
+ return M_BITMAPDATA->IsOk() ;
+}
+
bool wxBitmap::Create(CGImageRef image)
{
UnRef();
return M_BITMAPDATA->GetWidth() ;
}
+double wxBitmap::GetScaleFactor() const
+{
+ wxCHECK_MSG( IsOk(), -1, wxT("invalid bitmap") );
+
+ return M_BITMAPDATA->GetScaleFactor() ;
+}
+
int wxBitmap::GetDepth() const
{
wxCHECK_MSG( IsOk(), -1, wxT("invalid bitmap") );