Angband
Typedefs | Functions | Variables
z-textblock.h File Reference

Text output bugger (?NRM) code. More...

#include "z-file.h"

Go to the source code of this file.

Typedefs

typedef struct textblock textblock
 Opaque text_block type. More...
 
typedef void(* text_writer )(ang_file *f)
 

Functions

textblocktextblock_new (void)
 Create a new textblock object and return it. More...
 
void textblock_free (textblock *tb)
 Free a textblock object. More...
 
void textblock_append (textblock *tb, const char *fmt,...)
 Add text to a text block, formatted. More...
 
void textblock_append_c (textblock *tb, byte attr, const char *fmt,...)
 Add coloured text to a text block, formatted. More...
 
void textblock_append_pict (textblock *tb, byte attr, int c)
 Add a graphics tile to a text block. More...
 
void textblock_append_utf8 (textblock *tb, const char *utf8_string)
 Append a UTF-8 string to the textblock. More...
 
const wchar_t * textblock_text (textblock *tb)
 Return a pointer to the text inputted thus far. More...
 
const bytetextblock_attrs (textblock *tb)
 Return a pointer to the text attrs. More...
 
size_t textblock_calculate_lines (textblock *tb, size_t **line_starts, size_t **line_lengths, size_t width)
 Given a certain width, split a textblock into wrapped lines of text. More...
 
void textblock_to_file (textblock *tb, ang_file *f, int indent, int wrap_at)
 Output a textblock to file. More...
 
void text_out_to_file (byte attr, const char *str)
 Write text to the given file and apply line-wrapping. More...
 
void text_out (const char *fmt,...)
 Output text to the screen or to a file depending on the selected text_out hook. More...
 
void text_out_c (byte a, const char *fmt,...)
 Output text to the screen (in color) or to a file depending on the selected hook. More...
 
void text_out_e (const char *fmt,...)
 Output text to the screen or to a file depending on the selected hook. More...
 
errr text_lines_to_file (const char *path, text_writer writer)
 Write a text file from given input. More...
 

Variables

ang_filetext_out_file
 Hack - the destination file for text_out_to_file. More...
 
void(* text_out_hook )(byte a, const char *str)
 

text_out()

More...
 
int text_out_wrap
 Hack – Where to wrap the text when using text_out(). More...
 
int text_out_indent
 Hack – Indentation for the text when using text_out(). More...
 
int text_out_pad
 Hack – Padding after wrapping. More...
 

Detailed Description

Text output bugger (?NRM) code.

Copyright (c) 2010 Andi Sidwell Copyright (c) 2011 Peter Denison

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Typedef Documentation

typedef void(* text_writer)(ang_file *f)
typedef struct textblock textblock

Opaque text_block type.

Function Documentation

errr text_lines_to_file ( const char *  path,
text_writer  writer 
)

Write a text file from given input.

Parameters
paththe path to write to
writerthe text-writing function

References file_close(), file_delete(), file_exists(), file_move(), file_open(), FTYPE_TEXT, MODE_WRITE, NULL, safe_setuid_drop(), safe_setuid_grab(), and strnfmt().

Referenced by dump_save(), lore_save(), and pile_integrity_fail().

void text_out ( const char *  fmt,
  ... 
)

Output text to the screen or to a file depending on the selected text_out hook.

References buf, COLOUR_WHITE, text_out_hook, void(), and vstrnfmt().

Referenced by class_help(), curse_menu_browser(), race_help(), show_splashscreen(), spell_menu_browser(), spoil_artifact(), spoiler_underline(), store_display_help(), and target_display_help().

void text_out_c ( byte  a,
const char *  fmt,
  ... 
)

Output text to the screen (in color) or to a file depending on the selected hook.

References buf, text_out_hook, void(), and vstrnfmt().

Referenced by item_menu_browser(), store_display_help(), and target_display_help().

void text_out_e ( const char *  fmt,
  ... 
)

Output text to the screen or to a file depending on the selected hook.

