• 0

A text layout control!


Question

I'm currently working on a text control that's supposed to clone the behaviour of the mIRC channel textbox. As you'd guess, it's for an IRC client.

However am I in need of a few tips and head ups about how to create such a thing efficiently. It should be restricted to text only, no graphical smily screw arounds, which simplifies the deal.

My current approach is to line, word and format break the line, generate formatting objects to be fed straight into the systems text drawing APIs. It'll regenerate the objects on window resizes.

Currently word and line breaking works by using a lookup table that stores character widths. To find the word break location, I just fly thru the string adding up character widths until I found the best spot to break the word for the remaining render width. Measuring strings works the same way, the API I'm coding against doesn't feature measuring APIs without instancing an object each time I want to measure one. Also my method is currently faster than object instantiation thing.

The next thing to be committed soon will be text selection. I've already ideas about how to do it, by reusing the existing text breaking code.

The reason I'm posting this, is that I'm in awe in the performance of Microsoft Word, compared to mIRC and Klient. Word renders stuff in a jiffy, selecting text like some epileptic up and down barely agitates by CPU graph. mIRC and Klient however make it jump to 80-98% depending on the size of text snippets.

So, anyone already worked on that type of controls and has tips or guides about such a task?

Don't suggest reusing controls, which are licensed under (L)GPL, I'm trying to avoid releasing my source code, especially since the resulting executable should be monolithic (though I've an assembly resolver aside that can load assemblies out of an archive).

Link to comment
Share on other sites

11 answers to this question

Recommended Posts

  • 0

a) I'm working with Avalon.

b) A webbrowser control is overkill and overhead royally for what I need. Least memory consumption is one of the things I want to accomplish.

c) The next best things to a rich text box in Longhorn would be:

- The DocumentViewer, which would be fed with XAML, which however adds UI widgets around it I don't need, and considering it's power is equal to PDF, guess what overhead it incurs yet again. And IIRC it'd need to reparse the whole XAML snippet each update.

- A TextPanel, which doesn't support any type of text selection. Useless like this.

And to get back to the WinForms rich text box, it has too many quirks that annoy me. Also I want it to start rendering from the bottom, a rich text box doesn't give me that (and empty line hacks don't cut it on resizes).

Link to comment
Share on other sites

  • 0

I don't see the problem. Whether it's GDIs DrawString or Avalons DrawText, where's the problem? The semantics happen above the drawing commands. I mentioned Avalon only to dismiss that rich text box and web browser suggestion.

I'm currently just researching the best methods to realize a fast text layouter with selection capabilities, and it's not exactly the type of subject you find easily on the web.

Link to comment
Share on other sites

  • 0

OK. I wasn't sure if the differences were great between the two. I haven't looked at Longhorn's API at all.

I'll play around with some stuff and let you know if I come up with anything that might be useful. Time is my only issue.

Just to clarify, are you inheriting from a textbox or creating one from scratch?

Link to comment
Share on other sites

  • 0

Scratch.

And it works more or less, I'm just inquiring for infos about best practises. No need to try to code something yourself for me.

Link to comment
Share on other sites

  • 0

Well, I had some email convo with Joe Beda, one of the Avalon architects, and got some tips. For speed reasons it looks like I'll be using a visual per line. And for each line I'll be slicing and dicing the string into single measured words.

Link to comment
Share on other sites

  • 0

I've done something similar to what you are attempting. Here is what I did:

First I sublcassed CListBox.

In order to make the list box have multiple lines, you will need to make the control owner drawn (variable). Over-ride the MeasureItem function, so that you set the height of each entry yourself. When you draw the text here, make sure and pass the DT_WORDBREAK and DT_CALCRECT options to the device context's DrawText function.

In order to achieve different colored text, you will need to use the device context function SetTextColor() in the DrawItem function (which is over-ridden). You can also set the background color with FillSolidRect().

I haven't really gone into the minor details of what you would need to do, this is more of an overview. If you are confortable with windows programming, this might be enough for you. If you have questions though - just ask :)

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.