Index: apps/gui/gwps.c =================================================================== --- apps/gui/gwps.c (revision 20706) +++ apps/gui/gwps.c (working copy) @@ -249,7 +249,38 @@ { viewportmanager_set_statusbar(wpsbars); } - +#ifdef HAVE_TOUCHSCREEN +static int wps_get_touchaction(struct wps_data *data) +{ + short x,y; + short vx, vy; + int type = action_get_touchscreen_press(&x, &y); + int i; + struct touchregion *r; + if (type != BUTTON_REL) + return ACTION_TOUCHSCREEN; + for (i=0; itouchregion_count; i++) + { + r = &data->touchregion[i]; + /* make sure this region's viewport is visible */ + if (r->wvp->hidden_flags&VP_DRAW_HIDDEN) + continue; + /* reposition the touch inside the viewport */ + vx = x - r->wvp->vp.x; + vy = y - r->wvp->vp.y; + /* check if its inside this viewport */ + if (vx >= 0 && vx < r->wvp->vp.x + r->wvp->vp.width && + vy >= 0 && vy < r->wvp->vp.y + r->wvp->vp.height) + { + /* now see if the point is inside this region */ + if (vx >= r->x && vx < r->x+r->width && + vy >= r->y && vy < r->y+r->height) + return r->action; + } + } + return ACTION_TOUCHSCREEN; +} +#endif /* The WPS can be left in two ways: * a) call a function, which draws over the wps. In this case, the wps * will be still active (i.e. the below function didn't return) @@ -349,6 +380,10 @@ playlist or if using the sleep timer. */ if (!(audio_status() & AUDIO_STATUS_PLAY)) exit = true; +#ifdef HAVE_TOUCHSCREEN + if (button == ACTION_TOUCHSCREEN) + button = wps_get_touchaction(gui_wps[SCREEN_MAIN].data); +#endif /* The iPods/X5/M5 use a single button for the A-B mode markers, defined as ACTION_WPSAB_SINGLE in their config files. */ #ifdef ACTION_WPSAB_SINGLE Index: apps/gui/wps_parser.c =================================================================== --- apps/gui/wps_parser.c (revision 20706) +++ apps/gui/wps_parser.c (working copy) @@ -156,7 +156,10 @@ static int parse_albumart_conditional(const char *wps_bufptr, struct wps_token *token, struct wps_data *wps_data); #endif /* HAVE_ALBUMART */ - +#ifdef HAVE_TOUCHSCREEN +static int parse_touchregion(const char *wps_bufptr, + struct wps_token *token, struct wps_data *wps_data); +#endif #ifdef CONFIG_RTC #define WPS_RTC_REFRESH WPS_REFRESH_DYNAMIC #else @@ -337,6 +340,8 @@ #endif { WPS_TOKEN_SETTING, "St", WPS_REFRESH_DYNAMIC, parse_setting }, + + { WPS_NO_TOKEN, "T", 0, parse_touchregion }, { WPS_TOKEN_UNKNOWN, "", 0, NULL } /* the array MUST end with an empty string (first char is \0) */ @@ -1142,6 +1147,68 @@ }; #endif /* HAVE_ALBUMART */ +#ifdef HAVE_TOUCHSCREEN +struct touchaction {char* s; int action;}; +static struct touchaction touchactions[] = { + {"play", ACTION_WPS_PLAY }, {"stop", ACTION_WPS_STOP }, + {"prev", ACTION_WPS_SKIPPREV }, {"next", ACTION_WPS_SKIPNEXT }, + {"menu", ACTION_WPS_MENU }, {"browse", ACTION_WPS_BROWSE } +}; +static int parse_touchregion(const char *wps_bufptr, + struct wps_token *token, struct wps_data *wps_data) +{ + unsigned i; + struct touchregion *region; + const char *ptr = wps_bufptr; + const char *action; + int x,y,w,h; + + /* format: %T|x|y|width|height|action| + * action is one of: + * play - play/pause playback + * stop - stop playback, exit the wps + * prev + * next + * ffwd + * rwd + * menu + * browse + */ + + if ((wps_data->touchregion_count +1 >= MAX_TOUCHREGIONS) || (*ptr != '|')) + return WPS_ERROR_INVALID_PARAM; + ptr++; + + if (!(ptr = parse_list("dddds", NULL, '|', ptr, &x, &y, &w, &h, &action))) + return WPS_ERROR_INVALID_PARAM; + + /* Check there is a terminating | */ + if (*ptr != '|') + return WPS_ERROR_INVALID_PARAM; + + /* should probably do some bounds checking here with the viewport... but later */ + region = &wps_data->touchregion[wps_data->touchregion_count]; + region->action = ACTION_NONE; + region->x = x; + region->y = y; + region->width = w; + region->height = h; + region->wvp = &wps_data->viewports[wps_data->num_viewports]; + i = 0; + while ((region->action == ACTION_NONE) && + (i < sizeof(touchactions)/sizeof(*touchactions))) + { + if (!strncmp(touchactions[i].s, action, strlen(touchactions[i].s))) + region->action = touchactions[i].action; + i++; + } + if (region->action == ACTION_NONE) + return WPS_ERROR_INVALID_PARAM; + wps_data->touchregion_count++; + return skip_end_of_line(wps_bufptr); +} +#endif + /* 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) { Index: apps/gui/gwps.h =================================================================== --- apps/gui/gwps.h (revision 20706) +++ apps/gui/gwps.h (working copy) @@ -363,6 +368,17 @@ char label; }; +#ifdef HAVE_TOUCHSCREEN +struct touchregion { + struct wps_viewport* wvp;/* The viewport this region is in */ + short int x; /* x-pos */ + short int y; /* y-pos */ + short int width; /* width */ + short int height; /* height */ + int action; /* action this button will return */ +}; +#define MAX_TOUCHREGIONS 12 +#endif /* wps_data this struct holds all necessary data which describes the viewable content of a wps */ @@ -399,6 +415,11 @@ bool full_line_progressbar; #endif +#ifdef HAVE_TOUCHSCREEN + struct touchregion touchregion[MAX_TOUCHREGIONS]; + short touchregion_count; +#endif + #ifdef HAVE_REMOTE_LCD bool remote_wps; #endif