When drawing using wxRendererNative onto the wxGCDC of a wxScrolled, the drawing ends up in the wrong position after scrolling, and gets truncated.
diff --git a/samples/scroll/scroll.cpp b/samples/scroll/scroll.cpp index c709332286..65eea1c2f6 100644 --- a/samples/scroll/scroll.cpp +++ b/samples/scroll/scroll.cpp @@ -14,6 +14,8 @@ #include "wx/wx.h" #endif +#include "wx/dcgraph.h" +#include "wx/renderer.h" #include "wx/sizer.h" #include "wx/log.h" #include "wx/tglbtn.h" @@ -52,7 +54,9 @@ public: private: void OnPaint(wxPaintEvent& WXUNUSED(event)) { - wxPaintDC dc(this); + wxPaintDC paintDC(this); + wxGraphicsContext* gc = wxGraphicsRenderer::GetDefaultRenderer()->CreateContext(paintDC); + wxGCDC dc(gc); // this call is vital: it adjusts the dc to account for the current // scroll offset @@ -61,6 +65,15 @@ private: dc.SetPen( *wxRED_PEN ); dc.SetBrush( *wxTRANSPARENT_BRUSH ); dc.DrawRectangle( 0, 0, WIDTH, HEIGHT ); + + constexpr int Y1 = 40, Y2 = 80, X1 = 50, X2 = 90; + + dc.SetPen(*wxBLUE_PEN); + dc.DrawLine(X1, Y1, X2, Y1); + dc.DrawLine(X1, Y2, X2, Y2); + + wxRendererNative::Get().DrawTreeItemButton(this, dc, wxRect(X1 - 30, Y1 - 8, 16, 16), 0); + wxRendererNative::Get().DrawCheckBox(this, dc, wxRect(X2 + 20, Y2 - 12, 24, 24), 0); } };
Correct result, before scrolling:
image.png (view on web)Wrong result, after scrolling:
image.png (view on web)—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
I do see this, thanks, will try to have a look. It seems to be MSW-specific as this works correctly in wxGTK.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
The linked PR fixes the provided example, please check if it works with your actual code. TIA!
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
The PR does seem to fix the issue with the default renderer, however the Direct2D renderer produces duplicate images when scrolling down. (Change GetDefaultRenderer() to GetDirect2DRenderer() in the repro code to see this.)
image.png (view on web)—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
I see this, thanks, but I don't see why does this happen. Transform matrix related code in D2D renderer is rather complex and I'm not sure if the problem is in it or something else. I thought D2D could somehow apply the transform to the native HDC we get from it, but inserting
diff --git a/src/common/dcgraph.cpp b/src/common/dcgraph.cpp index 0604b1063d..0fa7edcafd 100644 --- a/src/common/dcgraph.cpp +++ b/src/common/dcgraph.cpp @@ -119,7 +119,15 @@ WXHDC wxGCDC::AcquireHDC() { wxGraphicsContext* const gc = GetGraphicsContext(); wxCHECK_MSG(gc, nullptr, "can't acquire HDC because there is no wxGraphicsContext"); - return gc->GetNativeHDC(); + WXHDC hdc = gc->GetNativeHDC(); + + POINT ptViewOrg, ptWinOrg; + GetViewportOrgEx(hdc, &ptViewOrg); + GetWindowOrgEx(hdc, &ptWinOrg); + wxLogDebug("wxGCDC::AcquireHDC: ViewportOrg=(%d,%d), WindowOrg=(%d,%d)", + ptViewOrg.x, ptViewOrg.y, ptWinOrg.x, ptWinOrg.y); + + return hdc; } void wxGCDC::ReleaseHDC(WXHDC hdc)
shows that the origin is always 0, so that's not it either. I'm afraid I'll have to abandon this for now as I don't have any other ideas.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
That's understandable; thanks for your investigation.
I tinkered a bit more with it, so I'll write what I found for future reference.
I suspect this is some form of a buffering/caching issue (rather than a drawing or coordinates issue), because at specific scroll amounts the drawing actually shows up twice:
image.png (view on web)Also, calling Refresh() makes the wrong ones disappear, and calling SetDoubleBuffered(true) makes the problem go away altogether.
So from my perspective your PR is good to be merged; I'll use SetDoubleBuffered(true) to work around the rest.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Thanks, I'll keep this open with the updated title because the problem is still there.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()