summaryrefslogtreecommitdiff
path: root/apps/screens.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/screens.c')
-rw-r--r--apps/screens.c280
1 files changed, 160 insertions, 120 deletions
diff --git a/apps/screens.c b/apps/screens.c
index 2c7d5fe9b1..1cbda99d0f 100644
--- a/apps/screens.c
+++ b/apps/screens.c
@@ -46,11 +46,16 @@
46#include "led.h" 46#include "led.h"
47#include "sound.h" 47#include "sound.h"
48#include "wps-display.h" 48#include "wps-display.h"
49#if defined(HAVE_LCD_BITMAP)
50#include "widgets.h"
51#endif
49#ifdef HAVE_MMC 52#ifdef HAVE_MMC
50#include "ata_mmc.h" 53#include "ata_mmc.h"
51#endif 54#endif
52 55
53#ifdef HAVE_LCD_BITMAP 56#ifdef HAVE_LCD_BITMAP
57#define SCROLLBAR_WIDTH 6
58
54#define BMPHEIGHT_usb_logo 32 59#define BMPHEIGHT_usb_logo 32
55#define BMPWIDTH_usb_logo 100 60#define BMPWIDTH_usb_logo 100
56static const unsigned char usb_logo[] = { 61static const unsigned char usb_logo[] = {
@@ -1269,156 +1274,186 @@ bool shutdown_screen(void)
1269} 1274}
1270#endif 1275#endif
1271 1276
1272bool browse_id3(void) 1277int draw_id3_item(int line, int top, int header, const char* body)
1273{ 1278{
1274 struct mp3entry* id3 = audio_current_track(); 1279 if (line >= top)
1275 int button; 1280 {
1276 int menu_pos = 0; 1281#if defined(HAVE_LCD_BITMAP)
1282 const int rows = LCD_HEIGHT / font_get(FONT_UI)->height;
1283#else
1284 const int rows = 2;
1285#endif
1286 int y = line - top;
1287
1288 if (y < rows)
1289 {
1290 lcd_puts(0, y, str(header));
1291 }
1292
1293 if (++y < rows)
1294 {
1295 lcd_puts_scroll(0, y,
1296 body ? (const unsigned char*) body : str(LANG_ID3_NO_INFO));
1297 }
1298 }
1299
1300 return line + 2;
1301}
1302
1277#if CONFIG_HWCODEC == MASNONE 1303#if CONFIG_HWCODEC == MASNONE
1278 int menu_max = 12; 1304#define ID3_ITEMS 13
1279#else 1305#else
1280 int menu_max = 10; 1306#define ID3_ITEMS 11
1281#endif 1307#endif
1308
1309bool browse_id3(void)
1310{
1311 char buf[32];
1312 const struct mp3entry* id3 = audio_current_track();
1313#if defined(HAVE_LCD_BITMAP)
1314 const int y_margin = lcd_getymargin();
1315 const int line_height = font_get(FONT_UI)->height;
1316 const int rows = (LCD_HEIGHT - y_margin) / line_height;
1317 const bool show_scrollbar = global_settings.scrollbar
1318 && (ID3_ITEMS * 2 > rows);
1319#else
1320 const int rows = 2;
1321#endif
1322 const int top_max = (ID3_ITEMS * 2) - (rows & ~1);
1323 int top = 0;
1324 int button;
1282 bool exit = false; 1325 bool exit = false;
1283 char scroll_text[MAX_PATH];
1284 1326
1285 if (!(audio_status() & AUDIO_STATUS_PLAY)) 1327 if (!id3 || (!(audio_status() & AUDIO_STATUS_PLAY)))
1328 {
1286 return false; 1329 return false;
1330 }
1331
1332#if defined(HAVE_LCD_BITMAP)
1333 lcd_setmargins(show_scrollbar ? SCROLLBAR_WIDTH : 0, y_margin);
1334#endif
1287 1335
1288 while (!exit) 1336 while (!exit)
1289 { 1337 {
1338 int line = 0;
1339 int old_top = top;
1340 char* body;
1341
1290 lcd_clear_display(); 1342 lcd_clear_display();
1343 status_draw(true);
1344 line = draw_id3_item(line, top, LANG_ID3_TITLE, id3->title);
1345 line = draw_id3_item(line, top, LANG_ID3_ARTIST, id3->artist);
1346 line = draw_id3_item(line, top, LANG_ID3_ALBUM, id3->album);
1291 1347
1292 switch (menu_pos) 1348 if (id3->track_string)
1293 { 1349 {
1294 case 0: 1350 body = id3->track_string;
1295 lcd_puts(0, 0, str(LANG_ID3_TITLE)); 1351 }
1296 lcd_puts_scroll(0, 1, id3->title ? id3->title : 1352 else if (id3->tracknum)
1297 (char*)str(LANG_ID3_NO_TITLE)); 1353 {
1298 break; 1354 snprintf(buf, sizeof(buf), "%d", id3->tracknum);
1299 1355 body = buf;
1300 case 1: 1356 }
1301 lcd_puts(0, 0, str(LANG_ID3_ARTIST)); 1357 else
1302 lcd_puts_scroll(0, 1, 1358 {
1303 id3->artist ? id3->artist : 1359 body = NULL;
1304 (char*)str(LANG_ID3_NO_ARTIST)); 1360 }
1305 break;
1306
1307 case 2:
1308 lcd_puts(0, 0, str(LANG_ID3_ALBUM));
1309 lcd_puts_scroll(0, 1, id3->album ? id3->album :
1310 (char*)str(LANG_ID3_NO_ALBUM));
1311 break;
1312
1313 case 3:
1314 lcd_puts(0, 0, str(LANG_ID3_TRACKNUM));
1315
1316 if (id3->track_string) {
1317 lcd_puts_scroll(0, 1, id3->track_string);
1318 }
1319 else if (id3->tracknum) {
1320 snprintf(scroll_text,sizeof(scroll_text), "%d",
1321 id3->tracknum);
1322 lcd_puts_scroll(0, 1, scroll_text);
1323 }
1324 else
1325 lcd_puts_scroll(0, 1, str(LANG_ID3_NO_TRACKNUM));
1326 break;
1327 1361
1328 case 4: 1362 line = draw_id3_item(line, top, LANG_ID3_TRACKNUM, body);
1329 lcd_puts(0, 0, str(LANG_ID3_GENRE));
1330 1363
1331 if (id3->genre_string) { 1364 body = id3->genre_string ? id3->genre_string : id3_get_genre(id3);
1332 lcd_puts_scroll(0, 1, id3->genre_string); 1365 line = draw_id3_item(line, top, LANG_ID3_GENRE, body);
1333 }
1334 else {
1335 lcd_puts_scroll(0, 1,
1336 id3_get_genre(id3) ?
1337 id3_get_genre(id3) :
1338 (char*)str(LANG_ID3_NO_INFO));
1339 }
1340 break;
1341 1366
1342 case 5: 1367 if (id3->year_string)
1343 lcd_puts(0, 0, str(LANG_ID3_YEAR)); 1368 {
1344 if (id3->year_string) { 1369 body = id3->year_string;
1345 lcd_puts_scroll(0, 1, id3->year_string); 1370 }
1346 } 1371 else if (id3->year)
1347 else if (id3->year) { 1372 {
1348 snprintf(scroll_text,sizeof(scroll_text), "%d", 1373 snprintf(buf, sizeof(buf), "%d", id3->year);
1349 id3->year); 1374 body = buf;
1350 lcd_puts_scroll(0, 1, scroll_text); 1375 }
1351 } 1376 else
1352 else 1377 {
1353 lcd_puts_scroll(0, 1, str(LANG_ID3_NO_INFO)); 1378 body = NULL;
1354 break; 1379 }
1355 1380
1356 case 6: 1381 line = draw_id3_item(line, top, LANG_ID3_YEAR, body);
1357 lcd_puts(0, 0, str(LANG_ID3_LENGHT));
1358 wps_format_time(scroll_text, sizeof(scroll_text), id3->length);
1359 lcd_puts(0, 1, scroll_text);
1360 break;
1361 1382
1362 case 7: 1383 wps_format_time(buf, sizeof(buf), id3->length);
1363 lcd_puts(0, 0, str(LANG_ID3_PLAYLIST)); 1384 line = draw_id3_item(line, top, LANG_ID3_LENGHT, buf);
1364 snprintf(scroll_text,sizeof(scroll_text), "%d/%d",
1365 playlist_get_display_index(), playlist_amount());
1366 lcd_puts_scroll(0, 1, scroll_text);
1367 break;
1368 1385
1386 snprintf(buf, sizeof(buf), "%d/%d", playlist_get_display_index(),
1387 playlist_amount());
1388 line = draw_id3_item(line, top, LANG_ID3_PLAYLIST, buf);
1369 1389
1370 case 8: 1390 snprintf(buf, sizeof(buf), "%d kbps", id3->bitrate);
1371 lcd_puts(0, 0, str(LANG_ID3_BITRATE)); 1391 line = draw_id3_item(line, top, LANG_ID3_BITRATE, buf);
1372 snprintf(scroll_text,sizeof(scroll_text), "%d kbps",
1373 id3->bitrate);
1374 lcd_puts(0, 1, scroll_text);
1375 break;
1376 1392
1377 case 9: 1393 snprintf(buf, sizeof(buf), "%d Hz", id3->frequency);
1378 lcd_puts(0, 0, str(LANG_ID3_FRECUENCY)); 1394 line = draw_id3_item(line, top, LANG_ID3_FRECUENCY, buf);
1379 snprintf(scroll_text,sizeof(scroll_text), "%d Hz",
1380 id3->frequency);
1381 lcd_puts(0, 1, scroll_text);
1382 break;
1383 1395
1384 case 10:
1385 lcd_puts(0, 0, str(LANG_ID3_PATH));
1386 lcd_puts_scroll(0, 1, id3->path);
1387 break;
1388#if CONFIG_HWCODEC == MASNONE 1396#if CONFIG_HWCODEC == MASNONE
1389 case 11: 1397 line = draw_id3_item(line, top, LANG_ID3_TRACK_GAIN,
1390 lcd_puts(0, 0, str(LANG_ID3_TRACK_GAIN)); 1398 id3->track_gain_string);
1391 lcd_puts(0, 1, id3->track_gain_string
1392 ? id3->track_gain_string
1393 : (char*) str(LANG_ID3_NO_GAIN));
1394 break;
1395 1399
1396 case 12: 1400 line = draw_id3_item(line, top, LANG_ID3_ALBUM_GAIN,
1397 lcd_puts(0, 0, str(LANG_ID3_ALBUM_GAIN)); 1401 id3->album_gain_string);
1398 lcd_puts(0, 1, id3->album_gain_string
1399 ? id3->album_gain_string
1400 : (char*) str(LANG_ID3_NO_GAIN));
1401 break;
1402#endif 1402#endif
1403 }
1404 lcd_update();
1405 1403
1406 button = button_get(true); 1404 line = draw_id3_item(line, top, LANG_ID3_PATH, id3->path);
1407 1405
1408 switch(button) 1406#if defined(HAVE_LCD_BITMAP)
1407 if (show_scrollbar)
1409 { 1408 {
1409 scrollbar(0, y_margin, SCROLLBAR_WIDTH - 1, rows * line_height,
1410 ID3_ITEMS * 2 + (rows & 1), top, top + rows, VERTICAL);
1411 }
1412#endif
1413
1414 while (!exit && (top == old_top))
1415 {
1416 status_draw(false);
1417 lcd_update();
1418 button = button_get_w_tmo(HZ / 2);
1419
1420 switch(button)
1421 {
1422 /* It makes more sense to have the keys mapped "backwards" when
1423 * scrolling a list.
1424 */
1425#if defined(HAVE_LCD_BITMAP)
1426 case SETTINGS_INC:
1427 case SETTINGS_INC | BUTTON_REPEAT:
1428#else
1410 case SETTINGS_DEC: 1429 case SETTINGS_DEC:
1411 if (menu_pos > 0) 1430#endif
1412 menu_pos--; 1431 if (top > 0)
1413 else 1432 {
1414 menu_pos = menu_max; 1433 top -= 2;
1434 }
1435 else if (!(button & BUTTON_REPEAT))
1436 {
1437 top = top_max;
1438 }
1439
1415 break; 1440 break;
1416 1441
1442#if defined(HAVE_LCD_BITMAP)
1443 case SETTINGS_DEC:
1444 case SETTINGS_DEC | BUTTON_REPEAT:
1445#else
1417 case SETTINGS_INC: 1446 case SETTINGS_INC:
1418 if (menu_pos < menu_max) 1447#endif
1419 menu_pos++; 1448 if (top < top_max)
1420 else 1449 {
1421 menu_pos = 0; 1450 top += 2;
1451 }
1452 else if (!(button & BUTTON_REPEAT))
1453 {
1454 top = 0;
1455 }
1456
1422 break; 1457 break;
1423 1458
1424#ifdef SETTINGS_OK2 1459#ifdef SETTINGS_OK2
@@ -1426,17 +1461,22 @@ bool browse_id3(void)
1426#endif 1461#endif
1427 case SETTINGS_CANCEL: 1462 case SETTINGS_CANCEL:
1428 lcd_stop_scroll(); 1463 lcd_stop_scroll();
1429 /* eat release event */ 1464 /* Eat release event */
1430 button_get(true); 1465 button_get(true);
1431 exit = true; 1466 exit = true;
1432 break; 1467 break;
1433 1468
1434 default: 1469 default:
1435 if(default_event_handler(button) == SYS_USB_CONNECTED) 1470 if (default_event_handler(button) == SYS_USB_CONNECTED)
1471 {
1436 return true; 1472 return true;
1473 }
1474
1437 break; 1475 break;
1476 }
1438 } 1477 }
1439 } 1478 }
1479
1440 return false; 1480 return false;
1441} 1481}
1442 1482