39static unsigned int osd_idgen = 0;
40static OSD_t *osd_list = NULL;
49static int osd_lines = 0;
51static int osd_tabLen = 0;
52static int osd_hyphenLen = 0;
57static OSD_t *osd_get(
unsigned int osd );
58static int osd_free(
OSD_t *osd );
59static void osd_calcDimensions (
void);
61static int osd_sortCompare(
const void * arg1,
const void * arg2 );
62static void osd_sort (
void);
63static void osd_wordwrap(
OSD_t* osd );
65static int osd_sortCompare(
const void *arg1,
const void *arg2 )
67 const OSD_t *osd1, *osd2;
86 for (
int i=0; i<m; i++) {
87 ret = strcmp( osd1->
msg[i], osd2->
msg[i] );
99 if (osd1->
id > osd2->
id)
101 else if (osd1->
id < osd2->
id)
109static void osd_sort (
void)
111 qsort( osd_list,
array_size(osd_list),
sizeof(
OSD_t), osd_sortCompare );
122unsigned int osd_create(
const char *title,
int nitems,
const char **items,
int priority )
128 if (osd_list == NULL)
131 memset( osd, 0,
sizeof(
OSD_t) );
132 osd->
id =
id = ++osd_idgen;
136 osd->
title = strdup(title);
141 for (
int i=0; i<nitems; i++) {
147 osd_calcDimensions();
155static void osd_wordwrap(
OSD_t* osd )
158 char title[STRMAX_SHORT];
167 snprintf( title,
sizeof(title), _(
"%s #b(%dx)#0"), osd->
title, osd->
duplicates+1 );
176 int chunk_len = iter.
l_end - iter.l_begin + 1;
177 char *chunk = malloc( chunk_len );
178 snprintf( chunk, chunk_len,
"%s", &iter.
text[iter.l_begin] );
184 int msg_len, w, has_tab;
185 const char *chunk_fmt;
187 free(osd->
items[i][l]);
190 msg_len = strlen(osd->
msg[i]);
195 has_tab = !!(osd->
msg[i][0] ==
'\t');
196 w = osd_w - (has_tab ? osd_tabLen : osd_hyphenLen);
198 chunk_fmt = has_tab ?
" %s" :
"- %s";
202 int chunk_len = iter.
l_end - iter.l_begin + strlen( chunk_fmt ) - 1;
203 char *chunk = malloc( chunk_len );
204 snprintf( chunk, chunk_len, chunk_fmt, &iter.
text[iter.l_begin] );
206 chunk_fmt = has_tab ?
" %s" :
"%s";
207 iter.
width = has_tab ? osd_w - osd_tabLen - osd_hyphenLen : osd_w - osd_hyphenLen;
217static OSD_t *osd_get(
unsigned int osd )
220 OSD_t *ll = &osd_list[i];
224 WARN(_(
"OSD '%d' not found."), osd);
231static int osd_free(
OSD_t *osd )
237 free(osd->
items[i][j]);
254int osd_destroy(
unsigned int osd )
256 for (
int i=0; i<
array_size( osd_list ); i++) {
257 OSD_t *ll = &osd_list[i];
262 osd_free( &osd_list[i] );
265 array_erase( &osd_list, &osd_list[i], &osd_list[i+1] );
268 osd_calcDimensions();
278 WARN(_(
"OSD '%u' not found to destroy."), osd );
289int osd_active(
unsigned int osd,
int msg )
291 OSD_t *o = osd_get(osd);
301 osd_calcDimensions();
311int osd_getActive(
unsigned int osd )
313 OSD_t *o = osd_get(osd);
328int osd_setup(
int x,
int y,
int w,
int h )
341 osd_calcDimensions();
352 OSD_t *ll = &osd_list[i];
363void osd_render (
void)
369 if (osd_list == NULL)
373 gl_renderRect( osd_x-5., osd_y-(osd_rh+5.), osd_w+10., osd_rh+10, &cBlackHilight );
380 OSD_t *ll = &osd_list[k];
399 const glColour *
c = (i == (int)ll->
active) ? &cFontWhite : &cFontGrey;
404 x = osd_x + osd_hyphenLen;
417static void osd_calcDimensions (
void)
422 if (osd_list == NULL)
427 OSD_t *ll = &osd_list[k];
435 OSD_t *ll = &osd_list[k];
442 for (
int m=k+1; m<
array_size(osd_list); m++) {
443 OSD_t *lm = &osd_list[m];
448 int is_duplicate = 1;
452 if (strcmp(lm->
items[i][j], ll->
items[i][j]) != 0 ) {
475 OSD_t *ll = &osd_list[k];
492 osd_rh =
MIN( len, osd_h );
501char *osd_getTitle(
unsigned int osd )
503 OSD_t *o = osd_get(osd);
516char **osd_getItems(
unsigned int osd )
518 OSD_t *o = osd_get(osd);
530int osd_setHide(
unsigned int osd,
int state )
532 OSD_t *o = osd_get(osd);
537 osd_calcDimensions();
547int osd_getHide(
unsigned int osd )
549 OSD_t *o = osd_get(osd);
561int osd_setPriority(
unsigned int osd,
int priority )
563 OSD_t *o = osd_get(osd);
569 osd_calcDimensions();
579int osd_getPriority(
unsigned int osd )
581 OSD_t *o = osd_get(osd);
Provides macros to work with dynamic arrays.
#define array_free(ptr_array)
Frees memory allocated and sets array to NULL.
#define array_resize(ptr_array, new_size)
Resizes the array to accomodate new_size elements.
#define array_create_size(basic_type, capacity)
Creates a new dynamic array of ‘basic_type’ with an initial capacity.
#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’.
int gl_printLineIteratorNext(glPrintLineIterator *iter)
Updates iter with the next line's information.
void gl_printRaw(const glFont *ft_font, double x, double y, const glColour *c, double outlineR, const char *text)
Prints text on screen.
int gl_printWidthRaw(const glFont *ft_font, const char *text)
Gets the width that it would take to print some text.
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_printMaxRaw(const glFont *ft_font, const int max, double x, double y, const glColour *c, double outlineR, const char *text)
Behaves like gl_printRaw but stops displaying text after a certain distance.
Header file with generic functions and naev-specifics.
void gl_renderRect(double x, double y, double w, double h, const glColour *c)
Renders a rectangle.
On Screen Display element.
The state of a line iteration. This matches the process of rendering text into an on-screen box: An e...