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