summaryrefslogtreecommitdiff
path: root/apps/menu.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/menu.c')
-rw-r--r--apps/menu.c122
1 files changed, 105 insertions, 17 deletions
diff --git a/apps/menu.c b/apps/menu.c
index 0bd21b9108..f187b5d82b 100644
--- a/apps/menu.c
+++ b/apps/menu.c
@@ -17,6 +17,7 @@
17 * 17 *
18 ****************************************************************************/ 18 ****************************************************************************/
19#include <stdbool.h> 19#include <stdbool.h>
20#include <stdlib.h>
20 21
21#include "hwcompat.h" 22#include "hwcompat.h"
22#include "lcd.h" 23#include "lcd.h"
@@ -42,6 +43,7 @@ struct menu {
42 int cursor; 43 int cursor;
43 struct menu_items* items; 44 struct menu_items* items;
44 int itemcount; 45 int itemcount;
46 int (*callback)(int, int);
45}; 47};
46 48
47#define MAX_MENUS 5 49#define MAX_MENUS 5
@@ -123,7 +125,7 @@ void put_cursorxy(int x, int y, bool on)
123 } 125 }
124} 126}
125 127
126static void menu_draw(int m) 128void menu_draw(int m)
127{ 129{
128 int i = 0; 130 int i = 0;
129#ifdef HAVE_LCD_BITMAP 131#ifdef HAVE_LCD_BITMAP
@@ -216,7 +218,7 @@ static void put_cursor(int m, int target)
216 218
217} 219}
218 220
219int menu_init(struct menu_items* mitems, int count) 221int menu_init(struct menu_items* mitems, int count, int (*callback)(int, int))
220{ 222{
221 int i; 223 int i;
222 224
@@ -234,6 +236,7 @@ int menu_init(struct menu_items* mitems, int count)
234 menus[i].itemcount = count; 236 menus[i].itemcount = count;
235 menus[i].top = 0; 237 menus[i].top = 0;
236 menus[i].cursor = 0; 238 menus[i].cursor = 0;
239 menus[i].callback = callback;
237 240
238 return i; 241 return i;
239} 242}
@@ -246,6 +249,7 @@ void menu_exit(int m)
246int menu_show(int m) 249int menu_show(int m)
247{ 250{
248 bool exit = false; 251 bool exit = false;
252 int key;
249#ifdef HAVE_LCD_BITMAP 253#ifdef HAVE_LCD_BITMAP
250 int fw, fh; 254 int fw, fh;
251 int menu_lines; 255 int menu_lines;
@@ -260,7 +264,16 @@ int menu_show(int m)
260 menu_draw(m); 264 menu_draw(m);
261 265
262 while (!exit) { 266 while (!exit) {
263 switch( button_get_w_tmo(HZ/2) ) { 267 key = button_get_w_tmo(HZ/2);
268
269 /*
270 * "short-circuit" the default keypresses by running the callback function
271 */
272
273 if( menus[m].callback != NULL )
274 key = menus[m].callback(key, m); /* make sure there's no match in the switch */
275
276 switch( key ) {
264#ifdef HAVE_RECORDER_KEYPAD 277#ifdef HAVE_RECORDER_KEYPAD
265 case BUTTON_UP: 278 case BUTTON_UP:
266 case BUTTON_UP | BUTTON_REPEAT: 279 case BUTTON_UP | BUTTON_REPEAT:
@@ -326,20 +339,6 @@ int menu_show(int m)
326 exit = true; 339 exit = true;
327 break; 340 break;
328 341
329#ifdef HAVE_RECORDER_KEYPAD
330 case BUTTON_F2:
331 if (f2_screen())
332 return MENU_ATTACHED_USB;
333 menu_draw(m);
334 break;
335
336 case BUTTON_F3:
337 if (f3_screen())
338 return MENU_ATTACHED_USB;
339 menu_draw(m);
340 break;
341#endif
342
343 case SYS_USB_CONNECTED: 342 case SYS_USB_CONNECTED:
344 usb_screen(); 343 usb_screen();
345#ifdef HAVE_LCD_CHARCELLS 344#ifdef HAVE_LCD_CHARCELLS
@@ -369,3 +368,92 @@ bool menu_run(int m)
369 } 368 }
370 return false; 369 return false;
371} 370}
371
372/*
373 * Property function - return the current cursor for "menu"
374 */
375
376int menu_cursor(int menu)
377{
378 return menus[menu].cursor;
379}
380
381/*
382 * Property function - return the "menu" description at "position"
383 */
384
385char* menu_description(int menu, int position)
386{
387 return menus[menu].items[position].desc;
388}
389
390/*
391 * Delete the element "position" from the menu items in "menu"
392 */
393
394void menu_delete(int menu, int position)
395{
396 int i;
397
398 /* copy the menu item from the one below */
399 for( i = position; i < (menus[menu].itemcount - 1); i++)
400 menus[menu].items[i] = menus[menu].items[i + 1];
401
402 /* reduce the count */
403 menus[menu].itemcount--;
404
405 /* adjust if this was the last menu item and the cursor was on it */
406 if( menus[menu].itemcount <= menus[menu].cursor)
407 menus[menu].cursor = menus[menu].itemcount - 1;
408}
409
410/*
411 * Property function - return the "count" of menu items in "menu"
412 */
413
414int menu_count(int menu)
415{
416 return menus[menu].itemcount;
417}
418
419/*
420 * Allows a menu item at the current cursor position in "menu" to be moved up the list
421 */
422
423bool menu_moveup(int menu)
424{
425 struct menu_items swap;
426
427 /* can't be the first item ! */
428 if( menus[menu].cursor == 0)
429 return false;
430
431 /* use a temporary variable to do the swap */
432 swap = menus[menu].items[menus[menu].cursor - 1];
433 menus[menu].items[menus[menu].cursor - 1] = menus[menu].items[menus[menu].cursor];
434 menus[menu].items[menus[menu].cursor] = swap;
435 menus[menu].cursor--;
436
437 return true;
438}
439
440/*
441 * Allows a menu item at the current cursor position in "menu" to be moved down the list
442 */
443
444bool menu_movedown(int menu)
445{
446 struct menu_items swap;
447
448 /* can't be the last item ! */
449 if( menus[menu].cursor == menus[menu].itemcount - 1)
450 return false;
451
452 /* use a temporary variable to do the swap */
453 swap = menus[menu].items[menus[menu].cursor + 1];
454 menus[menu].items[menus[menu].cursor + 1] = menus[menu].items[menus[menu].cursor];
455 menus[menu].items[menus[menu].cursor] = swap;
456 menus[menu].cursor++;
457
458 return true;
459}