apply mask to result after paint operations so that qt doesn't clobber the mask
also fixes small memory leak
This commit is contained in:
committed by
Vadim Zeitlin
parent
65af28271e
commit
694decea6e
@@ -124,7 +124,7 @@ static QImage ConvertImage( const wxImage &image )
|
|||||||
class wxBitmapRefData: public wxGDIRefData
|
class wxBitmapRefData: public wxGDIRefData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxBitmapRefData() { }
|
wxBitmapRefData() { m_mask = NULL; }
|
||||||
|
|
||||||
wxBitmapRefData( int width, int height, int depth )
|
wxBitmapRefData( int width, int height, int depth )
|
||||||
{
|
{
|
||||||
@@ -132,15 +132,23 @@ class wxBitmapRefData: public wxGDIRefData
|
|||||||
m_qtPixmap = QBitmap( width, height );
|
m_qtPixmap = QBitmap( width, height );
|
||||||
else
|
else
|
||||||
m_qtPixmap = QPixmap( width, height );
|
m_qtPixmap = QPixmap( width, height );
|
||||||
|
m_mask = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxBitmapRefData( QPixmap pix )
|
wxBitmapRefData( QPixmap pix )
|
||||||
{
|
{
|
||||||
m_qtPixmap = pix;
|
m_qtPixmap = pix;
|
||||||
|
m_mask = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual ~wxBitmapRefData() { delete m_mask; }
|
||||||
|
|
||||||
QPixmap m_qtPixmap;
|
QPixmap m_qtPixmap;
|
||||||
wxMask m_mask;
|
wxMask *m_mask;
|
||||||
|
|
||||||
|
private:
|
||||||
|
wxBitmapRefData(const wxBitmapRefData&other);
|
||||||
|
wxBitmapRefData& operator=(const wxBitmapRefData&other);
|
||||||
};
|
};
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -255,27 +263,26 @@ int wxBitmap::GetDepth() const
|
|||||||
#if wxUSE_IMAGE
|
#if wxUSE_IMAGE
|
||||||
wxImage wxBitmap::ConvertToImage() const
|
wxImage wxBitmap::ConvertToImage() const
|
||||||
{
|
{
|
||||||
return ConvertImage(M_PIXDATA.toImage());
|
QPixmap pixmap(M_PIXDATA);
|
||||||
|
if(M_MASK && M_MASK->GetHandle())
|
||||||
|
pixmap.setMask(*M_MASK->GetHandle());
|
||||||
|
return ConvertImage(pixmap.toImage());
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // wxUSE_IMAGE
|
#endif // wxUSE_IMAGE
|
||||||
|
|
||||||
wxMask *wxBitmap::GetMask() const
|
wxMask *wxBitmap::GetMask() const
|
||||||
{
|
{
|
||||||
return M_MASK.GetHandle() ? &M_MASK : NULL;
|
return M_MASK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxBitmap::SetMask(wxMask *mask)
|
void wxBitmap::SetMask(wxMask *mask)
|
||||||
{
|
{
|
||||||
if(mask && mask->GetHandle() )
|
AllocExclusive();
|
||||||
{
|
delete M_MASK;
|
||||||
M_MASK = *mask;
|
M_MASK = mask;
|
||||||
M_PIXDATA.setMask( *mask->GetHandle() );
|
|
||||||
} else
|
|
||||||
M_MASK = wxMask();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
wxBitmap wxBitmap::GetSubBitmap(const wxRect& rect) const
|
wxBitmap wxBitmap::GetSubBitmap(const wxRect& rect) const
|
||||||
{
|
{
|
||||||
return wxBitmap(M_PIXDATA.copy(wxQtConvertRect(rect)));
|
return wxBitmap(M_PIXDATA.copy(wxQtConvertRect(rect)));
|
||||||
@@ -438,9 +445,8 @@ wxGDIRefData *wxBitmap::CloneGDIRefData(const wxGDIRefData *data) const
|
|||||||
{
|
{
|
||||||
const wxBitmapRefData* oldRef = static_cast<const wxBitmapRefData*>(data);
|
const wxBitmapRefData* oldRef = static_cast<const wxBitmapRefData*>(data);
|
||||||
wxBitmapRefData *d = new wxBitmapRefData;
|
wxBitmapRefData *d = new wxBitmapRefData;
|
||||||
d->m_qtPixmap = oldRef->m_qtPixmap.copy();// copy not needed
|
d->m_qtPixmap = oldRef->m_qtPixmap; //.copy();// copy not needed
|
||||||
d->m_mask = oldRef->m_mask;
|
d->m_mask = oldRef->m_mask ? new wxMask(*oldRef->m_mask) : NULL;
|
||||||
|
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -649,20 +649,8 @@ void wxQtDCImpl::DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
|
|||||||
m_qtPainter->setBackground(savedBrush);
|
m_qtPainter->setBackground(savedBrush);
|
||||||
m_qtPainter->setPen(savedPen);
|
m_qtPainter->setPen(savedPen);
|
||||||
} else {
|
} else {
|
||||||
if ( !useMask && bmp.GetMask() )
|
if(useMask && bmp.GetMask() && bmp.GetMask()->GetHandle())
|
||||||
{
|
pix.setMask(*bmp.GetMask()->GetHandle());
|
||||||
// Temporarly disable mask
|
|
||||||
QBitmap mask;
|
|
||||||
mask = pix.mask();
|
|
||||||
pix.setMask( QBitmap() );
|
|
||||||
|
|
||||||
// Draw
|
|
||||||
m_qtPainter->drawPixmap(x, y, pix);
|
|
||||||
|
|
||||||
// Restore saved mask
|
|
||||||
pix.setMask( mask );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
m_qtPainter->drawPixmap(x, y, pix);
|
m_qtPainter->drawPixmap(x, y, pix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -69,8 +69,12 @@ void wxMemoryDCImpl::DoSelect( const wxBitmap& bitmap )
|
|||||||
|
|
||||||
m_selected = bitmap;
|
m_selected = bitmap;
|
||||||
if ( bitmap.IsOk() && !bitmap.GetHandle()->isNull() ) {
|
if ( bitmap.IsOk() && !bitmap.GetHandle()->isNull() ) {
|
||||||
|
QPixmap pixmap(*bitmap.GetHandle());
|
||||||
|
// apply mask before converting to image
|
||||||
|
if(bitmap.GetMask() && bitmap.GetMask()->GetHandle())
|
||||||
|
pixmap.setMask(*bitmap.GetMask()->GetHandle());
|
||||||
// create the intermediate image for the pixmap:
|
// create the intermediate image for the pixmap:
|
||||||
m_qtImage = new QImage( bitmap.GetHandle()->toImage() );
|
m_qtImage = new QImage( pixmap.toImage() );
|
||||||
// start drawing on the intermediary device:
|
// start drawing on the intermediary device:
|
||||||
m_ok = m_qtPainter->begin( m_qtImage );
|
m_ok = m_qtPainter->begin( m_qtImage );
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user