Change tinygl_text to have pos

main
Michael Hayes 14 years ago
parent 691778132b
commit c1fef5ff4c

@ -29,7 +29,7 @@ static void show_num (char ch, uint8_t count)
buffer[1] = count / 10 + '0';
buffer[2] = count % 10 + '0';
buffer[3] = 0;
tinygl_text (buffer);
tinygl_text (buffer, tinygl_point (0, 0));
}
@ -43,9 +43,9 @@ 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?");
tinygl_text ("NUM?", tinygl_point (0, 0));
pacer_init (LOOP_RATE);

@ -37,18 +37,13 @@ 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);
tinygl_text (string, tinygl_point (0, 0));
return ch;
}
@ -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 ();

@ -27,7 +27,7 @@ int main (void)
tinygl_font_set (&font5x7_1);
tinygl_text_speed_set (MESSAGE_RATE);
tinygl_text ("HELLO WORLD");
tinygl_text ("HELLO WORLD", tinygl_point (0, 0));
pacer_init (LOOP_RATE);

@ -26,9 +26,9 @@ 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");
tinygl_text ("HELLO WORLD", tinygl_point (0, 0));
pacer_init (LOOP_RATE);

@ -29,8 +29,9 @@ int main (void)
tinygl_font_set (&font5x7_1);
tinygl_text_speed_set (MESSAGE_RATE);
tinygl_text_mode_set (TINYGL_TEXT_MODE_SCROLL);
tinygl_text ("HELLO WORLD");
tinygl_text ("HELLO WORLD", tinygl_point (0, 0));
pacer_init (LOOP_RATE);
@ -48,7 +49,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);
}

@ -85,7 +85,7 @@ static void show_char (char ch)
buffer[0] = ch;
buffer[1] = 0;
tinygl_text (buffer);
tinygl_text (buffer, tinygl_point (0, 0));
}

@ -89,7 +89,7 @@ static void show_char (char ch)
buffer[0] = ch;
buffer[1] = 0;
tinygl_text (buffer);
tinygl_text (buffer, tinygl_point (0, TINYGL_HEIGHT - 1));
}
@ -99,7 +99,7 @@ static void show_num (char ch, uint8_t num)
buffer[0] = ch;
uint8toa (num, buffer + 1, 0);
tinygl_text (buffer);
tinygl_text (buffer, tinygl_point (0, TINYGL_HEIGHT - 1));
}
@ -112,7 +112,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_text_mode_set (TINYGL_TEXT_MODE_SCROLL);
tinygl_text_dir_set (TINYGL_TEXT_DIR_ROTATE);
tinygl_text_speed_set (MESSAGE_RATE);
navswitch_init ();

@ -156,7 +156,7 @@ int main (void)
pacer_init (LOOP_RATE);
tinygl_text ("X");
tinygl_text ("X", tinygl_point (0, 0));
led_set (LED1, 0);
while (1)
@ -176,7 +176,7 @@ int main (void)
if (seq != -1)
{
tinygl_text (strings[seq]);
tinygl_text (strings[seq], tinygl_point (0, 0));
transmit (&codeseqs[seq * CODESEQ_LEN_MAX]);
}
@ -199,7 +199,7 @@ int main (void)
{
if (capture (codeseq, CODESEQ_LEN_MAX))
{
tinygl_text ("?");
tinygl_text ("?", tinygl_point (0, 0));
led_set (LED1, 1);
state = STATE_STORE;
break;
@ -227,7 +227,7 @@ int main (void)
{
memcpy (&codeseqs[seq * CODESEQ_LEN_MAX], codeseq, sizeof (codeseq));
codeseqs_write (codeseqs, CODESEQ_LEN_MAX, CODESEQ_NUM);
tinygl_text (strings[seq]);
tinygl_text (strings[seq], tinygl_point (0, 0));
led_set (LED1, 0);
state = STATE_NORMAL;
}

@ -29,7 +29,7 @@ static void show_count (uint8_t count)
buffer[0] = 'S';
buffer[1] = count + '0';
buffer[2] = 0;
tinygl_text (buffer);
tinygl_text (buffer, tinygl_point (0, TINYGL_HEIGHT - 1));
}
@ -40,7 +40,7 @@ static void show_err (uint8_t err)
buffer[0] = 'E';
buffer[1] = err + '0';
buffer[2] = 0;
tinygl_text (buffer);
tinygl_text (buffer, tinygl_point (0, TINYGL_HEIGHT - 1));
}
@ -52,7 +52,8 @@ int main (void)
tinygl_init (LOOP_RATE);
tinygl_font_set (&font3x5_1);
tinygl_text_speed_set (MESSAGE_RATE);
tinygl_text_mode_set (TINYGL_TEXT_MODE_ROTATE_SCROLL_DOWN);
tinygl_text_mode_set (TINYGL_TEXT_MODE_SCROLL);
tinygl_text_dir_set (TINYGL_TEXT_DIR_ROTATE);
navswitch_init ();
ir_serial_init ();

