diff options
author | Ben Basha <benbasha@rockbox.org> | 2006-02-10 13:57:11 +0000 |
---|---|---|
committer | Ben Basha <benbasha@rockbox.org> | 2006-02-10 13:57:11 +0000 |
commit | e0622ab588583d1148af54c0e856ae63339a3491 (patch) | |
tree | 89ee56eb249b4a02399690e35ea3d08d031ffcb9 /apps/gui | |
parent | 1e385fdaeb7f21d70c8f2dea180ce75461ac27b9 (diff) | |
download | rockbox-e0622ab588583d1148af54c0e856ae63339a3491.tar.gz rockbox-e0622ab588583d1148af54c0e856ae63339a3491.zip |
add a bitmap progress bar option + add %P|filename.bmp| tag to the WPS
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8648 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/gui')
-rw-r--r-- | apps/gui/gwps-common.c | 76 | ||||
-rw-r--r-- | apps/gui/gwps.c | 1 | ||||
-rw-r--r-- | apps/gui/gwps.h | 6 | ||||
-rw-r--r-- | apps/gui/scrollbar.c | 91 | ||||
-rw-r--r-- | apps/gui/scrollbar.h | 4 |
5 files changed, 172 insertions, 6 deletions
diff --git a/apps/gui/gwps-common.c b/apps/gui/gwps-common.c index 34d868f6a2..c918fddf5c 100644 --- a/apps/gui/gwps-common.c +++ b/apps/gui/gwps-common.c | |||
@@ -190,6 +190,61 @@ bool wps_data_preload_tags(struct wps_data *data, char *buf, | |||
190 | break; | 190 | break; |
191 | #endif | 191 | #endif |
192 | 192 | ||
193 | case 'P': | ||
194 | /* progress bar image */ | ||
195 | { | ||
196 | int ret = 0; | ||
197 | char *ptr = buf+2; | ||
198 | char *pos = NULL; | ||
199 | char imgname[MAX_PATH]; | ||
200 | |||
201 | /* format: %P|filename.bmp| */ | ||
202 | { | ||
203 | /* get filename */ | ||
204 | pos = strchr(ptr, '|'); | ||
205 | if ((pos - ptr) < | ||
206 | (int)sizeof(imgname)-ROCKBOX_DIR_LEN-2) | ||
207 | { | ||
208 | memcpy(imgname, bmpdir, bmpdirlen); | ||
209 | imgname[bmpdirlen] = '/'; | ||
210 | memcpy(&imgname[bmpdirlen+1], | ||
211 | ptr, pos - ptr); | ||
212 | imgname[bmpdirlen+1+pos-ptr] = 0; | ||
213 | } | ||
214 | else | ||
215 | /* filename too long */ | ||
216 | imgname[0] = 0; | ||
217 | |||
218 | ptr = pos+1; | ||
219 | |||
220 | /* load the image */ | ||
221 | data->progressbar.bm.data=data->img_buf_ptr; | ||
222 | ret = read_bmp_file(imgname, &data->progressbar.bm, | ||
223 | data->img_buf_free, | ||
224 | FORMAT_ANY|FORMAT_TRANSPARENT); | ||
225 | |||
226 | if (ret > 0) | ||
227 | { | ||
228 | #if LCD_DEPTH == 16 | ||
229 | if (ret % 2) ret++; | ||
230 | /* Always consume an even number of bytes */ | ||
231 | #endif | ||
232 | |||
233 | data->img_buf_ptr += ret; | ||
234 | data->img_buf_free -= ret; | ||
235 | |||
236 | if (data->progressbar.bm.width <= LCD_WIDTH) { | ||
237 | data->progressbar.have_bitmap_pb=true; | ||
238 | return true; | ||
239 | } else | ||
240 | return false; | ||
241 | } | ||
242 | |||
243 | } | ||
244 | } | ||
245 | |||
246 | break; | ||
247 | |||
193 | case 'x': | 248 | case 'x': |
194 | /* Preload images so the %xd# tag can display it */ | 249 | /* Preload images so the %xd# tag can display it */ |
195 | { | 250 | { |
@@ -1536,12 +1591,21 @@ bool gui_wps_refresh(struct gui_wps *gwps, int ffwd_offset, | |||
1536 | if (!data->progress_end) | 1591 | if (!data->progress_end) |
1537 | data->progress_end=display->width; | 1592 | data->progress_end=display->width; |
1538 | 1593 | ||
1539 | gui_scrollbar_draw(display, data->progress_start, sb_y, | 1594 | if (gwps->data->progressbar.have_bitmap_pb) |
1540 | data->progress_end-data->progress_start, | 1595 | gui_bitmap_scrollbar_draw(display, data->progressbar.bm, |
1541 | data->progress_height, | 1596 | data->progress_start, sb_y, |
1542 | state->id3->length?state->id3->length:1, 0, | 1597 | data->progress_end-data->progress_start, |
1543 | state->id3->length?state->id3->elapsed + state->ff_rewind_count:0, | 1598 | data->progressbar.bm.height, |
1544 | HORIZONTAL); | 1599 | state->id3->length?state->id3->length:1, 0, |
1600 | state->id3->length?state->id3->elapsed + state->ff_rewind_count:0, | ||
1601 | HORIZONTAL); | ||
1602 | else | ||
1603 | gui_scrollbar_draw(display, data->progress_start, sb_y, | ||
1604 | data->progress_end-data->progress_start, | ||
1605 | data->progress_height, | ||
1606 | state->id3->length?state->id3->length:1, 0, | ||
1607 | state->id3->length?state->id3->elapsed + state->ff_rewind_count:0, | ||
1608 | HORIZONTAL); | ||
1545 | #ifdef AB_REPEAT_ENABLE | 1609 | #ifdef AB_REPEAT_ENABLE |
1546 | if ( ab_repeat_mode_enabled() ) | 1610 | if ( ab_repeat_mode_enabled() ) |
1547 | ab_draw_markers(display, state->id3->length, 0, sb_y, | 1611 | ab_draw_markers(display, state->id3->length, 0, sb_y, |
diff --git a/apps/gui/gwps.c b/apps/gui/gwps.c index 024c3cc79f..166b2ec770 100644 --- a/apps/gui/gwps.c +++ b/apps/gui/gwps.c | |||
@@ -811,6 +811,7 @@ void wps_data_init(struct wps_data *wps_data) | |||
811 | } | 811 | } |
812 | wps_data->wps_sb_tag = false; | 812 | wps_data->wps_sb_tag = false; |
813 | wps_data->show_sb_on_wps = false; | 813 | wps_data->show_sb_on_wps = false; |
814 | wps_data->progressbar.have_bitmap_pb=false; | ||
814 | #else /* HAVE_LCD_CHARCELLS */ | 815 | #else /* HAVE_LCD_CHARCELLS */ |
815 | for(i = 0; i < 8; i++) | 816 | for(i = 0; i < 8; i++) |
816 | wps_data->wps_progress_pat[i] = 0; | 817 | wps_data->wps_progress_pat[i] = 0; |
diff --git a/apps/gui/gwps.h b/apps/gui/gwps.h index 4d586147af..2f63a4d1e4 100644 --- a/apps/gui/gwps.h +++ b/apps/gui/gwps.h | |||
@@ -263,6 +263,11 @@ struct gui_img{ | |||
263 | bool display; /* is to be displayed */ | 263 | bool display; /* is to be displayed */ |
264 | bool always_display; /* not using the preload/display mechanism */ | 264 | bool always_display; /* not using the preload/display mechanism */ |
265 | }; | 265 | }; |
266 | |||
267 | struct prog_img{ /*progressbar image*/ | ||
268 | struct bitmap bm; | ||
269 | bool have_bitmap_pb; | ||
270 | }; | ||
266 | #endif | 271 | #endif |
267 | 272 | ||
268 | struct align_pos { | 273 | struct align_pos { |
@@ -293,6 +298,7 @@ struct wps_data | |||
293 | { | 298 | { |
294 | #ifdef HAVE_LCD_BITMAP | 299 | #ifdef HAVE_LCD_BITMAP |
295 | struct gui_img img[MAX_IMAGES]; | 300 | struct gui_img img[MAX_IMAGES]; |
301 | struct prog_img progressbar; | ||
296 | unsigned char img_buf[IMG_BUFSIZE]; | 302 | unsigned char img_buf[IMG_BUFSIZE]; |
297 | unsigned char* img_buf_ptr; | 303 | unsigned char* img_buf_ptr; |
298 | int img_buf_free; | 304 | int img_buf_free; |
diff --git a/apps/gui/scrollbar.c b/apps/gui/scrollbar.c index 73c523f56a..4cf92f4b47 100644 --- a/apps/gui/scrollbar.c +++ b/apps/gui/scrollbar.c | |||
@@ -21,6 +21,7 @@ | |||
21 | #ifdef HAVE_LCD_BITMAP | 21 | #ifdef HAVE_LCD_BITMAP |
22 | #include "config.h" | 22 | #include "config.h" |
23 | #include "limits.h" | 23 | #include "limits.h" |
24 | #include "bmp.h" | ||
24 | 25 | ||
25 | void gui_scrollbar_draw(struct screen * screen, int x, int y, | 26 | void gui_scrollbar_draw(struct screen * screen, int x, int y, |
26 | int width, int height, int items, | 27 | int width, int height, int items, |
@@ -101,4 +102,94 @@ void gui_scrollbar_draw(struct screen * screen, int x, int y, | |||
101 | else | 102 | else |
102 | screen->fillrect(x + start + 1, y + 1, size, height - 2); | 103 | screen->fillrect(x + start + 1, y + 1, size, height - 2); |
103 | } | 104 | } |
105 | |||
106 | void gui_bitmap_scrollbar_draw(struct screen * screen, struct bitmap bm, int x, int y, | ||
107 | int width, int height, int items, | ||
108 | int min_shown, int max_shown, | ||
109 | enum orientation orientation) | ||
110 | { | ||
111 | int min; | ||
112 | int max; | ||
113 | int inner_len; | ||
114 | int start; | ||
115 | int size; | ||
116 | |||
117 | screen->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); | ||
118 | |||
119 | /* clear pixels in progress bar */ | ||
120 | screen->fillrect(x, y, width, height); | ||
121 | |||
122 | /* min should be min */ | ||
123 | if(min_shown < max_shown) { | ||
124 | min = min_shown; | ||
125 | max = max_shown; | ||
126 | } | ||
127 | else { | ||
128 | min = max_shown; | ||
129 | max = min_shown; | ||
130 | } | ||
131 | |||
132 | /* limit min and max */ | ||
133 | if(min < 0) | ||
134 | min = 0; | ||
135 | if(min > items) | ||
136 | min = items; | ||
137 | |||
138 | if(max < 0) | ||
139 | max = 0; | ||
140 | if(max > items) | ||
141 | max = items; | ||
142 | |||
143 | if (orientation == VERTICAL) | ||
144 | inner_len = height; | ||
145 | else | ||
146 | inner_len = width; | ||
147 | |||
148 | /* avoid overflows */ | ||
149 | while (items > (INT_MAX / inner_len)) { | ||
150 | items >>= 1; | ||
151 | min >>= 1; | ||
152 | max >>= 1; | ||
153 | } | ||
154 | |||
155 | /* calc start and end of the knob */ | ||
156 | if (items > 0 && items > (max - min)) { | ||
157 | size = inner_len * (max - min) / items; | ||
158 | if (size == 0) { /* width of knob is null */ | ||
159 | size = 1; | ||
160 | start = (inner_len - 1) * min / items; | ||
161 | } else { | ||
162 | start = (inner_len - size) * min / (items - (max - min)); | ||
163 | } | ||
164 | } else { /* if null draw full bar */ | ||
165 | size = inner_len; | ||
166 | start = 0; | ||
167 | } | ||
168 | |||
169 | screen->set_drawmode(DRMODE_SOLID); | ||
170 | |||
171 | if(orientation == VERTICAL) { | ||
172 | #if LCD_DEPTH > 1 | ||
173 | if (bm.format == FORMAT_MONO) | ||
174 | #endif | ||
175 | screen->mono_bitmap_part(bm.data, 0, 0, | ||
176 | bm.width, x, y + start, width, size); | ||
177 | #if LCD_DEPTH > 1 | ||
178 | else | ||
179 | screen->transparent_bitmap_part((fb_data *)bm.data, 0, 0, | ||
180 | bm.width, x, y + start, width, size); | ||
181 | #endif | ||
182 | } else { | ||
183 | #if LCD_DEPTH > 1 | ||
184 | if (bm.format == FORMAT_MONO) | ||
185 | #endif | ||
186 | screen->mono_bitmap_part(bm.data, 0, 0, | ||
187 | bm.width, x + start, y, size, height); | ||
188 | #if LCD_DEPTH > 1 | ||
189 | else | ||
190 | screen->transparent_bitmap_part((fb_data *)bm.data, 0, 0, | ||
191 | bm.width, x + start, y, size, height); | ||
192 | #endif | ||
193 | } | ||
194 | } | ||
104 | #endif /* HAVE_LCD_BITMAP */ | 195 | #endif /* HAVE_LCD_BITMAP */ |
diff --git a/apps/gui/scrollbar.h b/apps/gui/scrollbar.h index d7d0be7a7e..541cc2d4df 100644 --- a/apps/gui/scrollbar.h +++ b/apps/gui/scrollbar.h | |||
@@ -44,5 +44,9 @@ extern void gui_scrollbar_draw(struct screen * screen, int x, int y, | |||
44 | int width, int height, int items, | 44 | int width, int height, int items, |
45 | int min_shown, int max_shown, | 45 | int min_shown, int max_shown, |
46 | enum orientation orientation); | 46 | enum orientation orientation); |
47 | extern void gui_bitmap_scrollbar_draw(struct screen * screen, struct bitmap bm, int x, int y, | ||
48 | int width, int height, int items, | ||
49 | int min_shown, int max_shown, | ||
50 | enum orientation orientation); | ||
47 | #endif /* HAVE_LCD_BITMAP */ | 51 | #endif /* HAVE_LCD_BITMAP */ |
48 | #endif /* _GUI_SCROLLBAR_H_ */ | 52 | #endif /* _GUI_SCROLLBAR_H_ */ |