/** * @brief Prints a block of text that fits in the dimensions given. * * Positions are based on origin being top-left. * * @param ft_font Font to use. * @param width Maximum width to print to. * @param height Maximum height to print to. * @param bx X position to display text at. * @param by Y position to display text at. * @param c Colour to use (NULL defaults to white). * @param fmt Text to display formatted like printf. * @return 0 on success. * prints text with line breaks included to a maximum width and height preset */ int gl_printTextRaw( const glFont *ft_font, const int width, const int height, double bx, double by, const glColour* c, const char *text ) { int p, s; double x,y; size_t i, ret; uint32_t ch; if (ft_font == NULL) ft_font = &gl_defFont; glFontStash *stsh = gl_fontGetStash( ft_font ); x = bx; y = by + height - (double)stsh->h; /* y is top left corner */ /* Clears restoration. */ gl_printRestoreClear(); i = 0; s = 0; p = 0; /* where we last drew up to */ while (y - by > -1e-5) { ret = p + gl_printWidthForText( ft_font, &text[p], width ); /* Must restore stuff. */ gl_printRestoreLast(); /* Render it. */ gl_fontRenderStart(stsh, x, y, c); for (i=p; i<ret; ) { ch = u8_nextchar( text, &i); s = gl_fontRenderGlyph( stsh, ch, c, s ); } gl_fontRenderEnd(); if (ch == '\0') break; p = i; if ((text[p] == '\n') || (text[p] == ' ')) p++; /* Skip "empty char". */ y -= 1.5*(double)stsh->h; /* move position down */ } return 0; }
/** * @brief Renders the overlays. */ void omsg_render( double dt ) { int i, j; double x, y; omsg_t *omsg; glFont *font; glColour col; /* Case nothing to do. */ if (omsg_array == NULL) return; /* Center. */ x = omsg_center_x - omsg_center_w/2.; y = omsg_center_y; /* Render. */ for (i=0; i<array_size(omsg_array); i++) { omsg = &omsg_array[i]; /* Check if time to erase. */ omsg->duration -= dt; if (omsg->duration < 0.) { omsg_free( omsg ); array_erase( &omsg_array, &omsg[0], &omsg[1] ); i--; continue; } /* Must have a message. */ if (omsg->msg == NULL) continue; /* Render. */ font = omsg_getFont( omsg->font ); memcpy( &col, omsg->col, sizeof(glColour) ); if (omsg->duration < 1.) col.a = omsg->duration; for (j=0; j<omsg->nlines; j++) { y -= font->h * 1.5; if (j>0) gl_printRestoreLast(); gl_printMidRaw( font, omsg_center_w, x, y, &col, omsg->msg[j] ); } } }