Add tinygl_draw_string

This commit is contained in:
Michael Hayes
2011-08-30 23:40:39 +00:00
parent ab139beab9
commit 63c438107d
3 changed files with 43 additions and 2 deletions
+1 -1
View File
@@ -78,7 +78,7 @@ static void button_task_init (void)
static void display_note (void) static void display_note (void)
{ {
tinygl_clear (); tinygl_clear ();
tinygl_text (note_names[note]); tinygl_draw_string (note_names[note], tinygl_point (0, 0), 1);
} }
+34 -1
View File
@@ -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. /** Display a character.
@param ch character to display @param ch character to display
@return 1 if character fully displayed. */ @return 1 if character fully displayed. */
+8
View File
@@ -153,6 +153,14 @@ void tinygl_font_set (font_t *pfont);
void tinygl_draw_char (char ch, tinygl_point_t offset, bool rotate); 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. /** Draw point.
@param point coordinates of point @param point coordinates of point
@param pixel_value pixel value to draw point. */ @param pixel_value pixel value to draw point. */