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 )
59 for (
int i = 0; i <
array_size( omsg_array ); i++ )
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 );
94 iter.
l_end - iter.l_begin ) );
100static int omsg_getFontID(
int size )
105 if ( omsg_font_array == NULL )
109 for (
int i = 0; i <
array_size( omsg_font_array ); i++ )
110 if ( size == omsg_font_array[i].size )
115 gl_fontInit( &font->
font, _( FONT_MONOSPACE_PATH ), size, FONT_PATH_PREFIX,
124static glFont *omsg_getFont(
int font )
126 return &omsg_font_array[font].font;
136void omsg_position(
double center_x,
double center_y,
double width )
138 omsg_center_x = center_x;
139 omsg_center_y = center_y;
140 omsg_center_w = width;
146void omsg_cleanup(
void )
149 for (
int i = 0; i <
array_size( omsg_font_array ); i++ )
152 omsg_font_array = NULL;
155 for (
int i = 0; i <
array_size( omsg_array ); i++ )
156 omsg_free( &omsg_array[i] );
164void omsg_render(
double dt )
169 if ( omsg_array == NULL )
173 x = omsg_center_x - omsg_center_w / 2.;
177 for (
int i = 0; i <
array_size( omsg_array ); i++ ) {
178 omsg_t *omsg = &omsg_array[i];
182 glColour col = omsg->
col;
212unsigned int omsg_add(
const char *msg,
double duration,
int fontsize,
213 const glColour *col )
219 if ( omsg_array == NULL )
223 font = omsg_getFontID( fontsize );
227 memset( omsg, 0,
sizeof(
omsg_t ) );
228 omsg->
id = ++omsg_idgen;
232 omsg_setMsg( omsg, msg );
245int omsg_change(
unsigned int id,
const char *msg,
double duration )
247 omsg_t *omsg = omsg_get(
id );
251 omsg_setMsg( omsg, msg );
262int omsg_exists(
unsigned int id )
264 return ( omsg_get(
id ) != NULL );
272void omsg_rm(
unsigned int id )
274 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...