Guest User

Add support for x,y value in percentage to several tags

a guest
Jul 20th, 2014
275
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. From e2d24cf8d706ed8b25ff053323915c97fe473c8c Mon Sep 17 00:00:00 2001
  2. From: papaloco1234 <rock1104.tw@yahoo.com.tw>
  3. Date: Sat, 22 Feb 2014 08:22:45 +0100
  4. Subject: [PATCH] Add support for x,y value in percentage to BAR_PARAMS, %xl,
  5.  %dr, %T, %St, %xl and %Cl
  6.  
  7. Change-Id: I1630b6d22e810d4f523e27a7312e0fec1e7dcf62
  8. ---
  9.  apps/gui/skin_engine/skin_parser.c | 116 ++++++++++++++++++++++++++++++++-----
  10.  lib/skin_parser/tag_table.c        |  13 ++---
  11.  2 files changed, 106 insertions(+), 23 deletions(-)
  12.  
  13. diff --git a/apps/gui/skin_engine/skin_parser.c b/apps/gui/skin_engine/skin_parser.c
  14. index a76a06a..85e76d2 100644
  15. --- a/apps/gui/skin_engine/skin_parser.c
  16. +++ b/apps/gui/skin_engine/skin_parser.c
  17. @@ -398,8 +398,15 @@ static int parse_image_load(struct skin_element *element,
  18.          subimages = get_param(element, 2)->data.number;
  19.      else if (element->params_count > 3)
  20.      {
  21. -        x = get_param(element, 2)->data.number;
  22. -        y = get_param(element, 3)->data.number;
  23. +        if (get_param(element, 2)->type == PERCENT)
  24. +            x = get_param(element, 2)->data.number * curr_vp->vp.width / 1000;
  25. +        else
  26. +            x = get_param(element, 2)->data.number;
  27. +        if (get_param(element, 3)->type == PERCENT)
  28. +            y = get_param(element, 3)->data.number * curr_vp->vp.height / 1000;
  29. +        else
  30. +            y = get_param(element, 3)->data.number;
  31. +
  32.          if (element->params_count == 5)
  33.              subimages = get_param(element, 4)->data.number;
  34.      }
  35. @@ -641,16 +648,27 @@ static int parse_drawrectangle( struct skin_element *element,
  36.      if (!rect)
  37.          return -1;
  38.  
  39. -    rect->x = get_param(element, 0)->data.number;
  40. -    rect->y = get_param(element, 1)->data.number;
  41. +    if (get_param(element, 0)->type == PERCENT)
  42. +        rect->x = get_param(element, 0)->data.number * curr_vp->vp.width / 1000;
  43. +    else
  44. +        rect->x = get_param(element, 0)->data.number;
  45. +
  46. +    if (get_param(element, 1)->type == PERCENT)
  47. +        rect->y = get_param(element, 1)->data.number * curr_vp->vp.height / 1000;
  48. +    else
  49. +        rect->y = get_param(element, 1)->data.number;
  50.  
  51.      if (isdefault(get_param(element, 2)))
  52.          rect->width = curr_vp->vp.width - rect->x;
  53. +    else if (get_param(element, 2)->type == PERCENT)
  54. +        rect->width = get_param(element, 2)->data.number * curr_vp->vp.width / 1000;
  55.      else
  56.          rect->width = get_param(element, 2)->data.number;
  57.  
  58.      if (isdefault(get_param(element, 3)))
  59.          rect->height = curr_vp->vp.height - rect->y;
  60. +    else if (get_param(element, 3)->type == PERCENT)
  61. +        rect->height = get_param(element, 3)->data.number * curr_vp->vp.height / 1000;
  62.      else
  63.          rect->height = get_param(element, 3)->data.number;
  64.  
  65. @@ -923,7 +941,12 @@ static int parse_progressbar_tag(struct skin_element* element,
  66.      /* (x, y, width, height, ...) */
  67.      if (!isdefault(param))
  68.      {
  69. -        pb->x = param->data.number;
  70. +        if (param->type == PERCENT)
  71. +        {
  72. +            pb->x = param->data.number *  vp->width / 1000;
  73. +        }
  74. +        else
  75. +            pb->x = param->data.number;
  76.          if (pb->x < 0 || pb->x >= vp->width)
  77.              return WPS_ERROR_INVALID_PARAM;
  78.      }
  79. @@ -933,7 +956,12 @@ static int parse_progressbar_tag(struct skin_element* element,
  80.  
  81.      if (!isdefault(param))
  82.      {
  83. -        pb->y = param->data.number;
  84. +        if (param->type == PERCENT)
  85. +        {
  86. +           pb->y = param->data.number *  vp->height / 1000;
  87. +        }
  88. +        else
  89. +            pb->y = param->data.number;
  90.          if (pb->y < 0 || pb->y >= vp->height)
  91.              return WPS_ERROR_INVALID_PARAM;
  92.      }
  93. @@ -943,7 +971,12 @@ static int parse_progressbar_tag(struct skin_element* element,
  94.  
  95.      if (!isdefault(param))
  96.      {
  97. -        pb->width = param->data.number;
  98. +        if (param->type == PERCENT)
  99. +        {
  100. +           pb->width = param->data.number *  vp->width / 1000;
  101. +        }
  102. +        else
  103. +            pb->width = param->data.number;
  104.          if (pb->width <= 0 || (pb->x + pb->width) > vp->width)
  105.              return WPS_ERROR_INVALID_PARAM;
  106.      }
  107. @@ -954,7 +987,12 @@ static int parse_progressbar_tag(struct skin_element* element,
  108.      if (!isdefault(param))
  109.      {
  110.          int max;
  111. -        pb->height = param->data.number;
  112. +        if (param->type == PERCENT)
  113. +        {
  114. +           pb->height = param->data.number *  vp->height / 1000;
  115. +        }
  116. +        else
  117. +           pb->height = param->data.number;
  118.          /* include y in check only if it was non-default */
  119.          max = (pb->y > 0) ? pb->y + pb->height : pb->height;
  120.          if (pb->height <= 0 || max > vp->height)
  121. @@ -1211,6 +1249,18 @@ static int parse_albumart_load(struct skin_element* element,
  122.      aa->width = get_param(element, 2)->data.number;
  123.      aa->height = get_param(element, 3)->data.number;
  124.  
  125. +    if (!isdefault(get_param(element, 0)) && get_param(element, 0)->type == PERCENT)
  126. +        aa->x = get_param(element, 0)->data.number * curr_vp->vp.width / 1000;
  127. +
  128. +    if (!isdefault(get_param(element, 1)) && get_param(element, 1)->type == PERCENT)
  129. +        aa->y = get_param(element, 1)->data.number * curr_vp->vp.height / 1000;
  130. +
  131. +    if (!isdefault(get_param(element, 2)) && get_param(element, 2)->type == PERCENT)
  132. +        aa->width = get_param(element, 2)->data.number * curr_vp->vp.width / 1000;
  133. +
  134. +    if (!isdefault(get_param(element, 3)) && get_param(element, 3)->type == PERCENT)
  135. +        aa->height = get_param(element, 3)->data.number * curr_vp->vp.height / 1000;
  136. +
  137.      aa->vp = PTRTOSKINOFFSET(skin_buffer, &curr_vp->vp);
  138.      aa->draw_handle = -1;
  139.  
  140. @@ -1519,10 +1569,7 @@ static int parse_touchregion(struct skin_element *element,
  141.      {
  142.          region->label = PTRTOSKINOFFSET(skin_buffer, get_param_text(element, 0));
  143.          p = 1;
  144. -        /* "[SI]III[SI]|SS" is the param list. There MUST be 4 numbers
  145. -         * followed by at least one string. Verify that here */
  146. -        if (element->params_count < 6 ||
  147. -            get_param(element, 4)->type != INTEGER)
  148. +        if (element->params_count < 6)
  149.              return WPS_ERROR_INVALID_PARAM;
  150.      }
  151.      else
  152. @@ -1530,11 +1577,48 @@ static int parse_touchregion(struct skin_element *element,
  153.          region->label = PTRTOSKINOFFSET(skin_buffer, NULL);
  154.          p = 0;
  155.      }
  156. +/*x*/
  157. +    struct skin_tag_parameter *param = get_param(element, p);
  158. +    region->x = 0;
  159. +    if (!isdefault(param))
  160. +    {
  161. +        if (param->type == INTEGER)
  162. +            region->x = param->data.number;
  163. +        else if (param->type == PERCENT)
  164. +            region->x = param->data.number * curr_vp->vp.width / 1000;
  165. +    }
  166. +/*y*/  
  167. +    param = get_param(element, ++p);
  168. +    region->y = 0;
  169. +    if (!isdefault(param))
  170. +    {
  171. +        if (param->type == INTEGER)
  172. +            region->y = param->data.number;
  173. +        else if (param->type == PERCENT)
  174. +            region->y  =param->data.number * curr_vp->vp.width / 1000;
  175. +    }
  176. +/*width*/
  177. +    param = get_param(element, ++p);
  178. +    region->width = curr_vp->vp.width;
  179. +    if (!isdefault(param))
  180. +    {
  181. +        if (param->type == INTEGER)
  182. +            region->width =param->data.number;
  183. +        else if (param->type == PERCENT)
  184. +            region->width = curr_vp->vp.width  * param->data.number / 1000;
  185. +    }
  186. +/*height*/    
  187. +    param = get_param(element, ++p);
  188. +    region->height = curr_vp->vp.height;
  189. +    if (!isdefault(param))
  190. +    {
  191. +        if (param->type == INTEGER)
  192. +            region->height =param->data.number;
  193. +        else if (param->type == PERCENT)
  194. +            region->height = curr_vp->vp.height  * param->data.number / 1000;
  195. +    }
  196. +    p++;
  197.  
  198. -    region->x = get_param(element, p++)->data.number;
  199. -    region->y = get_param(element, p++)->data.number;
  200. -    region->width = get_param(element, p++)->data.number;
  201. -    region->height = get_param(element, p++)->data.number;
  202.      region->wvp = PTRTOSKINOFFSET(skin_buffer, curr_vp);
  203.      region->armed = false;
  204.      region->reverse_bar = false;
  205. diff --git a/lib/skin_parser/tag_table.c b/lib/skin_parser/tag_table.c
  206. index 24dcf18..2cea048 100644
  207. --- a/lib/skin_parser/tag_table.c
  208. +++ b/lib/skin_parser/tag_table.c
  209. @@ -22,7 +22,7 @@
  210.  #include "tag_table.h"
  211.  
  212.  #include <string.h>
  213. -#define BAR_PARAMS "?iiii|s*"
  214. +#define BAR_PARAMS "?[iP][iP][iP][iP]|s*"
  215.  /* The tag definition table */
  216.  static const struct tag_info legal_tags[] =
  217.  {
  218. @@ -176,13 +176,13 @@ static const struct tag_info legal_tags[] =
  219.      { SKIN_TOKEN_DISABLE_THEME,         "wd", "", 0|NOBREAK },
  220.      { SKIN_TOKEN_DRAW_INBUILTBAR,       "wi", "", SKIN_REFRESH_STATIC|NOBREAK },
  221.      
  222. -    { SKIN_TOKEN_IMAGE_PRELOAD,         "xl", "SF|III", 0|NOBREAK },
  223. +    { SKIN_TOKEN_IMAGE_PRELOAD,         "xl", "SF|[IP][IP]I", 0|NOBREAK },
  224.      { SKIN_TOKEN_IMAGE_PRELOAD_DISPLAY, "xd", "S|[IT]I", 0 },
  225.      { SKIN_TOKEN_IMAGE_DISPLAY,         "x", "SF|II", SKIN_REFRESH_STATIC|NOBREAK },
  226.      { SKIN_TOKEN_IMAGE_DISPLAY_9SEGMENT, "x9", "S", 0 },
  227.      
  228.      { SKIN_TOKEN_LOAD_FONT,             "Fl" , "IF|I", 0|NOBREAK },
  229. -    { SKIN_TOKEN_ALBUMART_LOAD,         "Cl" , "IIII|ss", 0|NOBREAK },
  230. +    { SKIN_TOKEN_ALBUMART_LOAD,         "Cl" , "[iP][iP][iP][iP]|ss", 0|NOBREAK },
  231.      { SKIN_TOKEN_ALBUMART_DISPLAY,      "Cd" , "", SKIN_REFRESH_STATIC },
  232.      { SKIN_TOKEN_ALBUMART_FOUND,        "C" , "", SKIN_REFRESH_STATIC },
  233.      
  234. @@ -214,7 +214,7 @@ static const struct tag_info legal_tags[] =
  235.      { SKIN_TOKEN_IMAGE_BACKDROP,        "X"  , "f", SKIN_REFRESH_STATIC|NOBREAK },
  236.      /* This uses the bar tag params also but the first item can be a string
  237.       * and we don't allow no params. */
  238. -    { SKIN_TOKEN_SETTING,               "St" , "[Si]|iiis*", SKIN_REFRESH_DYNAMIC },
  239. +    { SKIN_TOKEN_SETTING,               "St" , "[Sip]|[ip][ip][ip]s*", SKIN_REFRESH_DYNAMIC },
  240.      { SKIN_TOKEN_TRANSLATEDSTRING,      "Sx" , "S", SKIN_REFRESH_STATIC },
  241.      { SKIN_TOKEN_LANG_IS_RTL,           "Sr" , "", SKIN_REFRESH_STATIC },
  242.      
  243. @@ -224,8 +224,7 @@ static const struct tag_info legal_tags[] =
  244.       * [SI]III[SI]|SN <- SIIIIS|S or IIIIS|S
  245.       *  keep in sync with parse_touchregion() and parse_lasttouch() */
  246.      { SKIN_TOKEN_LASTTOUCH,             "Tl" , "|[SD]D", SKIN_REFRESH_DYNAMIC },
  247. -    { SKIN_TOKEN_TOUCHREGION,           "T"  , "[SI]III[SI]|S*", 0|NOBREAK },
  248. -    
  249. +    { SKIN_TOKEN_TOUCHREGION,           "T"  , "[Sip][ip][ip][ip][Sip]|S*", 0|NOBREAK },
  250.      { SKIN_TOKEN_HAVE_TOUCH,            "Tp", "", FEATURE_TAG },
  251.      
  252.      { SKIN_TOKEN_CURRENT_SCREEN,        "cs", "", SKIN_REFRESH_DYNAMIC },
  253. @@ -246,7 +245,7 @@ static const struct tag_info legal_tags[] =
  254.      { SKIN_TOKEN_VAR_TIMEOUT,           "vl",   "S|D", SKIN_REFRESH_DYNAMIC },
  255.  
  256.      { SKIN_TOKEN_SUBSTRING,             "ss",   "IiT|s", SKIN_REFRESH_DYNAMIC },
  257. -    { SKIN_TOKEN_DRAWRECTANGLE,         "dr",   "IIii|ss", SKIN_REFRESH_STATIC },
  258. +    { SKIN_TOKEN_DRAWRECTANGLE,         "dr",   "[IP][IP][ip][ip]|ss", SKIN_REFRESH_STATIC },
  259.      { SKIN_TOKEN_UNKNOWN,                ""   , "", 0 }
  260.      /* Keep this here to mark the end of the table */
  261.  };
  262. --
  263. 1.9.1
RAW Paste Data