@ -28,7 +28,7 @@ static void show_count (uint8_t count)
/* FIXME! */
buffer[0] = count + '0';
buffer[1] = 0;
tinygl_text (buffer);
tinygl_text (buffer, tinygl_point (0, 0));
}

@ -28,7 +28,7 @@ static void show_count (uint8_t count)
/* FIXME! */
buffer[0] = count + '0';
buffer[1] = 0;
tinygl_text (buffer);
tinygl_text (buffer, tinygl_point (0, 0));
}

@ -28,7 +28,7 @@ static void show_count (uint8_t count)
/* FIXME! */
buffer[0] = count + '0';
buffer[1] = 0;
tinygl_text (buffer);
tinygl_text (buffer, tinygl_point (0, 0));
}

@ -27,7 +27,7 @@ static void show_char (char ch)
buffer[0] = ch;
buffer[1] = 0;
tinygl_text (buffer);
tinygl_text (buffer, tinygl_point (0, 0));
}

@ -86,7 +86,7 @@ game_over_display (char *buffer)
*str++ = 'F';
uint8toa (spacey_shells_fired_get (), str, 0);
tinygl_clear ();
tinygl_text (buffer);
tinygl_text (buffer, tinygl_point (0, TINYGL_HEIGHT - 1));
}
@ -99,7 +99,7 @@ game_text_display (uint8_t num, char *buffer, char *msg)
*str++ = *msg++;
uint8toa (num, str, 0);
tinygl_clear ();
tinygl_text (buffer);
tinygl_text (buffer, tinygl_point (0, TINYGL_HEIGHT - 1));
}
@ -230,7 +230,8 @@ main (void)
tinygl_init (LOOP_RATE);
tinygl_font_set (&font3x5_1);
tinygl_text_mode_set (TINYGL_TEXT_MODE_ROTATE_SCROLL_DOWN);
tinygl_text_mode_set (TINYGL_TEXT_MODE_SCROLL);
tinygl_text_dir_set (TINYGL_TEXT_DIR_ROTATE);
tinygl_text_speed_set (10);
spacey_init (GAME_UPDATE_RATE, TINYGL_WIDTH, TINYGL_HEIGHT,
@ -286,7 +287,8 @@ main (void)
break;
case STATE_INIT:
tinygl_text ("SPACEY READY V" VERSION " BY MPH ");
tinygl_text ("SPACEY READY V" VERSION " BY MPH ",
tinygl_point (0, TINYGL_HEIGHT - 1));
state = STATE_READY;
break;

@ -91,7 +91,7 @@ game_over_display (char *buffer)
*str++ = '/';
uint8toa (spacey_shells_fired_get (), str, 0);
tinygl_clear ();
tinygl_text (buffer);
tinygl_text (buffer, tinygl_point (0, TINYGL_HEIGHT - 1));
}
@ -104,7 +104,7 @@ game_text_display (uint8_t num, char *buffer, char *msg)
*str++ = *msg++;
uint8toa (num, str, 0);
tinygl_clear ();
tinygl_text (buffer);
tinygl_text (buffer, tinygl_point (0, TINYGL_HEIGHT - 1));
}
@ -238,7 +238,8 @@ static void game_task (__unused__ void *data)
break;
case STATE_INIT:
tinygl_text ("SPACEY READY V" VERSION " BY MPH ");
tinygl_text ("SPACEY READY V" VERSION " BY MPH ",
tinygl_point (0, TINYGL_HEIGHT - 1));
state = STATE_READY;
break;
@ -277,7 +278,8 @@ static void display_task (__unused__ void *data)
tinygl_init (DISPLAY_UPDATE_RATE);
tinygl_font_set (&font3x5_1);
tinygl_text_mode_set (TINYGL_TEXT_MODE_ROTATE_SCROLL_DOWN);
tinygl_text_mode_set (TINYGL_TEXT_MODE_SCROLL);
tinygl_text_dir_set (TINYGL_TEXT_DIR_ROTATE);
tinygl_text_speed_set (10);
for (i = 0; i < ARRAY_SIZE (flashers); i++)

