summaryrefslogtreecommitdiff
path: root/firmware/drivers/lcd-2bit-vert.c
diff options
context:
space:
mode:
authorAndrew Mahone <andrew.mahone@gmail.com>2009-08-13 08:02:29 +0000
committerAndrew Mahone <andrew.mahone@gmail.com>2009-08-13 08:02:29 +0000
commite04f95eab9eaf51fcef2f56c258ea68d8df97d9d (patch)
tree4b61a8bce979386d83ba09bc74e20fe8d159bea0 /firmware/drivers/lcd-2bit-vert.c
parentce00e283b5c54523ebc9e8c83f5a59f4823d3139 (diff)
downloadrockbox-e04f95eab9eaf51fcef2f56c258ea68d8df97d9d.tar.gz
rockbox-e04f95eab9eaf51fcef2f56c258ea68d8df97d9d.zip
LCD bitmap driver code consolidation from FS#4817:
Move text-drawing code into firmware-drivers/lcd-bitmap-common.c, included by the various driver files. Add new static function LCDFN(putsxyofs_style) to draw styled text, and use it in both LCDFN(puts_style_offset) and LCDFN(scroll_fn). Merge lcd_gradient_rect functions, with new function containing simplified code for drawing one line of a multi-line gradient. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22289 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/drivers/lcd-2bit-vert.c')
-rw-r--r--firmware/drivers/lcd-2bit-vert.c226
1 files changed, 2 insertions, 224 deletions
diff --git a/firmware/drivers/lcd-2bit-vert.c b/firmware/drivers/lcd-2bit-vert.c
index 57d27d2ead..7342cbd4ff 100644
--- a/firmware/drivers/lcd-2bit-vert.c
+++ b/firmware/drivers/lcd-2bit-vert.c
@@ -404,7 +404,7 @@ void lcd_clear_viewport(void)
404 lastmode = current_vp->drawmode; 404 lastmode = current_vp->drawmode;
405 405
406 /* Invert the INVERSEVID bit and set basic mode to SOLID */ 406 /* Invert the INVERSEVID bit and set basic mode to SOLID */
407 current_vp->drawmode = (~lastmode & DRMODE_INVERSEVID) | 407 current_vp->drawmode = (~lastmode & DRMODE_INVERSEVID) |
408 DRMODE_SOLID; 408 DRMODE_SOLID;
409 409
410 lcd_fillrect(0, 0, current_vp->width, current_vp->height); 410 lcd_fillrect(0, 0, current_vp->width, current_vp->height);
@@ -1002,226 +1002,4 @@ void lcd_bitmap(const fb_data *src, int x, int y, int width, int height)
1002 lcd_bitmap_part(src, 0, 0, width, x, y, width, height); 1002 lcd_bitmap_part(src, 0, 0, width, x, y, width, height);
1003} 1003}
1004 1004
1005/* put a string at a given pixel position, skipping first ofs pixel columns */ 1005#include "lcd-bitmap-common.c"
1006static void lcd_putsxyofs(int x, int y, int ofs, const unsigned char *str)
1007{
1008 unsigned short ch;
1009 unsigned short *ucs;
1010 struct font* pf = font_get(current_vp->font);
1011
1012 ucs = bidi_l2v(str, 1);
1013
1014 while ((ch = *ucs++) != 0 && x < current_vp->width)
1015 {
1016 int width;
1017 const unsigned char *bits;
1018
1019 /* get proportional width and glyph bits */
1020 width = font_get_width(pf,ch);
1021
1022 if (ofs > width)
1023 {
1024 ofs -= width;
1025 continue;
1026 }
1027
1028 bits = font_get_bits(pf, ch);
1029
1030 lcd_mono_bitmap_part(bits, ofs, 0, width, x, y, width - ofs,
1031 pf->height);
1032
1033 x += width - ofs;
1034 ofs = 0;
1035 }
1036}
1037
1038/* put a string at a given pixel position */
1039void lcd_putsxy(int x, int y, const unsigned char *str)
1040{
1041 lcd_putsxyofs(x, y, 0, str);
1042}
1043
1044/*** line oriented text output ***/
1045
1046/* put a string at a given char position */
1047void lcd_puts(int x, int y, const unsigned char *str)
1048{
1049 lcd_puts_style_offset(x, y, str, STYLE_DEFAULT, 0);
1050}
1051
1052void lcd_puts_style(int x, int y, const unsigned char *str, int style)
1053{
1054 lcd_puts_style_offset(x, y, str, style, 0);
1055}
1056
1057void lcd_puts_offset(int x, int y, const unsigned char *str, int offset)
1058{
1059 lcd_puts_style_offset(x, y, str, STYLE_DEFAULT, offset);
1060}
1061
1062/* put a string at a given char position, style, and pixel position,
1063 * skipping first offset pixel columns */
1064void lcd_puts_style_offset(int x, int y, const unsigned char *str,
1065 int style, int offset)
1066{
1067 int xpos,ypos,w,h,xrect;
1068 int lastmode = current_vp->drawmode;
1069
1070 /* make sure scrolling is turned off on the line we are updating */
1071 lcd_scroll_stop_line(current_vp, y);
1072
1073 if(!str || !str[0])
1074 return;
1075
1076 lcd_getstringsize(str, &w, &h);
1077 xpos = x*w / utf8length((char *)str);
1078 ypos = y*h;
1079 current_vp->drawmode = (style & STYLE_INVERT) ?
1080 (DRMODE_SOLID|DRMODE_INVERSEVID) : DRMODE_SOLID;
1081 lcd_putsxyofs(xpos, ypos, offset, str);
1082 current_vp->drawmode ^= DRMODE_INVERSEVID;
1083 xrect = xpos + MAX(w - offset, 0);
1084 lcd_fillrect(xrect, ypos, current_vp->width - xrect, h);
1085 current_vp->drawmode = lastmode;
1086}
1087
1088/*** scrolling ***/
1089
1090void lcd_puts_scroll(int x, int y, const unsigned char *string)
1091{
1092 lcd_puts_scroll_style(x, y, string, STYLE_DEFAULT);
1093}
1094
1095void lcd_puts_scroll_style(int x, int y, const unsigned char *string, int style)
1096{
1097 lcd_puts_scroll_style_offset(x, y, string, style, 0);
1098}
1099
1100void lcd_puts_scroll_offset(int x, int y, const unsigned char *string, int offset)
1101{
1102 lcd_puts_scroll_style_offset(x, y, string, STYLE_DEFAULT, offset);
1103}
1104
1105void lcd_puts_scroll_style_offset(int x, int y, const unsigned char *string,
1106 int style, int offset)
1107{
1108 struct scrollinfo* s;
1109 int w, h;
1110
1111 if ((unsigned)y >= (unsigned)current_vp->height)
1112 return;
1113
1114 /* remove any previously scrolling line at the same location */
1115 lcd_scroll_stop_line(current_vp, y);
1116
1117 if (lcd_scroll_info.lines >= LCD_SCROLLABLE_LINES) return;
1118
1119 s = &lcd_scroll_info.scroll[lcd_scroll_info.lines];
1120
1121 s->start_tick = current_tick + lcd_scroll_info.delay;
1122 s->style = style;
1123 if (style & STYLE_INVERT) {
1124 lcd_puts_style_offset(x,y,string,STYLE_INVERT,offset);
1125 }
1126 else
1127 lcd_puts_offset(x,y,string,offset);
1128
1129 lcd_getstringsize(string, &w, &h);
1130
1131 if (current_vp->width - x * 8< w) {
1132 /* prepare scroll line */
1133 char *end;
1134
1135 memset(s->line, 0, sizeof s->line);
1136 strcpy(s->line, (char *)string);
1137
1138 /* get width */
1139 s->width = lcd_getstringsize((unsigned char *)s->line, &w, &h);
1140
1141 /* scroll bidirectional or forward only depending on the string
1142 width */
1143 if ( lcd_scroll_info.bidir_limit ) {
1144 s->bidir = s->width < (current_vp->width) *
1145 (100 + lcd_scroll_info.bidir_limit) / 100;
1146 }
1147 else
1148 s->bidir = false;
1149
1150 if (!s->bidir) { /* add spaces if scrolling in the round */
1151 strcat(s->line, " ");
1152 /* get new width incl. spaces */
1153 s->width = lcd_getstringsize((unsigned char *)s->line, &w, &h);
1154 }
1155
1156 end = strchr(s->line, '\0');
1157 strlcpy(end, (char *)string, current_vp->width/2);
1158
1159 s->vp = current_vp;
1160 s->y = y;
1161 s->len = utf8length((char *)string);
1162 s->offset = offset;
1163 s->startx = x * s->width / s->len;
1164 s->backward = false;
1165
1166 lcd_scroll_info.lines++;
1167 }
1168}
1169
1170void lcd_scroll_fn(void)
1171{
1172 struct font* pf;
1173 struct scrollinfo* s;
1174 int index;
1175 int xpos, ypos;
1176 int lastmode;
1177 struct viewport* old_vp = current_vp;
1178
1179 for ( index = 0; index < lcd_scroll_info.lines; index++ ) {
1180 s = &lcd_scroll_info.scroll[index];
1181
1182 /* check pause */
1183 if (TIME_BEFORE(current_tick, s->start_tick))
1184 continue;
1185
1186 lcd_set_viewport(s->vp);
1187
1188 if (s->backward)
1189 s->offset -= lcd_scroll_info.step;
1190 else
1191 s->offset += lcd_scroll_info.step;
1192
1193 pf = font_get(current_vp->font);
1194 xpos = s->startx;
1195 ypos = s->y * pf->height;
1196
1197 if (s->bidir) { /* scroll bidirectional */
1198 if (s->offset <= 0) {
1199 /* at beginning of line */
1200 s->offset = 0;
1201 s->backward = false;
1202 s->start_tick = current_tick + lcd_scroll_info.delay * 2;
1203 }
1204 if (s->offset >= s->width - (current_vp->width - xpos)) {
1205 /* at end of line */
1206 s->offset = s->width - (current_vp->width - xpos);
1207 s->backward = true;
1208 s->start_tick = current_tick + lcd_scroll_info.delay * 2;
1209 }
1210 }
1211 else {
1212 /* scroll forward the whole time */
1213 if (s->offset >= s->width)
1214 s->offset %= s->width;
1215 }
1216
1217 lastmode = current_vp->drawmode;
1218 current_vp->drawmode = (s->style&STYLE_INVERT) ?
1219 (DRMODE_SOLID|DRMODE_INVERSEVID) : DRMODE_SOLID;
1220 lcd_putsxyofs(xpos, ypos, s->offset, s->line);
1221 current_vp->drawmode = lastmode;
1222 lcd_update_viewport_rect(xpos, ypos,
1223 current_vp->width - xpos, pf->height);
1224 }
1225
1226 lcd_set_viewport(old_vp);
1227}