Search code examples
c++hookdirectx-9vertical-scrollingdrawtext

D3D9 Scrolling for DrawText C++


I am trying to vertically scroll a multi line text with C++ D3D9 Overlay Hook to an application in a specific rect, but I can't figure out how can I do it. So my question is, how can I somehow limit a region to draw a part of an entire text to that? (I plan to create a scrollbar in the end)

Solution:

void DrawFrame()
{
  RECT rect, scissorRect;

  SetRect(&scissorRect, 100, 100, 400, 400);
  SetRect(&rect, 100, 100 - y, 400, 1000);

  d3ddev->SetScissorRect(&scissorRect);
  d3ddev->SetRenderState(D3DRS_SCISSORTESTENABLE, TRUE);

  font->DrawTextA(0, "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", -1, &rect, DT_WORDBREAK, 0xFFFFFFFF);

  d3ddev->SetRenderState(D3DRS_SCISSORTESTENABLE, FALSE);
}

Solution

  • It's 2019, soon-to-be 2020, is there a reason you aren't using at least DirectX 11?

    Regardless, the easiest implementation is to keep track of the position of the text (or rectangle that the text is drawn to) to move it up and down/left and right and use a scissor rect to clip the text to only be visible within a certain region.