Ejemplo n.º 1
0
void font_render_wrapped(font *font, const char *text, int x, int y, int w, color c) {
    int len = strlen(text);
    if (font->w*len < w) {
        // short enough text that we don't need to wrap

        // render it centered, at least for now
        int xoff = (w - font->w*len)/2;
        font_render_len(font, text, len, x + xoff, y, c);
    } else {
        // ok, we actually have to do some real work
        // look ma, no mallocs!
        char *end = strchr(text, '\0');
        const char *start = text;
        const char *stop = start;
        const char *tmpstop;
        int maxlen = w/font->w;
        int yoff = 0;

        while (start != end) {
            while(1) {
                tmpstop = strchr(stop+1, ' ');
                if (tmpstop == NULL) {
                    stop = end-1;
                    break;
                } else if ((tmpstop - start) > maxlen) {
                    break;
                } else {
                    stop = tmpstop;
                }
            }
            int len = stop - start;
            int xoff = (w - font->w*len)/2;
            font_render_len(font, start, len, x + xoff, y + yoff, c);
            yoff += font->h+1;
            start = stop+1;
            stop = start;
        }
    }
}
Ejemplo n.º 2
0
void font_render(const font *font, const char *text, int x, int y, color c) {
    int len = strlen(text);
    font_render_len(font, text, len, x, y, c);
}