@ -152,7 +152,7 @@ game_over_display (char *buffer)
*str++ = '/';
uint8toa (spacey_shells_fired_get (), str, 0);
tinygl_clear ();
tinygl_text (buffer);
tinygl_text (buffer, tinygl_point (0, TINYGL_HEIGHT - 1));
}
@ -165,7 +165,7 @@ game_text_display (uint8_t num, char *buffer, char *msg)
*str++ = *msg++;
uint8toa (num, str, 0);
tinygl_clear ();
tinygl_text (buffer);
tinygl_text (buffer, tinygl_point (0, TINYGL_HEIGHT - 1));
}
@ -304,7 +304,8 @@ static void game_task (__unused__ void *data)
break;
case STATE_INIT:
tinygl_text ("SPACEY READY V" VERSION " BY MPH ");
tinygl_text ("SPACEY READY V" VERSION " BY MPH ",
tinygl_point (0, TINYGL_HEIGHT - 1));
mmelody_play (melody, game_intro_tune);
state = STATE_READY;
break;
@ -344,7 +345,8 @@ static void display_task (__unused__ void *data)
tinygl_init (DISPLAY_TASK_RATE);
tinygl_font_set (&font3x5_1);
tinygl_text_mode_set (TINYGL_TEXT_MODE_ROTATE_SCROLL_DOWN);
tinygl_text_mode_set (TINYGL_TEXT_MODE_SCROLL);
tinygl_text_dir_set (TINYGL_TEXT_DIR_ROTATE);
tinygl_text_speed_set (10);
for (i = 0; i < ARRAY_SIZE (flashers); i++)

@ -87,7 +87,7 @@ game_over_display (char *buffer)
*str++ = '/';
uint8toa (spacey_shells_fired_get (), str, 0);
tinygl_clear ();
tinygl_text (buffer);
tinygl_text (buffer, tinygl_point (0, TINYGL_HEIGHT - 1));
}
@ -100,7 +100,7 @@ game_text_display (uint8_t num, char *buffer, char *msg)
*str++ = *msg++;
uint8toa (num, str, 0);
tinygl_clear ();
tinygl_text (buffer);
tinygl_text (buffer, tinygl_point (0, TINYGL_HEIGHT - 1));
}
@ -241,7 +241,8 @@ main (void)
tinygl_init (LOOP_RATE);
tinygl_font_set (&font3x5_1);
tinygl_text_mode_set (TINYGL_TEXT_MODE_ROTATE_SCROLL_DOWN);
tinygl_text_mode_set (TINYGL_TEXT_MODE_SCROLL);
tinygl_text_dir_set (TINYGL_TEXT_DIR_ROTATE);
tinygl_text_speed_set (10);
navswitch_init ();
@ -302,7 +303,8 @@ main (void)
break;
case STATE_INIT:
tinygl_text ("SPACEY READY V" VERSION " BY MPH ");
tinygl_text ("SPACEY READY V" VERSION " BY MPH ",
tinygl_point (0, TINYGL_HEIGHT - 1));
state = STATE_READY;
break;

