9
0
Fork 0

menu: store repaint state in variable

Instead of calling print_menu_entry multiple times in each case, store
the repaint state in a variable and call it once at the end to save a
few bytes of binary space.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Sascha Hauer 2012-06-24 14:53:10 +02:00
parent fa37257ce0
commit 4f02e70d6d
1 changed files with 12 additions and 5 deletions

View File

@ -343,6 +343,9 @@ int menu_show(struct menu *m)
gotoXY(m->selected->num + 1, 3);
do {
struct menu_entry *old_selected = m->selected;
int repaint = 0;
if (m->auto_select >= 0)
ch = KEY_RETURN;
else
@ -352,24 +355,22 @@ int menu_show(struct menu *m)
switch (ch) {
case KEY_UP:
print_menu_entry(m, m->selected, 0);
m->selected = list_entry(m->selected->list.prev, struct menu_entry,
list);
if (&(m->selected->list) == &(m->entries)) {
m->selected = list_entry(m->selected->list.prev, struct menu_entry,
list);
}
print_menu_entry(m, m->selected, 1);
repaint = 1;
break;
case KEY_DOWN:
print_menu_entry(m, m->selected, 0);
m->selected = list_entry(m->selected->list.next, struct menu_entry,
list);
if (&(m->selected->list) == &(m->entries)) {
m->selected = list_entry(m->selected->list.next, struct menu_entry,
list);
}
print_menu_entry(m, m->selected, 1);
repaint = 1;
break;
case ' ':
if (m->selected->type != MENU_ENTRY_BOX)
@ -377,7 +378,7 @@ int menu_show(struct menu *m)
m->selected->box_state = !m->selected->box_state;
if (m->selected->action)
m->selected->action(m, m->selected);
print_menu_entry(m, m->selected, 1);
repaint = 1;
break;
case KEY_ENTER:
if (ch_previous == KEY_RETURN)
@ -395,6 +396,12 @@ int menu_show(struct menu *m)
default:
break;
}
if (repaint) {
print_menu_entry(m, old_selected, 0);
print_menu_entry(m, m->selected, 1);
}
ch_previous = ch;
} while(1);