/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 char _message_scale[ NUM_MESSAGE_BUFFERS ];
44
 
 
45
43
// time last frame
46
44
static unsigned long _last_millis;
47
45
 
52
50
static bool _do_draw_reset;
53
51
 
54
52
 
55
 
#define MASK_MODE_SIZE 0x07
56
 
#define MASK_MODE_POS 0x40
57
 
 
58
53
void reset_message_param( int message_num )
59
54
{
60
55
        if( _message_modes[ message_num ] & Text::MODE_HSCROLL )
61
56
        {
62
 
                switch( _message_modes[ message_num ] & MASK_MODE_SIZE )
 
57
                switch( _message_modes[ message_num ] & 0x1c )
63
58
                {
64
59
                case Text::MODE_ONEQUARTER:
65
60
                        _message_params[ message_num ] = -NUM_SEGMENTS / 4; break;
77
72
        }
78
73
        else
79
74
        {
80
 
                switch( _message_modes[ message_num ] & MASK_MODE_SIZE )
 
75
                switch( _message_modes[ message_num ] & 0x1c )
81
76
                {
82
77
                case Text::MODE_ONEQUARTER:
83
78
                        _message_params[ message_num ] = NUM_SEGMENTS / 4; break;
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
 
101
95
 
 
96
void Text::set_message( int message_num, PString &pstring )
 
97
{
 
98
        // update message
 
99
        _message_lens[ message_num ] = pstring.length();
 
100
}
 
101
 
 
102
 
 
103
void Text::reset_message( int message_num, char mode )
 
104
{
 
105
        _message_modes[ message_num ] = mode;
 
106
        reset_message_param( message_num );
 
107
}
 
108
 
 
109
 
102
110
void Text::reset()
103
111
{
104
112
        // reset renderer
106
114
        _last_millis = ::millis();
107
115
        _do_draw_reset = false;
108
116
 
109
 
        // clear all message modes (disable messages)
110
 
        for( int a = 0; a < NUM_MESSAGE_BUFFERS; a++ )
111
 
                _message_modes[ a ] = 0;
112
 
 
113
117
        // reset the text renderer's output buffer
114
118
        TextRenderer::reset_buffer();
115
119
}
116
120
 
117
121
 
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
122
void Text::draw_reset()
133
123
{
134
124
        // how many milliseconds have elapsed since last frame?
141
131
}
142
132
 
143
133
 
144
 
static void draw_message( int message_num, int segment )
 
134
void Text::draw( int message_num, int segment )
145
135
{
146
 
        TextRenderer::buffer_in_use();
147
 
 
148
136
        // 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 );
 
137
        if( _do_draw_reset && segment > NUM_SEGMENTS / 2 ) {
 
138
                _do_draw_reset = false;
153
139
 
154
 
                // add to horizontal scroll position
155
 
                if( _message_modes[ message_num ] & Text::MODE_HSCROLL ) {
 
140
                if( _message_modes[ message_num ] & MODE_HSCROLL )
 
141
                {
 
142
                        // add to horizontal scroll position
156
143
                        _message_params[ message_num ] +=
157
144
                                _duration * TEXT_SCROLL_SPEED / 1000;
158
145
                        long excess = _message_params[ message_num ] -
159
 
                                TextRenderer::get_width( _message_lens[ message_num ],
160
 
                                                _message_scale[ message_num ] );
 
146
                                TextRenderer::get_width( _message_lens[ message_num ] );
161
147
                        if( excess >= 0 ) {
162
148
                                reset_message_param( message_num );
163
149
                                _message_params[ message_num ] += excess;
167
153
 
168
154
        // calculate the width
169
155
        int width;
170
 
        switch( _message_modes[ message_num ] & MASK_MODE_SIZE )
 
156
        switch( _message_modes[ message_num ] & 0x1c )
171
157
        {
172
 
        case Text::MODE_ONEQUARTER:
 
158
        case MODE_ONEQUARTER:
173
159
                width = NUM_SEGMENTS / 4;
174
160
                break;
175
 
        case Text::MODE_ONETHIRD:
 
161
        case MODE_ONETHIRD:
176
162
                width = NUM_SEGMENTS / 3;
177
163
                break;
178
 
        case Text::MODE_HALF:
 
164
        case MODE_HALF:
179
165
                width = NUM_SEGMENTS / 2;
180
166
                break;
181
 
        case Text::MODE_TWOTHIRDS:
 
167
        case MODE_TWOTHIRDS:
182
168
                width = NUM_SEGMENTS * 2 / 3;
183
169
                break;
184
 
        case Text::MODE_THREEQUARTERS:
 
170
        case MODE_THREEQUARTERS:
185
171
                width = NUM_SEGMENTS * 3 / 4;
186
172
                break;
187
 
        case Text::MODE_ALL:
 
173
        case MODE_ALL:
188
174
                width = NUM_SEGMENTS;
189
175
                break;
190
176
        }
191
177
 
192
178
        // convert segment to display-space
193
 
        switch( _message_modes[ message_num ] & MASK_MODE_POS )
 
179
        switch( _message_modes[ message_num ] & 0x03 )
194
180
        {
195
 
        case Text::MODE_TOP:
 
181
        case MODE_TOP:
196
182
                if( segment < width / 2 )
197
183
                        segment += width / 2;
198
184
                else if( segment >= NUM_SEGMENTS - width / 2 )
200
186
                else
201
187
                        return;
202
188
                break;
203
 
        case Text::MODE_BOTTOM:
 
189
        case MODE_BOTTOM:
204
190
                if( segment > ( NUM_SEGMENTS - width ) / 2 &&
205
191
                        segment < ( NUM_SEGMENTS - width ) / 2 + width )
206
192
                {
213
199
 
214
200
        // render
215
201
        TextRenderer::render(
216
 
                Text::_messages[ message_num ], _message_lens[ message_num ],
 
202
                _messages[ message_num ], _message_lens[ message_num ],
217
203
                (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
 
 
 
204
                ( _message_modes[ message_num ] & 1 ) == 0, 0 );
 
205
}