/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-18 14:40:04 UTC
  • Revision ID: tim@ed.am-20120518144004-uuz2zrjmyr78wqd5
updated emacs compile command and readjusted clock shift

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();
131
139
}
132
140
 
133
141
 
 
142
void Text::post_draw()
 
143
{
 
144
        _do_draw_reset = false;
 
145
}
 
146
 
 
147
 
134
148
void Text::draw( int message_num, int segment )
135
149
{
 
150
        TextRenderer::buffer_in_use();
 
151
 
136
152
        // perform a mid-frame reset, as necessary
137
 
        if( _do_draw_reset && segment > NUM_SEGMENTS / 2 ) {
138
 
                _do_draw_reset = false;
 
153
        if( _do_draw_reset ) // && segment > NUM_SEGMENTS / 2 )
 
154
        {
 
155
                // reset message param?
 
156
                if( _message_recalc_flags & ( 1 << message_num ) ) {
 
157
                        _message_recalc_flags &= ~( 1 << message_num );
 
158
                        reset_message_param( message_num );
 
159
                }
139
160
 
140
 
                if( _message_modes[ message_num ] & MODE_HSCROLL )
141
 
                {
142
 
                        // add to horizontal scroll position
 
161
                // add to horizontal scroll position
 
162
                if( _message_modes[ message_num ] & MODE_HSCROLL ) {
143
163
                        _message_params[ message_num ] +=
144
164
                                _duration * TEXT_SCROLL_SPEED / 1000;
145
165
                        long excess = _message_params[ message_num ] -
146
 
                                TextRenderer::get_width( _message_lens[ message_num ] );
 
166
                                TextRenderer::get_width( _message_lens[ message_num ],
 
167
                                                _message_scale[ message_num ] );
147
168
                        if( excess >= 0 ) {
148
169
                                reset_message_param( message_num );
149
170
                                _message_params[ message_num ] += excess;
201
222
        TextRenderer::render(
202
223
                _messages[ message_num ], _message_lens[ message_num ],
203
224
                (long)segment + _message_params[ message_num ],
204
 
                ( _message_modes[ message_num ] & 1 ) == 0, 0 );
 
225
                ( _message_modes[ message_num ] & 1 ) == 0, 0,
 
226
                _message_scale[ message_num ] );
205
227
}