Note: The Agar manual pages follow certain conventions, notably concerning function return values. Please read AG_Intro(3) first.
SYNOPSIS
#include <agar/core.h> #include <agar/gui.h> |
DESCRIPTION
| The AG_Text interface uses an underlying font engine to render text. Currently, two font engines are supported: AG_FONT_VECTOR (for rendering any font supported by FreeType) and AG_FONT_BITMAP (for rendering simple pixmap fonts). |
RENDER SETTINGS
|
A number of settings which affect the rendering functions (see
RENDERING section) can be modified at any time, and are organized in a stack of
rendering attributes.
The AG_PushTextState() and AG_PopTextState() functions respectively push and pop the text rendering attribute stack. The attribute stack can hold AG_TEXT_STATES_MAX items (at least 32). The AG_TextFont() function selects font as the active font. AG_TextFontLookup() searches the font cache for the given font face, size and flags combination, possibly loading new fonts from disk (scanning all font-path directories). On success, the font is selected as the active font and returned. If no match is found, the function returns NULL. AG_TextFontPts() sets the size of the active font in points. AG_TextFontPct() sets the size of the active font, specified as percentage of current font size. An argument of 100% leaves the size unchanged. AG_TextJustify() selects the justification mode to use in multi-line rendering: enum ag_text_justify {
AG_TEXT_LEFT,
AG_TEXT_CENTER,
AG_TEXT_RIGHT
};
AG_TextValign() selects the vertical alignment mode to use where text is rendered to an area of arbitrary height: enum ag_text_valign {
AG_TEXT_TOP,
AG_TEXT_MIDDLE,
AG_TEXT_BOTTOM
};
AG_TextColor() sets the text color (see AG_Color(3)). AG_TextColorRGB() and AG_TextColorRGBA() accept individual color components. Similarly, AG_TextBG*() functions assign a background color for the surfaces returned by the rendering functions. |
RENDERING
|
The AG_TextRender() function renders text to a new, transparent surface. The input text may contain UTF-8 sequences. The AG_TextRenderf() variant accepts printf(3) style arguments. AG_TextRenderUCS4() renders text in UCS-4 format onto a new surface. AG_TextRenderGlyph() renders the specified UCS-4 encoded Unicode character. The function returns an AG_Glyph structure, which has the following public (read-only) members:
The AG_TextSize() and AG_TextSizeUCS4() functions return the minimal bounding box in pixels required for rendering the given text. The AG_TextSizeMulti() and AG_TextSizeMultiUCS4() variants also return the number of lines into nLines and the width in pixels of each line in the array wLines (which must be initialized to NULL). |
CANNED DIALOGS
|
The AG_TextMsg() function displays a text message window containing the given printf(3) formatted string, and an OK button. title is one of the following: enum ag_text_msg_title {
AG_MSG_ERROR,
AG_MSG_WARNING,
AG_MSG_INFO
};
AG_TextMsgFromError() displays a standard error message using the value of AG_GetError(3). AG_TextWarning() displays a standard warning message, but also provides the user with a Don't show again checkbox. The checkbox controls the AG_Config(3) value specified by disableKey. AG_TextError() displays an error message. It is equivalent to AG_TextMsg() with a AG_MSG_ERROR setting. AG_TextInfo() displays an informational message. Similar to AG_TextWarning(), a Don't show again option is provided to the user (and the setting is referenced by disableKey). The AG_TextTmsg() routine is a variant of AG_TextMsg() which displays the message for a specific amount of time, given in milliseconds. The AG_TextEditFloat() function displays a dialog asking for a floating-point value. The fp argument is a pointer to the variable, while min and max define the acceptable range. Unless unit is NULL, the argument indicates the unit system to use (as in AG_Units(3)). Similarly, AG_TextEditString() displays a dialog asking for a string, where buf is a pointer to the string buffer, and len is the size of the buffer. The AG_TextPromptString() creates a modal dialog asking the user for a text string. Once the user confirms the entry, the ok_fn() callback is invoked (see AG_Event(3) for details on the argument format). The entered string is the last argument on the stack. AG_TextPromptOptions() creates a dialog displaying a text string and an array of buttons. buttons is a set of existing AG_Button(3) widgets to display. |
FONT SELECTION
|
The AG_FetchFont() function retrieves the specified font face, loading it from file if it's not currently resident. If face is NULL, the default font.face configuration setting is used (see AG_Config(3)). The font file should reside in one of the directories specified in font-path setting. The size argument is specified in points (if -1 is passed, the default configuration setting font.size is used). If flags is -1, the default configuration setting font.flags is used. The function returns a pointer to the font object, or NULL if an error occured. The AG_DestroyFont() function releases a font object assuming it is no longer in use. AG_SetDefaultFont() sets the specified font object as the default font. AG_SetRTL() enables or disables right-to-left text mode. The AG_TextParseFontSpec() function parses a font specification of the form face,size,style (valid separators include :,./) and assigns the default font. This function is typically called prior to AG_InitGraphics() (e.g., to parse alternate fonts specified on the command line). |
SEE ALSO
AG_Intro(3), AG_Config(3), AG_Editable(3), AG_Label(3), AG_Surface(3), AG_Textbox(3), AG_Widget(3) The FreeType project - http://www.freetype.org/ Unicode home page - http://www.unicode.org/ |
HISTORY
| The AG_Text interface first appeared in Agar 1.0. The stack of rendering attributes was added in Agar 1.3. Right-to-left rendering first appeared in Agar 1.4.1. |
