diff --git a/apps/chooser/chooser.c b/apps/chooser/chooser.c index df49185..3d188a9 100644 --- a/apps/chooser/chooser.c +++ b/apps/chooser/chooser.c @@ -43,7 +43,7 @@ int main (void) tinygl_font_set (&font5x7_1); tinygl_text_speed_set (MESSAGE_RATE); - tinygl_text_mode_set (TINYGL_TEXT_MODE_SCROLL_LEFT); + tinygl_text_mode_set (TINYGL_TEXT_MODE_SCROLL); tinygl_text ("NUM?"); diff --git a/apps/fonttest1/fonttest1.c b/apps/fonttest1/fonttest1.c index 33db503..ac4f3a3 100644 --- a/apps/fonttest1/fonttest1.c +++ b/apps/fonttest1/fonttest1.c @@ -37,15 +37,10 @@ static void choose_font (int font_num) } -static char show_char (int font_num, char ch) +static char show_char (char ch) { char string[2]; - if (ch < FONT_FIRST (fonts[font_num])) - ch = FONT_LAST (fonts[font_num]); - else if (ch > FONT_LAST (fonts[font_num])) - ch = FONT_FIRST (fonts[font_num]); - string[0] = ch; string[1] = 0; tinygl_text (string); @@ -68,7 +63,7 @@ int main (void) choose_font (font_num); tinygl_text_speed_set (10); - c = show_char (font_num, c); + c = show_char (c); /* Paced loop. */ while (1) @@ -85,17 +80,19 @@ int main (void) font_num = 0; choose_font (font_num); - c = show_char (font_num, c); + c = show_char (c); } else if (navswitch_push_event_p (NAVSWITCH_WEST) || navswitch_push_event_p (NAVSWITCH_SOUTH)) { - c = show_char (font_num, c - 1); + if (font_contains_p (fonts[font_num], c - 1)) + c = show_char (c - 1); } else if (navswitch_push_event_p (NAVSWITCH_EAST) || navswitch_push_event_p (NAVSWITCH_NORTH)) { - c = show_char (font_num, c + 1); + if (font_contains_p (fonts[font_num], c + 1)) + c = show_char (c + 1); } tinygl_update (); diff --git a/apps/hello3/hello3.c b/apps/hello3/hello3.c index aca1cca..3cae5e2 100644 --- a/apps/hello3/hello3.c +++ b/apps/hello3/hello3.c @@ -26,7 +26,7 @@ int main (void) tinygl_font_set (&font5x7_1); tinygl_text_speed_set (MESSAGE_RATE); - tinygl_text_mode_set (TINYGL_TEXT_MODE_SCROLL_LEFT); + tinygl_text_mode_set (TINYGL_TEXT_MODE_SCROLL); tinygl_text ("HELLO WORLD"); diff --git a/apps/hello4/hello4.c b/apps/hello4/hello4.c index e981028..c76ab4c 100644 --- a/apps/hello4/hello4.c +++ b/apps/hello4/hello4.c @@ -48,7 +48,7 @@ int main (void) tinygl_text_mode_set (TINYGL_TEXT_MODE_STEP); if (navswitch_push_event_p (NAVSWITCH_EAST)) - tinygl_text_mode_set (TINYGL_TEXT_MODE_SCROLL_LEFT); + tinygl_text_mode_set (TINYGL_TEXT_MODE_SCROLL); } diff --git a/apps/ir_grab2/ir_grab2.c b/apps/ir_grab2/ir_grab2.c index 98c31c7..51aba11 100644 --- a/apps/ir_grab2/ir_grab2.c +++ b/apps/ir_grab2/ir_grab2.c @@ -13,7 +13,7 @@ #include "ir.h" #include "delay.h" #include "uint8toa.h" -#include "../fonts/font3x5_1.h" +#include "../fonts/font3x5_1_r.h" /* Define polling rate in Hz. */ @@ -111,8 +111,8 @@ int main (void) system_init (); tinygl_init (LOOP_RATE); - tinygl_font_set (&font3x5_1); - tinygl_text_mode_set (TINYGL_TEXT_MODE_ROTATE_SCROLL_DOWN); + tinygl_font_set (&font3x5_1_r); + tinygl_text_mode_set (TINYGL_TEXT_MODE_SCROLL); tinygl_text_speed_set (MESSAGE_RATE); navswitch_init (); diff --git a/apps/ir_serial_test1/ir_serial_test1.c b/apps/ir_serial_test1/ir_serial_test1.c index aa27c62..fa0f991 100644 --- a/apps/ir_serial_test1/ir_serial_test1.c +++ b/apps/ir_serial_test1/ir_serial_test1.c @@ -11,7 +11,7 @@ #include "tinygl.h" #include "pacer.h" #include "ir_serial.h" -#include "../fonts/font3x5_1.h" +#include "../fonts/font3x5_1_r.h" /* Define polling rate in Hz. */ @@ -50,9 +50,9 @@ int main (void) system_init (); tinygl_init (LOOP_RATE); - tinygl_font_set (&font3x5_1); + tinygl_font_set (&font3x5_1_r); tinygl_text_speed_set (MESSAGE_RATE); - tinygl_text_mode_set (TINYGL_TEXT_MODE_ROTATE_SCROLL_DOWN); + tinygl_text_mode_set (TINYGL_TEXT_MODE_SCROLL); navswitch_init (); ir_serial_init (); diff --git a/apps/space10/space10.c b/apps/space10/space10.c index a433146..55cdc2b 100644 --- a/apps/space10/space10.c +++ b/apps/space10/space10.c @@ -17,7 +17,7 @@ #include "spacey.h" #include "eeprom.h" #include "uint8toa.h" -#include "../fonts/font3x5_1.h" +#include "../fonts/font3x5_1_r.h" #define VERSION "1.6" @@ -229,8 +229,8 @@ main (void) &flasher_patterns[FLASH_MODE_ALIEN]); tinygl_init (LOOP_RATE); - tinygl_font_set (&font3x5_1); - tinygl_text_mode_set (TINYGL_TEXT_MODE_ROTATE_SCROLL_DOWN); + tinygl_font_set (&font3x5_1_r); + tinygl_text_mode_set (TINYGL_TEXT_MODE_SCROLL); tinygl_text_speed_set (10); spacey_init (GAME_UPDATE_RATE, TINYGL_WIDTH, TINYGL_HEIGHT, diff --git a/apps/space11/space11.c b/apps/space11/space11.c index a903164..921828d 100644 --- a/apps/space11/space11.c +++ b/apps/space11/space11.c @@ -17,7 +17,7 @@ #include "spacey.h" #include "eeprom.h" #include "uint8toa.h" -#include "../fonts/font3x5_1.h" +#include "../fonts/font3x5_1_r.h" #define VERSION "1.6" @@ -276,8 +276,8 @@ static void display_task (__unused__ void *data) uint8_t i; tinygl_init (DISPLAY_UPDATE_RATE); - tinygl_font_set (&font3x5_1); - tinygl_text_mode_set (TINYGL_TEXT_MODE_ROTATE_SCROLL_DOWN); + tinygl_font_set (&font3x5_1_r); + tinygl_text_mode_set (TINYGL_TEXT_MODE_SCROLL); tinygl_text_speed_set (10); for (i = 0; i < ARRAY_SIZE (flashers); i++) diff --git a/apps/space12/space12.c b/apps/space12/space12.c index fd8f7f0..6d8c988 100644 --- a/apps/space12/space12.c +++ b/apps/space12/space12.c @@ -17,7 +17,7 @@ #include "spacey.h" #include "eeprom.h" #include "uint8toa.h" -#include "../fonts/font3x5_1.h" +#include "../fonts/font3x5_1_r.h" #include "tweeter.h" #include "mmelody.h" #include "pio.h" @@ -343,8 +343,8 @@ static void display_task (__unused__ void *data) uint8_t i; tinygl_init (DISPLAY_TASK_RATE); - tinygl_font_set (&font3x5_1); - tinygl_text_mode_set (TINYGL_TEXT_MODE_ROTATE_SCROLL_DOWN); + tinygl_font_set (&font3x5_1_r); + tinygl_text_mode_set (TINYGL_TEXT_MODE_SCROLL); tinygl_text_speed_set (10); for (i = 0; i < ARRAY_SIZE (flashers); i++) diff --git a/apps/space9/space9.c b/apps/space9/space9.c index dbeef3d..2517194 100644 --- a/apps/space9/space9.c +++ b/apps/space9/space9.c @@ -17,7 +17,7 @@ #include "spacey.h" #include "eeprom.h" #include "uint8toa.h" -#include "../fonts/font3x5_1.h" +#include "../fonts/font3x5_1_r.h" #define VERSION "1.6" @@ -240,8 +240,8 @@ main (void) &flasher_patterns[FLASH_MODE_ALIEN]); tinygl_init (LOOP_RATE); - tinygl_font_set (&font3x5_1); - tinygl_text_mode_set (TINYGL_TEXT_MODE_ROTATE_SCROLL_DOWN); + tinygl_font_set (&font3x5_1_r); + tinygl_text_mode_set (TINYGL_TEXT_MODE_SCROLL); tinygl_text_speed_set (10); navswitch_init (); diff --git a/apps/squeak3/squeak3.c b/apps/squeak3/squeak3.c index 5804143..eee2f30 100644 --- a/apps/squeak3/squeak3.c +++ b/apps/squeak3/squeak3.c @@ -11,7 +11,7 @@ #include "task.h" #include "tweeter.h" #include "tinygl.h" -#include "../fonts/font3x5_1.h" +#include "../fonts/font3x5_1_r.h" /* Connect piezo tweeter to outermost pins of UCFK4 P1 connector. */ @@ -77,7 +77,7 @@ static void button_task_init (void) static void display_note (void) { tinygl_clear (); - tinygl_draw_string (note_names[note], tinygl_point (0, 0), 1); + tinygl_draw_string (note_names[note], tinygl_point (0, 0)); } @@ -122,8 +122,8 @@ static void button_task (__unused__ void *data) static void display_task_init (void) { tinygl_init (DISPLAY_TASK_RATE); - tinygl_font_set (&font3x5_1); - tinygl_text_mode_set (TINYGL_TEXT_MODE_ROTATE_STEP); + tinygl_font_set (&font3x5_1_r); + tinygl_text_mode_set (TINYGL_TEXT_MODE_STEP); display_note (); } diff --git a/apps/squeak4/squeak4.c b/apps/squeak4/squeak4.c index 3cc1f44..06ce5f3 100644 --- a/apps/squeak4/squeak4.c +++ b/apps/squeak4/squeak4.c @@ -11,7 +11,7 @@ #include "tweeter.h" #include "mmelody.h" #include "tinygl.h" -#include "../fonts/font3x5_1.h" +#include "../fonts/font3x5_1_r.h" /* Connect piezo tweeter to outermost pins of UCFK4 P1 connector. */ @@ -51,7 +51,7 @@ note_play (tweeter_t tweeter, tweeter_note_t note, uint8_t velocity) { tinygl_clear (); if (note != 0 && velocity != 0) - tinygl_draw_string (note_names[note % 12], tinygl_point (0, 0), 1); + tinygl_draw_string (note_names[note % 12], tinygl_point (0, 0)); tweeter_note_play (tweeter, note, velocity); } @@ -126,8 +126,8 @@ static void button_task (__unused__ void *data) static void display_task_init (void) { tinygl_init (DISPLAY_TASK_RATE); - tinygl_font_set (&font3x5_1); - tinygl_text_mode_set (TINYGL_TEXT_MODE_ROTATE_STEP); + tinygl_font_set (&font3x5_1_r); + tinygl_text_mode_set (TINYGL_TEXT_MODE_STEP); } diff --git a/apps/task2/task2.c b/apps/task2/task2.c index 6de0409..3aea31c 100644 --- a/apps/task2/task2.c +++ b/apps/task2/task2.c @@ -39,7 +39,7 @@ static void display_task_init (void) tinygl_init (DISPLAY_TASK_RATE); tinygl_font_set (&font5x7_1); tinygl_text_speed_set (MESSAGE_RATE); - tinygl_text_mode_set (TINYGL_TEXT_MODE_SCROLL_LEFT); + tinygl_text_mode_set (TINYGL_TEXT_MODE_SCROLL); tinygl_text ("HELLO WORLD "); } diff --git a/utils/tinygl.c b/utils/tinygl.c index 07d6eab..5cbfcec 100644 --- a/utils/tinygl.c +++ b/utils/tinygl.c @@ -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->height; x++) - { - 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 (x = 0; x < font->width; x++) + for (y = 0; y < font->height; y++) { - 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; diff --git a/utils/tinygl.h b/utils/tinygl.h index 185e50e..0aae922 100644 --- a/utils/tinygl.h +++ b/utils/tinygl.h @@ -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