Takes strings with "embedded formatting", such that something within {red}{/} will be printed in red.

Note that such formatting will be treated as a "breakpoint" for the printing, so if used within words may lead to part of the word being moved to the next line.

References buf, color_text_to_attr(), COLOUR_WHITE, next_section(), start, tag, text, text_out_hook, void(), and vstrnfmt().

Referenced by class_help(), ego_menu(), print_menu_instructions(), race_help(), show_splashscreen(), and skill_help().

void text_out_to_file ( byte  a,
const char *  str 
)

Write text to the given file and apply line-wrapping.

Hook function for text_out(). Make sure that text_out_file points to an open text-file.

Long lines will be wrapped at text_out_wrap, or at column 75 if that is not set; or at a newline character. Note that punctuation can sometimes be placed one column beyond the wrap limit.

You must be careful to end all file output with a newline character to "flush" the stored line position.

References buf, file_write(), file_writec(), i, my_strcpy(), text_out_indent, text_out_wrap, and void().

Referenced by spoil_artifact().

void textblock_append ( textblock tb,
const char *  fmt,
  ... 
)
void textblock_append_c ( textblock tb,
byte  attr,
const char *  fmt,
  ... 
)
void textblock_append_pict ( textblock tb,
byte  attr,
int  c 
)
void textblock_append_utf8 ( textblock tb,
const char *  utf8_string 
)

Append a UTF-8 string to the textblock.

This is needed in order for proper file writing. Normally, textblocks convert to the system's encoding when a string is appended. However, there are still some strings in the game that are imported from external files as UTF-8. Instead of requiring each port to provide another converter back to UTF-8, we'll just use the original strings as is.

Parameters
tbis the textblock we are appending to.
utf8_stringis the C string that is encoded as UTF-8.

References textblock::attrs, COLOUR_WHITE, i, textblock::strlen, textblock::text, and textblock_resize_if_needed().

Referenced by lore_append_flavor(), and spoil_mon_info().

const byte* textblock_attrs ( textblock tb)

Return a pointer to the text attrs.

References textblock::attrs.

Referenced by test_colour(), textui_textblock_place(), and textui_textblock_show().

size_t textblock_calculate_lines ( textblock tb,
size_t **  line_starts,
size_t **  line_lengths,
size_t  width 
)

Given a certain width, split a textblock into wrapped lines of text.

Trailing empty lines are trimmed.

Parameters
tbThe textblock to wrap.
line_startsOn return, an array (indexed by line number) of character indexes to the text of tb where each line begins.
line_lengthsOn return, an array (indexed by line number) of line lengths.
widthThe maximum permitted width of each line.
Returns
Number of lines in output.

References new_line(), NULL, textblock::strlen, text, textblock_text(), and width.

Referenced by edit_text(), textblock_to_file(), textui_textblock_place(), and textui_textblock_show().

void textblock_free ( textblock tb)
textblock* textblock_new ( void  )
const wchar_t* textblock_text ( textblock tb)

Return a pointer to the text inputted thus far.

References textblock::text.

Referenced by test_append(), test_length(), textblock_calculate_lines(), textui_textblock_place(), and textui_textblock_show().

void textblock_to_file ( textblock tb,
ang_file f,
int  indent,
int  wrap_at 
)

Variable Documentation

ang_file* text_out_file

Hack - the destination file for text_out_to_file.

Referenced by spoil_artifact().

void(* text_out_hook)(byte a, const char *str)
int text_out_indent
int text_out_pad

Hack – Padding after wrapping.

Referenced by curse_menu_browser(), item_menu_browser(), spell_menu_browser(), and text_out_to_screen().

int text_out_wrap

Hack – Where to wrap the text when using text_out().

Use the default value (for example the screen width) when 'text_out_wrap' is 0.

Referenced by curse_menu_browser(), display_player_xtra_info(), ego_menu(), item_menu_browser(), spell_menu_browser(), store_display_recalc(), text_out_to_file(), and text_out_to_screen().