wxRendererNative draws at wrong position on wxGCDC in wxScrolled (Issue #25966)

36 views
Skip to first unread message

rudolfwalter

unread,
Nov 11, 2025, 3:15:48 PM (9 days ago) Nov 11
to wx-...@googlegroups.com, Subscribed
rudolfwalter created an issue (wxWidgets/wxWidgets#25966)

Description

When drawing using wxRendererNative onto the wxGCDC of a wxScrolled, the drawing ends up in the wrong position after scrolling, and gets truncated.

Repro:

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)

Platform and version information

  • wxWidgets version: both 3.2.2.1 and 3.3/master
  • wxWidgets port: wxMSW
  • OS: Windows 11 24H2
  • other: 150% DPI, light mode


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/25966@github.com>

VZ

unread,
Nov 11, 2025, 4:11:35 PM (9 days ago) Nov 11
to wx-...@googlegroups.com, Subscribed
vadz left a comment (wxWidgets/wxWidgets#25966)

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.Message ID: <wxWidgets/wxWidgets/issues/25966/3518739148@github.com>

VZ

unread,
Nov 11, 2025, 5:09:35 PM (9 days ago) Nov 11
to wx-...@googlegroups.com, Subscribed
vadz left a comment (wxWidgets/wxWidgets#25966)

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.Message ID: <wxWidgets/wxWidgets/issues/25966/3518907283@github.com>

rudolfwalter

unread,
Nov 13, 2025, 8:06:40 AM (8 days ago) Nov 13
to wx-...@googlegroups.com, Subscribed
rudolfwalter left a comment (wxWidgets/wxWidgets#25966)

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.Message ID: <wxWidgets/wxWidgets/issues/25966/3527736534@github.com>

VZ

unread,
Nov 13, 2025, 5:24:11 PM (7 days ago) Nov 13
to wx-...@googlegroups.com, Subscribed
vadz left a comment (wxWidgets/wxWidgets#25966)

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.Message ID: <wxWidgets/wxWidgets/issues/25966/3529963733@github.com>

rudolfwalter

unread,
Nov 14, 2025, 1:18:53 PM (6 days ago) Nov 14
to wx-...@googlegroups.com, Subscribed
rudolfwalter left a comment (wxWidgets/wxWidgets#25966)

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.Message ID: <wxWidgets/wxWidgets/issues/25966/3533986905@github.com>

VZ

unread,
Nov 16, 2025, 12:35:20 PM (4 days ago) Nov 16
to wx-...@googlegroups.com, Subscribed
vadz left a comment (wxWidgets/wxWidgets#25966)

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.Message ID: <wxWidgets/wxWidgets/issues/25966/3539009898@github.com>

Reply all
Reply to author
Forward
0 new messages