This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Aug 4th, 2011  |  syntax: None  |  size: 7.27 KB  |  views: 68  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. diff --git a/apps/gui/bitmap/list-skinned.c b/apps/gui/bitmap/list-skinned.c
  2. new file mode 100644
  3. index 0000000..0d19168
  4. --- /dev/null
  5. +++ b/apps/gui/bitmap/list-skinned.c
  6. @@ -0,0 +1,195 @@
  7. +/***************************************************************************
  8. + *             __________               __   ___.
  9. + *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
  10. + *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
  11. + *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
  12. + *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
  13. + *                     \/            \/     \/    \/            \/
  14. + * $Id$
  15. + *
  16. + * Copyright (C) 2011 by Jonathan Gordon
  17. + *
  18. + * This program is free software; you can redistribute it and/or
  19. + * modify it under the terms of the GNU General Public License
  20. + * as published by the Free Software Foundation; either version 2
  21. + * of the License, or (at your option) any later version.
  22. + *
  23. + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  24. + * KIND, either express or implied.
  25. + *
  26. + ****************************************************************************/
  27. +
  28. +#include "config.h"
  29. +#include "lcd.h"
  30. +#include "font.h"
  31. +#include "button.h"
  32. +#include "string.h"
  33. +#include "settings.h"
  34. +#include "kernel.h"
  35. +#include "system.h"
  36. +#include "file.h"
  37. +
  38. +#include "action.h"
  39. +#include "screen_access.h"
  40. +#include "list.h"
  41. +#include "scrollbar.h"
  42. +#include "lang.h"
  43. +#include "sound.h"
  44. +#include "misc.h"
  45. +#include "viewport.h"
  46. +#include "statusbar-skinned.h"
  47. +#include "skin_engine/skin_engine.h"
  48. +#include "appevents.h"
  49. +
  50. +static struct listitem_viewport_cfg *listcfg[NB_SCREENS] = {NULL};
  51. +static char *current_item_text_ptr, current_item_text[2048];
  52. +static enum themable_icons current_item_icon;
  53. +void skinlist_set_cfg(enum screen_type screen,
  54. +                      struct listitem_viewport_cfg *cfg)
  55. +{
  56. +    if (listcfg[screen] != cfg)
  57. +    {
  58. +        listcfg[screen] = cfg;
  59. +        list_init();
  60. +    }
  61. +}
  62. +
  63. +char* skinlist_get_item_text(void)
  64. +{
  65. +    const char* ret = P2STR((unsigned char*)current_item_text_ptr);
  66. +    return ret;
  67. +}
  68. +enum themable_icons skinlist_get_item_icon(void)
  69. +{
  70. +    return current_item_icon;
  71. +}
  72. +static bool is_selected = false;
  73. +bool skinlist_is_selected_item(void)
  74. +{
  75. +    return is_selected;
  76. +}
  77. +int skinlist_get_line_count(enum screen_type screen, struct gui_synclist *list)
  78. +{
  79. +    struct viewport *parent = (list->parent[screen]);
  80. +    if (listcfg[screen] == NULL)
  81. +        return -1;
  82. +    if (listcfg[screen]->tile == true)
  83. +    {
  84. +        int rows = (parent->height / listcfg[screen]->height);
  85. +        int cols = (parent->width / listcfg[screen]->width);
  86. +        return rows*cols;
  87. +    }
  88. +    else
  89. +        return  (parent->height / listcfg[screen]->height);
  90. +}
  91. +
  92. +
  93. +static int current_item;
  94. +static int current_first_shown, current_last_shown;
  95. +void skinlist_get_scrollbar(int* nb_item, int* first_shown, int* last_shown)
  96. +{
  97. +    *nb_item = current_item;
  98. +    *first_shown = current_first_shown;
  99. +    *last_shown = current_last_shown;
  100. +}
  101. +
  102. +bool skinlist_draw(struct screen *display, struct gui_synclist *list)
  103. +{
  104. +    int cur_line, display_lines;
  105. +    const int screen = display->screen_type;
  106. +    struct viewport *parent = (list->parent[screen]);
  107. +    char* label = NULL;
  108. +    const int list_start_item = list->start_item[screen];
  109. +    struct gui_wps wps;
  110. +    if (listcfg[screen] == NULL)
  111. +        return false;
  112. +    wps.display = display;
  113. +    wps.data = listcfg[screen]->data;
  114. +    display_lines = skinlist_get_line_count(screen, list);
  115. +    label = listcfg[screen]->label;
  116. +    display->set_viewport(parent);
  117. +    display->clear_viewport();
  118. +    current_item = list->selected_item;
  119. +    current_first_shown = list_start_item;
  120. +    current_last_shown = list_start_item+display_lines;
  121. +    if (current_last_shown >= list->nb_items)
  122. +        current_last_shown = list->nb_items;
  123. +    for (cur_line = 0; cur_line < display_lines; cur_line++)
  124. +    {
  125. +        struct skin_element* viewport;
  126. +        struct skin_viewport* skin_viewport;
  127. +        if (list_start_item+cur_line+1 > list->nb_items)
  128. +            break;
  129. +        is_selected = list->show_selection_marker &&
  130. +                list_start_item+cur_line == list->selected_item;
  131. +        current_item_text_ptr = list->callback_get_item_name(
  132. +                    list_start_item+cur_line,
  133. +                    list->data, current_item_text, 2048);
  134. +        if (list->callback_get_item_icon != NULL)
  135. +            current_item_icon = list->callback_get_item_icon(
  136. +                                    list_start_item+cur_line, list->data);
  137. +        
  138. +        for (viewport = listcfg[screen]->data->tree;
  139. +             viewport;
  140. +             viewport = viewport->next)
  141. +        {
  142. +            int origional_x, origional_y;
  143. +            int origional_w, origional_h;
  144. +            skin_viewport = (struct skin_viewport*)viewport->data;
  145. +            if (viewport->children == 0 || !skin_viewport->label ||
  146. +                (skin_viewport->label && strcmp(label, skin_viewport->label))
  147. +                )
  148. +                continue;
  149. +
  150. +            origional_x = skin_viewport->vp.x;
  151. +            origional_y = skin_viewport->vp.y;
  152. +            origional_w = skin_viewport->vp.width;
  153. +            origional_h = skin_viewport->vp.height;
  154. +            if (listcfg[screen]->tile)
  155. +            {
  156. +                int cols = (parent->width / listcfg[screen]->width);
  157. +                int col = (list_start_item+cur_line)%cols;
  158. +                int row = (list_start_item+cur_line)/cols;
  159. +                
  160. +                skin_viewport->vp.x = parent->x + listcfg[screen]->width*col + origional_x;
  161. +                skin_viewport->vp.y = parent->y + listcfg[screen]->height*row + origional_y;
  162. +            }
  163. +            else
  164. +            {
  165. +                skin_viewport->vp.x = parent->x;
  166. +                skin_viewport->vp.y = parent->y +
  167. +                                   (listcfg[screen]->height*cur_line);
  168. +            }
  169. +            display->set_viewport(&skin_viewport->vp);
  170. +#ifdef HAVE_LCD_BITMAP
  171. +            /* Set images to not to be displayed */
  172. +            struct skin_token_list *imglist = wps.data->images;
  173. +            while (imglist)
  174. +            {
  175. +                struct gui_img *img = (struct gui_img *)imglist->token->value.data;
  176. +                img->display = -1;
  177. +                imglist = imglist->next;
  178. +            }
  179. +#endif
  180. +            skin_render_viewport(viewport->children[0],
  181. +                                 &wps, skin_viewport, SKIN_REFRESH_ALL);
  182. +#ifdef HAVE_LCD_BITMAP
  183. +            wps_display_images(&wps, &skin_viewport->vp);
  184. +#endif
  185. +
  186. +            skin_viewport->vp.x = origional_x;
  187. +            skin_viewport->vp.y = origional_y;
  188. +            skin_viewport->vp.width = origional_w;
  189. +            skin_viewport->vp.height = origional_h;
  190. +        }
  191. +    }
  192. +    display->set_viewport(parent);
  193. +    display->update_viewport();
  194. +    current_item_text_ptr = list->callback_get_item_name(
  195. +                list->selected_item,
  196. +                list->data, current_item_text, 2048);
  197. +    /* Abuse the callback to force the sbs to update */
  198. +    send_event(LCD_EVENT_ACTIVATION, NULL);
  199. +    return true;
  200. +}
  201. +
clone this paste RAW Paste Data