/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-03-09 23:42:20 UTC
  • Revision ID: tim@ed.am-20120309234220-xr1vxzve0o5n2oss
added support for eclipse project and converted to a manual Makefile

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