@ -38,7 +38,7 @@ int main (void)
pacer_init (LOOP_RATE);
tinygl_text ("#");
tinygl_text ("#", tinygl_point (0, 0));
/* Paced loop. */
while (1)
@ -69,11 +69,11 @@ int main (void)
switch (event)
{
case SPACEY_EVENT_ALIEN_HIT:
tinygl_text ("*");
tinygl_text ("*", tinygl_point (0, 0));
break;
case SPACEY_EVENT_ALIEN_LANDED:
tinygl_text ("@");
tinygl_text ("@", tinygl_point (0, 0));
break;
}

@ -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_text (note_names[note], tinygl_point (0, TINYGL_HEIGHT - 1));
}
@ -123,7 +123,8 @@ 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_text_mode_set (TINYGL_TEXT_MODE_SCROLL);
tinygl_text_dir_set (TINYGL_TEXT_DIR_ROTATE);
display_note ();
}

@ -51,7 +51,8 @@ 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_text (note_names[note % 12],
tinygl_point (0, TINYGL_HEIGHT - 1));
tweeter_note_play (tweeter, note, velocity);
}
@ -127,7 +128,8 @@ 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_text_mode_set (TINYGL_TEXT_MODE_SCROLL);
tinygl_text_dir_set (TINYGL_TEXT_DIR_ROTATE);
}

@ -39,9 +39,10 @@ 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_dir_set (TINYGL_TEXT_DIR_ROTATE);
tinygl_text ("HELLO WORLD ");
tinygl_text ("HELLO WORLD ", tinygl_point (0, TINYGL_HEIGHT - 1));
}

@ -23,7 +23,7 @@ static void show_count (uint8_t count)
/* FIXME! */
buffer[0] = count + '0';
buffer[1] = 0;
tinygl_text (buffer);
tinygl_text (buffer, tinygl_point (0, 0));
}

@ -24,7 +24,7 @@ static void show_count (uint8_t count)
/* FIXME! */
buffer[0] = count + '0';
buffer[1] = 0;
tinygl_text (buffer);
tinygl_text (buffer, tinygl_point (0, 0));
}

