51
48
// recalculate message params, based on _duration
52
49
static bool _do_draw_reset;
51
// recalculate messages parameters (after message reset)
52
static unsigned char _message_recalc_flags;
55
#define MASK_MODE_SIZE 0x07
56
#define MASK_MODE_POS 0x40
58
55
void reset_message_param( int message_num )
60
57
if( _message_modes[ message_num ] & Text::MODE_HSCROLL )
62
switch( _message_modes[ message_num ] & MASK_MODE_SIZE )
59
switch( _message_modes[ message_num ] & 0x1c )
64
61
case Text::MODE_ONEQUARTER:
65
62
_message_params[ message_num ] = -NUM_SEGMENTS / 4; break;
93
90
_message_params[ message_num ] = NUM_SEGMENTS; break;
95
92
_message_params[ message_num ] = -( _message_params[ message_num ] -
96
TextRenderer::get_width( _message_lens[ message_num ],
97
_message_scale[ message_num ] ) ) / 2;
93
TextRenderer::get_width( _message_lens[ message_num ] ) ) / 2;
98
void Text::set_message( int message_num, PString &pstring )
101
_message_lens[ message_num ] = pstring.length();
105
void Text::reset_message( int message_num, char mode )
107
_message_modes[ message_num ] = mode;
108
_message_recalc_flags |= 1 << message_num;
102
112
void Text::reset()
104
114
// reset renderer
106
116
_last_millis = ::millis();
107
117
_do_draw_reset = false;
109
// clear all message modes (disable messages)
110
for( int a = 0; a < NUM_MESSAGE_BUFFERS; a++ )
111
_message_modes[ a ] = 0;
118
_message_recalc_flags = 0;
113
120
// reset the text renderer's output buffer
114
121
TextRenderer::reset_buffer();
118
void Text::set_up_message( int message_num, char mode, char scale )
120
_message_modes[ message_num ] = mode;
121
_message_scale[ message_num ] = scale;
125
void Text::set_message_text( int message_num, PString &pstring )
128
_message_lens[ message_num ] = pstring.length();
132
125
void Text::draw_reset()
134
127
// how many milliseconds have elapsed since last frame?
144
static void draw_message( int message_num, int segment )
137
void Text::draw( int message_num, int segment )
146
139
TextRenderer::buffer_in_use();
148
141
// perform a mid-frame reset, as necessary
149
if( _do_draw_reset ) // && segment > NUM_SEGMENTS / 2 )
151
// reset message param
152
reset_message_param( message_num );
142
if( _do_draw_reset && segment > NUM_SEGMENTS / 2 ) {
143
_do_draw_reset = false;
145
// reset message param?
146
if( _message_recalc_flags & ( 1 << message_num ) ) {
147
_message_recalc_flags &= ~( 1 << message_num );
148
reset_message_param( message_num );
154
151
// add to horizontal scroll position
155
if( _message_modes[ message_num ] & Text::MODE_HSCROLL ) {
152
if( _message_modes[ message_num ] & MODE_HSCROLL ) {
156
153
_message_params[ message_num ] +=
157
154
_duration * TEXT_SCROLL_SPEED / 1000;
158
155
long excess = _message_params[ message_num ] -
159
TextRenderer::get_width( _message_lens[ message_num ],
160
_message_scale[ message_num ] );
156
TextRenderer::get_width( _message_lens[ message_num ] );
161
157
if( excess >= 0 ) {
162
158
reset_message_param( message_num );
163
159
_message_params[ message_num ] += excess;
168
164
// calculate the width
170
switch( _message_modes[ message_num ] & MASK_MODE_SIZE )
166
switch( _message_modes[ message_num ] & 0x1c )
172
case Text::MODE_ONEQUARTER:
168
case MODE_ONEQUARTER:
173
169
width = NUM_SEGMENTS / 4;
175
case Text::MODE_ONETHIRD:
176
172
width = NUM_SEGMENTS / 3;
178
case Text::MODE_HALF:
179
175
width = NUM_SEGMENTS / 2;
181
case Text::MODE_TWOTHIRDS:
182
178
width = NUM_SEGMENTS * 2 / 3;
184
case Text::MODE_THREEQUARTERS:
180
case MODE_THREEQUARTERS:
185
181
width = NUM_SEGMENTS * 3 / 4;
188
184
width = NUM_SEGMENTS;
192
188
// convert segment to display-space
193
switch( _message_modes[ message_num ] & MASK_MODE_POS )
189
switch( _message_modes[ message_num ] & 0x03 )
196
192
if( segment < width / 2 )
197
193
segment += width / 2;
198
194
else if( segment >= NUM_SEGMENTS - width / 2 )
215
211
TextRenderer::render(
216
Text::_messages[ message_num ], _message_lens[ message_num ],
212
_messages[ message_num ], _message_lens[ message_num ],
217
213
(long)segment + _message_params[ message_num ],
218
( _message_modes[ message_num ] & MASK_MODE_POS ) == Text::MODE_BOTTOM,
219
0, _message_scale[ message_num ] );
223
void Text::draw( int segment )
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 );
230
// turn off any requested draw reset after all messages are drawn
231
_do_draw_reset = false;
214
( _message_modes[ message_num ] & 1 ) == 0, 0 );