1
0
Fork 0
forked from len0rd/rockbox

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
This commit is contained in:
Dave Chapman 2007-11-12 21:34:01 +00:00
parent 4b65cb67a5
commit f6ef46b73f
3 changed files with 67 additions and 14 deletions

View file

@ -1352,6 +1352,13 @@ static char *get_token_value(struct gui_wps *gwps,
return NULL; return NULL;
#endif #endif
#ifdef HAVE_LCD_BITMAP
case WPS_TOKEN_ALIGN_SCROLLMARGIN:
gwps->display->setmargins(token->value.i,
gwps->display->getymargin());
return NULL;
#endif
default: default:
return NULL; return NULL;
} }
@ -1454,6 +1461,11 @@ static bool get_line(struct gui_wps *gwps,
align->center = NULL; align->center = NULL;
align->right = NULL; align->right = NULL;
#ifdef HAVE_LCD_BITMAP
/* Reset margins - only bitmap targets modify them */
gwps->display->setmargins(0, gwps->display->getymargin());
#endif
/* Process all tokens of the desired subline */ /* Process all tokens of the desired subline */
last_token_idx = wps_last_token_index(data, line, subline); last_token_idx = wps_last_token_index(data, line, subline);
for (i = wps_first_token_index(data, line, subline); for (i = wps_first_token_index(data, line, subline);
@ -1677,12 +1689,13 @@ static void write_line(struct screen *display,
bool scroll) bool scroll)
{ {
int left_width = 0; /* left_xpos would always be 0 */ int left_width = 0, left_xpos;
int center_width = 0, center_xpos; int center_width = 0, center_xpos;
int right_width = 0, right_xpos; int right_width = 0, right_xpos;
int ypos; int ypos;
int space_width; int space_width;
int string_height; int string_height;
int scroll_width;
/* calculate different string sizes and positions */ /* calculate different string sizes and positions */
display->getstringsize((unsigned char *)" ", &space_width, &string_height); display->getstringsize((unsigned char *)" ", &space_width, &string_height);
@ -1691,19 +1704,21 @@ static void write_line(struct screen *display,
&left_width, &string_height); &left_width, &string_height);
} }
if (format_align->center != 0) {
display->getstringsize((unsigned char *)format_align->center,
&center_width, &string_height);
}
center_xpos=(display->width - center_width) / 2;
if (format_align->right != 0) { if (format_align->right != 0) {
display->getstringsize((unsigned char *)format_align->right, display->getstringsize((unsigned char *)format_align->right,
&right_width, &string_height); &right_width, &string_height);
} }
if (format_align->center != 0) {
display->getstringsize((unsigned char *)format_align->center,
&center_width, &string_height);
}
left_xpos = display->getxmargin();
right_xpos = (display->width - right_width); right_xpos = (display->width - right_width);
center_xpos = (display->width + left_xpos - center_width) / 2;
scroll_width = display->width - left_xpos;
/* Checks for overlapping strings. /* Checks for overlapping strings.
If needed the overlapping strings will be merged, separated by a If needed the overlapping strings will be merged, separated by a
@ -1712,7 +1727,7 @@ static void write_line(struct screen *display,
/* CASE 1: left and centered string overlap */ /* CASE 1: left and centered string overlap */
/* there is a left string, need to merge left and center */ /* there is a left string, need to merge left and center */
if ((left_width != 0 && center_width != 0) && if ((left_width != 0 && center_width != 0) &&
(left_width + space_width > center_xpos)) { (left_xpos + left_width + space_width > center_xpos)) {
/* replace the former separator '\0' of left and /* replace the former separator '\0' of left and
center string with a space */ center string with a space */
*(--format_align->center) = ' '; *(--format_align->center) = ' ';
@ -1723,7 +1738,7 @@ static void write_line(struct screen *display,
} }
/* there is no left string, move center to left */ /* there is no left string, move center to left */
if ((left_width == 0 && center_width != 0) && if ((left_width == 0 && center_width != 0) &&
(left_width > center_xpos)) { (left_xpos + left_width > center_xpos)) {
/* move the center string to the left string */ /* move the center string to the left string */
format_align->left = format_align->center; format_align->left = format_align->center;
/* calculate the new width and position of the string */ /* calculate the new width and position of the string */
@ -1764,7 +1779,7 @@ static void write_line(struct screen *display,
was one or it has been merged in case 1 or 2 */ was one or it has been merged in case 1 or 2 */
/* there is a left string, need to merge left and right */ /* there is a left string, need to merge left and right */
if ((left_width != 0 && center_width == 0 && right_width != 0) && if ((left_width != 0 && center_width == 0 && right_width != 0) &&
(left_width + space_width > right_xpos)) { (left_xpos + left_width + space_width > right_xpos)) {
/* replace the former separator '\0' of left and /* replace the former separator '\0' of left and
right string with a space */ right string with a space */
*(--format_align->right) = ' '; *(--format_align->right) = ' ';
@ -1787,7 +1802,9 @@ static void write_line(struct screen *display,
ypos = (line * string_height) + display->getymargin(); ypos = (line * string_height) + display->getymargin();
if (scroll && left_width > display->width) if (scroll && ((left_width > scroll_width) ||
(center_width > scroll_width) ||
(right_width > scroll_width)))
{ {
display->puts_scroll(0, line, display->puts_scroll(0, line,
(unsigned char *)format_align->left); (unsigned char *)format_align->left);
@ -1797,7 +1814,7 @@ static void write_line(struct screen *display,
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
/* clear the line first */ /* clear the line first */
display->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); display->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
display->fillrect(0, ypos, display->width, string_height); display->fillrect(left_xpos, ypos, display->width, string_height);
display->set_drawmode(DRMODE_SOLID); display->set_drawmode(DRMODE_SOLID);
#endif #endif
@ -1808,7 +1825,7 @@ static void write_line(struct screen *display,
/* print aligned strings */ /* print aligned strings */
if (left_width != 0) if (left_width != 0)
{ {
display->putsxy(0, ypos, display->putsxy(left_xpos, ypos,
(unsigned char *)format_align->left); (unsigned char *)format_align->left);
} }
if (center_width != 0) if (center_width != 0)

View file

@ -124,6 +124,7 @@ enum wps_token_type {
WPS_TOKEN_ALIGN_LEFT, WPS_TOKEN_ALIGN_LEFT,
WPS_TOKEN_ALIGN_CENTER, WPS_TOKEN_ALIGN_CENTER,
WPS_TOKEN_ALIGN_RIGHT, WPS_TOKEN_ALIGN_RIGHT,
WPS_TOKEN_ALIGN_SCROLLMARGIN,
/* Sublines */ /* Sublines */
WPS_TOKEN_SUBLINE_TIMEOUT, WPS_TOKEN_SUBLINE_TIMEOUT,

View file

@ -115,6 +115,8 @@ static int parse_dir_level(const char *wps_bufptr,
struct wps_token *token, struct wps_data *wps_data); struct wps_token *token, struct wps_data *wps_data);
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
static int parse_scrollmargin(const char *wps_bufptr,
struct wps_token *token, struct wps_data *wps_data);
static int parse_image_special(const char *wps_bufptr, static int parse_image_special(const char *wps_bufptr,
struct wps_token *token, struct wps_data *wps_data); struct wps_token *token, struct wps_data *wps_data);
static int parse_statusbar_enable(const char *wps_bufptr, static int parse_statusbar_enable(const char *wps_bufptr,
@ -277,7 +279,12 @@ static const struct wps_tag all_tags[] = {
{ WPS_TOKEN_CROSSFADE, "xf", WPS_REFRESH_DYNAMIC, NULL }, { WPS_TOKEN_CROSSFADE, "xf", WPS_REFRESH_DYNAMIC, NULL },
#endif #endif
#ifdef HAVE_LCD_BITMAP
{ WPS_TOKEN_ALIGN_SCROLLMARGIN, "s", WPS_REFRESH_SCROLL,
parse_scrollmargin },
#else
{ WPS_NO_TOKEN, "s", WPS_REFRESH_SCROLL, NULL }, { WPS_NO_TOKEN, "s", WPS_REFRESH_SCROLL, NULL },
#endif
{ WPS_TOKEN_SUBLINE_TIMEOUT, "t", 0, parse_subline_timeout }, { WPS_TOKEN_SUBLINE_TIMEOUT, "t", 0, parse_subline_timeout },
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
@ -832,6 +839,34 @@ static int parse_albumart_conditional(const char *wps_bufptr,
}; };
#endif /* HAVE_ALBUMART */ #endif /* HAVE_ALBUMART */
#ifdef HAVE_LCD_BITMAP
static int parse_scrollmargin(const char *wps_bufptr, struct wps_token *token,
struct wps_data *wps_data)
{
const char* p;
const char* pend;
(void)wps_data; /* Kill the warning */
/* valid tag looks like %s or %s|12| */
if(*wps_bufptr == '|')
{
p = wps_bufptr + 1;
if(isdigit(*p) && (pend = strchr(p, '|')))
{
token->value.i = atoi(p);
return(pend - wps_bufptr + 1);
}
} else {
token->value.i = 0;
}
return(0);
}
#endif
/* Parse a generic token from the given string. Return the length read */ /* Parse a generic token from the given string. Return the length read */
static int parse_token(const char *wps_bufptr, struct wps_data *wps_data) static int parse_token(const char *wps_bufptr, struct wps_data *wps_data)
{ {