25
25
#include "config.h"
26
26
#include "Arduino.h"
27
27
#include <avr/pgmspace.h>
31
// the proportion of the display to use (in segments)
32
#define BIG_SEGMENTS ( NUM_SEGMENTS * 2 / 3 )
33
#define SMALL_SEGMENTS ( NUM_SEGMENTS - BIG_TEXT_SEGMENTS )
34
#define HALF_SEGMENTS ( NUM_SEGMENTS / 2 )
30
37
// the buffer for the message
51
55
// recalculate message params, based on _duration
52
56
static bool _do_draw_reset;
54
// recalculate messages parameters (after message reset)
55
static unsigned char _message_recalc_flags;
58
59
void reset_message_param( int message_num )
60
if( _message_modes[ message_num ] & Text::MODE_HSCROLL )
62
switch( _message_modes[ message_num ] & 0x1c )
64
case Text::MODE_ONEQUARTER:
65
_message_params[ message_num ] = -NUM_SEGMENTS / 4; break;
66
case Text::MODE_ONETHIRD:
67
_message_params[ message_num ] = -NUM_SEGMENTS / 3; break;
69
_message_params[ message_num ] = -NUM_SEGMENTS / 2; break;
70
case Text::MODE_TWOTHIRDS:
71
_message_params[ message_num ] = -NUM_SEGMENTS * 2 / 3; break;
72
case Text::MODE_THREEQUARTERS:
73
_message_params[ message_num ] = -NUM_SEGMENTS * 3 / 4; break;
75
_message_params[ message_num ] = -NUM_SEGMENTS; break;
80
switch( _message_modes[ message_num ] & 0x1c )
82
case Text::MODE_ONEQUARTER:
83
_message_params[ message_num ] = NUM_SEGMENTS / 4; break;
84
case Text::MODE_ONETHIRD:
85
_message_params[ message_num ] = NUM_SEGMENTS / 3; break;
87
_message_params[ message_num ] = NUM_SEGMENTS / 2; break;
88
case Text::MODE_TWOTHIRDS:
89
_message_params[ message_num ] = NUM_SEGMENTS * 2 / 3; break;
90
case Text::MODE_THREEQUARTERS:
91
_message_params[ message_num ] = NUM_SEGMENTS * 3 / 4; break;
93
_message_params[ message_num ] = NUM_SEGMENTS; break;
95
_message_params[ message_num ] = -( _message_params[ message_num ] -
96
TextRenderer::get_width( _message_lens[ message_num ],
97
_message_scale[ message_num ] ) ) / 2;
61
switch( _message_modes[ message_num ] )
64
_message_params[ message_num ] = -BIG_SEGMENTS;
67
_message_params[ message_num ] = -HALF_SEGMENTS;
71
_message_params[ message_num ] = -( BIG_SEGMENTS -
72
TextRenderer::get_width( _message_lens[ message_num ] ) ) / 2;
76
_message_params[ message_num ] = -( HALF_SEGMENTS -
77
TextRenderer::get_width( _message_lens[ message_num ] ) ) / 2;
109
void Text::reset_message( int message_num, char mode, int scale )
90
void Text::set_message_mode( int message_num, char mode )
111
92
_message_modes[ message_num ] = mode;
112
_message_recalc_flags |= 1 << message_num;
113
_message_scale[ message_num ] = scale;
93
reset_message_param( message_num );
142
void Text::post_draw()
144
_do_draw_reset = false;
148
121
void Text::draw( int message_num, int segment )
150
TextRenderer::buffer_in_use();
152
123
// perform a mid-frame reset, as necessary
153
if( _do_draw_reset ) // && segment > NUM_SEGMENTS / 2 )
155
// reset message param?
156
if( _message_recalc_flags & ( 1 << message_num ) ) {
157
_message_recalc_flags &= ~( 1 << message_num );
158
reset_message_param( message_num );
124
if( _do_draw_reset && segment > NUM_SEGMENTS / 2 ) {
125
_do_draw_reset = false;
161
// add to horizontal scroll position
162
if( _message_modes[ message_num ] & MODE_HSCROLL ) {
127
if( _message_modes[ message_num ] & MODE_HSCROLL )
129
// add to horizontal scroll position
163
130
_message_params[ message_num ] +=
164
131
_duration * TEXT_SCROLL_SPEED / 1000;
165
132
long excess = _message_params[ message_num ] -
166
TextRenderer::get_width( _message_lens[ message_num ],
167
_message_scale[ message_num ] );
133
TextRenderer::get_width( _message_lens[ message_num ] );
168
134
if( excess >= 0 ) {
169
135
reset_message_param( message_num );
170
136
_message_params[ message_num ] += excess;
222
186
TextRenderer::render(
223
187
_messages[ message_num ], _message_lens[ message_num ],
224
188
(long)segment + _message_params[ message_num ],
225
( _message_modes[ message_num ] & 1 ) == 0, 0,
226
_message_scale[ message_num ] );
189
_message_modes[ message_num ] & 1 == 0, 0 );