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-vert.c | 226 +-------------------------------------- 1 file changed, 2 insertions(+), 224 deletions(-) (limited to 'firmware/drivers/lcd-2bit-vert.c') diff --git a/firmware/drivers/lcd-2bit-vert.c b/firmware/drivers/lcd-2bit-vert.c index 57d27d2..7342cbd 100644 --- a/firmware/drivers/lcd-2bit-vert.c +++ b/firmware/drivers/lcd-2bit-vert.c @@ -404,7 +404,7 @@ void lcd_clear_viewport(void) lastmode = current_vp->drawmode; /* Invert the INVERSEVID bit and set basic mode to SOLID */ - current_vp->drawmode = (~lastmode & DRMODE_INVERSEVID) | + current_vp->drawmode = (~lastmode & DRMODE_INVERSEVID) | DRMODE_SOLID; lcd_fillrect(0, 0, current_vp->width, current_vp->height); @@ -1002,226 +1002,4 @@ void lcd_bitmap(const fb_data *src, int x, int y, int width, int height) lcd_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 lcd_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); - - lcd_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 lcd_putsxy(int x, int y, const unsigned char *str) -{ - lcd_putsxyofs(x, y, 0, str); -} - -/*** line oriented text output ***/ - -/* put a string at a given char position */ -void lcd_puts(int x, int y, const unsigned char *str) -{ - lcd_puts_style_offset(x, y, str, STYLE_DEFAULT, 0); -} - -void lcd_puts_style(int x, int y, const unsigned char *str, int style) -{ - lcd_puts_style_offset(x, y, str, style, 0); -} - -void lcd_puts_offset(int x, int y, const unsigned char *str, int offset) -{ - lcd_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 lcd_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 */ - lcd_scroll_stop_line(current_vp, y); - - if(!str || !str[0]) - return; - - lcd_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; - lcd_putsxyofs(xpos, ypos, offset, str); - current_vp->drawmode ^= DRMODE_INVERSEVID; - xrect = xpos + MAX(w - offset, 0); - lcd_fillrect(xrect, ypos, current_vp->width - xrect, h); - current_vp->drawmode = lastmode; -} - -/*** scrolling ***/ - -void lcd_puts_scroll(int x, int y, const unsigned char *string) -{ - lcd_puts_scroll_style(x, y, string, STYLE_DEFAULT); -} - -void lcd_puts_scroll_style(int x, int y, const unsigned char *string, int style) -{ - lcd_puts_scroll_style_offset(x, y, string, style, 0); -} - -void lcd_puts_scroll_offset(int x, int y, const unsigned char *string, int offset) -{ - lcd_puts_scroll_style_offset(x, y, string, STYLE_DEFAULT, offset); -} - -void lcd_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 */ - lcd_scroll_stop_line(current_vp, y); - - if (lcd_scroll_info.lines >= LCD_SCROLLABLE_LINES) return; - - s = &lcd_scroll_info.scroll[lcd_scroll_info.lines]; - - s->start_tick = current_tick + lcd_scroll_info.delay; - s->style = style; - if (style & STYLE_INVERT) { - lcd_puts_style_offset(x,y,string,STYLE_INVERT,offset); - } - else - lcd_puts_offset(x,y,string,offset); - - lcd_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, (char *)string); - - /* get width */ - s->width = lcd_getstringsize((unsigned char *)s->line, &w, &h); - - /* scroll bidirectional or forward only depending on the string - width */ - if ( lcd_scroll_info.bidir_limit ) { - s->bidir = s->width < (current_vp->width) * - (100 + lcd_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 = lcd_getstringsize((unsigned char *)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; - - lcd_scroll_info.lines++; - } -} - -void lcd_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 < lcd_scroll_info.lines; index++ ) { - s = &lcd_scroll_info.scroll[index]; - - /* check pause */ - if (TIME_BEFORE(current_tick, s->start_tick)) - continue; - - lcd_set_viewport(s->vp); - - if (s->backward) - s->offset -= lcd_scroll_info.step; - else - s->offset += lcd_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 + lcd_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 + lcd_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; - lcd_putsxyofs(xpos, ypos, s->offset, s->line); - current_vp->drawmode = lastmode; - lcd_update_viewport_rect(xpos, ypos, - current_vp->width - xpos, pf->height); - } - - lcd_set_viewport(old_vp); -} +#include "lcd-bitmap-common.c" -- cgit v1.1