diff options
author | Andreas Eversberg <jolly@eversberg.eu> | 2011-12-15 05:58:24 +0100 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2012-02-03 23:59:35 +0100 |
commit | 593d905f0fa70631a1329aa1c1191a888ca0c99f (patch) | |
tree | 914d2a5bb595e92f9f696be413e73417e1dd8588 /src/target/firmware/fb | |
parent | 30dd87115c56fa6915881d93cd4d0ccb18dab035 (diff) |
firmare/framebuffer: Option to center text
This is usefull, because actual width of proportional font text and display
width may not be known to application.
Diffstat (limited to 'src/target/firmware/fb')
-rw-r--r-- | src/target/firmware/fb/fb_bw8.c | 20 | ||||
-rw-r--r-- | src/target/firmware/fb/fb_rgb332.c | 20 |
2 files changed, 39 insertions, 1 deletions
diff --git a/src/target/firmware/fb/fb_bw8.c b/src/target/firmware/fb/fb_bw8.c index 7365713a..7a8323df 100644 --- a/src/target/firmware/fb/fb_bw8.c +++ b/src/target/firmware/fb/fb_bw8.c @@ -189,7 +189,25 @@ fb_bw8_putstr(char *str,int maxwidth){ int bitmap_offs,bitmap_bit; // offset inside bitmap, bit number of pixel int fb8_offs; // offset to current pixel in framebuffer uint8_t and_mask,or_mask; // to draw on framebuffer - uint8_t *p; // pointer into framebuffer memory + uint8_t *p; // pointer into framebuffer memorya + int total_w; // total width + + /* center, if maxwidth < 0 */ + if (maxwidth < 0) { + total_w = 0; + /* count width of string */ + for(p=str;*p;p++){ + fchr = fb_font_get_char(font,*p); + if(!fchr) /* FIXME: Does '?' exist in every font? */ + fchr = fb_font_get_char(font,'?'); + total_w += fchr->width; + + } // str + if (total_w <= framebuffer->width) + framebuffer->cursor_x = + (framebuffer->width - total_w) >> 1; + maxwidth = framebuffer->width; + } x1 = framebuffer->cursor_x; // first col (incl!) x2 = x1 + maxwidth - 1; // last col (incl!) diff --git a/src/target/firmware/fb/fb_rgb332.c b/src/target/firmware/fb/fb_rgb332.c index 223e792d..26cbeec5 100644 --- a/src/target/firmware/fb/fb_rgb332.c +++ b/src/target/firmware/fb/fb_rgb332.c @@ -205,6 +205,26 @@ int fb_rgb332_putstr(char *str,int maxwidth){ int byte_per_line; // depending on character width in font int bitmap_offs,bitmap_bit; // offset inside bitmap, bit number of pixel uint8_t *p,fgpixel,bgpixel; // pointer into framebuffer memory + int total_w; // total width + + /* center, if maxwidth < 0 */ + if (maxwidth < 0) { + total_w = 0; + /* count width of string */ + for(p=str;*p;p++){ + fchr = fb_font_get_char(font,*p); + if(!fchr) /* FIXME: Does '?' exist in every font? */ + fchr = fb_font_get_char(font,'?'); + total_w += fchr->width; + + } // str + if (total_w <= framebuffer->width) + framebuffer->cursor_x = + (framebuffer->width - total_w) >> 1; + else + framebuffer->cursor_x = 1; + maxwidth = framebuffer->width; + } x1 = framebuffer->cursor_x; // first col (incl!) x2 = x1 + maxwidth - 1; // last col (incl!) |