diff options
author | Dave Chapman <dave@dchapman.com> | 2007-11-12 21:34:01 +0000 |
---|---|---|
committer | Dave Chapman <dave@dchapman.com> | 2007-11-12 21:34:01 +0000 |
commit | f6ef46b73f628586aef988246d253f3e5154119d (patch) | |
tree | 50da730905477a3dce9909b575c3353e310310ef /apps/gui/gwps-common.c | |
parent | 4b65cb67a52dab50530c19c1f647d1b3985bb1a8 (diff) | |
download | rockbox-f6ef46b73f628586aef988246d253f3e5154119d.tar.gz rockbox-f6ef46b73f628586aef988246d253f3e5154119d.zip |
FS#8135 - add an optional "left margin" parameter to the %s WPS tag - e.g. %s|100|. This patch uses parts of the scroll-margins patch (FS#2954), but is much smaller, only offers a left-margin, and only affects the WPS code.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15604 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/gui/gwps-common.c')
-rw-r--r-- | apps/gui/gwps-common.c | 45 |
1 files changed, 31 insertions, 14 deletions
diff --git a/apps/gui/gwps-common.c b/apps/gui/gwps-common.c index 00505afbed..f1486461c9 100644 --- a/apps/gui/gwps-common.c +++ b/apps/gui/gwps-common.c | |||
@@ -1352,6 +1352,13 @@ static char *get_token_value(struct gui_wps *gwps, | |||
1352 | return NULL; | 1352 | return NULL; |
1353 | #endif | 1353 | #endif |
1354 | 1354 | ||
1355 | #ifdef HAVE_LCD_BITMAP | ||
1356 | case WPS_TOKEN_ALIGN_SCROLLMARGIN: | ||
1357 | gwps->display->setmargins(token->value.i, | ||
1358 | gwps->display->getymargin()); | ||
1359 | return NULL; | ||
1360 | #endif | ||
1361 | |||
1355 | default: | 1362 | default: |
1356 | return NULL; | 1363 | return NULL; |
1357 | } | 1364 | } |
@@ -1454,6 +1461,11 @@ static bool get_line(struct gui_wps *gwps, | |||
1454 | align->center = NULL; | 1461 | align->center = NULL; |
1455 | align->right = NULL; | 1462 | align->right = NULL; |
1456 | 1463 | ||
1464 | #ifdef HAVE_LCD_BITMAP | ||
1465 | /* Reset margins - only bitmap targets modify them */ | ||
1466 | gwps->display->setmargins(0, gwps->display->getymargin()); | ||
1467 | #endif | ||
1468 | |||
1457 | /* Process all tokens of the desired subline */ | 1469 | /* Process all tokens of the desired subline */ |
1458 | last_token_idx = wps_last_token_index(data, line, subline); | 1470 | last_token_idx = wps_last_token_index(data, line, subline); |
1459 | for (i = wps_first_token_index(data, line, subline); | 1471 | for (i = wps_first_token_index(data, line, subline); |
@@ -1677,12 +1689,13 @@ static void write_line(struct screen *display, | |||
1677 | bool scroll) | 1689 | bool scroll) |
1678 | { | 1690 | { |
1679 | 1691 | ||
1680 | int left_width = 0; /* left_xpos would always be 0 */ | 1692 | int left_width = 0, left_xpos; |
1681 | int center_width = 0, center_xpos; | 1693 | int center_width = 0, center_xpos; |
1682 | int right_width = 0, right_xpos; | 1694 | int right_width = 0, right_xpos; |
1683 | int ypos; | 1695 | int ypos; |
1684 | int space_width; | 1696 | int space_width; |
1685 | int string_height; | 1697 | int string_height; |
1698 | int scroll_width; | ||
1686 | 1699 | ||
1687 | /* calculate different string sizes and positions */ | 1700 | /* calculate different string sizes and positions */ |
1688 | display->getstringsize((unsigned char *)" ", &space_width, &string_height); | 1701 | display->getstringsize((unsigned char *)" ", &space_width, &string_height); |
@@ -1691,19 +1704,21 @@ static void write_line(struct screen *display, | |||
1691 | &left_width, &string_height); | 1704 | &left_width, &string_height); |
1692 | } | 1705 | } |
1693 | 1706 | ||
1694 | if (format_align->center != 0) { | ||
1695 | display->getstringsize((unsigned char *)format_align->center, | ||
1696 | ¢er_width, &string_height); | ||
1697 | } | ||
1698 | |||
1699 | center_xpos=(display->width - center_width) / 2; | ||
1700 | |||
1701 | if (format_align->right != 0) { | 1707 | if (format_align->right != 0) { |
1702 | display->getstringsize((unsigned char *)format_align->right, | 1708 | display->getstringsize((unsigned char *)format_align->right, |
1703 | &right_width, &string_height); | 1709 | &right_width, &string_height); |
1704 | } | 1710 | } |
1705 | 1711 | ||
1712 | if (format_align->center != 0) { | ||
1713 | display->getstringsize((unsigned char *)format_align->center, | ||
1714 | ¢er_width, &string_height); | ||
1715 | } | ||
1716 | |||
1717 | left_xpos = display->getxmargin(); | ||
1706 | right_xpos = (display->width - right_width); | 1718 | right_xpos = (display->width - right_width); |
1719 | center_xpos = (display->width + left_xpos - center_width) / 2; | ||
1720 | |||
1721 | scroll_width = display->width - left_xpos; | ||
1707 | 1722 | ||
1708 | /* Checks for overlapping strings. | 1723 | /* Checks for overlapping strings. |
1709 | If needed the overlapping strings will be merged, separated by a | 1724 | If needed the overlapping strings will be merged, separated by a |
@@ -1712,7 +1727,7 @@ static void write_line(struct screen *display, | |||
1712 | /* CASE 1: left and centered string overlap */ | 1727 | /* CASE 1: left and centered string overlap */ |
1713 | /* there is a left string, need to merge left and center */ | 1728 | /* there is a left string, need to merge left and center */ |
1714 | if ((left_width != 0 && center_width != 0) && | 1729 | if ((left_width != 0 && center_width != 0) && |
1715 | (left_width + space_width > center_xpos)) { | 1730 | (left_xpos + left_width + space_width > center_xpos)) { |
1716 | /* replace the former separator '\0' of left and | 1731 | /* replace the former separator '\0' of left and |
1717 | center string with a space */ | 1732 | center string with a space */ |
1718 | *(--format_align->center) = ' '; | 1733 | *(--format_align->center) = ' '; |
@@ -1723,7 +1738,7 @@ static void write_line(struct screen *display, | |||
1723 | } | 1738 | } |
1724 | /* there is no left string, move center to left */ | 1739 | /* there is no left string, move center to left */ |
1725 | if ((left_width == 0 && center_width != 0) && | 1740 | if ((left_width == 0 && center_width != 0) && |
1726 | (left_width > center_xpos)) { | 1741 | (left_xpos + left_width > center_xpos)) { |
1727 | /* move the center string to the left string */ | 1742 | /* move the center string to the left string */ |
1728 | format_align->left = format_align->center; | 1743 | format_align->left = format_align->center; |
1729 | /* calculate the new width and position of the string */ | 1744 | /* calculate the new width and position of the string */ |
@@ -1764,7 +1779,7 @@ static void write_line(struct screen *display, | |||
1764 | was one or it has been merged in case 1 or 2 */ | 1779 | was one or it has been merged in case 1 or 2 */ |
1765 | /* there is a left string, need to merge left and right */ | 1780 | /* there is a left string, need to merge left and right */ |
1766 | if ((left_width != 0 && center_width == 0 && right_width != 0) && | 1781 | if ((left_width != 0 && center_width == 0 && right_width != 0) && |
1767 | (left_width + space_width > right_xpos)) { | 1782 | (left_xpos + left_width + space_width > right_xpos)) { |
1768 | /* replace the former separator '\0' of left and | 1783 | /* replace the former separator '\0' of left and |
1769 | right string with a space */ | 1784 | right string with a space */ |
1770 | *(--format_align->right) = ' '; | 1785 | *(--format_align->right) = ' '; |
@@ -1787,7 +1802,9 @@ static void write_line(struct screen *display, | |||
1787 | ypos = (line * string_height) + display->getymargin(); | 1802 | ypos = (line * string_height) + display->getymargin(); |
1788 | 1803 | ||
1789 | 1804 | ||
1790 | if (scroll && left_width > display->width) | 1805 | if (scroll && ((left_width > scroll_width) || |
1806 | (center_width > scroll_width) || | ||
1807 | (right_width > scroll_width))) | ||
1791 | { | 1808 | { |
1792 | display->puts_scroll(0, line, | 1809 | display->puts_scroll(0, line, |
1793 | (unsigned char *)format_align->left); | 1810 | (unsigned char *)format_align->left); |
@@ -1797,7 +1814,7 @@ static void write_line(struct screen *display, | |||
1797 | #ifdef HAVE_LCD_BITMAP | 1814 | #ifdef HAVE_LCD_BITMAP |
1798 | /* clear the line first */ | 1815 | /* clear the line first */ |
1799 | display->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); | 1816 | display->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); |
1800 | display->fillrect(0, ypos, display->width, string_height); | 1817 | display->fillrect(left_xpos, ypos, display->width, string_height); |
1801 | display->set_drawmode(DRMODE_SOLID); | 1818 | display->set_drawmode(DRMODE_SOLID); |
1802 | #endif | 1819 | #endif |
1803 | 1820 | ||
@@ -1808,7 +1825,7 @@ static void write_line(struct screen *display, | |||
1808 | /* print aligned strings */ | 1825 | /* print aligned strings */ |
1809 | if (left_width != 0) | 1826 | if (left_width != 0) |
1810 | { | 1827 | { |
1811 | display->putsxy(0, ypos, | 1828 | display->putsxy(left_xpos, ypos, |
1812 | (unsigned char *)format_align->left); | 1829 | (unsigned char *)format_align->left); |
1813 | } | 1830 | } |
1814 | if (center_width != 0) | 1831 | if (center_width != 0) |