/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-17 22:48:38 UTC
  • Revision ID: tim@ed.am-20120517224838-25hjd6umh35vmtwn
updated arduino.mk

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
static signed long _message_params[ NUM_MESSAGE_BUFFERS ];
41
41
 
42
42
// text scaling factors
43
 
static char _message_scale[ NUM_MESSAGE_BUFFERS ];
 
43
static int _message_scale[ NUM_MESSAGE_BUFFERS ];
44
44
 
45
45
// time last frame
46
46
static unsigned long _last_millis;
51
51
// recalculate message params, based on _duration
52
52
static bool _do_draw_reset;
53
53
 
 
54
// recalculate messages parameters (after message reset)
 
55
static unsigned char _message_recalc_flags;
54
56
 
55
 
#define MASK_MODE_SIZE 0x07
56
 
#define MASK_MODE_POS 0x40
57
57
 
58
58
void reset_message_param( int message_num )
59
59
{
60
60
        if( _message_modes[ message_num ] & Text::MODE_HSCROLL )
61
61
        {
62
 
                switch( _message_modes[ message_num ] & MASK_MODE_SIZE )
 
62
                switch( _message_modes[ message_num ] & 0x1c )
63
63
                {
64
64
                case Text::MODE_ONEQUARTER:
65
65
                        _message_params[ message_num ] = -NUM_SEGMENTS / 4; break;
77
77
        }
78
78
        else
79
79
        {
80
 
                switch( _message_modes[ message_num ] & MASK_MODE_SIZE )
 
80
                switch( _message_modes[ message_num ] & 0x1c )
81
81
                {
82
82
                case Text::MODE_ONEQUARTER:
83
83
                        _message_params[ message_num ] = NUM_SEGMENTS / 4; break;
99
99
}
100
100
 
101
101
 
 
102
void Text::set_message( int message_num, PString &pstring )
 
103
{
 
104
        // update message
 
105
        _message_lens[ message_num ] = pstring.length();
 
106
}
 
107
 
 
108
 
 
109
void Text::reset_message( int message_num, char mode, int scale )
 
110
{
 
111
        _message_modes[ message_num ] = mode;
 
112
        _message_recalc_flags |= 1 << message_num;
 
113
        _message_scale[ message_num ] = scale;
 
114
}
 
115
 
 
116
 
102
117
void Text::reset()
103
118
{
104
119
        // reset renderer
105
120
        _duration = 0;
106
121
        _last_millis = ::millis();
107
122
        _do_draw_reset = false;
108
 
 
109
 
        // clear all message modes (disable messages)
110
 
        for( int a = 0; a < NUM_MESSAGE_BUFFERS; a++ )
111
 
                _message_modes[ a ] = 0;
 
123
        _message_recalc_flags = 0;
112
124
 
113
125
        // reset the text renderer's output buffer
114
126
        TextRenderer::reset_buffer();
115
127
}
116
128
 
117
129
 
118
 
void Text::set_up_message( int message_num, char mode, char scale )
119
 
{
120
 
        _message_modes[ message_num ] = mode;
121
 
        _message_scale[ message_num ] = scale;
122
 
}
123
 
 
124
 
 
125
 
void Text::set_message_text( int message_num, PString &pstring )
126
 
{
127
 
        // update message
128
 
        _message_lens[ message_num ] = pstring.length();
129
 
}
130
 
 
131
 
 
132
130
void Text::draw_reset()
133
131
{
134
132
        // how many milliseconds have elapsed since last frame?
141
139
}
142
140
 
143
141
 
144
 
static void draw_message( int message_num, int segment )
 
142
void Text::draw( int message_num, int segment )
145
143
{
146
144
        TextRenderer::buffer_in_use();
147
145
 
148
146
        // perform a mid-frame reset, as necessary
149
 
        if( _do_draw_reset ) // && segment > NUM_SEGMENTS / 2 )
150
 
        {
151
 
                // reset message param
152
 
                reset_message_param( message_num );
 
147
        if( _do_draw_reset && segment > NUM_SEGMENTS / 2 ) {
 
148
                _do_draw_reset = false;
 
149
 
 
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
                }
153
155
 
154
156
                // add to horizontal scroll position
155
 
                if( _message_modes[ message_num ] & Text::MODE_HSCROLL ) {
 
157
                if( _message_modes[ message_num ] & MODE_HSCROLL ) {
156
158
                        _message_params[ message_num ] +=
157
159
                                _duration * TEXT_SCROLL_SPEED / 1000;
158
160
                        long excess = _message_params[ message_num ] -
167
169
 
168
170
        // calculate the width
169
171
        int width;
170
 
        switch( _message_modes[ message_num ] & MASK_MODE_SIZE )
 
172
        switch( _message_modes[ message_num ] & 0x1c )
171
173
        {
172
 
        case Text::MODE_ONEQUARTER:
 
174
        case MODE_ONEQUARTER:
173
175
                width = NUM_SEGMENTS / 4;
174
176
                break;
175
 
        case Text::MODE_ONETHIRD:
 
177
        case MODE_ONETHIRD:
176
178
                width = NUM_SEGMENTS / 3;
177
179
                break;
178
 
        case Text::MODE_HALF:
 
180
        case MODE_HALF:
179
181
                width = NUM_SEGMENTS / 2;
180
182
                break;
181
 
        case Text::MODE_TWOTHIRDS:
 
183
        case MODE_TWOTHIRDS:
182
184
                width = NUM_SEGMENTS * 2 / 3;
183
185
                break;
184
 
        case Text::MODE_THREEQUARTERS:
 
186
        case MODE_THREEQUARTERS:
185
187
                width = NUM_SEGMENTS * 3 / 4;
186
188
                break;
187
 
        case Text::MODE_ALL:
 
189
        case MODE_ALL:
188
190
                width = NUM_SEGMENTS;
189
191
                break;
190
192
        }
191
193
 
192
194
        // convert segment to display-space
193
 
        switch( _message_modes[ message_num ] & MASK_MODE_POS )
 
195
        switch( _message_modes[ message_num ] & 0x03 )
194
196
        {
195
 
        case Text::MODE_TOP:
 
197
        case MODE_TOP:
196
198
                if( segment < width / 2 )
197
199
                        segment += width / 2;
198
200
                else if( segment >= NUM_SEGMENTS - width / 2 )
200
202
                else
201
203
                        return;
202
204
                break;
203
 
        case Text::MODE_BOTTOM:
 
205
        case MODE_BOTTOM:
204
206
                if( segment > ( NUM_SEGMENTS - width ) / 2 &&
205
207
                        segment < ( NUM_SEGMENTS - width ) / 2 + width )
206
208
                {
213
215
 
214
216
        // render
215
217
        TextRenderer::render(
216
 
                Text::_messages[ message_num ], _message_lens[ message_num ],
 
218
                _messages[ message_num ], _message_lens[ message_num ],
217
219
                (long)segment + _message_params[ message_num ],
218
 
                ( _message_modes[ message_num ] & MASK_MODE_POS ) == Text::MODE_BOTTOM,
219
 
                0, _message_scale[ message_num ] );
220
 
}
221
 
 
222
 
 
223
 
void Text::draw( int segment )
224
 
{
225
 
        // draw any active messages
226
 
        for( int a = 0; a < NUM_MESSAGE_BUFFERS; a++ )
227
 
                if( _message_modes[ a ] & MASK_MODE_SIZE )
228
 
                        draw_message( a, segment );
229
 
 
230
 
        // turn off any requested draw reset after all messages are drawn
231
 
        _do_draw_reset = false;
232
 
}
233
 
 
 
220
                ( _message_modes[ message_num ] & 1 ) == 0, 0,
 
221
                _message_scale[ message_num ] );
 
222
}