/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 20:53:26 UTC
  • Revision ID: tim@ed.am-20120509205326-23nmnh3i05hotlro
moved modes to a subdirectory

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
28
 
30
29
 
31
30
// the buffer for the message
40
39
// mode-specific message parameters
41
40
static signed long _message_params[ NUM_MESSAGE_BUFFERS ];
42
41
 
 
42
// text scaling factors
 
43
static int _message_scale[ NUM_MESSAGE_BUFFERS ];
 
44
 
43
45
// time last frame
44
46
static unsigned long _last_millis;
45
47
 
49
51
// recalculate message params, based on _duration
50
52
static bool _do_draw_reset;
51
53
 
 
54
// recalculate messages parameters (after message reset)
 
55
static unsigned char _message_recalc_flags;
 
56
 
52
57
 
53
58
void reset_message_param( int message_num )
54
59
{
88
93
                        _message_params[ message_num ] = NUM_SEGMENTS; break;
89
94
                }
90
95
                _message_params[ message_num ] = -( _message_params[ message_num ] -
91
 
                        TextRenderer::get_width( _message_lens[ message_num ] ) ) / 2;
 
96
                        TextRenderer::get_width( _message_lens[ message_num ],
 
97
                                        _message_scale[ message_num ] ) ) / 2;
92
98
        }
93
99
}
94
100
 
100
106
}
101
107
 
102
108
 
103
 
void Text::reset_message( int message_num, char mode )
 
109
void Text::reset_message( int message_num, char mode, int scale )
104
110
{
105
111
        _message_modes[ message_num ] = mode;
106
 
        reset_message_param( message_num );
 
112
        _message_recalc_flags |= 1 << message_num;
 
113
        _message_scale[ message_num ] = scale;
107
114
}
108
115
 
109
116
 
113
120
        _duration = 0;
114
121
        _last_millis = ::millis();
115
122
        _do_draw_reset = false;
 
123
        _message_recalc_flags = 0;
116
124
 
117
125
        // reset the text renderer's output buffer
118
126
        TextRenderer::reset_buffer();
133
141
 
134
142
void Text::draw( int message_num, int segment )
135
143
{
 
144
        TextRenderer::buffer_in_use();
 
145
 
136
146
        // perform a mid-frame reset, as necessary
137
147
        if( _do_draw_reset && segment > NUM_SEGMENTS / 2 ) {
138
148
                _do_draw_reset = false;
139
149
 
140
 
                if( _message_modes[ message_num ] & MODE_HSCROLL )
141
 
                {
142
 
                        // 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 ) {
143
158
                        _message_params[ message_num ] +=
144
159
                                _duration * TEXT_SCROLL_SPEED / 1000;
145
160
                        long excess = _message_params[ message_num ] -
146
 
                                TextRenderer::get_width( _message_lens[ message_num ] );
 
161
                                TextRenderer::get_width( _message_lens[ message_num ],
 
162
                                                _message_scale[ message_num ] );
147
163
                        if( excess >= 0 ) {
148
164
                                reset_message_param( message_num );
149
165
                                _message_params[ message_num ] += excess;
201
217
        TextRenderer::render(
202
218
                _messages[ message_num ], _message_lens[ message_num ],
203
219
                (long)segment + _message_params[ message_num ],
204
 
                ( _message_modes[ message_num ] & 1 ) == 0, 0 );
 
220
                ( _message_modes[ message_num ] & 1 ) == 0, 0,
 
221
                _message_scale[ message_num ] );
205
222
}