/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.cc

  • Committer: edam
  • Date: 2012-02-29 21:56:32 UTC
  • Revision ID: edam@waxworlds.org-20120229215632-kypb9491vx7bicef
moved some stuf round, created a re-usable pool of message buffers, genericised "modes" for messages

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#include "display.h"
29
29
 
30
30
 
 
31
// the proportion of the display to use (in segments)
 
32
#define BIG_SEGMENTS ( NUM_SEGMENTS * 2 / 3 )
 
33
#define SMALL_SEGMENTS ( NUM_SEGMENTS - BIG_TEXT_SEGMENTS )
 
34
#define HALF_SEGMENTS ( NUM_SEGMENTS / 2 )
 
35
 
 
36
 
31
37
// the buffer for the message
32
38
char Text::_messages[ NUM_MESSAGE_BUFFERS ][ MESSAGE_BUFFER_LEN ];
33
39
 
52
58
 
53
59
void reset_message_param( int message_num )
54
60
{
55
 
        if( _message_modes[ message_num ] & Text::MODE_HSCROLL )
56
 
        {
57
 
                switch( _message_modes[ message_num ] & 0x1c )
58
 
                {
59
 
                case Text::MODE_ONEQUARTER:
60
 
                        _message_params[ message_num ] = -NUM_SEGMENTS / 4; break;
61
 
                case Text::MODE_ONETHIRD:
62
 
                        _message_params[ message_num ] = -NUM_SEGMENTS / 3; break;
63
 
                case Text::MODE_HALF:
64
 
                        _message_params[ message_num ] = -NUM_SEGMENTS / 2; break;
65
 
                case Text::MODE_TWOTHIRDS:
66
 
                        _message_params[ message_num ] = -NUM_SEGMENTS * 2 / 3; break;
67
 
                case Text::MODE_THREEQUARTERS:
68
 
                        _message_params[ message_num ] = -NUM_SEGMENTS * 3 / 4; break;
69
 
                case Text::MODE_ALL:
70
 
                        _message_params[ message_num ] = -NUM_SEGMENTS; break;
71
 
                }
72
 
        }
73
 
        else
74
 
        {
75
 
                switch( _message_modes[ message_num ] & 0x1c )
76
 
                {
77
 
                case Text::MODE_ONEQUARTER:
78
 
                        _message_params[ message_num ] = NUM_SEGMENTS / 4; break;
79
 
                case Text::MODE_ONETHIRD:
80
 
                        _message_params[ message_num ] = NUM_SEGMENTS / 3; break;
81
 
                case Text::MODE_HALF:
82
 
                        _message_params[ message_num ] = NUM_SEGMENTS / 2; break;
83
 
                case Text::MODE_TWOTHIRDS:
84
 
                        _message_params[ message_num ] = NUM_SEGMENTS * 2 / 3; break;
85
 
                case Text::MODE_THREEQUARTERS:
86
 
                        _message_params[ message_num ] = NUM_SEGMENTS * 3 / 4; break;
87
 
                case Text::MODE_ALL:
88
 
                        _message_params[ message_num ] = NUM_SEGMENTS; break;
89
 
                }
90
 
                _message_params[ message_num ] = -( _message_params[ message_num ] -
91
 
                        TextRenderer::get_width( _message_lens[ message_num ] ) ) / 2;
 
61
        switch( _message_modes[ message_num ] )
 
62
        {
 
63
        case 'S':
 
64
                _message_params[ message_num ] = -BIG_SEGMENTS;
 
65
                break;
 
66
        case 's':
 
67
                _message_params[ message_num ] = -HALF_SEGMENTS;
 
68
                break;
 
69
        case 'B':
 
70
        case 'T':
 
71
                _message_params[ message_num ] = -( BIG_SEGMENTS -
 
72
                        TextRenderer::get_width( _message_lens[ message_num ] ) ) / 2;
 
73
                break;
 
74
        case 'b':
 
75
        case 't':
 
76
                _message_params[ message_num ] = -( HALF_SEGMENTS -
 
77
                        TextRenderer::get_width( _message_lens[ message_num ] ) ) / 2;
 
78
                break;
92
79
        }
93
80
}
94
81
 
100
87
}
101
88
 
102
89
 
103
 
void Text::reset_message( int message_num, char mode )
 
90
void Text::set_message_mode( int message_num, char mode )
104
91
{
105
92
        _message_modes[ message_num ] = mode;
106
93
        reset_message_param( message_num );
189
176
        case MODE_BOTTOM:
190
177
                if( segment > ( NUM_SEGMENTS - width ) / 2 &&
191
178
                        segment < ( NUM_SEGMENTS - width ) / 2 + width )
192
 
                {
193
 
                        segment = width - ( segment - ( NUM_SEGMENTS - width ) / 2 );
194
 
                }               
 
179
                        segment -= ( NUM_SEGMENTS - width ) / 2;
195
180
                else
196
181
                        return;
197
182
                break;
201
186
        TextRenderer::render(
202
187
                _messages[ message_num ], _message_lens[ message_num ],
203
188
                (long)segment + _message_params[ message_num ],
204
 
                ( _message_modes[ message_num ] & 1 ) == 0, 0 );
 
189
                _message_modes[ message_num ] & 1 == 0, 0 );
205
190
}