From f9c2d24bb6f4f99f6a3fa4f4898f36540e9284f8 Mon Sep 17 00:00:00 2001 From: ali kettab Date: Sun, 18 Feb 2024 17:32:15 +0100 Subject: [PATCH 1/2] wxQt! Refactoring only --- src/qt/brush.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/qt/brush.cpp b/src/qt/brush.cpp index 4c2d9d6dfd..b37b3cc601 100644 --- a/src/qt/brush.cpp +++ b/src/qt/brush.cpp @@ -74,6 +74,15 @@ public: m_style = data.m_style; } + void DoSetStipple(const wxBitmap& stipple) + { + m_qtBrush.setTexture(*stipple.GetHandle()); + if (stipple.GetMask() != nullptr) + m_style = wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE; + else + m_style = wxBRUSHSTYLE_STIPPLE; + } + bool operator == (const wxBrushRefData& data) const { return m_qtBrush == data.m_qtBrush; @@ -113,11 +122,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(m_refData)->DoSetStipple(stipple); } @@ -143,12 +149,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(m_refData)->DoSetStipple(stipple); } From eebb5a587f7e4a8ea33433378a3ba0df748e6d4c Mon Sep 17 00:00:00 2001 From: ali kettab Date: Sun, 18 Feb 2024 17:53:10 +0100 Subject: [PATCH 2/2] Added translucent stipple brush support under wxQt --- src/qt/brush.cpp | 32 ++++++++++++++++++++++++++++---- src/qt/dc.cpp | 20 ++------------------ 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/qt/brush.cpp b/src/qt/brush.cpp index b37b3cc601..53877420a2 100644 --- a/src/qt/brush.cpp +++ b/src/qt/brush.cpp @@ -13,6 +13,7 @@ #include "wx/qt/private/utils.h" #include "wx/bitmap.h" +#include #include wxIMPLEMENT_DYNAMIC_CLASS(wxBrush,wxGDIObject); @@ -76,11 +77,34 @@ public: void DoSetStipple(const wxBitmap& stipple) { - m_qtBrush.setTexture(*stipple.GetHandle()); - if (stipple.GetMask() != nullptr) - m_style = wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE; + m_style = wxBRUSHSTYLE_STIPPLE; + + if ( !stipple.GetMask() && stipple.GetDepth() == 32 ) + { + m_qtBrush.setTextureImage(stipple.GetHandle()->toImage()); + } else - m_style = wxBRUSHSTYLE_STIPPLE; + { + 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 diff --git a/src/qt/dc.cpp b/src/qt/dc.cpp index c1483c696e..cc82af2acb 100644 --- a/src/qt/dc.cpp +++ b/src/qt/dc.cpp @@ -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(); }