From 63c438107dbd55df384a5359e1478fbba94fe22a Mon Sep 17 00:00:00 2001 From: Michael Hayes Date: Tue, 30 Aug 2011 23:40:39 +0000 Subject: [PATCH] Add tinygl_draw_string --- apps/squeak3/squeak3.c | 2 +- utils/tinygl.c | 33 +++++++++++++++++++++++++++++++++ utils/tinygl.h | 8 ++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/apps/squeak3/squeak3.c b/apps/squeak3/squeak3.c index 2799224..7454f1f 100644 --- a/apps/squeak3/squeak3.c +++ b/apps/squeak3/squeak3.c @@ -78,7 +78,7 @@ static void button_task_init (void) static void display_note (void) { tinygl_clear (); - tinygl_text (note_names[note]); + tinygl_draw_string (note_names[note], tinygl_point (0, 0), 1); } diff --git a/utils/tinygl.c b/utils/tinygl.c index 25edc5e..68d3a23 100644 --- a/utils/tinygl.c +++ b/utils/tinygl.c @@ -177,10 +177,43 @@ void tinygl_draw_char (char ch, tinygl_point_t offset, bool rotate) } } } +} + + +/** Draw string (well, as much as possible) using current font. + @param str string to draw + @param offset coordinates of top left position + @param rotate non-zero to rotate string + @return number of whole characters drawn. */ +uint8_t tinygl_draw_string (const char *str, tinygl_point_t offset, bool rotate) +{ + uint8_t count = 0; + + while (*str) + { + if (rotate) + { + if (offset.y + font->width > TINYGL_HEIGHT) + break; + tinygl_draw_char (*str, offset, 1); + offset.y += font->width + 1; + } + else + { + if (offset.x + font->width > TINYGL_WIDTH) + break; + tinygl_draw_char (*str, offset, 0); + offset.x += font->width + 1; + } + count++; + str++; + } + return count; } + /** Display a character. @param ch character to display @return 1 if character fully displayed. */ diff --git a/utils/tinygl.h b/utils/tinygl.h index d04210c..55d0ab9 100644 --- a/utils/tinygl.h +++ b/utils/tinygl.h @@ -153,6 +153,14 @@ void tinygl_font_set (font_t *pfont); void tinygl_draw_char (char ch, tinygl_point_t offset, bool rotate); +/** Draw string (well, as much as possible) using current font. + @param str string to draw + @param offset coordinates of top left position + @param rotate non-zero to rotate string + @return number of whole characters drawn. */ +uint8_t tinygl_draw_string (const char *str, tinygl_point_t offset, + bool rotate); + /** Draw point. @param point coordinates of point @param pixel_value pixel value to draw point. */