summaryrefslogtreecommitdiff
path: root/firmware/drivers/lcd-1bit-vert.c
diff options
context:
space:
mode:
authorDave Chapman <dave@dchapman.com>2008-01-07 20:34:11 +0000
committerDave Chapman <dave@dchapman.com>2008-01-07 20:34:11 +0000
commit945c8a221ade41c462a93f8452320a806e5645b3 (patch)
tree2a17823e286e6252e60c44c7f4753d5c18ef5172 /firmware/drivers/lcd-1bit-vert.c
parent2a8f39820b49f116820356c2ca224f82f2106c21 (diff)
Add viewport capabilities to all the LCD drivers, and adapt scrolling code. This is the firmware/ part of FS#8385 - the changes to the WPS code still need more work and will be committed at a later date. NOTE: There are no user-visible changes with this commit - just the infrastructure.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16018 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/drivers/lcd-1bit-vert.c')
-rw-r--r--firmware/drivers/lcd-1bit-vert.c250
1 files changed, 171 insertions, 79 deletions
diff --git a/firmware/drivers/lcd-1bit-vert.c b/firmware/drivers/lcd-1bit-vert.c
index bd62e105cb..5c651a9613 100644
--- a/firmware/drivers/lcd-1bit-vert.c
+++ b/firmware/drivers/lcd-1bit-vert.c
@@ -35,10 +35,40 @@
unsigned char lcd_framebuffer[LCD_FBHEIGHT][LCD_FBWIDTH];
-static int drawmode = DRMODE_SOLID;
-static int xmargin = 0;
-static int ymargin = 0;
-static int curfont = FONT_SYSFIXED;
+static struct viewport default_vp =
+{
+ .x = 0,
+ .y = 0,
+ .width = LCD_WIDTH,
+ .height = LCD_HEIGHT,
+ .font = FONT_SYSFIXED,
+ .drawmode = DRMODE_SOLID,
+ .xmargin = 0,
+ .ymargin = 0,
+};
+
+static struct viewport* current_vp = &default_vp;
+
+/*** Viewports ***/
+
+void lcd_set_viewport(struct viewport* vp)
+{
+ if (vp == NULL)
+ current_vp = &default_vp;
+ else
+ current_vp = vp;
+}
+
+void lcd_update_viewport(void)
+{
+ lcd_update_rect(current_vp->x, current_vp->y,
+ current_vp->width, current_vp->height);
+}
+
+void lcd_update_viewport_rect(int x, int y, int width, int height)
+{
+ lcd_update_rect(current_vp->x + x, current_vp->y + y, width, height);
+}
/* LCD init */
void lcd_init(void)
@@ -53,38 +83,48 @@ void lcd_init(void)
void lcd_set_drawmode(int mode)
{
- drawmode = mode & (DRMODE_SOLID|DRMODE_INVERSEVID);
+ current_vp->drawmode = mode & (DRMODE_SOLID|DRMODE_INVERSEVID);
}
int lcd_get_drawmode(void)
{
- return drawmode;
+ return current_vp->drawmode;
}
void lcd_setmargins(int x, int y)
{
- xmargin = x;
- ymargin = y;
+ current_vp->xmargin = x;
+ current_vp->ymargin = y;
}
int lcd_getxmargin(void)
{
- return xmargin;
+ return current_vp->xmargin;
}
int lcd_getymargin(void)
{
- return ymargin;
+ return current_vp->ymargin;
+}
+
+int lcd_getwidth(void)
+{
+ return current_vp->width;
+}
+
+int lcd_getheight(void)
+{
+ return current_vp->height;
}
void lcd_setfont(int newfont)
{
- curfont = newfont;
+ current_vp->font = newfont;
}
int lcd_getstringsize(const unsigned char *str, int *w, int *h)
{
- return font_getstringsize(str, w, h, curfont);
+ return font_getstringsize(str, w, h, current_vp->font);
}
/*** low-level drawing functions ***/
@@ -187,17 +227,42 @@ lcd_blockfunc_type* const lcd_blockfuncs[8] = {
/* Clear the whole display */
void lcd_clear_display(void)
{
- unsigned bits = (drawmode & DRMODE_INVERSEVID) ? 0xFFu : 0;
+ unsigned bits = (current_vp->drawmode & DRMODE_INVERSEVID) ? 0xFFu : 0;
memset(lcd_framebuffer, bits, sizeof lcd_framebuffer);
lcd_scroll_info.lines = 0;
}
+void lcd_clear_viewport(void)
+{
+ int oldmode;
+
+ if (current_vp == &default_vp)
+ {
+ lcd_clear_display();
+ }
+ else
+ {
+ oldmode = current_vp->drawmode;
+
+ /* Invert the INVERSEVID bit and set basic mode to SOLID */
+ current_vp->drawmode = (~current_vp->drawmode & DRMODE_INVERSEVID) |
+ DRMODE_SOLID;
+
+ lcd_fillrect(0, 0, current_vp->width, current_vp->height);
+
+ current_vp->drawmode = oldmode;
+
+ lcd_scroll_stop(current_vp);
+ }
+}
+
/* Set a single pixel */
void lcd_drawpixel(int x, int y)
{
- if (((unsigned)x < LCD_WIDTH) && ((unsigned)y < LCD_HEIGHT))
- lcd_pixelfuncs[drawmode](x, y);
+ if (((unsigned)x < (unsigned)current_vp->width) &&
+ ((unsigned)y < (unsigned)current_vp->height))
+ lcd_pixelfuncs[current_vp->drawmode](current_vp->x + x, current_vp->y + y);
}
/* Draw a line */
@@ -209,7 +274,7 @@ void lcd_drawline(int x1, int y1, int x2, int y2)
int d, dinc1, dinc2;
int x, xinc1, xinc2;
int y, yinc1, yinc2;
- lcd_pixelfunc_type *pfunc = lcd_pixelfuncs[drawmode];
+ lcd_pixelfunc_type *pfunc = lcd_pixelfuncs[current_vp->drawmode];
deltax = abs(x2 - x1);
deltay = abs(y2 - y1);
@@ -253,8 +318,9 @@ void lcd_drawline(int x1, int y1, int x2, int y2)
for (i = 0; i < numpixels; i++)
{
- if (((unsigned)x < LCD_WIDTH) && ((unsigned)y < LCD_HEIGHT))
- pfunc(x, y);
+ if (((unsigned)x < (unsigned)current_vp->width) &&
+ ((unsigned)y < (unsigned)current_vp->height))
+ pfunc(current_vp->x + x, current_vp->y + y);
if (d < 0)
{
@@ -288,16 +354,22 @@ void lcd_hline(int x1, int x2, int y)
}
/* nothing to draw? */
- if (((unsigned)y >= LCD_HEIGHT) || (x1 >= LCD_WIDTH) || (x2 < 0))
+ if (((unsigned)y >= (unsigned)current_vp->height) || (x1 >= current_vp->width)
+ || (x2 < 0))
return;
/* clipping */
if (x1 < 0)
x1 = 0;
- if (x2 >= LCD_WIDTH)
- x2 = LCD_WIDTH-1;
+ if (x2 >= current_vp->width)
+ x2 = current_vp->width-1;
- bfunc = lcd_blockfuncs[drawmode];
+ /* adjust for viewport */
+ y += current_vp->y;
+ x1 += current_vp->x;
+ x2 += current_vp->x;
+
+ bfunc = lcd_blockfuncs[current_vp->drawmode];
dst = &lcd_framebuffer[y>>3][x1];
mask = 1 << (y & 7);
@@ -324,16 +396,22 @@ void lcd_vline(int x, int y1, int y2)
}
/* nothing to draw? */
- if (((unsigned)x >= LCD_WIDTH) || (y1 >= LCD_HEIGHT) || (y2 < 0))
+ if (((unsigned)x >= (unsigned)current_vp->width) || (y1 >= current_vp->height)
+ || (y2 < 0))
return;
/* clipping */
if (y1 < 0)
y1 = 0;
- if (y2 >= LCD_HEIGHT)
- y2 = LCD_HEIGHT-1;
+ if (y2 >= current_vp->height)
+ y2 = current_vp->height-1;
- bfunc = lcd_blockfuncs[drawmode];
+ /* adjust for viewport */
+ y1 += current_vp->y;
+ y2 += current_vp->y;
+ x += current_vp->x;
+
+ bfunc = lcd_blockfuncs[current_vp->drawmode];
dst = &lcd_framebuffer[y1>>3][x];
ny = y2 - (y1 & ~7);
mask = 0xFFu << (y1 & 7);
@@ -375,8 +453,8 @@ void lcd_fillrect(int x, int y, int width, int height)
bool fillopt = false;
/* nothing to draw? */
- if ((width <= 0) || (height <= 0) || (x >= LCD_WIDTH) || (y >= LCD_HEIGHT)
- || (x + width <= 0) || (y + height <= 0))
+ if ((width <= 0) || (height <= 0) || (x >= current_vp->width)
+ || (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
return;
/* clipping */
@@ -390,27 +468,31 @@ void lcd_fillrect(int x, int y, int width, int height)
height += y;
y = 0;
}
- if (x + width > LCD_WIDTH)
- width = LCD_WIDTH - x;
- if (y + height > LCD_HEIGHT)
- height = LCD_HEIGHT - y;
+ if (x + width > current_vp->width)
+ width = current_vp->width - x;
+ if (y + height > current_vp->height)
+ height = current_vp->height - y;
- if (drawmode & DRMODE_INVERSEVID)
+ /* adjust for viewport */
+ x += current_vp->x;
+ y += current_vp->y;
+
+ if (current_vp->drawmode & DRMODE_INVERSEVID)
{
- if (drawmode & DRMODE_BG)
+ if (current_vp->drawmode & DRMODE_BG)
{
fillopt = true;
}
}
else
{
- if (drawmode & DRMODE_FG)
+ if (current_vp->drawmode & DRMODE_FG)
{
fillopt = true;
bits = 0xFFu;
}
}
- bfunc = lcd_blockfuncs[drawmode];
+ bfunc = lcd_blockfuncs[current_vp->drawmode];
dst = &lcd_framebuffer[y>>3][x];
ny = height - 1 + (y & 7);
mask = 0xFFu << (y & 7);
@@ -470,8 +552,8 @@ void lcd_bitmap_part(const unsigned char *src, int src_x, int src_y,
lcd_blockfunc_type *bfunc;
/* nothing to draw? */
- if ((width <= 0) || (height <= 0) || (x >= LCD_WIDTH) || (y >= LCD_HEIGHT)
- || (x + width <= 0) || (y + height <= 0))
+ if ((width <= 0) || (height <= 0) || (x >= current_vp->width)
+ || (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
return;
/* clipping */
@@ -487,10 +569,14 @@ void lcd_bitmap_part(const unsigned char *src, int src_x, int src_y,
src_y -= y;
y = 0;
}
- if (x + width > LCD_WIDTH)
- width = LCD_WIDTH - x;
- if (y + height > LCD_HEIGHT)
- height = LCD_HEIGHT - y;
+ if (x + width > current_vp->width)
+ width = current_vp->width - x;
+ if (y + height > current_vp->height)
+ height = current_vp->height - y;
+
+ /* adjust for viewport */
+ x += current_vp->x;
+ y += current_vp->y;
src += stride * (src_y >> 3) + src_x; /* move starting point */
src_y &= 7;
@@ -499,13 +585,13 @@ void lcd_bitmap_part(const unsigned char *src, int src_x, int src_y,
shift = y & 7;
ny = height - 1 + shift + src_y;
- bfunc = lcd_blockfuncs[drawmode];
+ bfunc = lcd_blockfuncs[current_vp->drawmode];
mask = 0xFFu << (shift + src_y);
mask_bottom = 0xFFu >> (~ny & 7);
if (shift == 0)
{
- bool copyopt = (drawmode == DRMODE_SOLID);
+ bool copyopt = (current_vp->drawmode == DRMODE_SOLID);
for (; ny >= 8; ny -= 8)
{
@@ -582,11 +668,11 @@ 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(curfont);
+ struct font* pf = font_get(current_vp->font);
ucs = bidi_l2v(str, 1);
- while ((ch = *ucs++) != 0 && x < LCD_WIDTH)
+ while ((ch = *ucs++) != 0 && x < current_vp->width)
{
int width;
const unsigned char *bits;
@@ -639,24 +725,24 @@ 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 = drawmode;
+ int lastmode = current_vp->drawmode;
/* make sure scrolling is turned off on the line we are updating */
- lcd_scroll_info.lines &= ~(1 << y);
+ lcd_scroll_stop_line(current_vp, y);
if(!str || !str[0])
return;
lcd_getstringsize(str, &w, &h);
- xpos = xmargin + x*w / utf8length(str);
- ypos = ymargin + y*h;
- drawmode = (style & STYLE_INVERT) ?
- (DRMODE_SOLID|DRMODE_INVERSEVID) : DRMODE_SOLID;
+ xpos = current_vp->xmargin + x*w / utf8length(str);
+ ypos = current_vp->ymargin + y*h;
+ current_vp->drawmode = (style & STYLE_INVERT) ?
+ (DRMODE_SOLID|DRMODE_INVERSEVID) : DRMODE_SOLID;
lcd_putsxyofs(xpos, ypos, offset, str);
- drawmode ^= DRMODE_INVERSEVID;
+ current_vp->drawmode ^= DRMODE_INVERSEVID;
xrect = xpos + MAX(w - offset, 0);
- lcd_fillrect(xrect, ypos, LCD_WIDTH - xrect, h);
- drawmode = lastmode;
+ lcd_fillrect(xrect, ypos, current_vp->width - xrect, h);
+ current_vp->drawmode = lastmode;
}
/*** scrolling ***/
@@ -682,9 +768,15 @@ void lcd_puts_scroll_style_offset(int x, int y, const unsigned char *string,
struct scrollinfo* s;
int w, h;
- if(y>=LCD_SCROLLABLE_LINES) return;
+ 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[y];
+ s = &lcd_scroll_info.scroll[lcd_scroll_info.lines];
s->start_tick = current_tick + lcd_scroll_info.delay;
s->style = style;
@@ -696,7 +788,7 @@ void lcd_puts_scroll_style_offset(int x, int y, const unsigned char *string,
lcd_getstringsize(string, &w, &h);
- if (LCD_WIDTH - x * 8 - xmargin < w) {
+ if (current_vp->width - x * 8 - current_vp->xmargin < w) {
/* prepare scroll line */
char *end;
@@ -709,7 +801,7 @@ void lcd_puts_scroll_style_offset(int x, int y, const unsigned char *string,
/* scroll bidirectional or forward only depending on the string
width */
if ( lcd_scroll_info.bidir_limit ) {
- s->bidir = s->width < (LCD_WIDTH - xmargin) *
+ s->bidir = s->width < (current_vp->width - current_vp->xmargin) *
(100 + lcd_scroll_info.bidir_limit) / 100;
}
else
@@ -722,17 +814,16 @@ void lcd_puts_scroll_style_offset(int x, int y, const unsigned char *string,
}
end = strchr(s->line, '\0');
- strncpy(end, string, LCD_WIDTH/2);
+ strncpy(end, string, current_vp->width/2);
+ s->vp = current_vp;
+ s->y = y;
s->len = utf8length(string);
s->offset = offset;
- s->startx = xmargin + x * s->width / s->len;;
+ s->startx = current_vp->xmargin + x * s->width / s->len;;
s->backward = false;
- lcd_scroll_info.lines |= (1<<y);
+ lcd_scroll_info.lines++;
}
- else
- /* force a bit switch-off since it doesn't scroll */
- lcd_scroll_info.lines &= ~(1<<y);
}
void lcd_scroll_fn(void)
@@ -742,26 +833,25 @@ void lcd_scroll_fn(void)
int index;
int xpos, ypos;
int lastmode;
+ struct viewport* old_vp = current_vp;
- for ( index = 0; index < LCD_SCROLLABLE_LINES; index++ ) {
- /* really scroll? */
- if ((lcd_scroll_info.lines & (1 << index)) == 0)
- continue;
-
+ 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(curfont);
+ pf = font_get(current_vp->font);
xpos = s->startx;
- ypos = ymargin + index * pf->height;
+ ypos = current_vp->ymargin + s->y * pf->height;
if (s->bidir) { /* scroll bidirectional */
if (s->offset <= 0) {
@@ -770,9 +860,9 @@ void lcd_scroll_fn(void)
s->backward = false;
s->start_tick = current_tick + lcd_scroll_info.delay * 2;
}
- if (s->offset >= s->width - (LCD_WIDTH - xpos)) {
+ if (s->offset >= s->width - (current_vp->width - xpos)) {
/* at end of line */
- s->offset = s->width - (LCD_WIDTH - xpos);
+ s->offset = s->width - (current_vp->width - xpos);
s->backward = true;
s->start_tick = current_tick + lcd_scroll_info.delay * 2;
}
@@ -783,11 +873,13 @@ void lcd_scroll_fn(void)
s->offset %= s->width;
}
- lastmode = drawmode;
- drawmode = (s->style&STYLE_INVERT) ?
- (DRMODE_SOLID|DRMODE_INVERSEVID) : DRMODE_SOLID;
+ 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);
- drawmode = lastmode;
- lcd_update_rect(xpos, ypos, LCD_WIDTH - xpos, pf->height);
+ current_vp->drawmode = lastmode;
+ lcd_update_viewport_rect(xpos, ypos, current_vp->width - xpos, pf->height);
}
+
+ lcd_set_viewport(old_vp);
}