40static unsigned int osd_idgen = 0;
41static OSD_t *osd_list = NULL;
50static int osd_lines = 0;
52static int osd_tabLen = 0;
53static int osd_hyphenLen = 0;
58static OSD_t *osd_get(
unsigned int osd );
59static int osd_free(
OSD_t *osd );
60static void osd_calcDimensions(
void );
62static int osd_sortCompare(
const void *arg1,
const void *arg2 );
63static void osd_sort(
void );
64static void osd_wordwrap(
OSD_t *osd );
66static int osd_sortCompare(
const void *arg1,
const void *arg2 )
68 const OSD_t *osd1, *osd2;
87 for (
int i = 0; i < m; i++ ) {
88 ret = strcmp( osd1->
msg[i], osd2->
msg[i] );
100 if ( osd1->
id > osd2->
id )
102 else if ( osd1->
id < osd2->
id )
110static void osd_sort(
void )
112 qsort( osd_list,
array_size( osd_list ),
sizeof(
OSD_t ), osd_sortCompare );
123unsigned int osd_create(
const char *title,
int nitems,
const char **items,
124 int priority,
int hidden )
130 if ( osd_list == NULL )
133 memset( osd, 0,
sizeof(
OSD_t ) );
134 osd->
id =
id = ++osd_idgen;
138 osd->
title = strdup( title );
144 for (
int i = 0; i < nitems; i++ ) {
150 osd_calcDimensions();
158static void osd_wordwrap(
OSD_t *osd )
161 char title[STRMAX_SHORT];
172 snprintf( title,
sizeof( title ), _(
"%s #b(%dx)#0" ), osd->
title,
181 int chunk_len = iter.
l_end - iter.l_begin + 1;
182 char *chunk = malloc( chunk_len );
183 snprintf( chunk, chunk_len,
"%s", &iter.
text[iter.l_begin] );
189 int msg_len, w, has_tab;
190 const char *chunk_fmt;
192 free( osd->
items[i][l] );
195 msg_len = strlen( osd->
msg[i] );
200 has_tab = !!( osd->
msg[i][0] ==
'\t' );
201 w = osd_w - ( has_tab ? osd_tabLen : osd_hyphenLen );
204 chunk_fmt = has_tab ?
" %s" :
"- %s";
208 int chunk_len = iter.
l_end - iter.l_begin + strlen( chunk_fmt ) - 1;
209 char *chunk = malloc( chunk_len );
210 snprintf( chunk, chunk_len, chunk_fmt, &iter.
text[iter.l_begin] );
212 chunk_fmt = has_tab ?
" %s" :
"%s";
213 iter.
width = has_tab ? osd_w - osd_tabLen - osd_hyphenLen
214 : osd_w - osd_hyphenLen;
224static OSD_t *osd_get(
unsigned int osd )
226 for (
int i = 0; i <
array_size( osd_list ); i++ ) {
227 OSD_t *ll = &osd_list[i];
231 WARN( _(
"OSD '%d' not found." ), osd );
238static int osd_free(
OSD_t *osd )
244 free( osd->
items[i][j] );
261int osd_destroy(
unsigned int osd )
263 for (
int i = 0; i <
array_size( osd_list ); i++ ) {
264 OSD_t *ll = &osd_list[i];
269 osd_free( &osd_list[i] );
272 array_erase( &osd_list, &osd_list[i], &osd_list[i + 1] );
275 osd_calcDimensions();
285 WARN( _(
"OSD '%u' not found to destroy." ), osd );
296int osd_active(
unsigned int osd,
int msg )
298 OSD_t *o = osd_get( osd );
303 WARN( _(
"OSD '%s' only has %d items (requested %d)" ), o->
title,
309 osd_calcDimensions();
319int osd_getActive(
unsigned int osd )
321 OSD_t *o = osd_get( osd );
336int osd_setup(
int x,
int y,
int w,
int h )
349 osd_calcDimensions();
359 for (
int i = 0; i <
array_size( osd_list ); i++ ) {
360 OSD_t *ll = &osd_list[i];
371void osd_render(
void )
377 if ( osd_list == NULL )
380 NTracingZone( _ctx, 1 );
383 gl_renderRect( osd_x - 5., osd_y - ( osd_rh + 5. ), osd_w + 10., osd_rh + 10,
389 for (
int k = 0; k <
array_size( osd_list ); k++ ) {
391 OSD_t *ll = &osd_list[k];
405 if ( l >= osd_lines ) {
406 NTracingZoneEnd( _ctx );
413 ( i == (int)ll->
active ) ? &cFontWhite : &cFontGrey;
418 x = osd_x + osd_hyphenLen;
421 if ( l >= osd_lines ) {
422 NTracingZoneEnd( _ctx );
428 NTracingZoneEnd( _ctx );
434static void osd_calcDimensions(
void )
439 if ( osd_list == NULL )
443 for (
int k = 0; k <
array_size( osd_list ); k++ ) {
444 OSD_t *ll = &osd_list[k];
450 for (
int k = 0; k <
array_size( osd_list ); k++ ) {
452 OSD_t *ll = &osd_list[k];
459 for (
int m = k + 1; m <
array_size( osd_list ); m++ ) {
460 OSD_t *lm = &osd_list[m];
462 if ( ( strcmp( lm->
title, ll->
title ) == 0 ) &&
465 int is_duplicate = 1;
469 if ( strcmp( lm->
items[i][j], ll->
items[i][j] ) != 0 ) {
480 if ( is_duplicate ) {
491 for (
int k = 0; k <
array_size( osd_list ); k++ ) {
492 OSD_t *ll = &osd_list[k];
509 osd_rh =
MIN( len, osd_h );
518char *osd_getTitle(
unsigned int osd )
520 OSD_t *o = osd_get( osd );
533char **osd_getItems(
unsigned int osd )
535 OSD_t *o = osd_get( osd );
547int osd_setHide(
unsigned int osd,
int state )
549 OSD_t *o = osd_get( osd );
554 osd_calcDimensions();
564int osd_getHide(
unsigned int osd )
566 OSD_t *o = osd_get( osd );
578int osd_setPriority(
unsigned int osd,
int priority )
580 OSD_t *o = osd_get( osd );
586 osd_calcDimensions();
596int osd_getPriority(
unsigned int osd )
598 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...