Merge commit 'refs/pull/24337/head' of github.com:wxWidgets/wxWidgets

Add translucent stipple brush support under wxQt.

See #24337.
This commit is contained in:
Vadim Zeitlin 2024-02-19 03:39:43 +01:00
commit 2aea33c4ef
2 changed files with 38 additions and 28 deletions

View file

@ -13,6 +13,7 @@
#include "wx/qt/private/utils.h"
#include "wx/bitmap.h"
#include <QtGui/QBitmap>
#include <QtGui/QBrush>
wxIMPLEMENT_DYNAMIC_CLASS(wxBrush,wxGDIObject);
@ -74,6 +75,38 @@ public:
m_style = data.m_style;
}
void DoSetStipple(const wxBitmap& stipple)
{
m_style = wxBRUSHSTYLE_STIPPLE;
if ( !stipple.GetMask() && stipple.GetDepth() == 32 )
{
m_qtBrush.setTextureImage(stipple.GetHandle()->toImage());
}
else
{
if ( stipple.GetMask() || stipple.GetDepth() == 1 )
{
auto pixmap = stipple.GetMask() ? stipple.GetMask()->GetBitmap().GetHandle()
: stipple.GetHandle();
m_qtBrush.setTexture(*pixmap);
m_style = wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE;
}
else
{
m_qtBrush.setTexture(*stipple.GetHandle());
// Note: This code used to be in wxQtDCImpl::SetBrush().
// But, do we really need to do it ?
//Don't use the mask
QPixmap p = m_qtBrush.texture();
p.setMask(QBitmap());
m_qtBrush.setTexture(p);
}
}
}
bool operator == (const wxBrushRefData& data) const
{
return m_qtBrush == data.m_qtBrush;
@ -113,11 +146,8 @@ wxBrush::wxBrush(const wxColour& col, int style)
wxBrush::wxBrush(const wxBitmap& stipple)
{
m_refData = new wxBrushRefData();
M_BRUSHDATA.setTexture(*stipple.GetHandle());
if (stipple.GetMask() != nullptr)
M_STYLEDATA = wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE;
else
M_STYLEDATA = wxBRUSHSTYLE_STIPPLE;
static_cast<wxBrushRefData*>(m_refData)->DoSetStipple(stipple);
}
@ -143,12 +173,8 @@ void wxBrush::SetStyle(wxBrushStyle style)
void wxBrush::SetStipple(const wxBitmap& stipple)
{
AllocExclusive();
M_BRUSHDATA.setTexture(*stipple.GetHandle());
if (stipple.GetMask() != nullptr)
M_STYLEDATA = wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE;
else
M_STYLEDATA = wxBRUSHSTYLE_STIPPLE;
static_cast<wxBrushRefData*>(m_refData)->DoSetStipple(stipple);
}

View file

@ -194,26 +194,10 @@ void wxQtDCImpl::SetBrush(const wxBrush& brush)
if (brush.GetStyle() == wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE)
{
// Use a monochrome mask: use foreground color for the mask
QBrush b(brush.GetHandle());
b.setColor(m_textForegroundColour.GetQColor());
b.setTexture(b.texture().mask());
m_qtPainter->setBrush(b);
m_brush.SetColour(m_textForegroundColour);
}
else if (brush.GetStyle() == wxBRUSHSTYLE_STIPPLE)
{
//Don't use the mask
QBrush b(brush.GetHandle());
QPixmap p = b.texture();
p.setMask(QBitmap());
b.setTexture(p);
m_qtPainter->setBrush(b);
}
else
{
m_qtPainter->setBrush(brush.GetHandle());
}
m_qtPainter->setBrush(m_brush.GetHandle());
ApplyRasterColourOp();
}