2002-05-17 12:22:24 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 Robert E. Hak
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2002-05-26 17:03:17 +00:00
|
|
|
#include <stdbool.h>
|
2002-05-17 12:22:24 +00:00
|
|
|
#include "lcd.h"
|
|
|
|
#include "menu.h"
|
2002-05-21 14:25:45 +00:00
|
|
|
#include "button.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "debug.h"
|
2002-08-23 02:17:00 +00:00
|
|
|
#include "usb.h"
|
2002-08-11 09:17:47 +00:00
|
|
|
#include "panic.h"
|
2002-08-20 19:37:00 +00:00
|
|
|
#include "settings.h"
|
|
|
|
#include "status.h"
|
2002-08-30 13:49:32 +00:00
|
|
|
|
2002-06-14 08:47:44 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
#include "icons.h"
|
2002-08-30 13:49:32 +00:00
|
|
|
#include "widgets.h"
|
2002-06-14 08:47:44 +00:00
|
|
|
#endif
|
2002-08-30 13:49:32 +00:00
|
|
|
|
2002-08-11 09:17:47 +00:00
|
|
|
#ifdef LOADABLE_FONTS
|
|
|
|
#include "ajf.h"
|
|
|
|
#endif
|
2002-08-20 19:37:00 +00:00
|
|
|
|
2002-05-26 17:03:17 +00:00
|
|
|
struct menu {
|
2002-05-28 15:35:33 +00:00
|
|
|
int top;
|
2002-05-26 17:03:17 +00:00
|
|
|
int cursor;
|
|
|
|
struct menu_items* items;
|
|
|
|
int itemcount;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define MAX_MENUS 4
|
|
|
|
|
2002-05-28 15:35:33 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2002-08-30 13:49:32 +00:00
|
|
|
|
|
|
|
#define MARGIN_X (global_settings.scrollbar ? SCROLLBAR_WIDTH : 0) + CURSOR_WIDTH /* X pixel margin */
|
|
|
|
#define MARGIN_Y (global_settings.statusbar ? STATUSBAR_HEIGHT : 0) /* Y pixel margin */
|
|
|
|
|
|
|
|
#define LINE_X 0 /* X position the entry-list starts at */
|
2002-08-20 19:37:00 +00:00
|
|
|
#define LINE_Y (global_settings.statusbar ? 1 : 0) /* Y position the entry-list starts at */
|
|
|
|
#define LINE_HEIGTH 8 /* pixels for each text line */
|
2002-08-30 13:49:32 +00:00
|
|
|
|
2002-08-20 19:37:00 +00:00
|
|
|
#define MENU_LINES (LCD_HEIGHT / LINE_HEIGTH - LINE_Y)
|
2002-08-30 13:49:32 +00:00
|
|
|
|
|
|
|
#define CURSOR_X (global_settings.scrollbar ? 1 : 0)
|
|
|
|
#define CURSOR_Y 0 /* the cursor is not positioned in regard to
|
|
|
|
the margins, so this is the amount of lines
|
|
|
|
we add to the cursor Y position to position
|
|
|
|
it on a line */
|
|
|
|
#define CURSOR_WIDTH 4
|
|
|
|
|
|
|
|
#define SCROLLBAR_X 0
|
|
|
|
#define SCROLLBAR_Y lcd_getymargin()
|
|
|
|
#define SCROLLBAR_WIDTH 6
|
|
|
|
|
|
|
|
#else /* HAVE_LCD_BITMAP */
|
|
|
|
|
|
|
|
#define LINE_X 0 /* X position the entry-list starts at */
|
|
|
|
|
2002-05-28 15:35:33 +00:00
|
|
|
#define MENU_LINES 2
|
2002-08-30 13:49:32 +00:00
|
|
|
|
|
|
|
#define CURSOR_X 0
|
|
|
|
#define CURSOR_Y 0 /* not really used for players */
|
|
|
|
|
|
|
|
#endif /* HAVE_LCD_BITMAP */
|
2002-05-28 15:35:33 +00:00
|
|
|
|
2002-05-31 09:04:51 +00:00
|
|
|
#ifdef HAVE_NEW_CHARCELL_LCD
|
|
|
|
#define CURSOR_CHAR "\x7e"
|
|
|
|
#else
|
|
|
|
#define CURSOR_CHAR "\x89"
|
|
|
|
#endif
|
|
|
|
|
2002-05-26 17:03:17 +00:00
|
|
|
static struct menu menus[MAX_MENUS];
|
|
|
|
static bool inuse[MAX_MENUS] = { false };
|
2002-05-17 12:22:24 +00:00
|
|
|
|
2002-06-14 08:47:44 +00:00
|
|
|
/* count in letter posistions, NOT pixels */
|
|
|
|
void put_cursorxy(int x, int y, bool on)
|
|
|
|
{
|
2002-08-11 09:20:53 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2002-08-11 09:17:47 +00:00
|
|
|
#ifdef LOADABLE_FONTS
|
|
|
|
int fh;
|
|
|
|
unsigned char* font = lcd_getcurrentldfont();
|
|
|
|
fh = ajf_get_fontheight(font);
|
|
|
|
#else
|
|
|
|
int fh = 8;
|
2002-08-11 09:20:53 +00:00
|
|
|
#endif
|
2002-08-11 09:17:47 +00:00
|
|
|
#endif
|
|
|
|
|
2002-06-14 08:47:44 +00:00
|
|
|
/* place the cursor */
|
|
|
|
if(on) {
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
lcd_bitmap ( bitmap_icons_6x8[Cursor],
|
2002-08-20 19:37:00 +00:00
|
|
|
x*6, y*fh + lcd_getymargin(), 4, 8, true);
|
2002-06-15 11:39:36 +00:00
|
|
|
#elif defined(SIMULATOR)
|
2002-06-19 13:00:14 +00:00
|
|
|
/* player simulator */
|
2002-06-15 11:39:36 +00:00
|
|
|
unsigned char cursor[] = { 0x7f, 0x3e, 0x1c, 0x08 };
|
2002-08-09 09:13:00 +00:00
|
|
|
lcd_bitmap ( cursor, x*6, 12+y*16, 4, 8, true);
|
2002-06-14 08:47:44 +00:00
|
|
|
#else
|
|
|
|
lcd_puts(x, y, CURSOR_CHAR);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else {
|
2002-06-19 13:00:14 +00:00
|
|
|
#if defined(HAVE_LCD_BITMAP)
|
2002-06-14 08:47:44 +00:00
|
|
|
/* I use xy here since it needs to disregard the margins */
|
2002-08-20 19:37:00 +00:00
|
|
|
lcd_clearrect (x*6, y*fh + lcd_getymargin(), 4, 8);
|
2002-06-19 13:00:14 +00:00
|
|
|
#elif defined(SIMULATOR)
|
|
|
|
/* player simulator in action */
|
2002-08-09 09:13:00 +00:00
|
|
|
lcd_clearrect (x*6, 12+y*16, 4, 8);
|
2002-06-14 08:47:44 +00:00
|
|
|
#else
|
|
|
|
lcd_puts(x, y, " ");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-05-28 15:35:33 +00:00
|
|
|
static void menu_draw(int m)
|
|
|
|
{
|
|
|
|
int i = 0;
|
2002-08-11 09:17:47 +00:00
|
|
|
#ifdef LOADABLE_FONTS
|
|
|
|
int menu_lines;
|
|
|
|
int fh;
|
|
|
|
unsigned char* font = lcd_getcurrentldfont();
|
|
|
|
fh = ajf_get_fontheight(font);
|
2002-08-20 19:37:00 +00:00
|
|
|
if (global_settings.statusbar)
|
|
|
|
menu_lines = (LCD_HEIGHT - STATUSBAR_HEIGHT) / fh;
|
|
|
|
else
|
|
|
|
menu_lines = LCD_HEIGHT/fh;
|
2002-08-11 09:17:47 +00:00
|
|
|
#else
|
|
|
|
int menu_lines = MENU_LINES;
|
|
|
|
#endif
|
2002-05-28 15:35:33 +00:00
|
|
|
|
2002-08-22 21:45:22 +00:00
|
|
|
lcd_scroll_pause(); /* halt scroll first... */
|
|
|
|
lcd_clear_display(); /* ...then clean the screen */
|
2002-05-28 15:35:33 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2002-08-30 13:49:32 +00:00
|
|
|
lcd_setmargins(MARGIN_X,MARGIN_Y); /* leave room for cursor and icon */
|
2002-05-28 15:35:33 +00:00
|
|
|
lcd_setfont(0);
|
|
|
|
#endif
|
2002-08-20 19:37:00 +00:00
|
|
|
/* correct cursor pos if out of screen */
|
|
|
|
if (menus[m].cursor - menus[m].top >= menu_lines)
|
|
|
|
menus[m].top++;
|
|
|
|
|
2002-05-28 15:35:33 +00:00
|
|
|
for (i = menus[m].top;
|
2002-08-11 09:17:47 +00:00
|
|
|
(i < menus[m].itemcount) && (i<menus[m].top+menu_lines);
|
2002-05-28 15:35:33 +00:00
|
|
|
i++) {
|
2002-08-02 07:59:25 +00:00
|
|
|
if((menus[m].cursor - menus[m].top)==(i-menus[m].top))
|
2002-08-30 13:49:32 +00:00
|
|
|
lcd_puts_scroll(LINE_X, i-menus[m].top, menus[m].items[i].desc);
|
2002-08-02 07:59:25 +00:00
|
|
|
else
|
2002-08-30 13:49:32 +00:00
|
|
|
lcd_puts(LINE_X, i-menus[m].top, menus[m].items[i].desc);
|
2002-05-28 15:35:33 +00:00
|
|
|
}
|
2002-05-30 08:06:42 +00:00
|
|
|
|
2002-06-14 08:47:44 +00:00
|
|
|
/* place the cursor */
|
2002-08-30 13:49:32 +00:00
|
|
|
put_cursorxy(CURSOR_X, menus[m].cursor - menus[m].top, true);
|
2002-08-20 19:37:00 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2002-08-30 13:49:32 +00:00
|
|
|
if (global_settings.scrollbar)
|
|
|
|
scrollbar(SCROLLBAR_X, SCROLLBAR_Y, SCROLLBAR_WIDTH - 1,
|
|
|
|
LCD_HEIGHT - SCROLLBAR_Y, menus[m].itemcount, menus[m].top,
|
|
|
|
menus[m].top + menu_lines, VERTICAL);
|
2002-08-20 19:37:00 +00:00
|
|
|
#endif
|
2002-08-30 13:49:32 +00:00
|
|
|
status_draw();
|
2002-05-28 15:35:33 +00:00
|
|
|
lcd_update();
|
|
|
|
}
|
|
|
|
|
2002-05-21 14:25:45 +00:00
|
|
|
/*
|
|
|
|
* Move the cursor to a particular id,
|
|
|
|
* target: where you want it to be
|
|
|
|
*/
|
2002-05-26 17:03:17 +00:00
|
|
|
static void put_cursor(int m, int target)
|
2002-05-17 12:22:24 +00:00
|
|
|
{
|
2002-05-30 08:06:42 +00:00
|
|
|
bool do_update = true;
|
2002-08-11 09:17:47 +00:00
|
|
|
#ifdef LOADABLE_FONTS
|
|
|
|
int menu_lines;
|
|
|
|
int fh;
|
|
|
|
unsigned char* font = lcd_getcurrentldfont();
|
|
|
|
fh = ajf_get_fontheight(font);
|
2002-08-20 19:37:00 +00:00
|
|
|
if (global_settings.statusbar)
|
|
|
|
menu_lines = (LCD_HEIGHT-STATUSBAR_HEIGHT)/fh;
|
|
|
|
else
|
|
|
|
menu_lines = LCD_HEIGHT/fh;
|
2002-08-11 09:17:47 +00:00
|
|
|
#else
|
|
|
|
int menu_lines = MENU_LINES;
|
|
|
|
#endif
|
2002-08-30 13:49:32 +00:00
|
|
|
put_cursorxy(CURSOR_X, menus[m].cursor - menus[m].top, false);
|
2002-05-30 08:06:42 +00:00
|
|
|
menus[m].cursor = target;
|
2002-08-02 07:59:25 +00:00
|
|
|
menu_draw(m);
|
2002-05-28 15:35:33 +00:00
|
|
|
|
|
|
|
if ( target < menus[m].top ) {
|
|
|
|
menus[m].top--;
|
|
|
|
menu_draw(m);
|
2002-05-30 08:06:42 +00:00
|
|
|
do_update = false;
|
2002-05-28 15:35:33 +00:00
|
|
|
}
|
2002-08-11 09:17:47 +00:00
|
|
|
else if ( target-menus[m].top > menu_lines-1 ) {
|
2002-05-28 15:35:33 +00:00
|
|
|
menus[m].top++;
|
|
|
|
menu_draw(m);
|
2002-05-30 08:06:42 +00:00
|
|
|
do_update = false;
|
2002-05-28 15:35:33 +00:00
|
|
|
}
|
2002-05-30 08:06:42 +00:00
|
|
|
|
|
|
|
if (do_update) {
|
2002-08-30 13:49:32 +00:00
|
|
|
put_cursorxy(CURSOR_X, menus[m].cursor - menus[m].top, true);
|
2002-05-30 08:06:42 +00:00
|
|
|
lcd_update();
|
|
|
|
}
|
|
|
|
|
2002-05-17 12:22:24 +00:00
|
|
|
}
|
|
|
|
|
2002-05-26 17:03:17 +00:00
|
|
|
int menu_init(struct menu_items* mitems, int count)
|
2002-05-17 12:22:24 +00:00
|
|
|
{
|
2002-05-26 17:03:17 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for ( i=0; i<MAX_MENUS; i++ ) {
|
|
|
|
if ( !inuse[i] ) {
|
|
|
|
inuse[i] = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( i == MAX_MENUS ) {
|
|
|
|
DEBUGF("Out of menus!\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
menus[i].items = mitems;
|
|
|
|
menus[i].itemcount = count;
|
2002-05-28 15:35:33 +00:00
|
|
|
menus[i].top = 0;
|
2002-05-26 17:03:17 +00:00
|
|
|
menus[i].cursor = 0;
|
|
|
|
|
|
|
|
return i;
|
2002-05-17 12:22:24 +00:00
|
|
|
}
|
|
|
|
|
2002-05-26 17:03:17 +00:00
|
|
|
void menu_exit(int m)
|
2002-05-17 12:22:24 +00:00
|
|
|
{
|
2002-05-26 17:03:17 +00:00
|
|
|
inuse[m] = false;
|
2002-05-17 12:22:24 +00:00
|
|
|
}
|
|
|
|
|
2002-08-23 12:32:52 +00:00
|
|
|
Menu menu_run(int m)
|
2002-05-18 11:41:37 +00:00
|
|
|
{
|
2002-08-23 02:45:39 +00:00
|
|
|
#ifndef SIMULATOR
|
2002-08-23 02:26:22 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2002-08-23 02:17:00 +00:00
|
|
|
bool laststate;
|
2002-08-23 02:45:39 +00:00
|
|
|
#endif
|
2002-08-23 02:26:22 +00:00
|
|
|
#endif
|
2002-08-23 12:32:52 +00:00
|
|
|
Menu result = MENU_OK;
|
2002-08-23 02:17:00 +00:00
|
|
|
|
2002-05-26 17:03:17 +00:00
|
|
|
menu_draw(m);
|
2002-08-23 02:17:00 +00:00
|
|
|
|
2002-05-21 14:25:45 +00:00
|
|
|
while(1) {
|
2002-08-20 19:37:00 +00:00
|
|
|
switch( button_get_w_tmo(HZ/2) ) {
|
2002-05-21 14:25:45 +00:00
|
|
|
#ifdef HAVE_RECORDER_KEYPAD
|
|
|
|
case BUTTON_UP:
|
2002-08-10 09:04:55 +00:00
|
|
|
case BUTTON_UP | BUTTON_REPEAT:
|
2002-05-21 14:25:45 +00:00
|
|
|
#else
|
|
|
|
case BUTTON_LEFT:
|
2002-08-02 07:59:25 +00:00
|
|
|
case BUTTON_LEFT | BUTTON_REPEAT:
|
2002-05-21 14:25:45 +00:00
|
|
|
#endif
|
2002-05-29 14:25:06 +00:00
|
|
|
if (menus[m].cursor) {
|
2002-05-21 14:25:45 +00:00
|
|
|
/* move up */
|
2002-05-26 17:03:17 +00:00
|
|
|
put_cursor(m, menus[m].cursor-1);
|
2002-05-21 14:25:45 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef HAVE_RECORDER_KEYPAD
|
|
|
|
case BUTTON_DOWN:
|
2002-08-10 09:04:55 +00:00
|
|
|
case BUTTON_DOWN | BUTTON_REPEAT:
|
2002-05-18 11:41:37 +00:00
|
|
|
#else
|
2002-05-21 14:25:45 +00:00
|
|
|
case BUTTON_RIGHT:
|
2002-08-02 07:59:25 +00:00
|
|
|
case BUTTON_RIGHT | BUTTON_REPEAT:
|
2002-05-18 11:41:37 +00:00
|
|
|
#endif
|
2002-05-29 14:25:06 +00:00
|
|
|
if (menus[m].cursor < menus[m].itemcount-1) {
|
2002-05-21 14:25:45 +00:00
|
|
|
/* move down */
|
2002-05-26 17:03:17 +00:00
|
|
|
put_cursor(m, menus[m].cursor+1);
|
2002-05-21 14:25:45 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef HAVE_RECORDER_KEYPAD
|
|
|
|
case BUTTON_RIGHT:
|
|
|
|
#endif
|
|
|
|
case BUTTON_PLAY:
|
|
|
|
/* Erase current display state */
|
2002-08-22 21:45:22 +00:00
|
|
|
lcd_scroll_pause(); /* pause is better than stop when
|
|
|
|
are gonna clear the screen anyway */
|
2002-05-21 14:25:45 +00:00
|
|
|
lcd_clear_display();
|
|
|
|
|
2002-08-23 12:57:00 +00:00
|
|
|
/* if a child returns that the contents is changed, we
|
|
|
|
must remember this, even if we perhaps invoke other
|
|
|
|
children too before returning back */
|
|
|
|
if(MENU_DISK_CHANGED ==
|
|
|
|
menus[m].items[menus[m].cursor].function())
|
|
|
|
result = MENU_DISK_CHANGED;
|
2002-05-21 14:25:45 +00:00
|
|
|
|
|
|
|
/* Return to previous display state */
|
2002-05-26 17:03:17 +00:00
|
|
|
menu_draw(m);
|
2002-05-21 14:25:45 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef HAVE_RECORDER_KEYPAD
|
|
|
|
case BUTTON_LEFT:
|
2002-07-27 19:53:26 +00:00
|
|
|
case BUTTON_F1:
|
2002-05-21 14:25:45 +00:00
|
|
|
#else
|
|
|
|
case BUTTON_STOP:
|
2002-05-29 12:28:08 +00:00
|
|
|
case BUTTON_MENU:
|
2002-05-21 14:25:45 +00:00
|
|
|
#endif
|
2002-08-02 07:59:25 +00:00
|
|
|
lcd_stop_scroll();
|
2002-08-23 12:32:52 +00:00
|
|
|
return result;
|
2002-05-21 08:47:34 +00:00
|
|
|
|
2002-08-20 19:37:00 +00:00
|
|
|
#ifdef HAVE_RECORDER_KEYPAD
|
2002-08-30 13:49:32 +00:00
|
|
|
case BUTTON_F3: {
|
2002-08-20 19:37:00 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2002-08-30 13:49:32 +00:00
|
|
|
unsigned char state;
|
|
|
|
state = global_settings.statusbar << 1 | global_settings.scrollbar;
|
|
|
|
state = (state + 1) % 4;
|
|
|
|
global_settings.statusbar = state >> 1;
|
|
|
|
global_settings.scrollbar = state & 0x1;
|
|
|
|
settings_save();
|
|
|
|
|
|
|
|
menu_draw(m);
|
2002-08-20 19:37:00 +00:00
|
|
|
#endif
|
2002-08-30 13:49:32 +00:00
|
|
|
}
|
2002-08-20 19:37:00 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2002-08-23 02:17:00 +00:00
|
|
|
#ifndef SIMULATOR
|
|
|
|
case SYS_USB_CONNECTED:
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
laststate = statusbar(false);
|
|
|
|
#endif
|
|
|
|
usb_acknowledge(SYS_USB_CONNECTED_ACK);
|
|
|
|
usb_wait_for_disconnect(&button_queue);
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
statusbar(laststate);
|
|
|
|
#else
|
|
|
|
lcd_icon(ICON_PARAM, true);
|
|
|
|
#endif
|
2002-08-23 12:57:00 +00:00
|
|
|
menu_draw(m);
|
2002-08-23 12:41:25 +00:00
|
|
|
result = MENU_DISK_CHANGED;
|
2002-08-23 02:17:00 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2002-05-21 14:25:45 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-08-20 19:37:00 +00:00
|
|
|
status_draw();
|
2002-05-21 14:25:45 +00:00
|
|
|
lcd_update();
|
|
|
|
}
|
2002-08-23 12:32:52 +00:00
|
|
|
|
|
|
|
return result;
|
2002-05-18 11:41:37 +00:00
|
|
|
}
|