diff options
-rw-r--r-- | apps/menu.c | 75 |
1 files changed, 42 insertions, 33 deletions
diff --git a/apps/menu.c b/apps/menu.c index c18a881e07..a635990c56 100644 --- a/apps/menu.c +++ b/apps/menu.c | |||
@@ -24,8 +24,7 @@ | |||
24 | #include "debug.h" | 24 | #include "debug.h" |
25 | 25 | ||
26 | struct menu { | 26 | struct menu { |
27 | int menu_top; | 27 | int top; |
28 | int menu_bottom; | ||
29 | int cursor; | 28 | int cursor; |
30 | struct menu_items* items; | 29 | struct menu_items* items; |
31 | int itemcount; | 30 | int itemcount; |
@@ -33,18 +32,52 @@ struct menu { | |||
33 | 32 | ||
34 | #define MAX_MENUS 4 | 33 | #define MAX_MENUS 4 |
35 | 34 | ||
35 | #ifdef HAVE_LCD_BITMAP | ||
36 | #define MENU_LINES 6 | ||
37 | #else | ||
38 | #define MENU_LINES 2 | ||
39 | #endif | ||
40 | |||
36 | static struct menu menus[MAX_MENUS]; | 41 | static struct menu menus[MAX_MENUS]; |
37 | static bool inuse[MAX_MENUS] = { false }; | 42 | static bool inuse[MAX_MENUS] = { false }; |
38 | 43 | ||
44 | static void menu_draw(int m) | ||
45 | { | ||
46 | int i = 0; | ||
47 | |||
48 | lcd_clear_display(); | ||
49 | #ifdef HAVE_LCD_BITMAP | ||
50 | lcd_setmargins(0,0); | ||
51 | lcd_setfont(0); | ||
52 | #endif | ||
53 | for (i = menus[m].top; | ||
54 | (i < menus[m].itemcount) && (i<menus[m].top+MENU_LINES); | ||
55 | i++) { | ||
56 | lcd_puts(1, i-menus[m].top, menus[m].items[i].desc); | ||
57 | } | ||
58 | |||
59 | lcd_puts(0, menus[m].cursor - menus[m].top, "-"); | ||
60 | lcd_update(); | ||
61 | } | ||
62 | |||
39 | /* | 63 | /* |
40 | * Move the cursor to a particular id, | 64 | * Move the cursor to a particular id, |
41 | * target: where you want it to be | 65 | * target: where you want it to be |
42 | */ | 66 | */ |
43 | static void put_cursor(int m, int target) | 67 | static void put_cursor(int m, int target) |
44 | { | 68 | { |
45 | lcd_puts(0, menus[m].cursor, " "); | 69 | lcd_puts(0, menus[m].cursor - menus[m].top, " "); |
70 | |||
71 | if ( target < menus[m].top ) { | ||
72 | menus[m].top--; | ||
73 | menu_draw(m); | ||
74 | } | ||
75 | else if ( target > MENU_LINES-1 ) { | ||
76 | menus[m].top++; | ||
77 | menu_draw(m); | ||
78 | } | ||
46 | menus[m].cursor = target; | 79 | menus[m].cursor = target; |
47 | lcd_puts(0, menus[m].cursor, "-"); | 80 | lcd_puts(0, menus[m].cursor - menus[m].top, "-"); |
48 | } | 81 | } |
49 | 82 | ||
50 | int menu_init(struct menu_items* mitems, int count) | 83 | int menu_init(struct menu_items* mitems, int count) |
@@ -63,8 +96,7 @@ int menu_init(struct menu_items* mitems, int count) | |||
63 | } | 96 | } |
64 | menus[i].items = mitems; | 97 | menus[i].items = mitems; |
65 | menus[i].itemcount = count; | 98 | menus[i].itemcount = count; |
66 | menus[i].menu_top = 0; | 99 | menus[i].top = 0; |
67 | menus[i].menu_bottom = count-1; | ||
68 | menus[i].cursor = 0; | 100 | menus[i].cursor = 0; |
69 | 101 | ||
70 | return i; | 102 | return i; |
@@ -75,31 +107,8 @@ void menu_exit(int m) | |||
75 | inuse[m] = false; | 107 | inuse[m] = false; |
76 | } | 108 | } |
77 | 109 | ||
78 | static void menu_draw(int m) | ||
79 | { | ||
80 | int i = 0; | ||
81 | |||
82 | lcd_clear_display(); | ||
83 | #ifdef HAVE_LCD_BITMAP | ||
84 | lcd_setmargins(0,0); | ||
85 | lcd_setfont(0); | ||
86 | #endif | ||
87 | for (i = 0; i < menus[m].itemcount; i++) { | ||
88 | lcd_puts(1, i, menus[m].items[i].desc); | ||
89 | if (i < menus[m].menu_top) | ||
90 | menus[m].menu_top = i; | ||
91 | if (i > menus[m].menu_bottom) | ||
92 | menus[m].menu_bottom = i; | ||
93 | } | ||
94 | |||
95 | lcd_puts(0, menus[m].cursor, "-"); | ||
96 | lcd_update(); | ||
97 | } | ||
98 | |||
99 | void menu_run(int m) | 110 | void menu_run(int m) |
100 | { | 111 | { |
101 | int key; | ||
102 | |||
103 | menu_draw(m); | 112 | menu_draw(m); |
104 | 113 | ||
105 | while(1) { | 114 | while(1) { |
@@ -109,9 +118,9 @@ void menu_run(int m) | |||
109 | #else | 118 | #else |
110 | case BUTTON_LEFT: | 119 | case BUTTON_LEFT: |
111 | #endif | 120 | #endif |
112 | if (menus[m].cursor == menus[m].menu_top) { | 121 | if (menus[m].cursor == 0) { |
113 | /* wrap around to menu bottom */ | 122 | /* wrap around to menu bottom */ |
114 | put_cursor(m, menus[m].menu_bottom); | 123 | put_cursor(m, menus[m].itemcount-1); |
115 | } else { | 124 | } else { |
116 | /* move up */ | 125 | /* move up */ |
117 | put_cursor(m, menus[m].cursor-1); | 126 | put_cursor(m, menus[m].cursor-1); |
@@ -123,9 +132,9 @@ void menu_run(int m) | |||
123 | #else | 132 | #else |
124 | case BUTTON_RIGHT: | 133 | case BUTTON_RIGHT: |
125 | #endif | 134 | #endif |
126 | if (menus[m].cursor == menus[m].menu_bottom) { | 135 | if (menus[m].cursor == menus[m].itemcount-1) { |
127 | /* wrap around to menu top */ | 136 | /* wrap around to menu top */ |
128 | put_cursor(m, menus[m].menu_top); | 137 | put_cursor(m, 0); |
129 | } else { | 138 | } else { |
130 | /* move down */ | 139 | /* move down */ |
131 | put_cursor(m, menus[m].cursor+1); | 140 | put_cursor(m, menus[m].cursor+1); |