Skip to content

Commit 648532c

Browse files
committed
add gfxPrint_P()
1 parent 04b1e7a commit 648532c

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

src/gfx.c

+22-6
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ void gfxLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, GFX_COLOUR_t colour
217217
}
218218
}
219219

220-
static void sGfxPrint5x7(uint8_t size, int16_t x, int16_t y, GFX_COLOUR_t fg, GFX_COLOUR_t bg, const char *str)
220+
static void sGfxPrint5x7(uint8_t size, int16_t x, int16_t y, GFX_COLOUR_t fg, GFX_COLOUR_t bg, const char *str, const bool isProgMem)
221221
{
222222
#ifndef GFX_CHECK_BOUNDS
223223
// skip early, gfxPixel() will take care of the precise bounds
@@ -230,7 +230,7 @@ static void sGfxPrint5x7(uint8_t size, int16_t x, int16_t y, GFX_COLOUR_t fg, GF
230230
return;
231231
}
232232
#endif
233-
const int iLen = strlen(str);
233+
const int iLen = isProgMem ? strlen_P(str) : strlen(str);
234234
if ( (iLen > 255) || (iLen < 1) )
235235
{
236236
return;
@@ -239,7 +239,7 @@ static void sGfxPrint5x7(uint8_t size, int16_t x, int16_t y, GFX_COLOUR_t fg, GF
239239
for (uint8_t strIx = 0; strIx < len; strIx++)
240240
{
241241
// draw character...
242-
uint8_t *bitmap = adaGfxFontChar(str[strIx]);
242+
uint8_t *bitmap = adaGfxFontChar( isProgMem ? pgm_read_byte(&str[strIx]) : str[strIx] );
243243
for (uint8_t bitmapIx = 0; bitmapIx < 5; bitmapIx++)
244244
{
245245
// ...row by row
@@ -274,13 +274,29 @@ void gfxPrint(GFX_FONT_t font, int16_t x, int16_t y, GFX_COLOUR_t fg, GFX_COLOUR
274274
switch (font)
275275
{
276276
case GFX_FONT_5X7_1:
277-
sGfxPrint5x7(1, x, y, fg, bg, str);
277+
sGfxPrint5x7(1, x, y, fg, bg, str, false);
278278
break;
279279
case GFX_FONT_5X7_2:
280-
sGfxPrint5x7(2, x, y, fg, bg, str);
280+
sGfxPrint5x7(2, x, y, fg, bg, str, false);
281281
break;
282282
case GFX_FONT_5X7_3:
283-
sGfxPrint5x7(3, x, y, fg, bg, str);
283+
sGfxPrint5x7(3, x, y, fg, bg, str, false);
284+
break;
285+
}
286+
}
287+
288+
void gfxPrint_P(GFX_FONT_t font, int16_t x, int16_t y, GFX_COLOUR_t fg, GFX_COLOUR_t bg, const char *str)
289+
{
290+
switch (font)
291+
{
292+
case GFX_FONT_5X7_1:
293+
sGfxPrint5x7(1, x, y, fg, bg, str, true);
294+
break;
295+
case GFX_FONT_5X7_2:
296+
sGfxPrint5x7(2, x, y, fg, bg, str, true);
297+
break;
298+
case GFX_FONT_5X7_3:
299+
sGfxPrint5x7(3, x, y, fg, bg, str, true);
284300
break;
285301
}
286302
}

src/gfx.h

+14
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,20 @@ typedef enum GFX_FONT_e
169169
*/
170170
void gfxPrint(GFX_FONT_t font, int16_t x, int16_t y, GFX_COLOUR_t fg, GFX_COLOUR_t bg, const char *str);
171171

172+
//! print a string from progmem
173+
/*!
174+
Characters are 5 [px] wide and 7 [px] tall. Individual characters are separated by 1 [px].
175+
The \c size will scales these accordingly.
176+
177+
\param[in] font the font to use
178+
\param[in] x x coordinate of top left corner of the first letter
179+
\param[in] y y coordinate of top left corner of the first letter
180+
\param[in] fg foreground colour (letter outlines)
181+
\param[in] bg background colour
182+
\param[in] str the string
183+
*/
184+
void gfxPrint_P(GFX_FONT_t font, int16_t x, int16_t y, GFX_COLOUR_t fg, GFX_COLOUR_t bg, const char *str);
185+
172186
/* *************************************************************************** */
173187

174188
#endif // __GFX_H__

0 commit comments

Comments
 (0)