From 79ceb776d16ca13eb46c57ac682a8a770add918f Mon Sep 17 00:00:00 2001 From: Michael Hayes Date: Sat, 24 Sep 2011 11:26:37 +0000 Subject: [PATCH] Display multiple chars in step mode if they can fit --- apps/hello5/hello5.c | 2 +- apps/squeak4/squeak4.c | 2 +- utils/tinygl.c | 31 ++++++++++++++++++++++++------- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/apps/hello5/hello5.c b/apps/hello5/hello5.c index 2f7c615..d51f7c8 100644 --- a/apps/hello5/hello5.c +++ b/apps/hello5/hello5.c @@ -32,7 +32,7 @@ int main (void) tinygl_text_mode_set (TINYGL_TEXT_MODE_SCROLL); tinygl_text_dir_set (TINYGL_TEXT_DIR_ROTATE); - tinygl_text ("HELLO WORLD", tinygl_point (0, TINYGL_HEIGHT - 1)); + tinygl_text ("HELLO WORLD ", tinygl_point (0, TINYGL_HEIGHT - 1)); pacer_init (LOOP_RATE); diff --git a/apps/squeak4/squeak4.c b/apps/squeak4/squeak4.c index 7fc9145..2343434 100644 --- a/apps/squeak4/squeak4.c +++ b/apps/squeak4/squeak4.c @@ -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); } diff --git a/utils/tinygl.c b/utils/tinygl.c index 57dd1a3..4c04f54 100644 --- a/utils/tinygl.c +++ b/utils/tinygl.c @@ -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; @@ -229,15 +230,16 @@ static void tinygl_text_advance (void) case TINYGL_TEXT_MODE_STEP: 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: pos = tinygl.pos; - if (tinygl.dir == TINYGL_TEXT_DIR_ROTATE) + if (tinygl.dir == TINYGL_TEXT_DIR_ROTATE) pos.y += tinygl.scroll_pos; else pos.x -= tinygl.scroll_pos; @@ -265,7 +267,7 @@ void tinygl_text (const char *string, tinygl_point_t pos) { tinygl.message_index = 0; tinygl.scroll_pos = 0; - + /* Not much we can do without a font. */ if (!tinygl.font) return; @@ -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; + } }