@ -50,26 +50,6 @@ bool display_pixel_get (uint8_t col, uint8_t row)
}
/** Scroll display contents one column to left. */
void display_scroll_left (void)
{
int col;
for (col = 0; col < DISPLAY_WIDTH - 1; col++)
display[col] = display[col + 1];
}
/** Scroll display contents one row down. */
void display_scroll_down (void)
{
int col;
for (col = 0; col < DISPLAY_WIDTH; col++)
display[col] <<= 1;
}
/** Update display (perform refreshing). */
void display_update (void)
{

@ -30,14 +30,6 @@ void display_pixel_set (uint8_t col, uint8_t row, bool val);
bool display_pixel_get (uint8_t col, uint8_t row);
/** Scroll display contents one column to left. */
void display_scroll_left (void);
/** Scroll display contents one row down. */
void display_scroll_down (void);
/** Update display (perform refreshing). */
void display_update (void);

@ -12,29 +12,43 @@
enum {TINYGL_SPEED_DEFAULT = 20};
static uint16_t update_rate;
static uint16_t text_advance_period;
static font_t *font;
static tinygl_text_mode_t text_mode = TINYGL_TEXT_MODE_STEP;
static uint8_t message_index;
static uint8_t scroll_pos = 0;
static char message1[TINYGL_MESSAGE_SIZE] = "";
typedef struct tinygl_state_struct
{
tinygl_text_mode_t mode;
tinygl_text_dir_t dir;
tinygl_point_t pos;
uint16_t speed;
font_t *font;
uint16_t update_rate;
uint8_t message_index;
uint16_t text_advance_period;
uint8_t scroll_pos;
char message[TINYGL_MESSAGE_SIZE];
} tinygl_state_t;
static tinygl_state_t tinygl =
{
.mode = TINYGL_TEXT_MODE_STEP,
.dir = TINYGL_TEXT_DIR_NORMAL,
.speed = TINYGL_SPEED_DEFAULT
};
/** Draw point.
@param point coordinates of point
@param pos coordinates of point
@param pixel_value pixel value for line. */
void tinygl_draw_point (tinygl_point_t point, tinygl_pixel_value_t pixel_value)
void tinygl_draw_point (tinygl_point_t pos, tinygl_pixel_value_t pixel_value)
{
display_pixel_set (point.x, point.y, pixel_value);
display_pixel_set (pos.x, pos.y, pixel_value);
}
/** Draw line.
@param point1 coordinates of start of line
@param point2 coordinates of end of line
@param pos1 coordinates of start of line
@param pos2 coordinates of end of line
@param pixel_value pixel value for line. */
void tinygl_draw_line (tinygl_point_t point1, tinygl_point_t point2,
void tinygl_draw_line (tinygl_point_t pos1, tinygl_point_t pos2,
tinygl_pixel_value_t pixel_value)
{
int dx;
@ -44,8 +58,8 @@ void tinygl_draw_line (tinygl_point_t point1, tinygl_point_t point2,
/* Draw a line using Bresenham's algorithm. */
dx = point2.x - point1.x;
dy = point2.y - point1.y;
dx = pos2.x - pos1.x;
dy = pos2.y - pos1.y;
x_inc = dx >= 0 ? 1 : -1;
y_inc = dy >= 0 ? 1 : -1;
@ -60,15 +74,15 @@ void tinygl_draw_line (tinygl_point_t point1, tinygl_point_t point2,
error = dx / 2;
for (; point1.x != point2.x; point1.x += x_inc)
for (; pos1.x != pos2.x; pos1.x += x_inc)
{
tinygl_draw_point (point1, pixel_value);
tinygl_draw_point (pos1, pixel_value);
error -= dy;
if (error < 0)
{
error += dx;
point1.y += y_inc;
pos1.y += y_inc;
}
}
}
@ -77,19 +91,19 @@ void tinygl_draw_line (tinygl_point_t point1, tinygl_point_t point2,
int error;
error = dy / 2;
for (; point1.y != point2.y; point1.y += y_inc)
for (; pos1.y != pos2.y; pos1.y += y_inc)
{
tinygl_draw_point (point1, pixel_value);
tinygl_draw_point (pos1, pixel_value);
error -= dx;
if (error < 0)
{
error += dy;
point1.x += x_inc;
pos1.x += x_inc;
}
}
}
tinygl_draw_point (point1, pixel_value);
tinygl_draw_point (pos1, pixel_value);
}
@ -113,8 +127,8 @@ void tinygl_clear (void)
display_clear ();
/* Stop message display. */
message1[0] = 0;
message_index = 0;
tinygl.message[0] = 0;
tinygl.message_index = 0;
}
@ -125,73 +139,72 @@ void tinygl_clear (void)
@return 1 if pixel on; if pixel out of bounds return 0. */
static bool tinygl_font_pixel_get (char ch, uint8_t col, uint8_t row)
{
return font_pixel_get (font, ch, col, row);
return font_pixel_get (tinygl.font, ch, col, 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
@param pos coordinates of top left position
@return position to draw next character. */
tinygl_point_t tinygl_draw_char (char ch, tinygl_point_t offset, bool rotate)
tinygl_point_t tinygl_draw_char (char ch, tinygl_point_t pos)
{
uint8_t x;
uint8_t y;
if (rotate)
if (tinygl.dir == TINYGL_TEXT_DIR_ROTATE)
{
for (x = 0; x < font->height; x++)
for (y = 0; y < tinygl.font->width; y++)
{
for (y = 0; y < font->width; y++)
for (x = 0; x < tinygl.font->height; x++)
{
tinygl_draw_point (tinygl_point (x + offset.x,
TINYGL_HEIGHT - 1 - (y + offset.y)),
tinygl_draw_point (tinygl_point (x + pos.x, pos.y),
tinygl_font_pixel_get (ch, y, x));
}
pos.y--;
}
offset.y += font->width + 1;
/* Draw blank row. */
for (x = 0; x < tinygl.font->height; x++)
tinygl_draw_point (tinygl_point (x + pos.x, pos.y), 0);
pos.y--;
}
else
{
for (x = 0; x < font->width; x++)
for (x = 0; x < tinygl.font->width; x++)
{
for (y = 0; y < font->height; y++)
for (y = 0; y < tinygl.font->height; y++)
{
tinygl_draw_point (tinygl_point (x + offset.x, y + offset.y),
tinygl_draw_point (tinygl_point (pos.x, y + pos.y),
tinygl_font_pixel_get (ch, x, y));
}
pos.x++;
}
offset.x += font->width + 1;
/* Draw blank column. */
for (y = 0; y < tinygl.font->height; y++)
tinygl_draw_point (tinygl_point (pos.x, y + pos.y), 0);
pos.x++;
}
return offset;
return pos;
}
/** 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
@param pos coordinates of top left position
@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 pos)
{
uint8_t count = 0;
while (*str)
{
if (rotate)
{
if (offset.y + font->width > TINYGL_HEIGHT)
break;
tinygl_draw_char (*str, offset, 1);
}
else
{
if (offset.x + font->width > TINYGL_WIDTH)
break;
tinygl_draw_char (*str, offset, 0);
}
pos = tinygl_draw_char (*str, pos);
if (pos.x >= TINYGL_WIDTH || pos.y < 0)
break;
count++;
str++;
}
@ -199,85 +212,70 @@ 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)
/** Advance message. */
static void tinygl_text_advance (void)
{
uint8_t x;
uint8_t y;
if (!font)
return 0;
switch (text_mode)
if (!tinygl.message[tinygl.message_index])
{
case TINYGL_TEXT_MODE_SCROLL_LEFT:
display_scroll_left ();
for (y = 0; y < font->height; y++)
tinygl.message_index = 0;
}
if (tinygl.message[tinygl.message_index])
{
tinygl_point_t pos;
switch (tinygl.mode)
{
tinygl_draw_point (tinygl_point (TINYGL_WIDTH - 1, y),
tinygl_font_pixel_get (ch, scroll_pos, y));
}
break;
case TINYGL_TEXT_MODE_STEP:
if (tinygl.scroll_pos != 0)
break;
case TINYGL_TEXT_MODE_STEP:
if (scroll_pos != 0)
/* In step mode, display a single character. */
tinygl_draw_char (tinygl.message[tinygl.message_index], tinygl.pos);
break;
tinygl_draw_char (ch, tinygl_point (0, 0), 0);
break;
case TINYGL_TEXT_MODE_SCROLL:
pos = tinygl.pos;
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;
if (tinygl.dir == TINYGL_TEXT_DIR_ROTATE)
pos.y += tinygl.scroll_pos;
else
pos.x -= tinygl.scroll_pos;
case TINYGL_TEXT_MODE_ROTATE_STEP:
if (scroll_pos != 0)
/* In scroll mode, display as much as the string that will
fit on the display then scroll the reset. */
tinygl_draw_string (tinygl.message + tinygl.message_index, pos);
break;
}
tinygl_draw_char (ch, tinygl_point (0, 0), 1);
break;
tinygl.scroll_pos++;
if (tinygl.scroll_pos > tinygl.font->width)
{
tinygl.scroll_pos = 0;
tinygl.message_index++;
}
}
scroll_pos++;
if (scroll_pos > font->width)
scroll_pos = 0;
return scroll_pos == 0;
}
/** Advance message. */
static void tinygl_text_advance (void)
/** Display a message repeatedly.
@param string null terminated message to display
@param pos position on screen. */
void tinygl_text (const char *string, tinygl_point_t pos)
{
if (!message1[message_index])
{
message_index = 0;
}
tinygl.message_index = 0;
tinygl.scroll_pos = 0;
if (message1[message_index])
{
if (tinygl_display_char (message1[message_index]))
message_index++;
}
}
/* Not much we can do without a font. */
if (!tinygl.font)
return;
tinygl.text_advance_period = tinygl.update_rate /
(tinygl.speed * tinygl.font->width) * 10;
/** Display a message repeatedly.
@param string null terminated message to display. */
void tinygl_text (const char *string)
{
message_index = 0;
scroll_pos = 0;
strncpy (message1, string, sizeof (message1));
tinygl.pos = pos;
strncpy (tinygl.message, string, sizeof (tinygl.message));
}
@ -285,7 +283,7 @@ void tinygl_text (const char *string)
@param speed text advance speed (characters per 10 s). */
void tinygl_text_speed_set (uint8_t speed)
{
text_advance_period = update_rate / (speed * TINYGL_WIDTH) * 10;
tinygl.speed = speed;
}
@ -293,15 +291,23 @@ void tinygl_text_speed_set (uint8_t speed)
@param mode display mode. */
void tinygl_text_mode_set (tinygl_text_mode_t mode)
{
text_mode = mode;
tinygl.mode = mode;
}
/** Set the message display direction.
@param dir display direction. */
void tinygl_text_dir_set (tinygl_text_dir_t dir)
{
tinygl.dir = dir;
}
/** Set the font to use for text.
@param pfont pointer to font description. */
void tinygl_font_set (font_t *pfont)
@param font pointer to font description. */
void tinygl_font_set (font_t *font)
{
font = pfont;
tinygl.font = font;
}
@ -311,7 +317,7 @@ void tinygl_update (void)
static uint16_t tick = 0;
tick++;
if (tick >= text_advance_period)
if (tick >= tinygl.text_advance_period)
{
tick = 0;
@ -326,7 +332,7 @@ void tinygl_update (void)
@param rate rate in Hz that tinygl_update called. */
void tinygl_init (uint16_t rate)
{
update_rate = rate;
tinygl.update_rate = rate;
display_init ();

@ -56,8 +56,8 @@
tinygl_font_set (&font5x7_1);
tinygl_text_speed_set (10);
tinygl_text_mode_set (TINYGL_TEXT_MODE_SCROLL_LEFT);
tinygl_text ("HELLO WORLD ");
tinygl_text_mode_set (TINYGL_TEXT_MODE_SCROLL);
tinygl_text ("HELLO WORLD ", tinygl_point (0, 0));
while (1)
{
@ -110,14 +110,20 @@ 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;
/** Define text display directions. */
typedef enum
{
/* Normal text. */
TINYGL_TEXT_DIR_NORMAL,
/** Rotated text. */
TINYGL_TEXT_DIR_ROTATE,
} tinygl_text_dir_t;
/** Construct a point from a pair of coordinates.
@param x x coordinate
@param y y coordinate
@ -131,8 +137,9 @@ static inline tinygl_point_t tinygl_point (tinygl_coord_t x, tinygl_coord_t y)
/** Display a message repeatedly.
@param string null terminated message to display. */
void tinygl_text (const char *string);
@param string null terminated message to display
@param pos position on screen. */
void tinygl_text (const char *string, tinygl_point_t pos);
/** Set the message update speed.
@ -145,6 +152,11 @@ void tinygl_text_speed_set (uint8_t speed);
void tinygl_text_mode_set (tinygl_text_mode_t mode);
/** Set the message display direction.
@param dir display direction. */
void tinygl_text_dir_set (tinygl_text_dir_t dir);
/** Set the font to use for text.
@param pfont pointer to font description. */
void tinygl_font_set (font_t *pfont);
@ -152,31 +164,29 @@ 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
@param pos coordinates of top left position
@return position to draw next character. */
tinygl_point_t tinygl_draw_char (char ch, tinygl_point_t offset, bool rotate);
tinygl_point_t tinygl_draw_char (char ch, tinygl_point_t pos);
/** 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
@param pos coordinates of top left position
@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 pos);
/** Draw point.
@param point coordinates of point
@param pos coordinates of point
@param pixel_value pixel value to draw point. */
void tinygl_draw_point (tinygl_point_t point, tinygl_pixel_value_t pixel_value);
void tinygl_draw_point (tinygl_point_t pos, tinygl_pixel_value_t pixel_value);
/** Draw line.
@param point1 coordinates of start of line
@param point2 coordinates of end of line
@param pos1 coordinates of start of line
@param pos2 coordinates of end of line
@param pixel_value pixel value to draw line. */
void tinygl_draw_line (tinygl_point_t point1, tinygl_point_t point2,
void tinygl_draw_line (tinygl_point_t pos1, tinygl_point_t pos2,
tinygl_pixel_value_t pixel_value);

Loading…
Cancel
Save