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
48
55
// recalculate message params, based on _duration
49
56
static bool _do_draw_reset;
51
// recalculate messages parameters (after message reset)
52
static unsigned char _message_recalc_flags;
55
59
void reset_message_param( int message_num )
57
if( _message_modes[ message_num ] & Text::MODE_HSCROLL )
59
switch( _message_modes[ message_num ] & 0x1c )
61
case Text::MODE_ONEQUARTER:
62
_message_params[ message_num ] = -NUM_SEGMENTS / 4; break;
63
case Text::MODE_ONETHIRD:
64
_message_params[ message_num ] = -NUM_SEGMENTS / 3; break;
66
_message_params[ message_num ] = -NUM_SEGMENTS / 2; break;
67
case Text::MODE_TWOTHIRDS:
68
_message_params[ message_num ] = -NUM_SEGMENTS * 2 / 3; break;
69
case Text::MODE_THREEQUARTERS:
70
_message_params[ message_num ] = -NUM_SEGMENTS * 3 / 4; break;
72
_message_params[ message_num ] = -NUM_SEGMENTS; break;
77
switch( _message_modes[ message_num ] & 0x1c )
79
case Text::MODE_ONEQUARTER:
80
_message_params[ message_num ] = NUM_SEGMENTS / 4; break;
81
case Text::MODE_ONETHIRD:
82
_message_params[ message_num ] = NUM_SEGMENTS / 3; break;
84
_message_params[ message_num ] = NUM_SEGMENTS / 2; break;
85
case Text::MODE_TWOTHIRDS:
86
_message_params[ message_num ] = NUM_SEGMENTS * 2 / 3; break;
87
case Text::MODE_THREEQUARTERS:
88
_message_params[ message_num ] = NUM_SEGMENTS * 3 / 4; break;
90
_message_params[ message_num ] = NUM_SEGMENTS; break;
92
_message_params[ message_num ] = -( _message_params[ message_num ] -
93
TextRenderer::get_width( _message_lens[ 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;
105
void Text::reset_message( int message_num, char mode )
90
void Text::set_message_mode( int message_num, char mode )
107
92
_message_modes[ message_num ] = mode;
108
_message_recalc_flags |= 1 << message_num;
93
reset_message_param( message_num );
137
121
void Text::draw( int message_num, int segment )
139
TextRenderer::buffer_in_use();
141
123
// perform a mid-frame reset, as necessary
142
124
if( _do_draw_reset && segment > NUM_SEGMENTS / 2 ) {
143
125
_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 ) {
127
if( _message_modes[ message_num ] & MODE_HSCROLL )
129
// add to horizontal scroll position
153
130
_message_params[ message_num ] +=
154
131
_duration * TEXT_SCROLL_SPEED / 1000;
155
132
long excess = _message_params[ message_num ] -
211
186
TextRenderer::render(
212
187
_messages[ message_num ], _message_lens[ message_num ],
213
188
(long)segment + _message_params[ message_num ],
214
( _message_modes[ message_num ] & 1 ) == 0, 0 );
189
_message_modes[ message_num ] & 1 == 0, 0 );