summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorNicolas Pennequin <nicolas.pennequin@free.fr>2007-11-18 13:24:39 +0000
committerNicolas Pennequin <nicolas.pennequin@free.fr>2007-11-18 13:24:39 +0000
commit572ecef486f972cc10475e201e211e9ce63733d8 (patch)
tree2e47455eecde00435b7d3bd73e0d06303e766c25 /apps
parent47167e70224cfce4fe68ac836b2b694bbe203bfb (diff)
downloadrockbox-572ecef486f972cc10475e201e211e9ce63733d8.tar.gz
rockbox-572ecef486f972cc10475e201e211e9ce63733d8.zip
Smarter conditional handling by storing the previous value. Updates are done only if the value has changed. This avoids unnecessary line or picture clearing, and should help fix some problems WPS creators were having.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15657 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r--apps/gui/gwps-common.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/apps/gui/gwps-common.c b/apps/gui/gwps-common.c
index 7f1c52c7bf..ca6fd6679d 100644
--- a/apps/gui/gwps-common.c
+++ b/apps/gui/gwps-common.c
@@ -1383,16 +1383,18 @@ static int find_conditional_end(struct wps_data *data, int index)
1383/* Return the index of the appropriate case for the conditional 1383/* Return the index of the appropriate case for the conditional
1384 that starts at cond_index. 1384 that starts at cond_index.
1385*/ 1385*/
1386static int evaluate_conditional(struct gui_wps *gwps, int cond_index) 1386static bool evaluate_conditional(struct gui_wps *gwps, int *token_index)
1387{ 1387{
1388 if (!gwps) 1388 if (!gwps)
1389 return 0; 1389 return false;
1390 1390
1391 struct wps_data *data = gwps->data; 1391 struct wps_data *data = gwps->data;
1392 1392
1393 int ret, i; 1393 int i;
1394 int cond_index = *token_index;
1394 char result[128], *value; 1395 char result[128], *value;
1395 int num_options = data->tokens[cond_index].value.i; 1396 unsigned char num_options = data->tokens[cond_index].value.i & 0xFF;
1397 unsigned char prev_val = (data->tokens[cond_index].value.i & 0xFF00) >> 8;
1396 1398
1397 /* treat ?xx<true> constructs as if they had 2 options. */ 1399 /* treat ?xx<true> constructs as if they had 2 options. */
1398 if (num_options < 2) 1400 if (num_options < 2)
@@ -1410,13 +1412,22 @@ static int evaluate_conditional(struct gui_wps *gwps, int cond_index)
1410 else if (intval > num_options || intval < 1) 1412 else if (intval > num_options || intval < 1)
1411 intval = num_options; 1413 intval = num_options;
1412 1414
1415 data->tokens[cond_index].value.i = (intval << 8) + num_options;
1416
1413 /* skip to the right enum case */ 1417 /* skip to the right enum case */
1414 int next = cond_index + 2; 1418 int next = cond_index + 2;
1415 for (i = 1; i < intval; i++) 1419 for (i = 1; i < intval; i++)
1416 { 1420 {
1417 next = data->tokens[next].value.i; 1421 next = data->tokens[next].value.i;
1418 } 1422 }
1419 ret = next; 1423 *token_index = next;
1424
1425 if (prev_val == intval)
1426 {
1427 /* Same conditional case as previously. Return without clearing the
1428 pictures */
1429 return false;
1430 }
1420 1431
1421#ifdef HAVE_LCD_BITMAP 1432#ifdef HAVE_LCD_BITMAP
1422 /* clear all pictures in the conditional */ 1433 /* clear all pictures in the conditional */
@@ -1435,7 +1446,7 @@ static int evaluate_conditional(struct gui_wps *gwps, int cond_index)
1435 } 1446 }
1436#endif 1447#endif
1437 1448
1438 return ret; 1449 return true;
1439} 1450}
1440 1451
1441/* Read a (sub)line to the given alignment format buffer. 1452/* Read a (sub)line to the given alignment format buffer.
@@ -1480,8 +1491,7 @@ static bool get_line(struct gui_wps *gwps,
1480 { 1491 {
1481 case WPS_TOKEN_CONDITIONAL: 1492 case WPS_TOKEN_CONDITIONAL:
1482 /* place ourselves in the right conditional case */ 1493 /* place ourselves in the right conditional case */
1483 i = evaluate_conditional(gwps, i); 1494 update |= evaluate_conditional(gwps, &i);
1484 update = true;
1485 break; 1495 break;
1486 1496
1487 case WPS_TOKEN_CONDITIONAL_OPTION: 1497 case WPS_TOKEN_CONDITIONAL_OPTION:
@@ -1589,7 +1599,7 @@ static void get_subline_timeout(struct gui_wps *gwps, int line, int subline)
1589 { 1599 {
1590 case WPS_TOKEN_CONDITIONAL: 1600 case WPS_TOKEN_CONDITIONAL:
1591 /* place ourselves in the right conditional case */ 1601 /* place ourselves in the right conditional case */
1592 i = evaluate_conditional(gwps, i); 1602 evaluate_conditional(gwps, &i);
1593 break; 1603 break;
1594 1604
1595 case WPS_TOKEN_CONDITIONAL_OPTION: 1605 case WPS_TOKEN_CONDITIONAL_OPTION: