/elec/propeller-clock

To get this branch, use:
bzr branch http://bzr.ed.am/elec/propeller-clock

« back to all changes in this revision

Viewing changes to src/text_renderer.cc

  • Committer: Tim Marston
  • Date: 2012-05-09 20:36:07 UTC
  • Revision ID: tim@ed.am-20120509203607-5sh14qikxjmm6p3y
updated arduino.mk

Show diffs side-by-side

added added

removed removed

25
25
#include "Arduino.h"
26
26
#include <avr/pgmspace.h>
27
27
#include "common.h"
 
28
#include "nvram.h"
28
29
 
29
30
 
30
31
// cached glyph
39
40
// output buffer
40
41
static unsigned char _output_buffer;
41
42
 
 
43
// does buffer need rendering?
 
44
static bool _need_render;
 
45
 
42
46
 
43
47
// cache a glyph
44
48
void cache_glyph( char c )
347
351
}
348
352
 
349
353
 
350
 
int TextRenderer::get_width( int message_len )
351
 
{
352
 
        return message_len * 8 * TEXT_SCALE;
 
354
void TextRenderer::init()
 
355
{
 
356
        Nvram::load( Nvram::NVRAM_FONT, _font );
 
357
        if( _font < 0 || _font >= 4 ) _font = 0;
 
358
}
 
359
 
 
360
 
 
361
int TextRenderer::get_width( int message_len, int scale )
 
362
{
 
363
        return message_len * 8 * scale;
353
364
}
354
365
 
355
366
 
356
367
void TextRenderer::render( const char *message, int message_len, int x,
357
 
                                                   bool y_flip, int y_shift )
 
368
                                                   bool y_flip, int y_shift, int scale )
358
369
{
359
370
        char glyph_col = 0;
360
371
 
362
373
        if( x >= 0 )
363
374
        {
364
375
                // scale font
365
 
                x /= TEXT_SCALE;
 
376
                x /= scale;
366
377
 
367
378
                int pos = x / 8;
368
379
                if( pos < message_len )
369
380
                {
370
 
                        // ensure correct glyph is cached and pull out colun of data
 
381
                        // ensure correct glyph is cached and pull out column of data
371
382
                        cache_glyph( message[ pos ] );
372
383
                        glyph_col = _glyph_cache[ x % 8 ];
373
384
                }
392
403
void TextRenderer::reset_buffer()
393
404
{
394
405
        _output_buffer = 0;
 
406
        _need_render = false;
 
407
}
 
408
 
 
409
 
 
410
void TextRenderer::buffer_in_use()
 
411
{
 
412
        _need_render = true;
395
413
}
396
414
 
397
415
 
398
416
void TextRenderer::output_buffer()
399
417
{
 
418
        if( !_need_render ) return;
 
419
 
400
420
        for( int a = 8; a >= 0; a-- ) {
401
421
                led( a, ( _output_buffer & 1 )? true : false );
402
422
                _output_buffer >>= 1;
405
425
}
406
426
 
407
427
 
408
 
void TextRenderer::select_font( int font_num )
409
 
{
410
 
        _font = font_num;
 
428
int TextRenderer::get_font()
 
429
{
 
430
        return _font;
 
431
}
 
432
 
 
433
 
 
434
void TextRenderer::inc_font()
 
435
{
 
436
        if( ++_font >= 4 )
 
437
                _font = 0;
 
438
        Nvram::save( Nvram::NVRAM_FONT, _font );
411
439
}