summaryrefslogtreecommitdiff
path: root/firmware/drivers/lcd-2bit-vi.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-vi.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-vi.c')
-rw-r--r--firmware/drivers/lcd-2bit-vi.c225
1 files changed, 2 insertions, 223 deletions
diff --git a/firmware/drivers/lcd-2bit-vi.c b/firmware/drivers/lcd-2bit-vi.c
index 0a73f0dd25..47f755f240 100644
--- a/firmware/drivers/lcd-2bit-vi.c
+++ b/firmware/drivers/lcd-2bit-vi.c
@@ -66,7 +66,7 @@ static struct viewport default_vp =
66 .bg_pattern = LCDM(DEFAULT_BG) 66 .bg_pattern = LCDM(DEFAULT_BG)
67}; 67};
68 68
69static struct viewport *current_vp IBSS_ATTR; 69static struct viewport * current_vp IBSS_ATTR;
70 70
71static unsigned fg_pattern IBSS_ATTR; 71static unsigned fg_pattern IBSS_ATTR;
72static unsigned bg_pattern IBSS_ATTR; 72static unsigned bg_pattern IBSS_ATTR;
@@ -1016,225 +1016,4 @@ void LCDFN(bitmap)(const FBFN(data) *src, int x, int y, int width, int height)
1016 LCDFN(bitmap_part)(src, 0, 0, width, x, y, width, height); 1016 LCDFN(bitmap_part)(src, 0, 0, width, x, y, width, height);
1017} 1017}
1018 1018
1019/* put a string at a given pixel position, skipping first ofs pixel columns */ 1019#include "lcd-bitmap-common.c"
1020static void LCDFN(putsxyofs)(int x, int y, int ofs, const unsigned char *str)
1021{
1022 unsigned short ch;
1023 unsigned short *ucs;
1024 struct font* pf = font_get(current_vp->font);
1025
1026 ucs = bidi_l2v(str, 1);
1027
1028 while ((ch = *ucs++) != 0 && x < current_vp->width)
1029 {
1030 int width;
1031 const unsigned char *bits;
1032
1033 /* get proportional width and glyph bits */
1034 width = font_get_width(pf, ch);
1035
1036 if (ofs > width)
1037 {
1038 ofs -= width;
1039 continue;
1040 }
1041
1042 bits = font_get_bits(pf, ch);
1043
1044 LCDFN(mono_bitmap_part)(bits, ofs, 0, width, x, y, width - ofs,
1045 pf->height);
1046
1047 x += width - ofs;
1048 ofs = 0;
1049 }
1050}
1051
1052/* put a string at a given pixel position */
1053void LCDFN(putsxy)(int x, int y, const unsigned char *str)
1054{
1055 LCDFN(putsxyofs)(x, y, 0, str);
1056}
1057
1058/*** line oriented text output ***/
1059
1060/* put a string at a given char position */
1061void LCDFN(puts)(int x, int y, const unsigned char *str)
1062{
1063 LCDFN(puts_style_offset)(x, y, str, STYLE_DEFAULT, 0);
1064}
1065
1066void LCDFN(puts_style)(int x, int y, const unsigned char *str, int style)
1067{
1068 LCDFN(puts_style_offset)(x, y, str, style, 0);
1069}
1070
1071void LCDFN(puts_offset)(int x, int y, const unsigned char *str, int offset)
1072{
1073 LCDFN(puts_style_offset)(x, y, str, STYLE_DEFAULT, offset);
1074}
1075
1076/* put a string at a given char position, style, and pixel position,
1077 * skipping first offset pixel columns */
1078void LCDFN(puts_style_offset)(int x, int y, const unsigned char *str,
1079 int style, int offset)
1080{
1081 int xpos,ypos,w,h,xrect;
1082 int lastmode = current_vp->drawmode;
1083
1084 /* make sure scrolling is turned off on the line we are updating */
1085 LCDFN(scroll_stop_line)(current_vp, y);
1086
1087 if(!str || !str[0])
1088 return;
1089
1090 LCDFN(getstringsize)(str, &w, &h);
1091 xpos = x*w / utf8length((char *)str);
1092 ypos = y*h;
1093 current_vp->drawmode = (style & STYLE_INVERT) ?
1094 (DRMODE_SOLID|DRMODE_INVERSEVID) : DRMODE_SOLID;
1095 LCDFN(putsxyofs)(xpos, ypos, offset, str);
1096 current_vp->drawmode ^= DRMODE_INVERSEVID;
1097 xrect = xpos + MAX(w - offset, 0);
1098 LCDFN(fillrect)(xrect, ypos, current_vp->width - xrect, h);
1099 current_vp->drawmode = lastmode;
1100}
1101
1102/*** scrolling ***/
1103void LCDFN(puts_scroll)(int x, int y, const unsigned char *string)
1104{
1105 LCDFN(puts_scroll_style)(x, y, string, STYLE_DEFAULT);
1106}
1107
1108void LCDFN(puts_scroll_style)(int x, int y, const unsigned char *string, int style)
1109{
1110 LCDFN(puts_scroll_style_offset)(x, y, string, style, 0);
1111}
1112
1113void LCDFN(puts_scroll_offset)(int x, int y, const unsigned char *string, int offset)
1114{
1115 LCDFN(puts_scroll_style_offset)(x, y, string, STYLE_DEFAULT, offset);
1116}
1117
1118void LCDFN(puts_scroll_style_offset)(int x, int y, const unsigned char *string,
1119 int style, int offset)
1120{
1121 struct scrollinfo* s;
1122 int w, h;
1123
1124 if ((unsigned)y >= (unsigned)current_vp->height)
1125 return;
1126
1127 /* remove any previously scrolling line at the same location */
1128 LCDFN(scroll_stop_line)(current_vp, y);
1129
1130 if (LCDFN(scroll_info).lines >= LCDM(SCROLLABLE_LINES)) return;
1131
1132 s = &LCDFN(scroll_info).scroll[LCDFN(scroll_info).lines];
1133
1134 s->start_tick = current_tick + LCDFN(scroll_info).delay;
1135 s->style = style;
1136 if (style & STYLE_INVERT) {
1137 LCDFN(puts_style_offset)(x,y,string,STYLE_INVERT,offset);
1138 }
1139 else
1140 LCDFN(puts_offset)(x,y,string,offset);
1141
1142 LCDFN(getstringsize)(string, &w, &h);
1143
1144 if (current_vp->width - x * 8 < w) {
1145 /* prepare scroll line */
1146 char *end;
1147
1148 memset(s->line, 0, sizeof s->line);
1149 strcpy(s->line, string);
1150
1151 /* get width */
1152 s->width = LCDFN(getstringsize)(s->line, &w, &h);
1153
1154 /* scroll bidirectional or forward only depending on the string
1155 width */
1156 if ( LCDFN(scroll_info).bidir_limit ) {
1157 s->bidir = s->width < (current_vp->width) *
1158 (100 + LCDFN(scroll_info).bidir_limit) / 100;
1159 }
1160 else
1161 s->bidir = false;
1162
1163 if (!s->bidir) { /* add spaces if scrolling in the round */
1164 strcat(s->line, " ");
1165 /* get new width incl. spaces */
1166 s->width = LCDFN(getstringsize)(s->line, &w, &h);
1167 }
1168
1169 end = strchr(s->line, '\0');
1170 strlcpy(end, (char *)string, current_vp->width/2);
1171
1172 s->vp = current_vp;
1173 s->y = y;
1174 s->len = utf8length((char *)string);
1175 s->offset = offset;
1176 s->startx = x * s->width / s->len;
1177 s->backward = false;
1178
1179 LCDFN(scroll_info).lines++;
1180 }
1181}
1182
1183void LCDFN(scroll_fn)(void)
1184{
1185 struct font* pf;
1186 struct scrollinfo* s;
1187 int index;
1188 int xpos, ypos;
1189 int lastmode;
1190 struct viewport* old_vp = current_vp;
1191
1192 for ( index = 0; index < LCDFN(scroll_info).lines; index++ ) {
1193 s = &LCDFN(scroll_info).scroll[index];
1194
1195 /* check pause */
1196 if (TIME_BEFORE(current_tick, s->start_tick))
1197 continue;
1198
1199 LCDFN(set_viewport)(s->vp);
1200
1201 if (s->backward)
1202 s->offset -= LCDFN(scroll_info).step;
1203 else
1204 s->offset += LCDFN(scroll_info).step;
1205
1206 pf = font_get(current_vp->font);
1207 xpos = s->startx;
1208 ypos = s->y * pf->height;
1209
1210 if (s->bidir) { /* scroll bidirectional */
1211 if (s->offset <= 0) {
1212 /* at beginning of line */
1213 s->offset = 0;
1214 s->backward = false;
1215 s->start_tick = current_tick + LCDFN(scroll_info).delay * 2;
1216 }
1217 if (s->offset >= s->width - (current_vp->width - xpos)) {
1218 /* at end of line */
1219 s->offset = s->width - (current_vp->width - xpos);
1220 s->backward = true;
1221 s->start_tick = current_tick + LCDFN(scroll_info).delay * 2;
1222 }
1223 }
1224 else {
1225 /* scroll forward the whole time */
1226 if (s->offset >= s->width)
1227 s->offset %= s->width;
1228 }
1229
1230 lastmode = current_vp->drawmode;
1231 current_vp->drawmode = (s->style&STYLE_INVERT) ?
1232 (DRMODE_SOLID|DRMODE_INVERSEVID) : DRMODE_SOLID;
1233 LCDFN(putsxyofs)(xpos, ypos, s->offset, s->line);
1234 current_vp->drawmode = lastmode;
1235 LCDFN(update_viewport_rect)(xpos, ypos,
1236 current_vp->width - xpos, pf->height);
1237 }
1238
1239 LCDFN(set_viewport)(old_vp);
1240}