37
46
static int _font = 0;
40
static unsigned char _output_buffer;
49
static unsigned long _last_millis;
51
// duration last frame (in case we can't calculate it this frame!)
52
static unsigned long _duration;
54
// scroll position (in segments )
55
static signed long _scroll;
350
int TextRenderer::get_width( int message_len )
365
// convert segment to display-space segment
366
int xform_segment( int segment )
352
return message_len * 8 * TEXT_SCALE;
368
if( segment < TEXT_DISPLAY_SEGMENTS / 2 )
369
return segment + TEXT_DISPLAY_SEGMENTS / 2;
370
else if( segment >= NUM_SEGMENTS - TEXT_DISPLAY_SEGMENTS / 2 )
371
return segment - ( NUM_SEGMENTS - TEXT_DISPLAY_SEGMENTS / 2 );
356
void TextRenderer::render( const char *message, int message_len, int x,
357
bool y_flip, int y_shift )
377
// draw a column of pixels from the current message
361
380
// handle negative x
368
if( pos < message_len )
370
// ensure correct glyph is cached and pull out colun of data
371
cache_glyph( message[ pos ] );
372
glyph_col = _glyph_cache[ x % 8 ];
389
// make sure the correct glyph is cached
391
cache_glyph( ( pos >= 0 && pos < (signed)_message.length() )? _message[ pos ] : ' ' );
378
for( int a = 7; a >= 0; a-- ) {
380
_output_buffer |= 1 << ( a + y_shift );
394
char col_data = _glyph_cache[ x % 8 ];
395
for( int a = 0; a < 8; a++ )
396
Display::led( 8 - a, ( col_data & ( 1 << a ) )? true : false );
400
PString &TextRenderer::get_pstring()
404
_last_millis = ::millis();
405
_scroll = -TEXT_DISPLAY_SEGMENTS;
411
void TextRenderer::draw_reset()
413
// how many milliseconds have elapsed since last frame?
414
unsigned long millis = ::millis();
415
if( millis > _last_millis )
416
_duration = millis - _last_millis;
417
_last_millis = millis;
419
// move on scroll pos
420
_scroll += ( _duration * TEXT_SCROLL_SPEED / 1000 );
421
if( _scroll > (signed long)_message.length() * 8 * TEXT_SCALE )
422
_scroll -= (signed long)_message.length() * 8 * TEXT_SCALE + TEXT_DISPLAY_SEGMENTS;
426
void TextRenderer::draw_scroll( int segment )
428
segment = xform_segment( segment );
384
for( int a = 0; a < 8; a++ ) {
386
_output_buffer |= 1 << ( a + y_shift );
392
void TextRenderer::reset_buffer()
398
void TextRenderer::output_buffer()
400
for( int a = 8; a >= 0; a-- ) {
401
Display::led( a, ( _output_buffer & 1 )? true : false );
402
_output_buffer >>= 1;
408
void TextRenderer::select_font( int font_num )
432
render( (long)segment + _scroll );