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
void reset_message_param( int message_num )
55
#define MASK_MODE_SIZE 0x07
56
#define MASK_MODE_POS 0x40
58
void reset_message_pos( 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
_message_params[ message_num ] = -NUM_SEGMENTS / 4; break;
65
_message_pos[ message_num ] = -NUM_SEGMENTS / 4; break;
63
66
case Text::MODE_ONETHIRD:
64
_message_params[ message_num ] = -NUM_SEGMENTS / 3; break;
67
_message_pos[ message_num ] = -NUM_SEGMENTS / 3; break;
65
68
case Text::MODE_HALF:
66
_message_params[ message_num ] = -NUM_SEGMENTS / 2; break;
69
_message_pos[ message_num ] = -NUM_SEGMENTS / 2; break;
67
70
case Text::MODE_TWOTHIRDS:
68
_message_params[ message_num ] = -NUM_SEGMENTS * 2 / 3; break;
71
_message_pos[ message_num ] = -NUM_SEGMENTS * 2 / 3; break;
69
72
case Text::MODE_THREEQUARTERS:
70
_message_params[ message_num ] = -NUM_SEGMENTS * 3 / 4; break;
73
_message_pos[ message_num ] = -NUM_SEGMENTS * 3 / 4; break;
71
74
case Text::MODE_ALL:
72
_message_params[ message_num ] = -NUM_SEGMENTS; break;
75
_message_pos[ message_num ] = -NUM_SEGMENTS; break;
77
switch( _message_modes[ message_num ] & 0x1c )
80
switch( _message_modes[ message_num ] & MASK_MODE_SIZE )
79
82
case Text::MODE_ONEQUARTER:
80
_message_params[ message_num ] = NUM_SEGMENTS / 4; break;
83
_message_pos[ message_num ] = NUM_SEGMENTS / 4; break;
81
84
case Text::MODE_ONETHIRD:
82
_message_params[ message_num ] = NUM_SEGMENTS / 3; break;
85
_message_pos[ message_num ] = NUM_SEGMENTS / 3; break;
83
86
case Text::MODE_HALF:
84
_message_params[ message_num ] = NUM_SEGMENTS / 2; break;
87
_message_pos[ message_num ] = NUM_SEGMENTS / 2; break;
85
88
case Text::MODE_TWOTHIRDS:
86
_message_params[ message_num ] = NUM_SEGMENTS * 2 / 3; break;
89
_message_pos[ message_num ] = NUM_SEGMENTS * 2 / 3; break;
87
90
case Text::MODE_THREEQUARTERS:
88
_message_params[ message_num ] = NUM_SEGMENTS * 3 / 4; break;
91
_message_pos[ message_num ] = NUM_SEGMENTS * 3 / 4; break;
89
92
case Text::MODE_ALL:
90
_message_params[ message_num ] = NUM_SEGMENTS; break;
93
_message_pos[ message_num ] = NUM_SEGMENTS; break;
92
_message_params[ message_num ] = -( _message_params[ message_num ] -
93
TextRenderer::get_width( _message_lens[ message_num ] ) ) / 2;
95
_message_pos[ message_num ] = -( _message_pos[ message_num ] -
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
_do_draw_reset = false;
118
_message_recalc_flags = 0;
108
// clear all message modes (disable messages)
109
for( int a = 0; a < NUM_MESSAGE_BUFFERS; a++ )
110
_message_modes[ a ] = 0;
120
112
// reset the text renderer's output buffer
121
113
TextRenderer::reset_buffer();
117
void Text::set_up_message( int message_num, char mode, char scale )
119
_message_modes[ message_num ] = mode;
120
_message_scale[ message_num ] = scale;
122
// horizontal scrolling messages need their position reset at start of mode
123
if( _message_modes[ message_num ] & MODE_HSCROLL )
124
reset_message_pos( message_num );
128
void Text::set_message_text( int message_num, PString &pstring )
131
_message_lens[ message_num ] = pstring.length();
133
// non-horizontal scrolling modes need their position reset whenever the
135
if( !( _message_modes[ message_num ] & MODE_HSCROLL ) )
136
reset_message_pos( message_num );
125
140
void Text::draw_reset()
127
142
// how many milliseconds have elapsed since last frame?
130
145
_duration = millis - _last_millis;
131
146
_last_millis = millis;
148
// we'll need to recalculate params for the frame, but we want to do it when
149
// we're not in the middle of a text display (to avoid tearing).
133
150
_do_draw_reset = true;
137
void Text::draw( int message_num, int segment )
154
static void draw_message( int message_num, int segment )
139
156
TextRenderer::buffer_in_use();
141
// 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 );
151
// add to horizontal scroll position
152
if( _message_modes[ message_num ] & MODE_HSCROLL ) {
153
_message_params[ message_num ] +=
154
_duration * TEXT_SCROLL_SPEED / 1000;
155
long excess = _message_params[ message_num ] -
156
TextRenderer::get_width( _message_lens[ message_num ] );
158
reset_message_param( message_num );
159
_message_params[ message_num ] += excess;
164
158
// calculate the width
166
switch( _message_modes[ message_num ] & 0x1c )
160
switch( _message_modes[ message_num ] & MASK_MODE_SIZE )
168
case MODE_ONEQUARTER:
162
case Text::MODE_ONEQUARTER:
169
163
width = NUM_SEGMENTS / 4;
165
case Text::MODE_ONETHIRD:
172
166
width = NUM_SEGMENTS / 3;
168
case Text::MODE_HALF:
175
169
width = NUM_SEGMENTS / 2;
171
case Text::MODE_TWOTHIRDS:
178
172
width = NUM_SEGMENTS * 2 / 3;
180
case MODE_THREEQUARTERS:
174
case Text::MODE_THREEQUARTERS:
181
175
width = NUM_SEGMENTS * 3 / 4;
184
178
width = NUM_SEGMENTS;
188
182
// convert segment to display-space
189
switch( _message_modes[ message_num ] & 0x03 )
183
switch( _message_modes[ message_num ] & MASK_MODE_POS )
192
186
if( segment < width / 2 )
193
187
segment += width / 2;
194
188
else if( segment >= NUM_SEGMENTS - width / 2 )
211
205
TextRenderer::render(
212
_messages[ message_num ], _message_lens[ message_num ],
213
(long)segment + _message_params[ message_num ],
214
( _message_modes[ message_num ] & 1 ) == 0, 0 );
206
Text::_messages[ message_num ], _message_lens[ message_num ],
207
(long)segment + _message_pos[ message_num ],
208
( _message_modes[ message_num ] & MASK_MODE_POS ) == Text::MODE_BOTTOM,
209
0, _message_scale[ message_num ] );
213
void Text::draw( int segment )
215
// perform a mid-frame reset, as necessary
216
if( _do_draw_reset && segment == NUM_SEGMENTS / 2 ) {
217
_do_draw_reset = false;
219
// go through the messages looking for an active one
220
for( int a = 0; a < NUM_MESSAGE_BUFFERS; a++ )
221
if( _message_modes[ a ] & MASK_MODE_SIZE )
223
// add to horizontal scroll position
224
if( _message_modes[ a ] & Text::MODE_HSCROLL ) {
226
_duration * TEXT_SCROLL_SPEED / 1000;
227
long excess = _message_pos[ a ] -
228
TextRenderer::get_width( _message_lens[ a ],
229
_message_scale[ a ] );
231
reset_message_pos( a );
232
_message_pos[ a ] += excess;
238
// draw any active messages
239
for( int a = 0; a < NUM_MESSAGE_BUFFERS; a++ )
240
if( _message_modes[ a ] & MASK_MODE_SIZE )
241
draw_message( a, segment );