Implement wxNonOwnedWindow::SetShape() taking wxGraphicsPath under wxQt

This is a copy and paste of wxMac's implementation to make wxRichToolTip
work under wxQt.
This commit is contained in:
ali kettab 2023-12-27 19:16:18 +01:00
parent 7a306c4a42
commit c7fdb41fcd
2 changed files with 24 additions and 7 deletions

View file

@ -62,8 +62,8 @@ public:
resized using SetSize().
As the overload above, this method is not guaranteed to work on all
platforms but currently does work in wxMSW, wxOSX/Cocoa and wxGTK (with
the appropriate but almost always present X11 extensions) ports.
platforms but currently does work in wxMSW, wxOSX/Cocoa, wxGTK and wxQt
(with the appropriate but almost always present X11 extensions) ports.
@since 2.9.3
*/

View file

@ -18,12 +18,12 @@
#ifndef WX_PRECOMP
#include "wx/dcclient.h"
#include "wx/region.h"
#include "wx/dcmemory.h"
#include "wx/region.h"
#endif // WX_PRECOMP
#include "wx/nonownedwnd.h"
#include "wx/graphics.h"
#include "wx/qt/private/converter.h"
#include "wx/qt/private/utils.h"
@ -57,10 +57,27 @@ bool wxNonOwnedWindow::DoSetRegionShape(const wxRegion& region)
}
#if wxUSE_GRAPHICS_CONTEXT
bool wxNonOwnedWindow::DoSetPathShape(const wxGraphicsPath& WXUNUSED(path))
bool wxNonOwnedWindow::DoSetPathShape(const wxGraphicsPath& path)
{
wxMISSING_IMPLEMENTATION( __FUNCTION__ );
return true;
// Convert the path to wxRegion by rendering the path on a window-sized
// bitmap, creating a mask from it and finally creating the region from
// this mask.
wxBitmap bmp(GetSize());
{
wxMemoryDC dc(bmp);
dc.SetBackground(*wxBLACK_BRUSH);
dc.Clear();
std::unique_ptr<wxGraphicsContext> context(wxGraphicsContext::Create(dc));
context->SetBrush(*wxWHITE_BRUSH);
context->SetAntialiasMode(wxANTIALIAS_NONE);
context->FillPath(path);
}
bmp.SetMask(new wxMask(bmp, *wxBLACK));
return DoSetRegionShape(wxRegion(bmp));
}
#endif