Original Post
I need to write a high quality multiline editable text box in OpenGL. The textbox must be resizable. It will only have one font. I don't expect the user to type more than 4k characters in it. It should be easy to support word wrap.
I need some kind of data structure & algorithm that is good for this kind of thing. The big problems with the easier approaches:
*can't use a simple block of memory because inserting directly in that block requires you to move everything down in the block
*can't use an array of char*'s that stores each line because when the user resizes the text box a lot this will fragment memory badly, plus all the new's and delete's are bad for framerate
One of the big problems is that I need an easy way to keep track of where the line beginnings are so I can render each line, rather than traversing the text each frame and determining which lines are visible, where the line breaks are and what the scrollbars should be set to.
Anyone have any ideas or references to algorithms/data structures for such a problem? I spend a bit of time looking at how some of the linux free source word processors handle it, but it seems kind of overkill.
I'm thinking along the line of splitting the text into a linked list of hunks that are like 24 characters long each and having another data structure like a deque to keep track of the line beginnings.
Edit - minor stuff
[edited by - Z01 on May 29, 2003 10:12:16 PM]