summaryrefslogtreecommitdiff
path: root/firmware/drivers/lcd-charcell.c
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2013-12-15 00:38:48 +0100
committerThomas Martitz <kugel@rockbox.org>2013-12-15 00:38:48 +0100
commitc72b454286864d728de676ebdf92288dd04ace45 (patch)
treebfe7ebfff65c3452b54661eafa844d28d0812a96 /firmware/drivers/lcd-charcell.c
parent1fc19042f72e9171b79c5a847cbce0c8939888c5 (diff)
downloadrockbox-c72b454286864d728de676ebdf92288dd04ace45.tar.gz
rockbox-c72b454286864d728de676ebdf92288dd04ace45.zip
Fix reds. Also apply the new scrolling to lcd charcell (this even uncovered an
error). Change-Id: I29243bb36b6cec1471bd6c0afc64e00547a68c50
Diffstat (limited to 'firmware/drivers/lcd-charcell.c')
-rw-r--r--firmware/drivers/lcd-charcell.c156
1 files changed, 50 insertions, 106 deletions
diff --git a/firmware/drivers/lcd-charcell.c b/firmware/drivers/lcd-charcell.c
index bdd02de1b6..db867cdb0a 100644
--- a/firmware/drivers/lcd-charcell.c
+++ b/firmware/drivers/lcd-charcell.c
@@ -110,11 +110,26 @@ void lcd_set_viewport(struct viewport* vp)
110#endif 110#endif
111} 111}
112 112
113struct viewport *lcd_get_viewport(bool *is_default)
114{
115 *is_default = (current_vp == &default_vp);
116 return current_vp;
117}
118
113void lcd_update_viewport(void) 119void lcd_update_viewport(void)
114{ 120{
115 lcd_update(); 121 lcd_update();
116} 122}
117 123
124void lcd_update_viewport_rect(int x, int y, int width, int height)
125{
126 (void) x;
127 (void) y;
128 (void) width;
129 (void) height;
130 lcd_update();
131}
132
118/** parameter handling **/ 133/** parameter handling **/
119 134
120int lcd_getwidth(void) 135int lcd_getwidth(void)
@@ -486,7 +501,7 @@ void lcd_puts_offset(int x, int y, const unsigned char *str, int offset)
486 return; 501 return;
487 502
488 /* make sure scrolling is turned off on the line we are updating */ 503 /* make sure scrolling is turned off on the line we are updating */
489 lcd_scroll_stop_viewport_line(current_vp, y); 504 lcd_scroll_stop_viewport_rect(current_vp, x, y, current_vp->width - x, 1);
490 505
491 x = lcd_putsxyofs(x, y, offset, str); 506 x = lcd_putsxyofs(x, y, offset, str);
492 while (x < current_vp->width) 507 while (x < current_vp->width)
@@ -499,8 +514,9 @@ void lcd_puts_scroll(int x, int y, const unsigned char *string)
499 lcd_puts_scroll_offset(x, y, string, 0); 514 lcd_puts_scroll_offset(x, y, string, 0);
500} 515}
501 516
502void lcd_puts_scroll_offset(int x, int y, const unsigned char *string, 517void lcd_puts_scroll_worker(int x, int y, const unsigned char *string,
503 int offset) 518 int offset,
519 void (*scroll_func)(struct scrollinfo *), void *data)
504{ 520{
505 struct scrollinfo* s; 521 struct scrollinfo* s;
506 int len; 522 int len;
@@ -509,7 +525,7 @@ void lcd_puts_scroll_offset(int x, int y, const unsigned char *string,
509 return; 525 return;
510 526
511 /* remove any previously scrolling line at the same location */ 527 /* remove any previously scrolling line at the same location */
512 lcd_scroll_stop_viewport_line(current_vp, y); 528 lcd_scroll_stop_viewport_rect(current_vp, x, y, current_vp->width - x, 1);
513 529
514 if (lcd_scroll_info.lines >= LCD_SCROLLABLE_LINES) return; 530 if (lcd_scroll_info.lines >= LCD_SCROLLABLE_LINES) return;
515 531
@@ -520,120 +536,48 @@ void lcd_puts_scroll_offset(int x, int y, const unsigned char *string,
520 lcd_puts_offset(x, y, string, offset); 536 lcd_puts_offset(x, y, string, offset);
521 len = utf8length(string); 537 len = utf8length(string);
522 538
523 if (current_vp->width - x < len) 539 if (current_vp->width - x >= len)
524 { 540 return;
525 /* prepare scroll line */ 541 /* prepare scroll line */
526 char *end; 542 strlcpy(s->linebuffer, string, sizeof s->linebuffer);
527 int count;
528
529 memset(s->line, 0, sizeof s->line);
530 strlcpy(s->line, string, sizeof s->line);
531
532 /* get width */
533 s->len = utf8length(s->line);
534
535 /* scroll bidirectional or forward only depending on the string width */
536 if (lcd_scroll_info.bidir_limit)
537 {
538 s->bidir = s->len < (current_vp->width) *
539 (100 + lcd_scroll_info.bidir_limit) / 100;
540 }
541 else
542 s->bidir = false;
543
544 if (!s->bidir) /* add spaces if scrolling in the round */
545 {
546 strlcat(s->line, " ", sizeof s->line);
547 /* get new width incl. spaces */
548 s->len += SCROLL_SPACING;
549 }
550 543
551 end = strchr(s->line, '\0'); 544 /* scroll bidirectional or forward only depending on the string width */
552 len = sizeof s->line - (end - s->line); 545 if (lcd_scroll_info.bidir_limit)
553 count = utf8seek(s->line, current_vp->width); 546 {
554 strlcpy(end, string, MIN(count, len)); 547 s->bidir = len < (current_vp->width) *
555 548 (100 + lcd_scroll_info.bidir_limit) / 100;
556 s->vp = current_vp;
557 s->y = y;
558 s->offset = offset;
559 s->startx = x;
560 s->backward = false;
561 lcd_scroll_info.lines++;
562 } 549 }
550 else
551 s->bidir = false;
552
553 s->scroll_func = scroll_func;
554 s->userdata = data;
555
556 s->vp = current_vp;
557 s->x = x;
558 s->y = y;
559 s->height = 1;
560 s->width = current_vp->width - x;
561 s->offset = offset;
562 s->backward = false;
563 lcd_scroll_info.lines++;
563} 564}
564 565
565void lcd_scroll_fn(void) 566void lcd_scroll_fn(struct scrollinfo* s)
566{ 567{
567 struct scrollinfo* s; 568 lcd_putsxyofs(s->x, s->y, s->offset, s->line);
568 int index;
569 int xpos, ypos;
570 bool update;
571 struct viewport* old_vp = current_vp;
572 bool makedelay;
573
574 update = false;
575 for ( index = 0; index < lcd_scroll_info.lines; index++ ) {
576 s = &lcd_scroll_info.scroll[index];
577
578 /* check pause */
579 if (TIME_BEFORE(current_tick, s->start_tick))
580 continue;
581
582 lcd_set_viewport(s->vp);
583
584 if (s->backward)
585 s->offset--;
586 else
587 s->offset++;
588
589 xpos = s->startx;
590 ypos = s->y;
591
592 makedelay = false;
593 if (s->bidir) /* scroll bidirectional */
594 {
595 if (s->offset <= 0) {
596 /* at beginning of line */
597 s->offset = 0;
598 s->backward = false;
599 makedelay = true;
600 }
601 else if (s->offset >= s->len - (current_vp->width - xpos)) {
602 /* at end of line */
603 s->offset = s->len - (current_vp->width - xpos);
604 s->backward = true;
605 makedelay = true;
606 }
607 }
608 else /* scroll forward the whole time */
609 {
610 if (s->offset >= s->len) {
611 s->offset = 0;
612 makedelay = true;
613 }
614 }
615
616 if (makedelay)
617 s->start_tick = current_tick + lcd_scroll_info.delay +
618 lcd_scroll_info.ticks;
619
620 lcd_putsxyofs(xpos, ypos, s->offset, s->line);
621 update = true;
622 }
623
624 lcd_set_viewport(old_vp);
625
626 if (lcd_cursor.enabled) 569 if (lcd_cursor.enabled)
627 { 570 {
628 if (--lcd_cursor.downcount <= 0) 571 if (--lcd_cursor.downcount <= 0)
629 { 572 {
630 lcd_cursor.downcount = lcd_cursor.divider; 573 lcd_cursor.downcount = lcd_cursor.divider;
631 lcd_cursor.visible = !lcd_cursor.visible; 574 lcd_cursor.visible = !lcd_cursor.visible;
632 update = true;
633 } 575 }
634 } 576 }
635
636 if (update)
637 lcd_update();
638} 577}
639 578
579void lcd_puts_scroll_offset(int x, int y, const unsigned char *string,
580 int offset)
581{
582 lcd_puts_scroll_worker(x, y, string, offset, lcd_scroll_fn, NULL);
583}