diff options
-rw-r--r-- | apps/gui/line.c | 3 | ||||
-rw-r--r-- | apps/gui/line.h | 24 | ||||
-rw-r--r-- | firmware/drivers/lcd-bitmap-common.c | 146 | ||||
-rw-r--r-- | firmware/export/lcd.h | 21 | ||||
-rw-r--r-- | firmware/export/scroll_engine.h | 3 |
5 files changed, 41 insertions, 156 deletions
diff --git a/apps/gui/line.c b/apps/gui/line.c index 9374279b60..3d563d171c 100644 --- a/apps/gui/line.c +++ b/apps/gui/line.c @@ -264,7 +264,6 @@ static void style_line(struct screen *display, int style = line->style; int width = display->getwidth(); int height = line->height == -1 ? display->getcharheight() : line->height; - unsigned mask = STYLE_MODE_MASK & ~STYLE_COLORED; /* mask out gradient and colorbar styles for non-color displays */ if (display->depth < 16) @@ -277,7 +276,7 @@ static void style_line(struct screen *display, style &= ~STYLE_COLORED; } - switch (style & mask) + switch (style & _STYLE_DECO_MASK) { #if (LCD_DEPTH > 1 || (defined(LCD_REMOTE_DEPTH) && LCD_REMOTE_DEPTH > 1)) case STYLE_GRADIENT: diff --git a/apps/gui/line.h b/apps/gui/line.h index d5350eb410..fa1522003c 100644 --- a/apps/gui/line.h +++ b/apps/gui/line.h @@ -29,6 +29,28 @@ #include "lcd.h" #include "screens.h" +/* Possible line decoration styles. Specify one of + * STYLE_NONE, _DEFAULT, _INVERT, _COLORBAR or _GRADIENT, and optionally + * or with STYLE_COLORED specifying line_desc.text_color */ +enum line_styles { + /* Just print the text. Do not clear or draw line decorations */ + STYLE_NONE = 0x00, + /* Line background filled with the bg color (or backdrop if present) */ + STYLE_DEFAULT = 0x01, + /* Like STYLE_DFEAULT except that text and background color will be swapped */ + STYLE_INVERT = 0x02, + /* Line background filled with line color line_desc.line_color */ + STYLE_COLORBAR = 0x04, + /* Line background filled with gradient, colors taken from + * line_desc.line_color and line_desc.line_end_color */ + STYLE_GRADIENT = 0x08, + /* Modifier for the text color, which will be taken from line_desc.text_color */ + STYLE_COLORED = 0x10, + /* These are used internally */ + _STYLE_DECO_MASK = 0x0f, + _STYLE_MODE_MASK = 0x7F, +}; + struct line_desc { /* height of the line (in pixels). -1 to inherit the height * from the font. The text will be centered if the height is larger, @@ -49,7 +71,7 @@ struct line_desc { * lcd format (convert with LCD_RGBPACK() if necessary) */ fb_data line_color, line_end_color; /* line decorations, see STYLE_DEFAULT etc. */ - int style; + enum line_styles style; /* whether the line can scroll */ bool scroll; }; diff --git a/firmware/drivers/lcd-bitmap-common.c b/firmware/drivers/lcd-bitmap-common.c index 7c5df5a3a8..e37da51a1b 100644 --- a/firmware/drivers/lcd-bitmap-common.c +++ b/firmware/drivers/lcd-bitmap-common.c @@ -41,6 +41,7 @@ #endif #if defined(MAIN_LCD) && defined(HAVE_LCD_COLOR) + /* Fill a rectangle with a gradient. This function draws only the partial * gradient. It assumes the original gradient is src_height high and skips * the first few rows. This is useful for drawing only the bottom half of @@ -107,47 +108,6 @@ void lcd_gradient_fillrect(int x, int y, int width, int height, lcd_gradient_fillrect_part(x, y, width, height, start_rgb, end_rgb, height, 0); } -/* Fill a text line with a gradient: - * x1, x2 - x pixel coordinates to start/stop - * y - y pixel to start from - * h - line height - * num_lines - number of lines to span the gradient over - * cur_line - current line being draw - */ -static void lcd_do_gradient_line(int x1, int x2, int y, unsigned h, - int num_lines, int cur_line) -{ - 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; - unsigned start_rgb, end_rgb; - 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; - } - start_rgb = LCD_RGBPACK(h_r >> 16, h_g >> 16, h_b >> 16); - - h_r -= h * rstep; - h_g -= h * gstep; - h_b -= h * bstep; - end_rgb = LCD_RGBPACK(h_r >> 16, h_g >> 16, h_b >> 16); - lcd_gradient_fillrect(x1, y, x2 - x1, h, start_rgb, end_rgb); -} - #endif void LCDFN(set_framebuffer)(FBFN(data) *fb) @@ -368,6 +328,8 @@ static void LCDFN(putsxyofs)(int x, int y, int ofs, const unsigned char *str) font_lock(current_vp->font, false); } +/*** pixel oriented text output ***/ + /* put a string at a given pixel position */ void LCDFN(putsxy)(int x, int y, const unsigned char *str) { @@ -385,90 +347,14 @@ void LCDFN(putsxyf)(int x, int y, const unsigned char *fmt, ...) LCDFN(putsxy)(x, y, buf); } -static void LCDFN(putsxyofs_style)(int xpos, int ypos, - const unsigned char *str, int style, - int offset) -{ - int lastmode = current_vp->drawmode; - int text_ypos = ypos; - int h = font_get(current_vp->font)->height; - - if ((style & STYLE_MODE_MASK) == STYLE_NONE) { - if (str[0]) - LCDFN(putsxyofs)(xpos, text_ypos, offset, str); - return; - } -#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_do_gradient_line(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(xpos, ypos, current_vp->width - xpos, h); - current_vp->drawmode = (style & STYLE_INVERT) ? - (DRMODE_SOLID|DRMODE_INVERSEVID) : DRMODE_SOLID; - } - if (str[0]) - lcd_putsxyofs(xpos, text_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)(xpos, ypos, current_vp->width - xpos, h); - current_vp->drawmode ^= DRMODE_INVERSEVID; - if (str[0]) - LCDFN(putsxyofs)(xpos, text_ypos, offset, str); -#endif - current_vp->drawmode = lastmode; -} - /*** Line oriented text output ***/ -static void LCDFN(putsofs_style)(int x, int y, const unsigned char *str, - int style, int x_offset) -{ - int xpos, ypos, h; - if(!str) - return; - - h = font_get(current_vp->font)->height; - if ((style&STYLE_XY_PIXELS) == 0) - { - xpos = x * LCDFN(getstringsize)(" ", NULL, NULL); - ypos = y * h; - } - else - { - xpos = x; - ypos = y; - } - LCDFN(scroll_stop_viewport_rect)(current_vp, xpos, ypos, current_vp->width - xpos, h); - LCDFN(putsxyofs_style)(xpos, ypos, str, style, x_offset); -} - void LCDFN(puts)(int x, int y, const unsigned char *str) { - LCDFN(putsofs_style)(x, y, str, STYLE_DEFAULT, 0); + int h; + x *= LCDFN(getstringsize)(" ", NULL, &h); + y *= h; + LCDFN(putsxyofs)(x, y, 0, str); } /* Formatting version of LCDFN(puts) */ @@ -500,11 +386,16 @@ static struct scrollinfo* find_scrolling_line(int x, int y) void LCDFN(scroll_fn)(struct scrollinfo* s) { - LCDFN(putsxyofs_style)(s->x, s->y, s->line, s->style, s->offset); + /* Fill with background/backdrop to clear area. + * cannot use clear_viewport_rect() since stops scrolling as well */ + LCDFN(set_drawmode)(DRMODE_SOLID|DRMODE_INVERSEVID); + LCDFN(fillrect)(s->x, s->y, s->width, s->height); + LCDFN(set_drawmode)(DRMODE_SOLID); + LCDFN(putsxyofs)(s->x, s->y, s->offset, s->line); } static void LCDFN(puts_scroll_worker)(int x, int y, const unsigned char *string, - int style, int x_offset, + int x_offset, bool linebased, void (*scroll_func)(struct scrollinfo *), void *data) @@ -534,7 +425,7 @@ static void LCDFN(puts_scroll_worker)(int x, int y, const unsigned char *string, if (restart) { /* remove any previously scrolling line at the same location */ LCDFN(scroll_stop_viewport_rect)(current_vp, x, y, width, height); - LCDFN(putsxyofs_style)(x, y, string, style, x_offset); + LCDFN(putsxyofs)(x, y, x_offset, string); if (LCDFN(scroll_info).lines >= LCDM(SCROLLABLE_LINES)) return; @@ -570,7 +461,6 @@ static void LCDFN(puts_scroll_worker)(int x, int y, const unsigned char *string, if (restart) { s->offset = x_offset; s->backward = false; - s->style = style; /* assign the rectangle. not necessary if continuing an earlier line */ s->x = x; s->y = y; @@ -588,14 +478,12 @@ void LCDFN(putsxy_scroll_func)(int x, int y, const unsigned char *string, if (!scroll_func) LCDFN(putsxyofs)(x, y, x_offset, string); else - LCDFN(puts_scroll_worker)(x, y, string, STYLE_NONE, x_offset, - false, scroll_func, data); + LCDFN(puts_scroll_worker)(x, y, string, x_offset, false, scroll_func, data); } void LCDFN(puts_scroll)(int x, int y, const unsigned char *string) { - LCDFN(puts_scroll_worker)(x, y, string, STYLE_DEFAULT, 0, - true, LCDFN(scroll_fn), NULL); + LCDFN(puts_scroll_worker)(x, y, string, 0, true, LCDFN(scroll_fn), NULL); } #if !defined(HAVE_LCD_COLOR) || !defined(MAIN_LCD) diff --git a/firmware/export/lcd.h b/firmware/export/lcd.h index bdeddf0b52..e7a75e893a 100644 --- a/firmware/export/lcd.h +++ b/firmware/export/lcd.h @@ -120,27 +120,6 @@ struct scrollinfo; #define STRIDE(screen, w, h) (screen==SCREEN_MAIN?STRIDE_MAIN((w), \ (h)):STRIDE_REMOTE((w),(h))) -#define STYLE_NONE 0x00000000 -#define STYLE_DEFAULT 0x01000000 -#define STYLE_COLORED 0x02000000 -#define STYLE_INVERT 0x04000000 -#define STYLE_COLORBAR 0x08000000 -#define STYLE_GRADIENT 0x10000000 -#define STYLE_MODE_MASK 0xFF000000 -/* HACK: This isnt really a style, We need to be able to tell some of - * the lcd API that we want to draw text to a specific pixel instead - * of a char. Remove this hack when the whole LCD api goes to fully - * pixel based positioning - jdgordon */ -#define STYLE_XY_PIXELS 0x00010000 -#define STYLE_COLOR_MASK 0x0000FFFF -#ifdef HAVE_LCD_COLOR -#define STYLE_CURLN_MASK 0x0000FF00 -#define STYLE_MAXLN_MASK 0x000000FF -#define CURLN_PACK(x) (((x)<<8) & STYLE_CURLN_MASK) -#define CURLN_UNPACK(x) ((unsigned char)(((x)&STYLE_CURLN_MASK) >> 8)) -#define NUMLN_PACK(x) ((x) & STYLE_MAXLN_MASK) -#define NUMLN_UNPACK(x) ((unsigned char)((x) & STYLE_MAXLN_MASK)) -#endif #ifdef HAVE_LCD_BITMAP #if LCD_DEPTH <=8 diff --git a/firmware/export/scroll_engine.h b/firmware/export/scroll_engine.h index e3fd720550..19a2bc4cca 100644 --- a/firmware/export/scroll_engine.h +++ b/firmware/export/scroll_engine.h @@ -69,9 +69,6 @@ struct scrollinfo int width, height; /* pixel to skip from the beginning of the string, increments as the text scrolls */ int offset; -#ifdef HAVE_LCD_BITMAP - int style; /* line style */ -#endif /* HAVE_LCD_BITMAP */ /* scroll presently forward or backward? */ bool backward; bool bidir; |