Font classes upgraded and available in CGE editor

Posted on

TCastleLabel, TCastleFont, TCastleBitmapFont demo
TCastleLabel, TCastleFont, TCastleBitmapFont demo - running

You can now add and configure fonts in CGE editor.

  1. Use the “Design -> Add Non-Visual Component” menu item, or the context menu (when you right-click in the hierarchy on the left). Font is added as “Non-Visual Component” to whatever parent you selected.

    The parent that keeps reference to the font node can be anything — TCastleComponent, TCastleTransform, TCastleUserInterace etc. It is similar to VCL/LCL non-visual components: it doesn’t really matter where you drop them on the form.

  2. Then assign this font to TCastleLabel.CustomFont. Or any other UI control descending from TCastleUserInterfaceFont, like TCastleButton or TCastleEdit.

    New property TCastleText.CustomFont is also available, and you can also assign to it using CGE editor. This allows to adjust the (potentially 3D) TCastleText in the same way.

Along with this change, we upgrade our font classes:

  1. Renames to better names:

    • TCastleFont -> TCastleAbstractFont

    • TTextureFont -> TCastleFont (definitely the most common font class you will use)

    • TSimpleTextureFont -> TCastleBitmapFont

    • TFontFamily -> TCastleFontFamily

    • TCustomizedFont -> for now not renamed and not published in CGE editor, as it doesn’t seem critical enough, use-case is only to provide multiple alternative “optimal sizes”. We may integrate this use-case into TCastleFont one day.

    Some unit cleanup has been done by the way: TCastleFontFamily has been moved to CastleFonts unit, and TRichText has been moved to CastleInternalRichText unit and CastleFontFamily unit has been deprecated. In effect: user code needs to use 1 less unit (no need to use CastleFontFamily unit), and some internal things (TRichText and friends) have been hidden to make API easier.

  2. TCastleFont gets new comfortable properties:

  3. TCastleBitmapFont gets comfortable properties:

  4. When the font is not loaded (e.g. TCastleFont.URL was not set, or TCastleFontFamily has TCastleFontFamily.Regular not set) then we always display some default font (Window.Container.DefaultFont, falling back on global default UIFont) to avoid having invisible e.g. TCastleLabel.

  5. As usual, assigning URL to ” (empty) is allowed and valid way to just “unload” the font.

  6. FreeType version distributed in our Windows DLLs has been updated.

  7. TCastleText is now a sans-serif font by default. This follows the UI default fonts.

  8. See examples, e.g. examples/fonts/text_tests for initial demos of it.

  9. TODO: Manual page about text and fonts will be soon updated to reflect all of the above.

Start the discussion at Castle Game Engine Forum