summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Gordon <rockbox@jdgordon.info>2012-06-24 21:52:18 +1000
committerJonathan Gordon <rockbox@jdgordon.info>2012-07-05 11:15:16 +1000
commitd336eb30f8098f4a8f0bc27dc40358b30e57decd (patch)
tree93d840e7096edf21469f6b4110ae7f49cab09c90
parent3d0459dfadf0071112cd8406b9c210123b667e03 (diff)
downloadrockbox-d336eb30f8098f4a8f0bc27dc40358b30e57decd.tar.gz
rockbox-d336eb30f8098f4a8f0bc27dc40358b30e57decd.zip
skin_engine: Automatically create touch regions for skin bars
skin bars now automatically create the touch region the same size as the bar on touchscreen targets. This means touches will magically "just work" for reveresed bars (rtl or otherwise). ~5% padding is added on all 4 sides of the region rectangle but this may need to be tweaked. Please consider the 'progressbar' and 'volume' touchregion actions to be deprecated. Kudos to my new wife for figuring out the bleedingly obvious way to do this! Change-Id: I997a7bcaa70fce9885808aae27953c7676e9c2ff
-rw-r--r--apps/gui/skin_engine/skin_parser.c88
-rw-r--r--apps/gui/skin_engine/skin_touchsupport.c5
-rw-r--r--apps/gui/skin_engine/wps_internals.h1
-rw-r--r--manual/appendix/wps_tags.tex9
-rw-r--r--wps/cabbiev2.240x320x16.mini2440.wps1
-rw-r--r--wps/cabbiev2.240x400x16.wps1
-rw-r--r--wps/cabbiev2.320x240x16.mrobe500.wps1
-rw-r--r--wps/cabbiev2.320x480x16.wps1
-rw-r--r--wps/cabbiev2.800x480x16.wps1
9 files changed, 101 insertions, 7 deletions
diff --git a/apps/gui/skin_engine/skin_parser.c b/apps/gui/skin_engine/skin_parser.c
index 4de0aae3b2..8e7d79b44f 100644
--- a/apps/gui/skin_engine/skin_parser.c
+++ b/apps/gui/skin_engine/skin_parser.c
@@ -871,6 +871,9 @@ static int parse_progressbar_tag(struct skin_element* element,
871 struct skin_tag_parameter *param = get_param(element, 0); 871 struct skin_tag_parameter *param = get_param(element, 0);
872 int curr_param = 0; 872 int curr_param = 0;
873 char *image_filename = NULL; 873 char *image_filename = NULL;
874#ifdef HAVE_TOUCHSCREEN
875 bool suppress_touchregion = false;
876#endif
874 877
875 if (element->params_count == 0 && 878 if (element->params_count == 0 &&
876 element->tag->type != SKIN_TOKEN_PROGRESSBAR) 879 element->tag->type != SKIN_TOKEN_PROGRESSBAR)
@@ -1008,6 +1011,10 @@ static int parse_progressbar_tag(struct skin_element* element,
1008 } 1011 }
1009 else if (!strcmp(text, "horizontal")) 1012 else if (!strcmp(text, "horizontal"))
1010 pb->horizontal = true; 1013 pb->horizontal = true;
1014#ifdef HAVE_TOUCHSCREEN
1015 else if (!strcmp(text, "notouch"))
1016 suppress_touchregion = true;
1017#endif
1011 else if (curr_param == 4) 1018 else if (curr_param == 4)
1012 image_filename = text; 1019 image_filename = text;
1013 1020
@@ -1055,6 +1062,61 @@ static int parse_progressbar_tag(struct skin_element* element,
1055 token->type = SKIN_TOKEN_LIST_SCROLLBAR; 1062 token->type = SKIN_TOKEN_LIST_SCROLLBAR;
1056 pb->type = token->type; 1063 pb->type = token->type;
1057 1064
1065#ifdef HAVE_TOUCHSCREEN
1066 if (!suppress_touchregion &&
1067 (token->type == SKIN_TOKEN_VOLUMEBAR || token->type == SKIN_TOKEN_PROGRESSBAR))
1068 {
1069 struct touchregion *region = skin_buffer_alloc(sizeof(*region));
1070 struct skin_token_list *item;
1071 int wpad, hpad;
1072
1073 if (!region)
1074 return 0;
1075
1076 if (token->type == SKIN_TOKEN_VOLUMEBAR)
1077 region->action = ACTION_TOUCH_VOLUME;
1078 else
1079 region->action = ACTION_TOUCH_SCROLLBAR;
1080
1081 /* try to add some extra space on either end to make pressing the
1082 * full bar easier. ~5% on either side
1083 */
1084 wpad = pb->width * 5 / 100;
1085 if (wpad > 10)
1086 wpad = 10;
1087 hpad = pb->height * 5 / 100;
1088 if (hpad > 10)
1089 hpad = 10;
1090
1091 region->x = pb->x - wpad;
1092 if (region->x < 0)
1093 region->x = 0;
1094 region->width = pb->width + 2 * wpad;
1095 if (region->x + region->width > curr_vp->vp.x + curr_vp->vp.width)
1096 region->width = curr_vp->vp.x + curr_vp->vp.width - region->x;
1097
1098 region->y = pb->y - hpad;
1099 if (region->y < 0)
1100 region->y = 0;
1101 region->height = pb->height + 2 * hpad;
1102 if (region->y + region->height > curr_vp->vp.y + curr_vp->vp.height)
1103 region->height = curr_vp->vp.y + curr_vp->vp.height - region->y;
1104
1105 region->wvp = PTRTOSKINOFFSET(skin_buffer, curr_vp);
1106 region->reverse_bar = false;
1107 region->allow_while_locked = false;
1108 region->press_length = PRESS;
1109 region->last_press = 0xffff;
1110 region->armed = false;
1111 region->bar = PTRTOSKINOFFSET(skin_buffer, pb);
1112
1113 item = new_skin_token_list_item(NULL, region);
1114 if (!item)
1115 return WPS_ERROR_INVALID_PARAM;
1116 add_to_ll_chain(&wps_data->touchregions, item);
1117 }
1118#endif
1119
1058 return 0; 1120 return 0;
1059 1121
1060#else 1122#else
@@ -1429,6 +1491,7 @@ static int parse_touchregion(struct skin_element *element,
1429 region->last_press = 0xffff; 1491 region->last_press = 0xffff;
1430 region->press_length = PRESS; 1492 region->press_length = PRESS;
1431 region->allow_while_locked = false; 1493 region->allow_while_locked = false;
1494 region->bar = -1;
1432 action = get_param_text(element, p++); 1495 action = get_param_text(element, p++);
1433 1496
1434 /* figure out the action */ 1497 /* figure out the action */
@@ -2324,6 +2387,31 @@ bool skin_data_load(enum screen_type screen, struct wps_data *wps_data,
2324#else 2387#else
2325 wps_data->wps_loaded = wps_data->tree >= 0; 2388 wps_data->wps_loaded = wps_data->tree >= 0;
2326#endif 2389#endif
2390
2391#ifdef HAVE_TOUCHSCREEN
2392 /* Check if there are any touch regions from the skin and not just
2393 * auto-created ones for bars */
2394 struct skin_token_list *regions = SKINOFFSETTOPTR(skin_buffer,
2395 wps_data->touchregions);
2396 bool user_touch_region_found = false;
2397 while (regions)
2398 {
2399 struct wps_token *token = SKINOFFSETTOPTR(skin_buffer, regions->token);
2400 struct touchregion *r = SKINOFFSETTOPTR(skin_buffer, token->value.data);
2401
2402 if (r->action != ACTION_TOUCH_SCROLLBAR &&
2403 r->action != ACTION_TOUCH_VOLUME)
2404 {
2405 user_touch_region_found = true;
2406 break;
2407 }
2408 regions = SKINOFFSETTOPTR(skin_buffer, regions->next);
2409 }
2410 regions = SKINOFFSETTOPTR(skin_buffer, wps_data->touchregions);
2411 if (regions && !user_touch_region_found)
2412 wps_data->touchregions = -1;
2413#endif
2414
2327 skin_buffer = NULL; 2415 skin_buffer = NULL;
2328 return true; 2416 return true;
2329} 2417}
diff --git a/apps/gui/skin_engine/skin_touchsupport.c b/apps/gui/skin_engine/skin_touchsupport.c
index 34f616b9a3..f685cd0b70 100644
--- a/apps/gui/skin_engine/skin_touchsupport.c
+++ b/apps/gui/skin_engine/skin_touchsupport.c
@@ -99,7 +99,6 @@ int skin_get_touchaction(struct wps_data *data, int* edge_offset,
99 /* reposition the touch within the area */ 99 /* reposition the touch within the area */
100 vx -= r->x; 100 vx -= r->x;
101 vy -= r->y; 101 vy -= r->y;
102
103 102
104 switch(r->action) 103 switch(r->action)
105 { 104 {
@@ -107,11 +106,13 @@ int skin_get_touchaction(struct wps_data *data, int* edge_offset,
107 case ACTION_TOUCH_VOLUME: 106 case ACTION_TOUCH_VOLUME:
108 if (edge_offset) 107 if (edge_offset)
109 { 108 {
109 struct progressbar *bar =
110 SKINOFFSETTOPTR(skin_buffer, r->bar);
110 if(r->width > r->height) 111 if(r->width > r->height)
111 *edge_offset = vx*100/r->width; 112 *edge_offset = vx*100/r->width;
112 else 113 else
113 *edge_offset = vy*100/r->height; 114 *edge_offset = vy*100/r->height;
114 if (r->reverse_bar) 115 if (r->reverse_bar || (bar && bar->invert_fill_direction))
115 *edge_offset = 100 - *edge_offset; 116 *edge_offset = 100 - *edge_offset;
116 } 117 }
117 temp = r; 118 temp = r;
diff --git a/apps/gui/skin_engine/wps_internals.h b/apps/gui/skin_engine/wps_internals.h
index d5e77708f8..ab2bc3579e 100644
--- a/apps/gui/skin_engine/wps_internals.h
+++ b/apps/gui/skin_engine/wps_internals.h
@@ -215,6 +215,7 @@ struct touchregion {
215 int value; 215 int value;
216 }; 216 };
217 long last_press; /* last tick this was pressed */ 217 long last_press; /* last tick this was pressed */
218 OFFSETTYPE(struct progressbar*) bar;
218}; 219};
219 220
220 221
diff --git a/manual/appendix/wps_tags.tex b/manual/appendix/wps_tags.tex
index 2d22b73792..14e0308940 100644
--- a/manual/appendix/wps_tags.tex
+++ b/manual/appendix/wps_tags.tex
@@ -676,6 +676,12 @@ display cycling round the defined sublines. See
676 Some tags can be used to display a bar which draws according to the value of 676 Some tags can be used to display a bar which draws according to the value of
677 the tag. To use these tags like a bar you need to use the following parameters 677 the tag. To use these tags like a bar you need to use the following parameters
678 (\%XX should be replaced with the actual tag). 678 (\%XX should be replaced with the actual tag).
679
680\opt{touchscreen}{
681 Volume and progress bars automatically create touch regions the same size
682 as the bar (slightly larger actually). This can be disabled with the
683 \config{notouch} option.
684}
679 685
680\begin{tagmap} 686\begin{tagmap}
681 \config{\%XX(x, y, width, height, [options])} 687 \config{\%XX(x, y, width, height, [options])}
@@ -706,6 +712,9 @@ display cycling round the defined sublines. See
706 ``slider'' option). 712 ``slider'' option).
707 \item[nobar] -- don't draw the bar or its frame (for use with the 713 \item[nobar] -- don't draw the bar or its frame (for use with the
708 ``slider'' option). 714 ``slider'' option).
715 \opt{touchscreen}{
716 \item[notouch] -- don't create the touchregion for progress/volume bars.
717 }
709\end{description} 718\end{description}
710 719
711Example: \config{\%pb(0,0,-,-,-,nofill, slider, slider\_image, invert)} -- draw 720Example: \config{\%pb(0,0,-,-,-,nofill, slider, slider\_image, invert)} -- draw
diff --git a/wps/cabbiev2.240x320x16.mini2440.wps b/wps/cabbiev2.240x320x16.mini2440.wps
index 8eba53e6f8..1a6c7f3f45 100644
--- a/wps/cabbiev2.240x320x16.mini2440.wps
+++ b/wps/cabbiev2.240x320x16.mini2440.wps
@@ -8,7 +8,6 @@
8%T(46,292,84,24,menu) 8%T(46,292,84,24,menu)
9%T(139,292,24,24,shuffle) 9%T(139,292,24,24,shuffle)
10%T(182,292,24,24,repmode) 10%T(182,292,24,24,repmode)
11%T(22,254,199,13,progressbar)
12%X(wpsbackdrop-240x320x16.bmp) 11%X(wpsbackdrop-240x320x16.bmp)
13%xl(A,lock-240x320x16.bmp,11,292,2) 12%xl(A,lock-240x320x16.bmp,11,292,2)
14%xl(B,battery-240x320x16.bmp,46,292,10) 13%xl(B,battery-240x320x16.bmp,46,292,10)
diff --git a/wps/cabbiev2.240x400x16.wps b/wps/cabbiev2.240x400x16.wps
index eb305b11d1..59a6074563 100644
--- a/wps/cabbiev2.240x400x16.wps
+++ b/wps/cabbiev2.240x400x16.wps
@@ -7,7 +7,6 @@
7%X(wpsbackdrop-240x400x16.bmp) 7%X(wpsbackdrop-240x400x16.bmp)
8%Cl(55,50,130,130,c,c) 8%Cl(55,50,130,130,c,c)
9%pb(22,284,199,13,pb-240x320x16.bmp) 9%pb(22,284,199,13,pb-240x320x16.bmp)
10%T(22,284,199,13,progressbar)
11%T(90,238,60,20,playlist) 10%T(90,238,60,20,playlist)
12%?Tl(2.5)<%Vd(t)|%Vd(u)> 11%?Tl(2.5)<%Vd(t)|%Vd(u)>
13%V(0,0,240,330,1) 12%V(0,0,240,330,1)
diff --git a/wps/cabbiev2.320x240x16.mrobe500.wps b/wps/cabbiev2.320x240x16.mrobe500.wps
index 1bad2bbd98..1ad14e48b8 100644
--- a/wps/cabbiev2.320x240x16.mrobe500.wps
+++ b/wps/cabbiev2.320x240x16.mrobe500.wps
@@ -6,7 +6,6 @@
6%T(0,207,84,24,menu) 6%T(0,207,84,24,menu)
7%T(218,211,24,24,shuffle) 7%T(218,211,24,24,shuffle)
8%T(261,207,24,24,repmode) 8%T(261,207,24,24,repmode)
9%T(10,162,300,15,progressbar)
10%X(wpsbackdrop-320x240x16.bmp) 9%X(wpsbackdrop-320x240x16.bmp)
11%xl(A,lock-320x240x16.bmp,91,207,2) 10%xl(A,lock-320x240x16.bmp,91,207,2)
12%xl(B,battery-320x240x16.bmp,126,207,10) 11%xl(B,battery-320x240x16.bmp,126,207,10)
diff --git a/wps/cabbiev2.320x480x16.wps b/wps/cabbiev2.320x480x16.wps
index 31957a2293..1aa5672efe 100644
--- a/wps/cabbiev2.320x480x16.wps
+++ b/wps/cabbiev2.320x480x16.wps
@@ -63,7 +63,6 @@
63# progressbar and bottom icons 63# progressbar and bottom icons
64%V(0,360,-,-,-) 64%V(0,360,-,-,-)
65%pb(20,11,280,-,pb-320x480x16.bmp) 65%pb(20,11,280,-,pb-320x480x16.bmp)
66%T(20,0,280,40,progressbar)
67 66
68#%?mh<%xd(Aa)|%xd(Ab)> 67#%?mh<%xd(Aa)|%xd(Ab)>
69#%?bp<%?bc<%xd(Ba)|%xd(Bb)>|%?bl<|%xd(Bc)|%xd(Bd)|%xd(Be)|%xd(Bf)|%xd(Bg)|%xd(Bh)|%xd(Bi)|%xd(Bj)>> 68#%?bp<%?bc<%xd(Ba)|%xd(Bb)>|%?bl<|%xd(Bc)|%xd(Bd)|%xd(Be)|%xd(Bf)|%xd(Bg)|%xd(Bh)|%xd(Bi)|%xd(Bj)>>
diff --git a/wps/cabbiev2.800x480x16.wps b/wps/cabbiev2.800x480x16.wps
index 07420da616..881718be03 100644
--- a/wps/cabbiev2.800x480x16.wps
+++ b/wps/cabbiev2.800x480x16.wps
@@ -49,7 +49,6 @@
49# progressbar and bottom icons 49# progressbar and bottom icons
50%V(0,323,-,33,-) 50%V(0,323,-,33,-)
51%pb(25,0,750,-,pb-800x480x16.bmp) 51%pb(25,0,750,-,pb-800x480x16.bmp)
52%T(25,0,750,50,progressbar)
53 52
54# volume 53# volume
55%V(344,400,108,60,-) 54%V(344,400,108,60,-)