Display multiple chars in step mode if they can fit
This commit is contained in:
@@ -128,7 +128,7 @@ static void display_task_init (void)
|
||||
{
|
||||
tinygl_init (DISPLAY_TASK_RATE);
|
||||
tinygl_font_set (&font3x5_1);
|
||||
tinygl_text_mode_set (TINYGL_TEXT_MODE_SCROLL);
|
||||
tinygl_text_mode_set (TINYGL_TEXT_MODE_STEP);
|
||||
tinygl_text_dir_set (TINYGL_TEXT_DIR_ROTATE);
|
||||
}
|
||||
|
||||
|
||||
+21
-4
@@ -22,7 +22,7 @@ typedef struct tinygl_state_struct
|
||||
uint16_t update_rate;
|
||||
uint8_t message_index;
|
||||
uint16_t text_advance_period;
|
||||
uint8_t scroll_pos;
|
||||
int8_t scroll_pos;
|
||||
char message[TINYGL_MESSAGE_SIZE];
|
||||
} tinygl_state_t;
|
||||
|
||||
@@ -202,10 +202,11 @@ uint8_t tinygl_draw_string (const char *str, tinygl_point_t pos)
|
||||
while (*str)
|
||||
{
|
||||
pos = tinygl_draw_char (*str, pos);
|
||||
count++;
|
||||
|
||||
if (pos.x >= TINYGL_WIDTH || pos.y < 0)
|
||||
break;
|
||||
|
||||
count++;
|
||||
str++;
|
||||
}
|
||||
return count;
|
||||
@@ -230,8 +231,9 @@ static void tinygl_text_advance (void)
|
||||
if (tinygl.scroll_pos != 0)
|
||||
break;
|
||||
|
||||
/* In step mode, display a single character. */
|
||||
tinygl_draw_char (tinygl.message[tinygl.message_index], tinygl.pos);
|
||||
tinygl.message_index +=
|
||||
tinygl_draw_string (tinygl.message + tinygl.message_index,
|
||||
tinygl.pos) - 1;
|
||||
break;
|
||||
|
||||
case TINYGL_TEXT_MODE_SCROLL:
|
||||
@@ -276,6 +278,21 @@ void tinygl_text (const char *string, tinygl_point_t pos)
|
||||
tinygl.pos = pos;
|
||||
|
||||
strncpy (tinygl.message, string, sizeof (tinygl.message));
|
||||
|
||||
if (tinygl.mode == TINYGL_TEXT_MODE_SCROLL)
|
||||
{
|
||||
uint8_t message_cols;
|
||||
uint8_t message_len;
|
||||
uint8_t cols;
|
||||
|
||||
message_len = strlen (string);
|
||||
message_cols = message_len * tinygl.font->width + message_len - 1;
|
||||
|
||||
cols = (tinygl.dir == TINYGL_TEXT_DIR_ROTATE) ? TINYGL_HEIGHT
|
||||
: TINYGL_WIDTH;
|
||||
if (message_cols > cols)
|
||||
tinygl.scroll_pos = -2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user