Simplify tinygl API by removing rotate options and using rotated font instead
This commit is contained in:
@@ -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?");
|
||||
|
||||
|
||||
@@ -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 ();
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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 ();
|
||||
|
||||
@@ -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 ();
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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++)
|
||||
|
||||
@@ -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++)
|
||||
|
||||
@@ -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 ();
|
||||
|
||||
@@ -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 ();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -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 ");
|
||||
}
|
||||
|
||||
+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