Atrinik Client 2.5
Functions | Variables
toolkit/text.c File Reference
#include <global.h>

Go to the source code of this file.

Functions

void text_init ()
void text_deinit ()
void text_offset_set (int x, int y)
void text_offset_reset ()
void text_color_set (int r, int g, int b)
void text_set_selection (sint64 *start, sint64 *end, uint8 *started)
const char * get_font_filename (int font)
int get_font_id (const char *name, size_t size)
static void reset_color (SDL_Surface *surface, SDL_Color *color, SDL_Color *orig_color)
char * text_strip_markup (char *buf, size_t *buf_len, uint8 do_free)
static void text_adjust_coords (SDL_Surface *surface, int *mx, int *my)
int text_color_parse (const char *color_notation, SDL_Color *color)
int blt_character (int *font, int orig_font, SDL_Surface *surface, SDL_Rect *dest, const char *cp, SDL_Color *color, SDL_Color *orig_color, uint64 flags, SDL_Rect *box, int *x_adjust)
int glyph_get_width (int font, char c)
int glyph_get_height (int font, char c)
void string_blt (SDL_Surface *surface, int font, const char *text, int x, int y, const char *color_notation, uint64 flags, SDL_Rect *box)
void string_blt_shadow (SDL_Surface *surface, int font, const char *text, int x, int y, const char *color_notation, const char *color_shadow_notation, uint64 flags, SDL_Rect *box)
void string_blt_format (SDL_Surface *surface, int font, int x, int y, const char *color_notation, uint64 flags, SDL_Rect *box, const char *text,...)
void string_blt_shadow_format (SDL_Surface *surface, int font, int x, int y, const char *color_notation, const char *color_shadow_notation, uint64 flags, SDL_Rect *box, const char *text,...)
int string_get_width (int font, const char *text, uint64 flags)
int string_get_height (int font, const char *text, uint64 flags)
void string_truncate_overflow (int font, char *text, int max_width)
void text_enable_debug ()

Variables

static uint8 text_debug = 0
static uint8 text_anchor_help_clicked = 0
static char text_anchor_help [HUGE_BUF]
static int text_offset_mx = -1
static int text_offset_my = -1
static sint64 * selection_start = NULL
static sint64 * selection_end = NULL
static uint8selection_started = NULL
SDL_Color text_link_color_default = {96, 160, 255, 0}
SDL_Color text_link_color = {0, 0, 0, 0}
font_struct fonts [FONTS_MAX]

Detailed Description

Text drawing API. Used SDL_ttf for rendering.

Definition in file text.c.


Function Documentation

int blt_character ( int *  font,
int  orig_font,
SDL_Surface *  surface,
SDL_Rect *  dest,
const char *  cp,
SDL_Color *  color,
SDL_Color *  orig_color,
uint64  flags,
SDL_Rect *  box,
int *  x_adjust 
)

Draw one character on the screen or parse markup (if applicable).

