summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomer Shalev <shalev.tomer@gmail.com>2009-10-05 19:59:16 +0000
committerTomer Shalev <shalev.tomer@gmail.com>2009-10-05 19:59:16 +0000
commit2438d1693b825ea2764b299f2ce7e3b9c50f2644 (patch)
treef0acf9ff2dda2952861495dc35538e36d59fdfd0
parent6b51e5b089e6ced46ab57292449356d02284ac84 (diff)
downloadrockbox-2438d1693b825ea2764b299f2ce7e3b9c50f2644.zip
rockbox-2438d1693b825ea2764b299f2ce7e3b9c50f2644.tar.gz
rockbox-2438d1693b825ea2764b299f2ce7e3b9c50f2644.tar.bz2
rockbox-2438d1693b825ea2764b299f2ce7e3b9c50f2644.tar.xz
- Use pointers instead of repeating access to array element
- Set const when possible git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22965 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/gui/bitmap/list.c129
1 files changed, 65 insertions, 64 deletions
diff --git a/apps/gui/bitmap/list.c b/apps/gui/bitmap/list.c
index 79df35b..5c582ae 100644
--- a/apps/gui/bitmap/list.c
+++ b/apps/gui/bitmap/list.c
@@ -70,28 +70,30 @@ static bool draw_title(struct screen *display, struct gui_synclist *list)
{
const int screen = display->screen_type;
int style = STYLE_DEFAULT;
- display->scroll_stop(&title_text[screen]);
+ struct viewport *title_text_vp = &title_text[screen];
+
+ display->scroll_stop(title_text_vp);
if (!list_display_title(list, screen))
return false;
- title_text[screen] = *(list->parent[screen]);
- title_text[screen].height = font_get(title_text[screen].font)->height;
+ *title_text_vp = *(list->parent[screen]);
+ title_text_vp->height = font_get(title_text_vp->font)->height;
if (list->title_icon != Icon_NOICON && global_settings.show_icons)
{
- struct viewport title_icon = title_text[screen];
- title_icon.width = get_icon_width(screen)
- + ICON_PADDING*2;
+ struct viewport title_icon = *title_text_vp;
+
+ title_icon.width = get_icon_width(screen) + ICON_PADDING * 2;
if (lang_is_rtl())
{
- title_icon.x = title_text[screen].width - ICON_PADDING -
+ title_icon.x = title_text_vp->width - ICON_PADDING -
get_icon_width(screen);
}
else
{
title_icon.x = ICON_PADDING;
- title_text[screen].x += title_icon.width;
+ title_text_vp->x += title_icon.width;
}
- title_text[screen].width -= title_icon.width;
+ title_text_vp->width -= title_icon.width;
display->set_viewport(&title_icon);
screen_put_icon(display, 0, 0, list->title_icon);
@@ -102,7 +104,7 @@ static bool draw_title(struct screen *display, struct gui_synclist *list)
style |= (STYLE_COLORED|list->title_color);
}
#endif
- display->set_viewport(&title_text[screen]);
+ display->set_viewport(title_text_vp);
display->puts_scroll_style(0, 0, list->title, style);
return true;
}
@@ -110,9 +112,11 @@ static bool draw_title(struct screen *display, struct gui_synclist *list)
void list_draw(struct screen *display, struct gui_synclist *list)
{
struct viewport list_icons;
- int start, end, line_height, style, i, scrollbar_in_left;
+ int start, end, line_height, style, i;
const int screen = display->screen_type;
+ const int list_start_item = list->start_item[screen];
const int icon_width = get_icon_width(screen) + ICON_PADDING;
+ const int scrollbar_in_left = global_settings.scrollbar == SCROLLBAR_LEFT;
const bool show_cursor = !global_settings.cursor_style &&
list->show_selection_marker;
struct viewport *parent = (list->parent[screen]);
@@ -121,71 +125,67 @@ void list_draw(struct screen *display, struct gui_synclist *list)
#endif
int item_offset, is_rtl = lang_is_rtl();
bool show_title;
+ struct viewport *list_text_vp = &list_text[screen];
+
line_height = font_get(parent->font)->height;
display->set_viewport(parent);
display->clear_viewport();
- display->scroll_stop(&list_text[screen]);
- list_text[screen] = *parent;
+ display->scroll_stop(list_text_vp);
+ *list_text_vp = *parent;
if ((show_title = draw_title(display, list)))
{
- list_text[screen].y += line_height;
- list_text[screen].height -= line_height;
+ list_text_vp->y += line_height;
+ list_text_vp->height -= line_height;
}
- start = list->start_item[screen];
- end = start + viewport_get_nb_lines(&list_text[screen]);
-
- scrollbar_in_left = (global_settings.scrollbar == SCROLLBAR_LEFT);
+ start = list_start_item;
+ end = start + viewport_get_nb_lines(list_text_vp);
/* draw the scrollbar if its needed */
if (global_settings.scrollbar &&
- viewport_get_nb_lines(&list_text[screen]) < list->nb_items)
+ viewport_get_nb_lines(list_text_vp) < list->nb_items)
{
struct viewport vp;
- vp = list_text[screen];
+ vp = *list_text_vp;
vp.width = SCROLLBAR_WIDTH;
- vp.height = line_height *
- viewport_get_nb_lines(&list_text[screen]);
+ vp.height = line_height * viewport_get_nb_lines(list_text_vp);
vp.x = parent->x;
- list_text[screen].width -= SCROLLBAR_WIDTH;
+ list_text_vp->width -= SCROLLBAR_WIDTH;
if (scrollbar_in_left)
- list_text[screen].x += SCROLLBAR_WIDTH;
+ list_text_vp->x += SCROLLBAR_WIDTH;
else
- vp.x += list_text[screen].width;
+ vp.x += list_text_vp->width;
display->set_viewport(&vp);
- gui_scrollbar_draw(display, 0, 0, SCROLLBAR_WIDTH-1,
- vp.height, list->nb_items,
- list->start_item[screen],
- list->start_item[screen] + end-start,
- VERTICAL);
+ gui_scrollbar_draw(display, 0, 0, SCROLLBAR_WIDTH-1, vp.height,
+ list->nb_items, list_start_item, list_start_item + end-start,
+ VERTICAL);
}
else if (show_title)
{
/* shift everything a bit in relation to the title... */
if (scrollbar_in_left)
{
- list_text[screen].width -= SCROLLBAR_WIDTH;
- list_text[screen].x += SCROLLBAR_WIDTH;
+ list_text_vp->width -= SCROLLBAR_WIDTH;
+ list_text_vp->x += SCROLLBAR_WIDTH;
}
}
-
+
/* setup icon placement */
- list_icons = list_text[screen];
- int icon_count = global_settings.show_icons &&
+ list_icons = *list_text_vp;
+ int icon_count = global_settings.show_icons &&
(list->callback_get_item_icon != NULL) ? 1 : 0;
if (show_cursor)
icon_count++;
if (icon_count)
{
list_icons.width = icon_width * icon_count;
- list_text[screen].width -=
- list_icons.width + ICON_PADDING;
+ list_text_vp->width -= list_icons.width + ICON_PADDING;
if (is_rtl)
- list_icons.x += list_text[screen].width;
+ list_icons.x += list_text_vp->width;
else
- list_text[screen].x += list_icons.width + ICON_PADDING;
+ list_text_vp->x += list_icons.width + ICON_PADDING;
}
-
+
for (i=start; i<end && i<list->nb_items; i++)
{
/* do the text */
@@ -196,14 +196,13 @@ void list_draw(struct screen *display, struct gui_synclist *list)
s = list->callback_get_item_name(i, list->data, entry_buffer,
sizeof(entry_buffer));
entry_name = P2STR(s);
- display->set_viewport(&list_text[screen]);
+ display->set_viewport(list_text_vp);
style = STYLE_DEFAULT;
/* position the string at the correct offset place */
int item_width,h;
display->getstringsize(entry_name, &item_width, &h);
- item_offset = gui_list_get_item_offset(list, item_width,
- text_pos, display,
- &list_text[screen]);
+ item_offset = gui_list_get_item_offset(list, item_width, text_pos,
+ display, list_text_vp);
#ifdef HAVE_LCD_COLOR
/* if the list has a color callback */
@@ -222,7 +221,7 @@ void list_draw(struct screen *display, struct gui_synclist *list)
{/* The selected item must be displayed scrolling */
if (global_settings.cursor_style == 1
#ifdef HAVE_REMOTE_LCD
- /* the global_settings.cursor_style check is here to make
+ /* the global_settings.cursor_style check is here to make
* sure if they want the cursor instead of bar it will work
*/
|| (display->depth < 16 && global_settings.cursor_style)
@@ -253,8 +252,7 @@ void list_draw(struct screen *display, struct gui_synclist *list)
}
#endif
/* if the text is smaller than the viewport size */
- if (item_offset> item_width
- - (list_text[screen].width - text_pos))
+ if (item_offset> item_width - (list_text_vp->width - text_pos))
{
/* don't scroll */
display->puts_style_offset(0, i-start, entry_name,
@@ -307,8 +305,9 @@ static bool scrolling=false;
static int gui_synclist_touchscreen_scrollbar(struct gui_synclist * gui_list,
int y)
{
- int screen = screens[SCREEN_MAIN].screen_type;
- int nb_lines = viewport_get_nb_lines(&list_text[screen]);
+ const int screen = screens[SCREEN_MAIN].screen_type;
+ const int nb_lines = viewport_get_nb_lines(&list_text[screen]);
+
if (nb_lines < gui_list->nb_items)
{
scrolling = true;
@@ -338,13 +337,16 @@ static int gui_synclist_touchscreen_scrollbar(struct gui_synclist * gui_list,
unsigned gui_synclist_do_touchscreen(struct gui_synclist * gui_list)
{
short x, y;
- int button = action_get_touchscreen_press(&x, &y);
+ const int button = action_get_touchscreen_press(&x, &y);
int line;
- struct screen *display = &screens[SCREEN_MAIN];
- int screen = display->screen_type;
+ const struct screen *display = &screens[SCREEN_MAIN];
+ const int screen = display->screen_type;
+ const int list_start_item = gui_list->start_item[screen];
+ const struct viewport *list_text_vp = &list_text[screen];
+
if (button == BUTTON_NONE)
return ACTION_NONE;
- if (x<list_text[screen].x)
+ if (x < list_text_vp->x)
{
/* Top left corner is GO_TO_ROOT */
if (y<list_text[SCREEN_MAIN].y)
@@ -362,7 +364,7 @@ unsigned gui_synclist_do_touchscreen(struct gui_synclist * gui_list)
}
else
{
- if(x>list_text[screen].x+list_text[screen].width &&
+ if (x > list_text_vp->x + list_text_vp->width &&
global_settings.scrollbar == SCROLLBAR_RIGHT)
return gui_synclist_touchscreen_scrollbar(gui_list, y);
@@ -378,30 +380,29 @@ unsigned gui_synclist_do_touchscreen(struct gui_synclist * gui_list)
* | will bring up the context menu of it. |
* |--------------------------------------------------------|
*/
- if (y > list_text[screen].y || button & BUTTON_REPEAT)
+ if (y > list_text_vp->y || button & BUTTON_REPEAT)
{
int line_height, actual_y;
- actual_y = y - list_text[screen].y;
+ actual_y = y - list_text_vp->y;
line_height = font_get(gui_list->parent[screen]->font)->height;
line = actual_y / line_height;
/* Pressed below the list*/
- if (gui_list->start_item[screen]+line >= gui_list->nb_items)
+ if (list_start_item + line >= gui_list->nb_items)
return ACTION_NONE;
/* Pressed a border */
if(UNLIKELY(actual_y % line_height == 0))
return ACTION_NONE;
- if (line != (gui_list->selected_item - gui_list->start_item[screen])
+ if (line != (gui_list->selected_item - list_start_item)
&& button ^ BUTTON_REL)
{
if(button & BUTTON_REPEAT)
scrolling = true;
- gui_synclist_select_item(gui_list, gui_list->start_item[screen]
- + line);
+ gui_synclist_select_item(gui_list, list_start_item + line);
return ACTION_REDRAW;
}
@@ -412,7 +413,7 @@ unsigned gui_synclist_do_touchscreen(struct gui_synclist * gui_list)
dead zones)
*/
if(global_settings.scrollbar == SCROLLBAR_RIGHT &&
- x > list_text[screen].x + list_text[screen].width -
+ x > list_text_vp->x + list_text_vp->width -
get_icon_width(SCREEN_MAIN))
return ACTION_NONE;
@@ -437,7 +438,7 @@ unsigned gui_synclist_do_touchscreen(struct gui_synclist * gui_list)
}
}
else if(button == BUTTON_REL &&
- line == gui_list->selected_item - gui_list->start_item[screen])
+ line == gui_list->selected_item - list_start_item)
{
/* Pen was released on either the same line as the previously
* selected one or an other one
@@ -449,7 +450,7 @@ unsigned gui_synclist_do_touchscreen(struct gui_synclist * gui_list)
return ACTION_NONE;
}
/* Everything above the items is cancel */
- else if (y < list_text[screen].y && button == BUTTON_REL)
+ else if (y < list_text_vp->.y && button == BUTTON_REL)
return ACTION_STD_CANCEL;
}
return ACTION_NONE;