22typedef struct omsg_font_s {
31typedef struct omsg_s {
38static omsg_t *omsg_array = NULL;
39static unsigned int omsg_idgen = 0;
41static double omsg_center_x = 0.;
42static double omsg_center_y = 0.;
43static double omsg_center_w = 100.;
48static omsg_t* omsg_get(
unsigned int id );
49static void omsg_free(
omsg_t *omsg );
50static void omsg_setMsg(
omsg_t *omsg,
const char *msg );
51static int omsg_getFontID(
int size );
52static glFont* omsg_getFont(
int font );
57static omsg_t* omsg_get(
unsigned int id )
60 if (omsg_array[i].
id ==
id)
61 return &omsg_array[i];
68static void omsg_free(
omsg_t *omsg )
79static void omsg_setMsg(
omsg_t *omsg,
const char *msg )
88 font = omsg_getFont( omsg->
font );
99static int omsg_getFontID(
int size )
104 if (omsg_font_array == NULL)
108 for (
int i=0; i<
array_size( omsg_font_array ); i++)
109 if (size == omsg_font_array[i].size)
114 gl_fontInit( &font->
font, _(FONT_MONOSPACE_PATH), size, FONT_PATH_PREFIX, 0 );
122static glFont* omsg_getFont(
int font )
124 return &omsg_font_array[ font ].
font;
134void omsg_position(
double center_x,
double center_y,
double width )
136 omsg_center_x = center_x;
137 omsg_center_y = center_y;
138 omsg_center_w = width;
144void omsg_cleanup (
void)
147 for (
int i=0; i<
array_size( omsg_font_array ); i++)
150 omsg_font_array = NULL;
154 omsg_free( &omsg_array[i] );
162void omsg_render(
double dt )
167 if (omsg_array == NULL)
171 x = omsg_center_x - omsg_center_w/2.;
175 for (
int i=0; i<
array_size(omsg_array); i++) {
176 omsg_t *omsg = &omsg_array[i];
180 glColour col = omsg->
col;
210unsigned int omsg_add(
const char *msg,
double duration,
int fontsize,
const glColour *col )
216 if (omsg_array == NULL)
220 font = omsg_getFontID( fontsize );
224 memset( omsg, 0,
sizeof(
omsg_t) );
225 omsg->
id = ++omsg_idgen;
229 omsg_setMsg( omsg, msg );
242int omsg_change(
unsigned int id,
const char *msg,
double duration )
244 omsg_t *omsg = omsg_get(
id);
248 omsg_setMsg( omsg, msg );
259int omsg_exists(
unsigned int id )
261 return (omsg_get(
id) != NULL);
269void omsg_rm(
unsigned int id )
271 omsg_t *omsg = omsg_get(
id);
Provides macros to work with dynamic arrays.
#define array_free(ptr_array)
Frees memory allocated and sets array to NULL.
#define array_erase(ptr_array, first, last)
Erases elements in interval [first, last).
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
#define array_grow(ptr_array)
Increases the number of elements by one and returns the last element.
#define array_push_back(ptr_array, element)
Adds a new element at the end of the array.
#define array_create(basic_type)
Creates a new dynamic array of ‘basic_type’.
void gl_printRestoreClear(void)
Clears the restoration.
int gl_printLineIteratorNext(glPrintLineIterator *iter)
Updates iter with the next line's information.
int gl_printMidRaw(const glFont *ft_font, int width, double x, double y, const glColour *c, double outlineR, const char *text)
Displays text centered in position and width.
void gl_freeFont(glFont *font)
Frees a loaded font. Caution: its glFontStash still has a slot in avail_fonts. At the time of writing...
void gl_printLineIteratorInit(glPrintLineIterator *iter, const glFont *ft_font, const char *text, int width)
Initialize an iterator object for breaking text into lines.
int gl_fontInit(glFont *font, const char *fname, const unsigned int h, const char *prefix, unsigned int flags)
Initializes a font.
void gl_printRestoreLast(void)
Restores last colour.
Header file with generic functions and naev-specifics.
char * strndup(const char *s, size_t n)
Return a pointer to a new string, which is a duplicate of the string s (or, if necessary,...
Represents a font in memory.
The state of a line iteration. This matches the process of rendering text into an on-screen box: An e...