Parameters:
[out]fontFont to use. One of FONT_xxx.
orig_fontOriginal font, used for the font tag.
surfaceSurface to draw on. If NULL, there is no drawing done, but the return value is still calculated along with dest->w.
destDestination, will have width (and x, if surface wasn't NULL) updated.
cpString we are working on, cp[0] is the character to draw.
colorColor to use.
orig_colorOriginal color.
flagsFlags as passed to string_blt().
Returns:
How many characters to jump. Usually 1, but can be more in case of markup tags that need to be jumped over, since they are not actually drawn.

Definition at line 458 of file text.c.

const char* get_font_filename ( int  font)

Get font's filename; removes the path/to/fontdir part from the font's path and returns it.

Parameters:
fontFont ID.
Returns:
The filename.

Definition at line 241 of file text.c.

int get_font_id ( const char *  name,
size_t  size 
)

Get font's ID from its xxx.ttf name (not including path) and the pixel size.

Parameters:
nameThe font name.
sizeThe size.
Returns:
The font ID, -1 if there is no such font.

Definition at line 265 of file text.c.

int glyph_get_height ( int  font,
char  c 
)

Get glyph's height.

Parameters:
fontFont of the glyph.
cThe glyph.
Returns:
The height.

Definition at line 1352 of file text.c.

int glyph_get_width ( int  font,
char  c 
)

Get glyph's width.

Parameters:
fontFont of the glyph.
cThe glyph.
Returns:
The width.

Definition at line 1330 of file text.c.

static void reset_color ( SDL_Surface *  surface,
SDL_Color *  color,
SDL_Color *  orig_color 
) [static]

Reset r, g, b values of 'color' to that of 'orig_color'.

Parameters:
surfaceIf NULL, will not do anything.
colorValues to copy to.
orig_colorValues to copy from.

Definition at line 298 of file text.c.

void string_blt ( SDL_Surface *  surface,
int  font,
const char *  text,
int  x,
int  y,
const char *  color_notation,
uint64  flags,
SDL_Rect *  box 
)

Draw a string on the specified surface.

Parameters:
surfaceSurface to draw on.
fontFont to use. One of FONT_xxx.
textThe string to draw.
xX position.
yY position.
color_notationColor to use.
flagsOne or a combination of Text flags.
boxIf word wrap was enabled by passing TEXT_WORD_WRAP as one of the 'flags', this is used to get the max width from. Also even if word wrap is disabled, this is used to get the max height from, if set (both box->w and box->h can be 0 to indicate unlimited).

Definition at line 1382 of file text.c.

void string_blt_format ( SDL_Surface *  surface,
int  font,
int  x,
int  y,
const char *  color_notation,
uint64  flags,
SDL_Rect *  box,
const char *  text,
  ... 
)

Like string_blt(), but allows using printf-like format specifiers.

Draw a string on the specified surface.

Parameters:
surfaceSurface to draw on.
fontFont to use. One of FONT_xxx.
textThe string to draw.
xX position.
yY position.
color_notationColor to use.
flagsOne or a combination of Text flags.
boxIf word wrap was enabled by passing TEXT_WORD_WRAP as one of the 'flags', this is used to get the max width from. Also even if word wrap is disabled, this is used to get the max height from, if set (both box->w and box->h can be 0 to indicate unlimited).

Definition at line 1671 of file text.c.

void string_blt_shadow ( SDL_Surface *  surface,
int  font,
const char *  text,
int  x,
int  y,
const char *  color_notation,
const char *  color_shadow_notation,
uint64  flags,
SDL_Rect *  box 
)

Draw a string with a shadow.

Parameters:
surfaceSurface to draw on.
fontFont to use. One of FONT_xxx.
textThe string to draw.
xX position.
yY position.
color_notationColor to use.
color_shadow_notationColor to use for the shadow.
flagsOne or a combination of Text flags.
boxIf word wrap was enabled by passing TEXT_WORD_WRAP as one of the 'flags', this is used to get the max width from. Also even if word wrap is disabled, this is used to get the max height from, if set (both box->w and box->h can be 0 to indicate unlimited).

Definition at line 1661 of file text.c.

void string_blt_shadow_format ( SDL_Surface *  surface,
int  font,
int  x,
int  y,
const char *  color_notation,
const char *  color_shadow_notation,
uint64  flags,
SDL_Rect *  box,
const char *  text,
  ... 
)

Like string_blt_shadow(), but allows using printf-like format specifiers.

Draw a string with a shadow.

Parameters:
surfaceSurface to draw on.
fontFont to use. One of FONT_xxx.
textThe string to draw.
xX position.
yY position.
color_notationColor to use.
color_shadow_notationColor to use for the shadow.
flagsOne or a combination of Text flags.
boxIf word wrap was enabled by passing TEXT_WORD_WRAP as one of the 'flags', this is used to get the max width from. Also even if word wrap is disabled, this is used to get the max height from, if set (both box->w and box->h can be 0 to indicate unlimited).

Definition at line 1686 of file text.c.

int string_get_height ( int  font,
const char *  text,
uint64  flags 
)

Calculate string's pixel height, taking into account markup, if applicable.

It is usually enough to use FONT_HEIGHT() to get the string's font height, unless markup is allowed, in which case the maximum used height might be different.

Parameters:
fontFont. One of FONT_xxx.
textString to get height of.
flagsOne or a combination of Text flags.
Returns:
The string's height.

Definition at line 1730 of file text.c.

int string_get_width ( int  font,
const char *  text,
uint64  flags 
)

Calculate string's pixel width, taking into account markup, if applicable.

Parameters:
fontFont. One of FONT_xxx.
textString to get width of.
flagsOne or a combination of Text flags.
Returns:
The string's width.

Definition at line 1704 of file text.c.

void string_truncate_overflow ( int  font,
char *  text,
int  max_width 
)

Truncate a text string if overflow would occur when rendering it.

Parameters:
fontFont used for the text.
textThe text.
max_widthMaximum possible width.

Definition at line 1765 of file text.c.

static void text_adjust_coords ( SDL_Surface *  surface,
int *  mx,
int *  my 
) [static]

Adjust mouse X/Y coordinates for mouse-related checks based on which surface we're using.

Parameters:
surfaceThe surface.
[out]mxMouse X, may be modified.
[out]myMouse Y, may be modified.

Definition at line 391 of file text.c.

int text_color_parse ( const char *  color_notation,
SDL_Color *  color 
)

Parse the given string as a HTML notation color, and store the RGB values in 'color'.

Parameters:
color_notationThe HTML notation to parse.
colorWhere the RGB values will be stored.
Returns:
1 if the notation was parsed successfully, 0 otherwise.

Definition at line 428 of file text.c.

void text_color_set ( int  r,
int  g,
int  b 
)

Set color to use for links. Will be reset to default color after the next call to string rendering is done.

Parameters:
rRed.
gGreen.
bBlue.

Definition at line 214 of file text.c.

void text_deinit ( )

Deinitializes the text API.

Definition at line 172 of file text.c.

void text_enable_debug ( )

Enable text debugging.

Definition at line 1786 of file text.c.

void text_init ( )

Initialize the text API. Should only be done once.

Definition at line 147 of file text.c.

void text_offset_reset ( )

Reset the text offset. This must be done after text_offset_set() and string_blt() calls eventually,

Definition at line 203 of file text.c.

void text_offset_set ( int  x,
int  y 
)

If string_blt() is called on surface that is not ScreenSurface, you must use this to set mouse X/Y detection offset, so things like links will work correctly.

Note that this is not required for widget surfaces, as it's done automatically by searching the widgets for the surface that is being used.

Parameters:
xX position of the surface.
yY position of the surface.

Definition at line 194 of file text.c.

void text_set_selection ( sint64 *  start,
sint64 *  end,
uint8 started 
)

Allow grabbing a text selection.

Parameters:
startPointer that will be used to store start of selection.
endPointer that will be used to store start of selection.
startedPointer that is used to determine whether to store selection data in start or end.
Note:
You must call this with all arguments set to NULL after your call to string drawing routines.

Definition at line 229 of file text.c.

char* text_strip_markup ( char *  buf,
size_t *  buf_len,
uint8  do_free 
)

Remove all markup tags, including their contents.

Entities will also be replaced with their proper replacements.

Parameters:
bufBuffer containing the text with markup, from which to remove tags.
[out]lenLength of 'buf'. This will contain the length of the new string, without markup tags. Can be NULL, in which case length of the original string will be calculated automatically.
do_freeIf 1, will automatically free 'buf'.
Returns:
Newly allocated string with markup removed, and entities replaced.

Definition at line 322 of file text.c.


Variable Documentation

font_struct fonts[FONTS_MAX]

All the usable fonts.

Definition at line 66 of file text.c.

sint64* selection_end = NULL [static]

Pointer to integer holding the selection end.

Definition at line 56 of file text.c.

sint64* selection_start = NULL [static]

Pointer to integer holding the selection start.

Definition at line 54 of file text.c.

uint8* selection_started = NULL [static]

If 1, selection start has been set, and the end should be updated next.

Definition at line 58 of file text.c.

char text_anchor_help[HUGE_BUF] [static]

Help GUI to open if text_anchor_help_clicked is 1.

Definition at line 46 of file text.c.

If not 0, text_anchor_help is used to open the help GUI after finishing drawing.

This is used so the text being drawn is not changed in the middle of the drawing by clicking on a link.

Definition at line 43 of file text.c.

uint8 text_debug = 0 [static]

If 1, all text shown using 'box' parameter of string_blt() for max width/height will have a frame around it.

Definition at line 35 of file text.c.

SDL_Color text_link_color = {0, 0, 0, 0}

Current text link color.

Definition at line 63 of file text.c.

SDL_Color text_link_color_default = {96, 160, 255, 0}

Default link color.

Definition at line 61 of file text.c.

int text_offset_mx = -1 [static]

Mouse X offset.

Definition at line 49 of file text.c.

int text_offset_my = -1 [static]

Mouse Y offset.

Definition at line 51 of file text.c.