0

I'm drawing a timeline in my application which can be zoomed in and out. But from a certain zoom, long lines cease to be painted. I discovered this had something to do with how long the line is. For a zoom down to nanoseconds, I can have a line as long as one billion pixels (logical units), representing one second (which is an extremely long time in my application). But such a long line isn't painted anymore.

Here is a sample to reproduce the problem (MFC application). I first set the viewport to start "long before" the visible region (emulating the scrollbar) and then attempt to draw a line whose one end should appear on the screen.

void CMFCApplication1Dlg::OnBnClickedIgnore()
{
    CDC dc;
    dc.Attach( ::GetDC(m_hWnd) );
    constexpr int Length=1000000000; // -1e9
    dc.SetViewportOrg( -Length, 80 );
    dc.MoveTo( 0, 0 );
    dc.LineTo( Length+100, 0 );
    dc.TextOutW( Length+100, 0, _T("Hello") );
}

But only the text is shown.

enter image description here

If I shorten the constexpr Length parameter to say one million, both the text and the line are drawn.

enter image description here

By experimentation, I found out that the breaking value is 0x08000000 - anything below that is painted well, anything beyond that isn't painted at all. Does anyone know why this is? Are there any other constraints to the coordinate inputs of GDI functions which Microsoft forgot to mention?

James Z
  • 12,209
  • 10
  • 24
  • 44
tomascz
  • 235
  • 1
  • 13
  • https://stackoverflow.com/questions/3468495/what-are-the-hard-bounds-for-drawing-coordinates-in-gdi seems relevant. – Jonathan Potter Nov 07 '20 at 22:12
  • I'm not surprised. All graphics system have this kind of artifacts issue when using big numbers fed directly into them, often due to internal computation, floating point limitation, etc. Have you tried to use transforms instead see if it fixes things? https://learn.microsoft.com/en-us/windows/win32/gdi/about-coordinate-spaces-and-transformations – Simon Mourier Nov 07 '20 at 22:22
  • Only for reference: device Used as the next space after page space. It only allows translation, which ensures the origin of the device space maps to the proper location in physical device space. Device space measures 2^27 units high by 2^27 units wide. Refer: [Transformation of Coordinate Spaces](https://learn.microsoft.com/en-us/windows/win32/gdi/transformation-of-coordinate-spaces) – Strive Sun Nov 11 '20 at 03:32

0 Answers0