Simplify tinygl API by removing rotate options and using rotated font instead
This commit is contained in:
+14
-60
@@ -131,34 +131,18 @@ static bool tinygl_font_pixel_get (char ch, uint8_t col, uint8_t row)
|
||||
|
||||
/** Draw character using current font.
|
||||
@param ch character to draw
|
||||
@param offset coordinates of top left position
|
||||
@param rotate non-zero to rotate character. */
|
||||
void tinygl_draw_char (char ch, tinygl_point_t offset, bool rotate)
|
||||
@param offset coordinates of top left position. */
|
||||
void tinygl_draw_char (char ch, tinygl_point_t offset)
|
||||
{
|
||||
uint8_t x;
|
||||
uint8_t y;
|
||||
|
||||
if (rotate)
|
||||
for (x = 0; x < font->width; x++)
|
||||
{
|
||||
for (x = 0; x < font->height; x++)
|
||||
for (y = 0; y < font->height; y++)
|
||||
{
|
||||
for (y = 0; y < font->width; y++)
|
||||
{
|
||||
tinygl_draw_point (tinygl_point (x + offset.x,
|
||||
TINYGL_HEIGHT - 1 - (y + offset.y)),
|
||||
tinygl_font_pixel_get (ch, y, x));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (x = 0; x < font->width; x++)
|
||||
{
|
||||
for (y = 0; y < font->height; y++)
|
||||
{
|
||||
tinygl_draw_point (tinygl_point (x + offset.x, y + offset.y),
|
||||
tinygl_font_pixel_get (ch, x, y));
|
||||
}
|
||||
tinygl_draw_point (tinygl_point (x + offset.x, y + offset.y),
|
||||
tinygl_font_pixel_get (ch, x, y));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -168,28 +152,17 @@ 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 tinygl_draw_string (const char *str, tinygl_point_t offset)
|
||||
{
|
||||
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;
|
||||
}
|
||||
if (offset.x + font->width > TINYGL_WIDTH)
|
||||
break;
|
||||
tinygl_draw_char (*str, offset);
|
||||
offset.x += font->width + 1;
|
||||
count++;
|
||||
str++;
|
||||
}
|
||||
@@ -197,13 +170,11 @@ uint8_t tinygl_draw_string (const char *str, tinygl_point_t offset, bool rotate)
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** Display a character.
|
||||
@param ch character to display
|
||||
@return 1 if character fully displayed. */
|
||||
static bool tinygl_display_char (char ch)
|
||||
{
|
||||
uint8_t x;
|
||||
uint8_t y;
|
||||
|
||||
if (!font)
|
||||
@@ -211,7 +182,7 @@ static bool tinygl_display_char (char ch)
|
||||
|
||||
switch (text_mode)
|
||||
{
|
||||
case TINYGL_TEXT_MODE_SCROLL_LEFT:
|
||||
case TINYGL_TEXT_MODE_SCROLL:
|
||||
display_scroll_left ();
|
||||
|
||||
for (y = 0; y < font->height; y++)
|
||||
@@ -225,27 +196,10 @@ static bool tinygl_display_char (char ch)
|
||||
if (scroll_pos != 0)
|
||||
break;
|
||||
|
||||
tinygl_draw_char (ch, tinygl_point (0, 0), 0);
|
||||
break;
|
||||
|
||||
case TINYGL_TEXT_MODE_ROTATE_SCROLL_DOWN:
|
||||
display_scroll_down ();
|
||||
|
||||
for (x = 0; x < font->height; x++)
|
||||
{
|
||||
tinygl_draw_point (tinygl_point (x, 0),
|
||||
tinygl_font_pixel_get (ch, scroll_pos, x));
|
||||
}
|
||||
break;
|
||||
|
||||
case TINYGL_TEXT_MODE_ROTATE_STEP:
|
||||
if (scroll_pos != 0)
|
||||
break;
|
||||
|
||||
tinygl_draw_char (ch, tinygl_point (0, 0), 1);
|
||||
tinygl_draw_char (ch, tinygl_point (0, 0));
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
scroll_pos++;
|
||||
if (scroll_pos > font->width)
|
||||
scroll_pos = 0;
|
||||
|
||||
+5
-11
@@ -110,11 +110,7 @@ typedef enum
|
||||
/* Stepping text. */
|
||||
TINYGL_TEXT_MODE_STEP,
|
||||
/** Scrolling text. */
|
||||
TINYGL_TEXT_MODE_SCROLL_LEFT,
|
||||
/** Rotated scrolling text. */
|
||||
TINYGL_TEXT_MODE_ROTATE_SCROLL_DOWN,
|
||||
/* Stepping rotated text. */
|
||||
TINYGL_TEXT_MODE_ROTATE_STEP
|
||||
TINYGL_TEXT_MODE_SCROLL
|
||||
} tinygl_text_mode_t;
|
||||
|
||||
|
||||
@@ -152,18 +148,16 @@ void tinygl_font_set (font_t *pfont);
|
||||
|
||||
/** Draw character using current font.
|
||||
@param ch character to draw
|
||||
@param offset coordinates of top left position
|
||||
@param rotate non-zero to rotate character. */
|
||||
void tinygl_draw_char (char ch, tinygl_point_t offset, bool rotate);
|
||||
@param offset coordinates of top left position. */
|
||||
void tinygl_draw_char (char ch, tinygl_point_t offset);
|
||||
|
||||
|
||||
/** 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 tinygl_draw_string (const char *str, tinygl_point_t offset);
|
||||
|
||||
|
||||
/** Draw point.
|
||||
@param point coordinates of point
|
||||
|
||||
Reference in New Issue
Block a user