summaryrefslogtreecommitdiff
path: root/firmware/drivers/lcd-2bit-horz.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/drivers/lcd-2bit-horz.c')
-rw-r--r--firmware/drivers/lcd-2bit-horz.c221
1 files changed, 1 insertions, 220 deletions
diff --git a/firmware/drivers/lcd-2bit-horz.c b/firmware/drivers/lcd-2bit-horz.c
index 463eece569..bb540a9ae1 100644
--- a/firmware/drivers/lcd-2bit-horz.c
+++ b/firmware/drivers/lcd-2bit-horz.c
@@ -956,223 +956,4 @@ void lcd_bitmap(const unsigned char *src, int x, int y, int width, int height)
956 lcd_bitmap_part(src, 0, 0, width, x, y, width, height); 956 lcd_bitmap_part(src, 0, 0, width, x, y, width, height);
957} 957}
958 958
959/* put a string at a given pixel position, skipping first ofs pixel columns */ 959#include "lcd-bitmap-common.c"
960static void lcd_putsxyofs(int x, int y, int ofs, const unsigned char *str)
961{
962 unsigned short ch;
963 unsigned short *ucs;
964 struct font* pf = font_get(current_vp->font);
965
966 ucs = bidi_l2v(str, 1);
967
968 while ((ch = *ucs++) != 0 && x < current_vp->width)
969 {
970 int width;
971 const unsigned char *bits;
972
973 /* get proportional width and glyph bits */
974 width = font_get_width(pf,ch);
975
976 if (ofs > width)
977 {
978 ofs -= width;
979 continue;
980 }
981
982 bits = font_get_bits(pf, ch);
983
984 lcd_mono_bitmap_part(bits, ofs, 0, width, x, y, width - ofs,
985 pf->height);
986
987 x += width - ofs;
988 ofs = 0;
989 }
990}
991
992/* put a string at a given pixel position */
993void lcd_putsxy(int x, int y, const unsigned char *str)
994{
995 lcd_putsxyofs(x, y, 0, str);
996}
997
998/*** line oriented text output ***/
999
1000/* put a string at a given char position */
1001void lcd_puts(int x, int y, const unsigned char *str)
1002{
1003 lcd_puts_style_offset(x, y, str, STYLE_DEFAULT, 0);
1004}
1005
1006void lcd_puts_style(int x, int y, const unsigned char *str, int style)
1007{
1008 lcd_puts_style_offset(x, y, str, style, 0);
1009}
1010
1011void lcd_puts_offset(int x, int y, const unsigned char *str, int offset)
1012{
1013 lcd_puts_style_offset(x, y, str, STYLE_DEFAULT, offset);
1014}
1015
1016/* put a string at a given char position, style, and pixel position,
1017 * skipping first offset pixel columns */
1018void lcd_puts_style_offset(int x, int y, const unsigned char *str,
1019 int style, int offset)
1020{
1021 int xpos,ypos,w,h,xrect;
1022 int lastmode = current_vp->drawmode;
1023
1024 /* make sure scrolling is turned off on the line we are updating */
1025 lcd_scroll_stop_line(current_vp, y);
1026
1027 if(!str || !str[0])
1028 return;
1029
1030 lcd_getstringsize(str, &w, &h);
1031 xpos = x*w / utf8length((char *)str);
1032 ypos = y*h;
1033 current_vp->drawmode = (style & STYLE_INVERT) ?
1034 (DRMODE_SOLID|DRMODE_INVERSEVID) : DRMODE_SOLID;
1035 lcd_putsxyofs(xpos, ypos, offset, str);
1036 current_vp->drawmode ^= DRMODE_INVERSEVID;
1037 xrect = xpos + MAX(w - offset, 0);
1038 lcd_fillrect(xrect, ypos, current_vp->width - xrect, h);
1039 current_vp->drawmode = lastmode;
1040}
1041
1042/*** scrolling ***/
1043void lcd_puts_scroll(int x, int y, const unsigned char *string)
1044{
1045 lcd_puts_scroll_style(x, y, string, STYLE_DEFAULT);
1046}
1047
1048void lcd_puts_scroll_style(int x, int y, const unsigned char *string, int style)
1049{
1050 lcd_puts_scroll_style_offset(x, y, string, style, 0);
1051}
1052
1053void lcd_puts_scroll_offset(int x, int y, const unsigned char *string, int offset)
1054{
1055 lcd_puts_scroll_style_offset(x, y, string, STYLE_DEFAULT, offset);
1056}
1057
1058void lcd_puts_scroll_style_offset(int x, int y, const unsigned char *string,
1059 int style, int offset)
1060{
1061 struct scrollinfo* s;
1062 int w, h;
1063
1064 if ((unsigned)y >= (unsigned)current_vp->height)
1065 return;
1066
1067 /* remove any previously scrolling line at the same location */
1068 lcd_scroll_stop_line(current_vp, y);
1069
1070 if (lcd_scroll_info.lines >= LCD_SCROLLABLE_LINES) return;
1071
1072 s = &lcd_scroll_info.scroll[lcd_scroll_info.lines];
1073
1074 s->start_tick = current_tick + lcd_scroll_info.delay;
1075 s->style = style;
1076 if (style & STYLE_INVERT) {
1077 lcd_puts_style_offset(x,y,string,STYLE_INVERT,offset);
1078 }
1079 else
1080 lcd_puts_offset(x,y,string,offset);
1081
1082 lcd_getstringsize(string, &w, &h);
1083
1084 if (current_vp->width - x * 8 < w) {
1085 /* prepare scroll line */
1086 char *end;
1087
1088 memset(s->line, 0, sizeof s->line);
1089 strcpy(s->line, (char *)string);
1090
1091 /* get width */
1092 s->width = lcd_getstringsize((unsigned char *)s->line, &w, &h);
1093
1094 /* scroll bidirectional or forward only depending on the string
1095 width */
1096 if ( lcd_scroll_info.bidir_limit ) {
1097 s->bidir = s->width < (current_vp->width) *
1098 (100 + lcd_scroll_info.bidir_limit) / 100;
1099 }
1100 else
1101 s->bidir = false;
1102
1103 if (!s->bidir) { /* add spaces if scrolling in the round */
1104 strcat(s->line, " ");
1105 /* get new width incl. spaces */
1106 s->width = lcd_getstringsize((unsigned char *)s->line, &w, &h);
1107 }
1108
1109 end = strchr(s->line, '\0');
1110 strlcpy(end, (char *)string, current_vp->width/2);
1111
1112 s->vp = current_vp;
1113 s->y = y;
1114 s->len = utf8length((char *)string);
1115 s->offset = offset;
1116 s->startx = x * s->width / s->len;
1117 s->backward = false;
1118 lcd_scroll_info.lines++;
1119 }
1120}
1121
1122void lcd_scroll_fn(void)
1123{
1124 struct font* pf;
1125 struct scrollinfo* s;
1126 int index;
1127 int xpos, ypos;
1128 int lastmode;
1129 struct viewport* old_vp = current_vp;
1130
1131 for ( index = 0; index < lcd_scroll_info.lines; index++ ) {
1132 s = &lcd_scroll_info.scroll[index];
1133
1134 /* check pause */
1135 if (TIME_BEFORE(current_tick, s->start_tick))
1136 continue;
1137
1138 lcd_set_viewport(s->vp);
1139
1140 if (s->backward)
1141 s->offset -= lcd_scroll_info.step;
1142 else
1143 s->offset += lcd_scroll_info.step;
1144
1145 pf = font_get(current_vp->font);
1146 xpos = s->startx;
1147 ypos = s->y * pf->height;
1148
1149 if (s->bidir) { /* scroll bidirectional */
1150 if (s->offset <= 0) {
1151 /* at beginning of line */
1152 s->offset = 0;
1153 s->backward = false;
1154 s->start_tick = current_tick + lcd_scroll_info.delay * 2;
1155 }
1156 if (s->offset >= s->width - (current_vp->width - xpos)) {
1157 /* at end of line */
1158 s->offset = s->width - (current_vp->width - xpos);
1159 s->backward = true;
1160 s->start_tick = current_tick + lcd_scroll_info.delay * 2;
1161 }
1162 }
1163 else {
1164 /* scroll forward the whole time */
1165 if (s->offset >= s->width)
1166 s->offset %= s->width;
1167 }
1168
1169 lastmode = current_vp->drawmode;
1170 current_vp->drawmode = (s->style&STYLE_INVERT) ?
1171 (DRMODE_SOLID|DRMODE_INVERSEVID) : DRMODE_SOLID;
1172 lcd_putsxyofs(xpos, ypos, s->offset, s->line);
1173 current_vp->drawmode = lastmode;
1174 lcd_update_viewport_rect(xpos, ypos, current_vp->width - xpos, pf->height);
1175 }
1176
1177 lcd_set_viewport(old_vp);
1178}