From ea4af865f11cd18ac1b3d33fb9951f7527a42ab7 Mon Sep 17 00:00:00 2001 From: inmarket Date: Mon, 14 Oct 2013 08:55:15 +1000 Subject: [PATCH] Compile time fix to text rendering. Updated gdisp Get/Set Display routines to a more logical API. --- include/gdisp/gdisp.h | 24 ++++++++++++++++++++---- src/gdisp/gdisp.c | 27 ++++++++++++++++++--------- 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/include/gdisp/gdisp.h b/include/gdisp/gdisp.h index 7f0f8012..0c8310bb 100644 --- a/include/gdisp/gdisp.h +++ b/include/gdisp/gdisp.h @@ -366,16 +366,32 @@ extern "C" { color_t gdispBlendColor(color_t fg, color_t bg, uint8_t alpha); /** - * @brief Set the current default display to the specified display - * @note The default display is used for the gdispXxxx functions. + * @brief Get the specified display + * @return The pointer to the display or NULL if the display doesn't exist + * @note The GDISP variable contains the display used by the gdispXxxx routines + * as opposed to the gdispGXxxx routines which take an explicit display + * parameter. * @note Displays are numbered from 0 to GDISP_TOTAL_DISPLAYS - 1 - * @note If an invalid display number is specified the request is ignored. * * @param[in] display The display number (0..n) * * @api */ -void gdispSetDisplay(unsigned display); +GDisplay *gdispGetDisplay(unsigned display); + +/** + * @brief Set the current default display to the specified display + * @note The default display is used for the gdispXxxx functions. + * @note The default display is contained in the variable GDISP. Using + * this function to set it protects against it being set to a NULL + * value. + * @note If a NULL is passed for the dispay this call is ignored. + * + * @param[in] display The display number (0..n) + * + * @api + */ +void gdispSetDisplay(GDisplay *g); /* Drawing Functions */ diff --git a/src/gdisp/gdisp.c b/src/gdisp/gdisp.c index 41f2f0f9..ca0411e3 100644 --- a/src/gdisp/gdisp.c +++ b/src/gdisp/gdisp.c @@ -448,9 +448,14 @@ void _gdispInit(void) { #endif } -void gdispSetDisplay(unsigned display) { - if (display < GDISP_TOTAL_DISPLAYS) - GDISP = &GDisplayArray[display]; +GDisplay *gdispGetDisplay(unsigned display) { + if (display >= GDISP_TOTAL_DISPLAYS) + return 0; + return &GDisplayArray[display]; +} + +void gdispSetDisplay(GDisplay *g) { + if (g) GDISP = g; } #if GDISP_NEED_STREAMING @@ -2106,12 +2111,12 @@ void gdispGDrawBox(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, co if (y < GD->t.clipy0 || y >= GD->t.clipy1 || x < GD->t.clipx0 || x+count > GD->t.clipx1) return; if (alpha == 255) { GD->p.x = x; GD->p.y = y; GD->p.x1 = x+count-1; GD->p.color = GD->t.color; - hline_clip(g); + hline_clip(GD); } else { for (; count; count--, x++) { GD->p.x = x; GD->p.y = y; GD->p.color = gdispBlendColor(GD->t.color, gdisp_lld_get_pixel_color(GD), alpha); - drawpixel_clip(g); + drawpixel_clip(GD); } } #undef GD @@ -2122,7 +2127,7 @@ void gdispGDrawBox(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, co if (y < GD->t.clipy0 || y >= GD->t.clipy1 || x < GD->t.clipx0 || x+count > GD->t.clipx1) return; if (alpha > 0x80) { // A best approximation when using anti-aliased fonts but we can't actually draw them anti-aliased GD->p.x = x; GD->p.y = y; GD->p.x1 = x+count-1; GD->p.color = GD->t.color; - hline_clip(g); + hline_clip(GD); } #undef GD } @@ -2138,7 +2143,7 @@ void gdispGDrawBox(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, co GD->p.color = gdispBlendColor(GD->t.color, GD->t.bgcolor, alpha); } GD->p.x = x; GD->p.y = y; GD->p.x1 = x+count-1; - hline_clip(g); + hline_clip(GD); #undef GD } #else @@ -2147,12 +2152,16 @@ void gdispGDrawBox(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, co /* Callback to render characters. */ static uint8_t drawcharglyph(int16_t x, int16_t y, mf_char ch, void *state) { - return mf_render_character(g->t.font, x, y, ch, drawcharline, state); + #define GD ((GDisplay *)state) + return mf_render_character(GD->t.font, x, y, ch, drawcharline, state); + #undef GD } /* Callback to render characters. */ static uint8_t fillcharglyph(int16_t x, int16_t y, mf_char ch, void *state) { - return mf_render_character(g->t.font, x, y, ch, fillcharline, state); + #define GD ((GDisplay *)state) + return mf_render_character(GD->t.font, x, y, ch, fillcharline, state); + #undef GD } void gdispGDrawChar(GDisplay *g, coord_t x, coord_t y, uint16_t c, font_t font, color_t color) {