forked from len0rd/rockbox
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
This commit is contained in:
parent
ce00e283b5
commit
e04f95eab9
6 changed files with 336 additions and 1236 deletions
|
@ -638,70 +638,6 @@ void lcd_fillrect(int x, int y, int width, int height)
|
|||
while (dst < dst_end);
|
||||
}
|
||||
|
||||
/* Fill a rectangle with a gradient */
|
||||
static void lcd_gradient_rect(int x1, int x2, int y, int h)
|
||||
{
|
||||
int old_pattern = current_vp->fg_pattern;
|
||||
|
||||
if (h == 0) return;
|
||||
|
||||
int h_r = RGB_UNPACK_RED(current_vp->lss_pattern) << 16;
|
||||
int h_b = RGB_UNPACK_BLUE(current_vp->lss_pattern) << 16;
|
||||
int h_g = RGB_UNPACK_GREEN(current_vp->lss_pattern) << 16;
|
||||
int rstep = (h_r - ((signed)RGB_UNPACK_RED(current_vp->lse_pattern) << 16)) / h;
|
||||
int gstep = (h_g - ((signed)RGB_UNPACK_GREEN(current_vp->lse_pattern) << 16)) / h;
|
||||
int bstep = (h_b - ((signed)RGB_UNPACK_BLUE(current_vp->lse_pattern) << 16)) / h;
|
||||
int count;
|
||||
|
||||
current_vp->fg_pattern = current_vp->lss_pattern;
|
||||
for(count = 0; count < h; count++) {
|
||||
lcd_hline(x1, x2, y + count);
|
||||
h_r -= rstep;
|
||||
h_g -= gstep;
|
||||
h_b -= bstep;
|
||||
current_vp->fg_pattern = LCD_RGBPACK(h_r >> 16, h_g >> 16, h_b >> 16);
|
||||
}
|
||||
|
||||
current_vp->fg_pattern = old_pattern;
|
||||
}
|
||||
|
||||
#define H_COLOR(lss, lse, cur_line, max_line) \
|
||||
(((lse) - (lss)) * (cur_line) / (max_line) + (lss))
|
||||
|
||||
/* Fill a rectangle with a gradient for scrolling line. To draw a gradient that
|
||||
covers several lines, we need to know how many lines will be covered
|
||||
(the num_lines arg), and which one is the current line within the selection
|
||||
(the cur_line arg). */
|
||||
static void lcd_gradient_rect_scroll(int x1, int x2, int y, int h,
|
||||
unsigned char num_lines, unsigned char cur_line)
|
||||
{
|
||||
if (h == 0 || num_lines == 0) return;
|
||||
|
||||
unsigned tmp_lss = current_vp->lss_pattern;
|
||||
unsigned tmp_lse = current_vp->lse_pattern;
|
||||
int lss_r = (signed)RGB_UNPACK_RED(current_vp->lss_pattern);
|
||||
int lss_b = (signed)RGB_UNPACK_BLUE(current_vp->lss_pattern);
|
||||
int lss_g = (signed)RGB_UNPACK_GREEN(current_vp->lss_pattern);
|
||||
int lse_r = (signed)RGB_UNPACK_RED(current_vp->lse_pattern);
|
||||
int lse_b = (signed)RGB_UNPACK_BLUE(current_vp->lse_pattern);
|
||||
int lse_g = (signed)RGB_UNPACK_GREEN(current_vp->lse_pattern);
|
||||
|
||||
int h_r = H_COLOR(lss_r, lse_r, cur_line, num_lines);
|
||||
int h_g = H_COLOR(lss_g, lse_g, cur_line, num_lines);
|
||||
int h_b = H_COLOR(lss_b, lse_b, cur_line, num_lines);
|
||||
lcd_set_selector_start(LCD_RGBPACK(h_r, h_g, h_b));
|
||||
|
||||
int l_r = H_COLOR(lss_r, lse_r, cur_line+1, num_lines);
|
||||
int l_g = H_COLOR(lss_g, lse_g, cur_line+1, num_lines);
|
||||
int l_b = H_COLOR(lss_b, lse_b, cur_line+1, num_lines);
|
||||
lcd_set_selector_end(LCD_RGBPACK(l_r, l_g, l_b));
|
||||
|
||||
lcd_gradient_rect(x1, x2, y, h);
|
||||
|
||||
current_vp->lss_pattern = tmp_lss;
|
||||
current_vp->lse_pattern = tmp_lse;
|
||||
}
|
||||
|
||||
/* About Rockbox' internal monochrome bitmap format:
|
||||
*
|
||||
* A bitmap contains one bit for every pixel that defines if that pixel is
|
||||
|
@ -977,285 +913,4 @@ void lcd_bitmap_transparent(const fb_data *src, int x, int y,
|
|||
lcd_bitmap_transparent_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;
|
||||
int oldfgcolor = current_vp->fg_pattern;
|
||||
int oldbgcolor = current_vp->bg_pattern;
|
||||
|
||||
/* 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(str);
|
||||
ypos = y*h;
|
||||
current_vp->drawmode = (style & STYLE_INVERT) ?
|
||||
(DRMODE_SOLID|DRMODE_INVERSEVID) : DRMODE_SOLID;
|
||||
if (style & STYLE_COLORED) {
|
||||
if (current_vp->drawmode == DRMODE_SOLID)
|
||||
current_vp->fg_pattern = style & STYLE_COLOR_MASK;
|
||||
else
|
||||
current_vp->bg_pattern = style & STYLE_COLOR_MASK;
|
||||
}
|
||||
current_vp->drawmode ^= DRMODE_INVERSEVID;
|
||||
xrect = xpos + MAX(w - offset, 0);
|
||||
|
||||
if (style & STYLE_GRADIENT) {
|
||||
current_vp->drawmode = DRMODE_FG;
|
||||
if (CURLN_UNPACK(style) == 0)
|
||||
lcd_gradient_rect(xpos, current_vp->width, ypos, h*NUMLN_UNPACK(style));
|
||||
current_vp->fg_pattern = current_vp->lst_pattern;
|
||||
}
|
||||
else if (style & STYLE_COLORBAR) {
|
||||
current_vp->drawmode = DRMODE_FG;
|
||||
current_vp->fg_pattern = current_vp->lss_pattern;
|
||||
lcd_fillrect(xpos, ypos, current_vp->width - xpos, h);
|
||||
current_vp->fg_pattern = current_vp->lst_pattern;
|
||||
}
|
||||
else {
|
||||
lcd_fillrect(xrect, ypos, current_vp->width - xrect, h);
|
||||
current_vp->drawmode = (style & STYLE_INVERT) ?
|
||||
(DRMODE_SOLID|DRMODE_INVERSEVID) : DRMODE_SOLID;
|
||||
}
|
||||
lcd_putsxyofs(xpos, ypos, offset, str);
|
||||
current_vp->drawmode = lastmode;
|
||||
current_vp->fg_pattern = oldfgcolor;
|
||||
current_vp->bg_pattern = oldbgcolor;
|
||||
}
|
||||
|
||||
/*** 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);
|
||||
}
|
||||
|
||||
/* Initialise a scrolling line at (x,y) in current viewport */
|
||||
|
||||
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;
|
||||
lcd_puts_style_offset(x,y,string,style,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, string);
|
||||
|
||||
/* get width */
|
||||
s->width = lcd_getstringsize(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(s->line, &w, &h);
|
||||
}
|
||||
|
||||
end = strchr(s->line, '\0');
|
||||
strlcpy(end, string, current_vp->width/2);
|
||||
|
||||
s->vp = current_vp;
|
||||
s->y = y;
|
||||
s->len = utf8length(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;
|
||||
unsigned old_fgcolor;
|
||||
unsigned old_bgcolor;
|
||||
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);
|
||||
old_fgcolor = current_vp->fg_pattern;
|
||||
old_bgcolor = current_vp->bg_pattern;
|
||||
|
||||
if (s->style&STYLE_COLORED) {
|
||||
if (s->style&STYLE_MODE_MASK) {
|
||||
current_vp->fg_pattern = old_fgcolor;
|
||||
current_vp->bg_pattern = s->style&STYLE_COLOR_MASK;
|
||||
}
|
||||
else {
|
||||
current_vp->fg_pattern = s->style&STYLE_COLOR_MASK;
|
||||
current_vp->bg_pattern = old_bgcolor;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
switch (s->style&STYLE_MODE_MASK) {
|
||||
case STYLE_INVERT:
|
||||
current_vp->drawmode = DRMODE_SOLID|DRMODE_INVERSEVID;
|
||||
break;
|
||||
case STYLE_COLORBAR:
|
||||
/* Solid colour line selector */
|
||||
current_vp->drawmode = DRMODE_FG;
|
||||
current_vp->fg_pattern = current_vp->lss_pattern;
|
||||
lcd_fillrect(xpos, ypos, current_vp->width - xpos, pf->height);
|
||||
current_vp->fg_pattern = current_vp->lst_pattern;
|
||||
break;
|
||||
case STYLE_GRADIENT:
|
||||
/* Gradient line selector */
|
||||
current_vp->drawmode = DRMODE_FG;
|
||||
lcd_gradient_rect_scroll(xpos, current_vp->width, ypos, (signed)pf->height,
|
||||
NUMLN_UNPACK(s->style),
|
||||
CURLN_UNPACK(s->style));
|
||||
current_vp->fg_pattern = current_vp->lst_pattern;
|
||||
break;
|
||||
default:
|
||||
current_vp->drawmode = DRMODE_SOLID;
|
||||
break;
|
||||
}
|
||||
lcd_putsxyofs(xpos, ypos, s->offset, s->line);
|
||||
current_vp->drawmode = lastmode;
|
||||
current_vp->fg_pattern = old_fgcolor;
|
||||
current_vp->bg_pattern = old_bgcolor;
|
||||
lcd_update_viewport_rect(xpos, ypos, current_vp->width - xpos, pf->height);
|
||||
}
|
||||
|
||||
lcd_set_viewport(old_vp);
|
||||
}
|
||||
#include "lcd-bitmap-common.c"
|
||||
|
|
|
@ -692,226 +692,4 @@ void LCDFN(bitmap)(const unsigned char *src, int x, int y, int width,
|
|||
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(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, string, current_vp->width/2);
|
||||
|
||||
s->vp = current_vp;
|
||||
s->y = y;
|
||||
s->len = utf8length(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"
|
||||
|
|
|
@ -956,223 +956,4 @@ void lcd_bitmap(const unsigned char *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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
329
firmware/drivers/lcd-bitmap-common.c
Normal file
329
firmware/drivers/lcd-bitmap-common.c
Normal file
|
@ -0,0 +1,329 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 2005 Dave Chapman
|
||||
* Text rendering
|
||||
* Copyright (C) 2006 Shachar Liberman
|
||||
* Offset text, scrolling
|
||||
* Copyright (C) 2007 Nicolas Pennequin, Tom Ross, Ken Fazzone, Akio Idehara
|
||||
* Color gradient background
|
||||
* Copyright (C) 2009 Andrew Mahone
|
||||
* Merged common LCD bitmap code
|
||||
*
|
||||
* Rockbox common bitmap LCD functions
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef LCDFN /* Not compiling for remote - define macros for main LCD. */
|
||||
#define LCDFN(fn) lcd_ ## fn
|
||||
#define FBFN(fn) fb_ ## fn
|
||||
#define LCDM(ma) LCD_ ## ma
|
||||
#define LCDNAME "lcd_"
|
||||
#define MAIN_LCD
|
||||
#endif
|
||||
|
||||
#if defined(MAIN_LCD) && defined(HAVE_LCD_COLOR)
|
||||
/* Fill a rectangle with a gradient */
|
||||
static void lcd_gradient_rect(int x1, int x2, int y, unsigned h,
|
||||
int num_lines, int cur_line)
|
||||
{
|
||||
int old_pattern = current_vp->fg_pattern;
|
||||
int step_mul;
|
||||
if (h == 0) return;
|
||||
|
||||
num_lines *= h;
|
||||
cur_line *= h;
|
||||
step_mul = (1 << 16) / (num_lines);
|
||||
int h_r = RGB_UNPACK_RED(current_vp->lss_pattern);
|
||||
int h_g = RGB_UNPACK_GREEN(current_vp->lss_pattern);
|
||||
int h_b = RGB_UNPACK_BLUE(current_vp->lss_pattern);
|
||||
int rstep = (h_r - RGB_UNPACK_RED(current_vp->lse_pattern)) * step_mul;
|
||||
int gstep = (h_g - RGB_UNPACK_GREEN(current_vp->lse_pattern)) * step_mul;
|
||||
int bstep = (h_b - RGB_UNPACK_BLUE(current_vp->lse_pattern)) * step_mul;
|
||||
h_r = (h_r << 16) + (1 << 15);
|
||||
h_g = (h_g << 16) + (1 << 15);
|
||||
h_b = (h_b << 16) + (1 << 15);
|
||||
if (cur_line)
|
||||
{
|
||||
h_r -= cur_line * rstep;
|
||||
h_g -= cur_line * gstep;
|
||||
h_b -= cur_line * bstep;
|
||||
}
|
||||
unsigned count;
|
||||
|
||||
for(count = 0; count < h; count++) {
|
||||
current_vp->fg_pattern = LCD_RGBPACK(h_r >> 16, h_g >> 16, h_b >> 16);
|
||||
lcd_hline(x1, x2, y + count);
|
||||
h_r -= rstep;
|
||||
h_g -= gstep;
|
||||
h_b -= bstep;
|
||||
}
|
||||
|
||||
current_vp->fg_pattern = old_pattern;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
static void LCDFN(putsxyofs_style)(int xpos, int ypos,
|
||||
const unsigned char *str, int style,
|
||||
int w, int h, int offset)
|
||||
{
|
||||
int lastmode = current_vp->drawmode;
|
||||
int xrect = xpos + MAX(w - offset, 0);
|
||||
#if defined(MAIN_LCD) && defined(HAVE_LCD_COLOR)
|
||||
int oldfgcolor = current_vp->fg_pattern;
|
||||
int oldbgcolor = current_vp->bg_pattern;
|
||||
current_vp->drawmode = DRMODE_SOLID | ((style & STYLE_INVERT) ?
|
||||
DRMODE_INVERSEVID : 0);
|
||||
if (style & STYLE_COLORED) {
|
||||
if (current_vp->drawmode == DRMODE_SOLID)
|
||||
current_vp->fg_pattern = style & STYLE_COLOR_MASK;
|
||||
else
|
||||
current_vp->bg_pattern = style & STYLE_COLOR_MASK;
|
||||
}
|
||||
current_vp->drawmode ^= DRMODE_INVERSEVID;
|
||||
if (style & STYLE_GRADIENT) {
|
||||
current_vp->drawmode = DRMODE_FG;
|
||||
lcd_gradient_rect(xpos, current_vp->width, ypos, h,
|
||||
NUMLN_UNPACK(style), CURLN_UNPACK(style));
|
||||
current_vp->fg_pattern = current_vp->lst_pattern;
|
||||
}
|
||||
else if (style & STYLE_COLORBAR) {
|
||||
current_vp->drawmode = DRMODE_FG;
|
||||
current_vp->fg_pattern = current_vp->lss_pattern;
|
||||
lcd_fillrect(xpos, ypos, current_vp->width - xpos, h);
|
||||
current_vp->fg_pattern = current_vp->lst_pattern;
|
||||
}
|
||||
else {
|
||||
lcd_fillrect(xrect, ypos, current_vp->width - xrect, h);
|
||||
current_vp->drawmode = (style & STYLE_INVERT) ?
|
||||
(DRMODE_SOLID|DRMODE_INVERSEVID) : DRMODE_SOLID;
|
||||
}
|
||||
lcd_putsxyofs(xpos, ypos, offset, str);
|
||||
current_vp->fg_pattern = oldfgcolor;
|
||||
current_vp->bg_pattern = oldbgcolor;
|
||||
#else
|
||||
current_vp->drawmode = DRMODE_SOLID | ((style & STYLE_INVERT) ?
|
||||
0 : DRMODE_INVERSEVID);
|
||||
LCDFN(fillrect)(xrect, ypos, current_vp->width - xrect, h);
|
||||
current_vp->drawmode ^= DRMODE_INVERSEVID;
|
||||
LCDFN(putsxyofs)(xpos, ypos, offset, str);
|
||||
#endif
|
||||
current_vp->drawmode = lastmode;
|
||||
}
|
||||
|
||||
/*** Line oriented text output ***/
|
||||
|
||||
/* put a string at a given char position */
|
||||
void LCDFN(puts_style_offset)(int x, int y, const unsigned char *str,
|
||||
int style, int offset)
|
||||
{
|
||||
int xpos, ypos, w, h;
|
||||
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;
|
||||
LCDFN(putsxyofs_style)(xpos, ypos, str, style, w, h, offset);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/*** scrolling ***/
|
||||
|
||||
void LCDFN(puts_scroll_style_offset)(int x, int y, const unsigned char *string,
|
||||
int style, int offset)
|
||||
{
|
||||
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 (LCDFN(scroll_info.lines) >= LCDM(SCROLLABLE_LINES)) return;
|
||||
if (!string)
|
||||
return;
|
||||
LCDFN(puts_style_offset)(x, y, string, style, offset);
|
||||
|
||||
LCDFN(getstringsize)(string, &w, &h);
|
||||
|
||||
if (current_vp->width - x * 8 < w) {
|
||||
/* prepare scroll line */
|
||||
struct scrollinfo* s;
|
||||
s = &LCDFN(scroll_info).scroll[LCDFN(scroll_info).lines];
|
||||
s->start_tick = current_tick + LCDFN(scroll_info).delay;
|
||||
s->style = style;
|
||||
|
||||
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, string, current_vp->width/2);
|
||||
|
||||
s->vp = current_vp;
|
||||
s->y = y;
|
||||
s->len = utf8length(string);
|
||||
s->offset = offset;
|
||||
s->startx = x * s->width / s->len;
|
||||
s->backward = false;
|
||||
|
||||
LCDFN(scroll_info).lines++;
|
||||
}
|
||||
}
|
||||
|
||||
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(scroll_fn)(void)
|
||||
{
|
||||
struct font* pf;
|
||||
struct scrollinfo* s;
|
||||
int index;
|
||||
int xpos, ypos;
|
||||
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;
|
||||
}
|
||||
LCDFN(putsxyofs_style)(xpos, ypos, s->line, s->style, s->width,
|
||||
pf->height, s->offset);
|
||||
LCDFN(update_viewport_rect)(xpos, ypos, current_vp->width - xpos,
|
||||
pf->height);
|
||||
}
|
||||
LCDFN(set_viewport)(old_vp);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue