From e04f95eab9eaf51fcef2f56c258ea68d8df97d9d Mon Sep 17 00:00:00 2001 From: Andrew Mahone Date: Thu, 13 Aug 2009 08:02:29 +0000 Subject: LCD bitmap driver code consolidation from FS#4817: Move text-drawing code into firmware-drivers/lcd-bitmap-common.c, included by the various driver files. Add new static function LCDFN(putsxyofs_style) to draw styled text, and use it in both LCDFN(puts_style_offset) and LCDFN(scroll_fn). Merge lcd_gradient_rect functions, with new function containing simplified code for drawing one line of a multi-line gradient. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22289 a1c6a512-1295-4272-9138-f99709370657 --- firmware/drivers/lcd-2bit-vi.c | 225 +---------------------------------------- 1 file changed, 2 insertions(+), 223 deletions(-) (limited to 'firmware/drivers/lcd-2bit-vi.c') diff --git a/firmware/drivers/lcd-2bit-vi.c b/firmware/drivers/lcd-2bit-vi.c index 0a73f0dd25..47f755f240 100644 --- a/firmware/drivers/lcd-2bit-vi.c +++ b/firmware/drivers/lcd-2bit-vi.c @@ -66,7 +66,7 @@ static struct viewport default_vp = .bg_pattern = LCDM(DEFAULT_BG) }; -static struct viewport *current_vp IBSS_ATTR; +static struct viewport * current_vp IBSS_ATTR; static unsigned fg_pattern IBSS_ATTR; static unsigned bg_pattern IBSS_ATTR; @@ -1016,225 +1016,4 @@ void LCDFN(bitmap)(const FBFN(data) *src, int x, int y, int width, int height) LCDFN(bitmap_part)(src, 0, 0, width, x, y, width, height); } -/* put a string at a given pixel position, skipping first ofs pixel columns */ -static void LCDFN(putsxyofs)(int x, int y, int ofs, const unsigned char *str) -{ - unsigned short ch; - unsigned short *ucs; - struct font* pf = font_get(current_vp->font); - - ucs = bidi_l2v(str, 1); - - while ((ch = *ucs++) != 0 && x < current_vp->width) - { - int width; - const unsigned char *bits; - - /* get proportional width and glyph bits */ - width = font_get_width(pf, ch); - - if (ofs > width) - { - ofs -= width; - continue; - } - - bits = font_get_bits(pf, ch); - - LCDFN(mono_bitmap_part)(bits, ofs, 0, width, x, y, width - ofs, - pf->height); - - x += width - ofs; - ofs = 0; - } -} - -/* put a string at a given pixel position */ -void LCDFN(putsxy)(int x, int y, const unsigned char *str) -{ - LCDFN(putsxyofs)(x, y, 0, str); -} - -/*** line oriented text output ***/ - -/* put a string at a given char position */ -void LCDFN(puts)(int x, int y, const unsigned char *str) -{ - LCDFN(puts_style_offset)(x, y, str, STYLE_DEFAULT, 0); -} - -void LCDFN(puts_style)(int x, int y, const unsigned char *str, int style) -{ - LCDFN(puts_style_offset)(x, y, str, style, 0); -} - -void LCDFN(puts_offset)(int x, int y, const unsigned char *str, int offset) -{ - LCDFN(puts_style_offset)(x, y, str, STYLE_DEFAULT, offset); -} - -/* put a string at a given char position, style, and pixel position, - * skipping first offset pixel columns */ -void LCDFN(puts_style_offset)(int x, int y, const unsigned char *str, - int style, int offset) -{ - int xpos,ypos,w,h,xrect; - int lastmode = current_vp->drawmode; - - /* make sure scrolling is turned off on the line we are updating */ - LCDFN(scroll_stop_line)(current_vp, y); - - if(!str || !str[0]) - return; - - LCDFN(getstringsize)(str, &w, &h); - xpos = x*w / utf8length((char *)str); - ypos = y*h; - current_vp->drawmode = (style & STYLE_INVERT) ? - (DRMODE_SOLID|DRMODE_INVERSEVID) : DRMODE_SOLID; - LCDFN(putsxyofs)(xpos, ypos, offset, str); - current_vp->drawmode ^= DRMODE_INVERSEVID; - xrect = xpos + MAX(w - offset, 0); - LCDFN(fillrect)(xrect, ypos, current_vp->width - xrect, h); - current_vp->drawmode = lastmode; -} - -/*** scrolling ***/ -void LCDFN(puts_scroll)(int x, int y, const unsigned char *string) -{ - LCDFN(puts_scroll_style)(x, y, string, STYLE_DEFAULT); -} - -void LCDFN(puts_scroll_style)(int x, int y, const unsigned char *string, int style) -{ - LCDFN(puts_scroll_style_offset)(x, y, string, style, 0); -} - -void LCDFN(puts_scroll_offset)(int x, int y, const unsigned char *string, int offset) -{ - LCDFN(puts_scroll_style_offset)(x, y, string, STYLE_DEFAULT, offset); -} - -void LCDFN(puts_scroll_style_offset)(int x, int y, const unsigned char *string, - int style, int offset) -{ - struct scrollinfo* s; - int w, h; - - if ((unsigned)y >= (unsigned)current_vp->height) - return; - - /* remove any previously scrolling line at the same location */ - LCDFN(scroll_stop_line)(current_vp, y); - - if (LCDFN(scroll_info).lines >= LCDM(SCROLLABLE_LINES)) return; - - s = &LCDFN(scroll_info).scroll[LCDFN(scroll_info).lines]; - - s->start_tick = current_tick + LCDFN(scroll_info).delay; - s->style = style; - if (style & STYLE_INVERT) { - LCDFN(puts_style_offset)(x,y,string,STYLE_INVERT,offset); - } - else - LCDFN(puts_offset)(x,y,string,offset); - - LCDFN(getstringsize)(string, &w, &h); - - if (current_vp->width - x * 8 < w) { - /* prepare scroll line */ - char *end; - - memset(s->line, 0, sizeof s->line); - strcpy(s->line, string); - - /* get width */ - s->width = LCDFN(getstringsize)(s->line, &w, &h); - - /* scroll bidirectional or forward only depending on the string - width */ - if ( LCDFN(scroll_info).bidir_limit ) { - s->bidir = s->width < (current_vp->width) * - (100 + LCDFN(scroll_info).bidir_limit) / 100; - } - else - s->bidir = false; - - if (!s->bidir) { /* add spaces if scrolling in the round */ - strcat(s->line, " "); - /* get new width incl. spaces */ - s->width = LCDFN(getstringsize)(s->line, &w, &h); - } - - end = strchr(s->line, '\0'); - strlcpy(end, (char *)string, current_vp->width/2); - - s->vp = current_vp; - s->y = y; - s->len = utf8length((char *)string); - s->offset = offset; - s->startx = x * s->width / s->len; - s->backward = false; - - LCDFN(scroll_info).lines++; - } -} - -void LCDFN(scroll_fn)(void) -{ - struct font* pf; - struct scrollinfo* s; - int index; - int xpos, ypos; - int lastmode; - struct viewport* old_vp = current_vp; - - for ( index = 0; index < LCDFN(scroll_info).lines; index++ ) { - s = &LCDFN(scroll_info).scroll[index]; - - /* check pause */ - if (TIME_BEFORE(current_tick, s->start_tick)) - continue; - - LCDFN(set_viewport)(s->vp); - - if (s->backward) - s->offset -= LCDFN(scroll_info).step; - else - s->offset += LCDFN(scroll_info).step; - - pf = font_get(current_vp->font); - xpos = s->startx; - ypos = s->y * pf->height; - - if (s->bidir) { /* scroll bidirectional */ - if (s->offset <= 0) { - /* at beginning of line */ - s->offset = 0; - s->backward = false; - s->start_tick = current_tick + LCDFN(scroll_info).delay * 2; - } - if (s->offset >= s->width - (current_vp->width - xpos)) { - /* at end of line */ - s->offset = s->width - (current_vp->width - xpos); - s->backward = true; - s->start_tick = current_tick + LCDFN(scroll_info).delay * 2; - } - } - else { - /* scroll forward the whole time */ - if (s->offset >= s->width) - s->offset %= s->width; - } - - lastmode = current_vp->drawmode; - current_vp->drawmode = (s->style&STYLE_INVERT) ? - (DRMODE_SOLID|DRMODE_INVERSEVID) : DRMODE_SOLID; - LCDFN(putsxyofs)(xpos, ypos, s->offset, s->line); - current_vp->drawmode = lastmode; - LCDFN(update_viewport_rect)(xpos, ypos, - current_vp->width - xpos, pf->height); - } - - LCDFN(set_viewport)(old_vp); -} +#include "lcd-bitmap-common.c" -- cgit v1.2.3