/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: Tim Marston
  • Date: 2012-05-09 21:36:01 UTC
  • Revision ID: tim@ed.am-20120509213601-kk1tqa9yg4xk45y9
added info mode, a '/' to the fonts and cleaned up a couple of bits

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include "config.h"
26
26
#include "Arduino.h"
27
27
#include <avr/pgmspace.h>
28
 
#include "display.h"
29
 
 
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
28
 
36
29
 
37
30
// the buffer for the message
46
39
// mode-specific message parameters
47
40
static signed long _message_params[ NUM_MESSAGE_BUFFERS ];
48
41
 
 
42
// text scaling factors
 
43
static int _message_scale[ NUM_MESSAGE_BUFFERS ];
 
44
 
49
45
// time last frame
50
46
static unsigned long _last_millis;
51
47
 
55
51
// recalculate message params, based on _duration
56
52
static bool _do_draw_reset;
57
53
 
 
54
// recalculate messages parameters (after message reset)
 
55
static unsigned char _message_recalc_flags;
 
56
 
58
57
 
59
58
void reset_message_param( int message_num )
60
59
{
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;
 
60
        if( _message_modes[ message_num ] & Text::MODE_HSCROLL )
 
61
        {
 
62
                switch( _message_modes[ message_num ] & 0x1c )
 
63
                {
 
64
                case Text::MODE_ONEQUARTER:
 
65
                        _message_params[ message_num ] = -NUM_SEGMENTS / 4; break;
 
66
                case Text::MODE_ONETHIRD:
 
67
                        _message_params[ message_num ] = -NUM_SEGMENTS / 3; break;
 
68
                case Text::MODE_HALF:
 
69
                        _message_params[ message_num ] = -NUM_SEGMENTS / 2; break;
 
70
                case Text::MODE_TWOTHIRDS:
 
71
                        _message_params[ message_num ] = -NUM_SEGMENTS * 2 / 3; break;
 
72
                case Text::MODE_THREEQUARTERS:
 
73
                        _message_params[ message_num ] = -NUM_SEGMENTS * 3 / 4; break;
 
74
                case Text::MODE_ALL:
 
75
                        _message_params[ message_num ] = -NUM_SEGMENTS; break;
 
76
                }
 
77
        }
 
78
        else
 
79
        {
 
80
                switch( _message_modes[ message_num ] & 0x1c )
 
81
                {
 
82
                case Text::MODE_ONEQUARTER:
 
83
                        _message_params[ message_num ] = NUM_SEGMENTS / 4; break;
 
84
                case Text::MODE_ONETHIRD:
 
85
                        _message_params[ message_num ] = NUM_SEGMENTS / 3; break;
 
86
                case Text::MODE_HALF:
 
87
                        _message_params[ message_num ] = NUM_SEGMENTS / 2; break;
 
88
                case Text::MODE_TWOTHIRDS:
 
89
                        _message_params[ message_num ] = NUM_SEGMENTS * 2 / 3; break;
 
90
                case Text::MODE_THREEQUARTERS:
 
91
                        _message_params[ message_num ] = NUM_SEGMENTS * 3 / 4; break;
 
92
                case Text::MODE_ALL:
 
93
                        _message_params[ message_num ] = NUM_SEGMENTS; break;
 
94
                }
 
95
                _message_params[ message_num ] = -( _message_params[ message_num ] -
 
96
                        TextRenderer::get_width( _message_lens[ message_num ],
 
97
                                        _message_scale[ message_num ] ) ) / 2;
79
98
        }
80
99
}
81
100
 
87
106
}
88
107
 
89
108
 
90
 
void Text::set_message_mode( int message_num, char mode )
 
109
void Text::reset_message( int message_num, char mode, int scale )
91
110
{
92
111
        _message_modes[ message_num ] = mode;
93
 
        reset_message_param( message_num );
 
112
        _message_recalc_flags |= 1 << message_num;
 
113
        _message_scale[ message_num ] = scale;
94
114
}
95
115
 
96
116
 
100
120
        _duration = 0;
101
121
        _last_millis = ::millis();
102
122
        _do_draw_reset = false;
 
123
        _message_recalc_flags = 0;
103
124
 
104
125
        // reset the text renderer's output buffer
105
126
        TextRenderer::reset_buffer();
120
141
 
121
142
void Text::draw( int message_num, int segment )
122
143
{
 
144
        TextRenderer::buffer_in_use();
 
145
 
123
146
        // perform a mid-frame reset, as necessary
124
147
        if( _do_draw_reset && segment > NUM_SEGMENTS / 2 ) {
125
148
                _do_draw_reset = false;
126
149
 
127
 
                if( _message_modes[ message_num ] & MODE_HSCROLL )
128
 
                {
129
 
                        // add to horizontal scroll position
 
150
                // reset message param?
 
151
                if( _message_recalc_flags & ( 1 << message_num ) ) {
 
152
                        _message_recalc_flags &= ~( 1 << message_num );
 
153
                        reset_message_param( message_num );
 
154
                }
 
155
 
 
156
                // add to horizontal scroll position
 
157
                if( _message_modes[ message_num ] & MODE_HSCROLL ) {
130
158
                        _message_params[ message_num ] +=
131
159
                                _duration * TEXT_SCROLL_SPEED / 1000;
132
160
                        long excess = _message_params[ message_num ] -
133
 
                                TextRenderer::get_width( _message_lens[ message_num ] );
 
161
                                TextRenderer::get_width( _message_lens[ message_num ],
 
162
                                                _message_scale[ message_num ] );
134
163
                        if( excess >= 0 ) {
135
164
                                reset_message_param( message_num );
136
165
                                _message_params[ message_num ] += excess;
176
205
        case MODE_BOTTOM:
177
206
                if( segment > ( NUM_SEGMENTS - width ) / 2 &&
178
207
                        segment < ( NUM_SEGMENTS - width ) / 2 + width )
179
 
                        segment -= ( NUM_SEGMENTS - width ) / 2;
 
208
                {
 
209
                        segment = width - ( segment - ( NUM_SEGMENTS - width ) / 2 );
 
210
                }               
180
211
                else
181
212
                        return;
182
213
                break;
186
217
        TextRenderer::render(
187
218
                _messages[ message_num ], _message_lens[ message_num ],
188
219
                (long)segment + _message_params[ message_num ],
189
 
                _message_modes[ message_num ] & 1 == 0, 0 );
 
220
                ( _message_modes[ message_num ] & 1 ) == 0, 0,
 
221
                _message_scale[ message_num ] );
190
222
}