Implement deep copy of wxBitmapRefData
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@42890 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -34,11 +34,13 @@ class WXDLLEXPORT wxPixelDataBase;
|
|||||||
class WXDLLEXPORT wxMask: public wxObject
|
class WXDLLEXPORT wxMask: public wxObject
|
||||||
{
|
{
|
||||||
DECLARE_DYNAMIC_CLASS(wxMask)
|
DECLARE_DYNAMIC_CLASS(wxMask)
|
||||||
DECLARE_NO_COPY_CLASS(wxMask)
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
wxMask();
|
wxMask();
|
||||||
|
|
||||||
|
// Copy constructor
|
||||||
|
wxMask(const wxMask& mask);
|
||||||
|
|
||||||
// Construct a mask from a bitmap and a colour indicating
|
// Construct a mask from a bitmap and a colour indicating
|
||||||
// the transparent area
|
// the transparent area
|
||||||
wxMask(const wxBitmap& bitmap, const wxColour& colour);
|
wxMask(const wxBitmap& bitmap, const wxColour& colour);
|
||||||
@@ -181,6 +183,11 @@ public:
|
|||||||
// makes sure that no cached images will be constructed until terminated
|
// makes sure that no cached images will be constructed until terminated
|
||||||
void *BeginRawAccess() ;
|
void *BeginRawAccess() ;
|
||||||
void EndRawAccess() ;
|
void EndRawAccess() ;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// ref counting code
|
||||||
|
virtual wxObjectRefData *CreateRefData() const;
|
||||||
|
virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
// _WX_BITMAP_H_
|
// _WX_BITMAP_H_
|
||||||
|
@@ -1168,13 +1168,13 @@ void wxMacMemoryBufferReleaseProc(void *info, const void *data, size_t size);
|
|||||||
|
|
||||||
class WXDLLEXPORT wxBitmapRefData: public wxGDIRefData
|
class WXDLLEXPORT wxBitmapRefData: public wxGDIRefData
|
||||||
{
|
{
|
||||||
DECLARE_NO_COPY_CLASS(wxBitmapRefData)
|
|
||||||
|
|
||||||
friend class WXDLLEXPORT wxIcon;
|
friend class WXDLLEXPORT wxIcon;
|
||||||
friend class WXDLLEXPORT wxCursor;
|
friend class WXDLLEXPORT wxCursor;
|
||||||
public:
|
public:
|
||||||
wxBitmapRefData(int width , int height , int depth);
|
wxBitmapRefData(int width , int height , int depth);
|
||||||
wxBitmapRefData();
|
wxBitmapRefData();
|
||||||
|
wxBitmapRefData(const wxBitmapRefData &tocopy);
|
||||||
|
|
||||||
virtual ~wxBitmapRefData();
|
virtual ~wxBitmapRefData();
|
||||||
|
|
||||||
void Free();
|
void Free();
|
||||||
|
@@ -153,6 +153,28 @@ void wxBitmapRefData::Init()
|
|||||||
m_hasAlpha = false;
|
m_hasAlpha = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxBitmapRefData::wxBitmapRefData(const wxBitmapRefData &tocopy)
|
||||||
|
{
|
||||||
|
Init();
|
||||||
|
Create(tocopy.m_width, tocopy.m_height, tocopy.m_depth);
|
||||||
|
|
||||||
|
if (tocopy.m_bitmapMask)
|
||||||
|
m_bitmapMask = new wxMask(*tocopy.m_bitmapMask);
|
||||||
|
|
||||||
|
unsigned char* dest = (unsigned char*)GetRawAccess();
|
||||||
|
unsigned char* source = (unsigned char*)tocopy.GetRawAccess();
|
||||||
|
size_t numbytes = tocopy.m_width * tocopy.m_height * 4;
|
||||||
|
|
||||||
|
for (size_t i=0; i<numbytes; i++)
|
||||||
|
{
|
||||||
|
*dest++ = *source++;
|
||||||
|
}
|
||||||
|
|
||||||
|
UseAlpha(tocopy.m_hasAlpha);
|
||||||
|
|
||||||
|
// TODO: Copy palette?
|
||||||
|
}
|
||||||
|
|
||||||
wxBitmapRefData::wxBitmapRefData()
|
wxBitmapRefData::wxBitmapRefData()
|
||||||
{
|
{
|
||||||
Init() ;
|
Init() ;
|
||||||
@@ -883,6 +905,16 @@ wxBitmap::wxBitmap(const wxString& filename, wxBitmapType type)
|
|||||||
LoadFile(filename, type);
|
LoadFile(filename, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxObjectRefData* wxBitmap::CreateRefData() const
|
||||||
|
{
|
||||||
|
return new wxBitmapRefData;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxObjectRefData* wxBitmap::CloneRefData(const wxObjectRefData* data) const
|
||||||
|
{
|
||||||
|
return new wxBitmapRefData(*wx_static_cast(const wxBitmapRefData *, data));
|
||||||
|
}
|
||||||
|
|
||||||
void * wxBitmap::GetRawAccess() const
|
void * wxBitmap::GetRawAccess() const
|
||||||
{
|
{
|
||||||
wxCHECK_MSG( Ok() , NULL , wxT("invalid bitmap") ) ;
|
wxCHECK_MSG( Ok() , NULL , wxT("invalid bitmap") ) ;
|
||||||
@@ -1341,6 +1373,26 @@ wxMask::wxMask()
|
|||||||
Init() ;
|
Init() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxMask::wxMask(const wxMask &tocopy)
|
||||||
|
{
|
||||||
|
Init();
|
||||||
|
|
||||||
|
m_bytesPerRow = tocopy.m_bytesPerRow;
|
||||||
|
m_width = tocopy.m_width;
|
||||||
|
m_height = tocopy.m_height;
|
||||||
|
|
||||||
|
size_t size = m_bytesPerRow * m_height;
|
||||||
|
unsigned char* dest = (unsigned char*)m_memBuf.GetWriteBuf( size );
|
||||||
|
unsigned char* source = (unsigned char*)tocopy.m_memBuf.GetData();
|
||||||
|
for (size_t i=0; i<size; i++)
|
||||||
|
{
|
||||||
|
*dest++ = *source++;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_memBuf.UngetWriteBuf( size ) ;
|
||||||
|
RealizeNative() ;
|
||||||
|
}
|
||||||
|
|
||||||
// Construct a mask from a bitmap and a colour indicating
|
// Construct a mask from a bitmap and a colour indicating
|
||||||
// the transparent area
|
// the transparent area
|
||||||
wxMask::wxMask( const wxBitmap& bitmap, const wxColour& colour )
|
wxMask::wxMask( const wxBitmap& bitmap, const wxColour& colour )
|
||||||
|
Reference in New Issue
Block a user