New Text Layout Engine

I have merged into the trunk the fonts branch where I was developing a new text layout engine. This provides an overload to FontSurface.DrawText which takes arguments like (string formatString, params object[] args), in a manner similar to string.Format, Console.WriteLine, or Debug.Print. This adds some special AgateLib specific features like being able to do:

  1. Surface swordIcon;
  2. FontSurface font;
  3. font.DrawText(0,0,"You found {0}Excalibur!", swordIcon);

As usual, where the "{0}" argument is substituted the 0-th object in the args array, however if that object is a Surface as in the above example, it will be drawn inline with the text.

There are other special objects that can be inserted too. These inherit from the AlterText object, and can be used like so:

  1. font.DrawText(0,0,"Some of this text {0}is green{1}.",
  2.     AlterText.Color(Color.Green), AlterText.Color(Color.Black));

The above code will cause the text "is green" to be colored green. There are some breaking changes in this update, in particular the characters { and } must be escaped by surrounding them in braces, e.g. {{} and {}}.

With this update also comes stateless drawing. Now the "impl" objects for surfaces and fonts do not track any state data. SurfaceImpl now only has one Draw method which takes a SurfaceState object. This greatly simplifies the implementation and maintenance of display drivers and also adds the ability to draw images with cached states. This is a major change in the interal structure of AgateLib and its drivers, so there may be regressions. Please report any issues so they can be fixed.

skelooth
Posted - Tue, 09/29/2009 - 07:26

that's a great feature. I wish I had the time resources to seriously develop with this library. Great job.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.