0

I have a string that stores all kind of logged data. This data should be accessible via a console. The console has of course only a limited height. Therefore, I do not need to render the entire text, but only, what is visible. For this I have a variable that stores how many pixels from the bottom (most recent) end of the text the user has scrolled up. Now I guess what I need is a way to find out which part of my text fits into my console, and how to tell DirectWrite to only render this.

What I have done so far: Right now I am using CreateTextLayout(...) and DrawTextLayout(...) to draw the complete text (right now just a small test text) without the scrolling ability.

CreateTextLayout(...) already takes arguments maxWidth and maxHeight. So maybe this takes care of the problem of rendering only what fits into the console.

I have also used DWRITE_PARAGRAPH_ALIGNMENT_FAR to have the newest text-lines visible. But how do I add the additional scrolling (best in form of additional pixels and not lines so that I can implement smooth scrolling via some time controlled incrementation)?

In short

  1. Does CreateTextLayout(...) handle the "render-only-what-is-visible part" for me?
  2. How do I include the scrolling part?

Edit: Changed the title, as it was not really summing up the question very well.

NOhs
  • 2,780
  • 3
  • 25
  • 59

1 Answers1

0

A TextLayout is an internal representation of the Text. Imagine it like a set of pictures (Glyphs) representing each Charakter (It's not exactly right but it's enough to explain). When you finally render the Text the render Target will only paint what is visible on the Screen, so it get's cut where it overlapps the HDC. This is how it could work:

When you call DrawTextLayout() you give the Function a Startpoint (origin) for Drawing. Substract the Scrolling-y-Value from the y Position of the origin... done.

If you want to learn more about Glyphs: -Catch22.com Has the Great but unfinished Neatpad tutorial using uniscribe (API of Horror but it gives an idea of how DirectWrite works internally)

-MSDN also has a Tutorial about how to work directly on the Glyphs via DirectWrite and how to wright your own renderer: https://msdn.microsoft.com/en-us/library/windows/desktop/dd941787%28v=vs.85%29.aspx

I hope I could help.

Random
  • 1