Мне такой подход совсем не по душе.
Вот то, что получилось у меня:
Код
void scrolling(char *Buffer, uint16_t *ScrlPos)
{
char tmp[50];
uint16_t bufferlen, len;
uint16_t pos = *ScrlPos;
uint8_t index = 0, offset = 0;
bufferlen = string_width(Buffer);
tmp[0] = 0;
if(bufferlen > pos)
{
do
{
tmp[offset] = Buffer[offset];
offset++;
}while((string_width(tmp) - 1) < pos);
offset--;
tmp[offset] = 0;
pos = *ScrlPos - string_width(tmp);
memset(tmp, 0, sizeof(tmp));
while(string_width(tmp) < (SCREEN_WIDTH + pos))
{
if((index + offset) >= strlen(Buffer))
break;
tmp[index] = Buffer[index + offset];
index++;
}
tmp[index] = 0;
}
else
{
pos -= bufferlen;
memset(tmp, 0, sizeof(tmp));
}
len = string_width(tmp);
if(len < (SCREEN_WIDTH + pos))
{
tmp[index++] = (char)'-';
tmp[index++] = (char)'-';
tmp[index++] = (char)'-';
tmp[index] = 0;
len = string_width(tmp, NULL_PIXEL);
if(len < (SCREEN_WIDTH + pos))
offset = 0;
while(string_width(tmp) < (SCREEN_WIDTH + pos))
{
tmp[index] = Buffer[offset];
index++;
offset++;
}
tmp[index] = 0;
}
string_print(tmp, pos);
*(ScrlPos)++;
if(*ScrlPos > (bufferlen + string_width(" - ")))
*ScrlPos = 0;
}
Вызывается так:
Код
uint16_t pos_in_string;
scrolling("Длинная бегущая строка", &pos_in_string);