diff options
Diffstat (limited to 'firmware/drivers/lcd.c')
-rw-r--r-- | firmware/drivers/lcd.c | 95 |
1 files changed, 82 insertions, 13 deletions
diff --git a/firmware/drivers/lcd.c b/firmware/drivers/lcd.c index 8abc638175..2293191139 100644 --- a/firmware/drivers/lcd.c +++ b/firmware/drivers/lcd.c | |||
@@ -547,7 +547,6 @@ void lcd_set_contrast(int val) | |||
547 | */ | 547 | */ |
548 | unsigned char lcd_framebuffer[LCD_WIDTH][LCD_HEIGHT/8]; | 548 | unsigned char lcd_framebuffer[LCD_WIDTH][LCD_HEIGHT/8]; |
549 | 549 | ||
550 | static int font=0; | ||
551 | static int xmargin=0; | 550 | static int xmargin=0; |
552 | static int ymargin=0; | 551 | static int ymargin=0; |
553 | 552 | ||
@@ -661,11 +660,6 @@ void lcd_clear_display (void) | |||
661 | #endif | 660 | #endif |
662 | } | 661 | } |
663 | 662 | ||
664 | void lcd_setfont(int newfont) | ||
665 | { | ||
666 | font = newfont; | ||
667 | } | ||
668 | |||
669 | void lcd_setmargins(int x, int y) | 663 | void lcd_setmargins(int x, int y) |
670 | { | 664 | { |
671 | xmargin = x; | 665 | xmargin = x; |
@@ -682,10 +676,11 @@ int lcd_getymargin(void) | |||
682 | return ymargin; | 676 | return ymargin; |
683 | } | 677 | } |
684 | 678 | ||
679 | static int curfont = FONT_SYSFIXED; | ||
680 | |||
685 | /* | 681 | /* |
686 | * Put a string at specified character position | 682 | * Put a string at specified character position |
687 | */ | 683 | */ |
688 | //FIXME require font parameter | ||
689 | void lcd_puts(int x, int y, unsigned char *str) | 684 | void lcd_puts(int x, int y, unsigned char *str) |
690 | { | 685 | { |
691 | int xpos,ypos,w,h; | 686 | int xpos,ypos,w,h; |
@@ -707,10 +702,10 @@ void lcd_puts(int x, int y, unsigned char *str) | |||
707 | if(!str || !str[0]) | 702 | if(!str || !str[0]) |
708 | return; | 703 | return; |
709 | 704 | ||
710 | lcd_getstringsize(str, font, &w, &h); | 705 | lcd_getstringsize(str, curfont, &w, &h); |
711 | xpos = xmargin + x*w / strlen(str); //FIXME why strlen? | 706 | xpos = xmargin + x*w / strlen(str); |
712 | ypos = ymargin + y*h; | 707 | ypos = ymargin + y*h; |
713 | lcd_putsxy( xpos, ypos, str, font); | 708 | lcd_putsxy( xpos, ypos, str, curfont); |
714 | lcd_clearrect(xpos + w, ypos, LCD_WIDTH - (xpos + w), h); | 709 | lcd_clearrect(xpos + w, ypos, LCD_WIDTH - (xpos + w), h); |
715 | #if defined(SIMULATOR) && defined(HAVE_LCD_CHARCELLS) | 710 | #if defined(SIMULATOR) && defined(HAVE_LCD_CHARCELLS) |
716 | /* this function is being used when simulating a charcell LCD and | 711 | /* this function is being used when simulating a charcell LCD and |
@@ -719,6 +714,80 @@ void lcd_puts(int x, int y, unsigned char *str) | |||
719 | #endif | 714 | #endif |
720 | } | 715 | } |
721 | 716 | ||
717 | /* set current font*/ | ||
718 | void lcd_setfont(int newfont) | ||
719 | { | ||
720 | curfont = newfont; | ||
721 | } | ||
722 | |||
723 | /* | ||
724 | * Return width and height of a given font. | ||
725 | */ | ||
726 | void lcd_getfontsize(int font, int *width, int *height) | ||
727 | { | ||
728 | struct font* pf = font_get(font); | ||
729 | |||
730 | *width = pf->maxwidth; | ||
731 | *height = pf->height; | ||
732 | } | ||
733 | |||
734 | |||
735 | /* | ||
736 | * Return width and height of a given font. | ||
737 | */ | ||
738 | int lcd_getstringsize(unsigned char *str, int font, int *w, int *h) | ||
739 | { | ||
740 | struct font* pf = font_get(font); | ||
741 | int ch; | ||
742 | int width = 0; | ||
743 | |||
744 | while((ch = *str++)) { | ||
745 | /* check input range*/ | ||
746 | if (ch < pf->firstchar || ch >= pf->firstchar+pf->size) | ||
747 | ch = pf->defaultchar; | ||
748 | ch -= pf->firstchar; | ||
749 | |||
750 | /* get proportional width and glyph bits*/ | ||
751 | width += pf->width? pf->width[ch]: pf->maxwidth; | ||
752 | } | ||
753 | *w = width; | ||
754 | *h = pf->height; | ||
755 | |||
756 | return width; | ||
757 | } | ||
758 | |||
759 | /* | ||
760 | * Put a string at specified bit position | ||
761 | */ | ||
762 | void lcd_putsxy(int x, int y, unsigned char *str, int font) | ||
763 | { | ||
764 | int ch; | ||
765 | struct font* pf = font_get(font); | ||
766 | |||
767 | while (((ch = *str++) != '\0')) { | ||
768 | bitmap_t *bits; | ||
769 | int width; | ||
770 | |||
771 | /* check input range*/ | ||
772 | if (ch < pf->firstchar || ch >= pf->firstchar+pf->size) | ||
773 | ch = pf->defaultchar; | ||
774 | ch -= pf->firstchar; | ||
775 | |||
776 | /* get proportional width and glyph bits*/ | ||
777 | width = pf->width ? pf->width[ch] : pf->maxwidth; | ||
778 | if (x + width > LCD_WIDTH) | ||
779 | break; | ||
780 | |||
781 | /* no partial-height drawing for now...*/ | ||
782 | if (y + pf->height > LCD_HEIGHT) | ||
783 | break; | ||
784 | bits = pf->bits + (pf->offset ? pf->offset[ch] : (pf->height * ch)); | ||
785 | |||
786 | lcd_bitmap((unsigned char *)bits, x, y, width, pf->height, true); | ||
787 | x += width; | ||
788 | } | ||
789 | } | ||
790 | |||
722 | /* | 791 | /* |
723 | * Display a bitmap at (x, y), size (nx, ny) | 792 | * Display a bitmap at (x, y), size (nx, ny) |
724 | * clear is true to clear destination area first | 793 | * clear is true to clear destination area first |
@@ -1038,14 +1107,14 @@ void lcd_puts_scroll(int x, int y, unsigned char* string ) | |||
1038 | unsigned char ch[2]; | 1107 | unsigned char ch[2]; |
1039 | int w, h; | 1108 | int w, h; |
1040 | int width, height; | 1109 | int width, height; |
1041 | lcd_getfontsize(font, &width, &height); | 1110 | lcd_getfontsize(curfont, &width, &height); |
1042 | 1111 | ||
1043 | ch[1] = 0; /* zero terminate */ | 1112 | ch[1] = 0; /* zero terminate */ |
1044 | ch[0] = string[0]; | 1113 | ch[0] = string[0]; |
1045 | width = 0; | 1114 | width = 0; |
1046 | s->space = 0; | 1115 | s->space = 0; |
1047 | while ( ch[0] && | 1116 | while ( ch[0] && |
1048 | (width + lcd_getstringsize(ch, 0, &w, &h) < | 1117 | (width + lcd_getstringsize(ch, curfont, &w, &h) < |
1049 | (LCD_WIDTH - x*8))) { | 1118 | (LCD_WIDTH - x*8))) { |
1050 | width += w; | 1119 | width += w; |
1051 | s->space++; | 1120 | s->space++; |
@@ -1058,7 +1127,7 @@ void lcd_puts_scroll(int x, int y, unsigned char* string ) | |||
1058 | 1127 | ||
1059 | #ifdef HAVE_LCD_BITMAP | 1128 | #ifdef HAVE_LCD_BITMAP |
1060 | s->space += 2; | 1129 | s->space += 2; |
1061 | lcd_getstringsize(string,0,&w,&h); | 1130 | lcd_getstringsize(string,curfont,&w,&h); |
1062 | if ( w > LCD_WIDTH - xmargin ) { | 1131 | if ( w > LCD_WIDTH - xmargin ) { |
1063 | #else | 1132 | #else |
1064 | if ( s->textlen > s->space ) { | 1133 | if ( s->textlen > s->space ) { |