summaryrefslogtreecommitdiffstats
path: root/uisimulator/menu.c
blob: 1619b33676bc1f2c5040edca27dad811abec802c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/***************************************************************************
 *             __________               __   ___.
 *   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.
 *
 ****************************************************************************/

#include "types.h"
#include "lcd.h"
#include "menu.h"

#include "tree.h"

#ifdef HAVE_LCD_BITMAP

#include "screensaver.h"
extern void tetris(void);


#define MENU_ITEM_FONT    0
#define MENU_ITEM_Y_LOC   6
#define MENU_LINE_HEIGHT  8

enum Main_Menu_Ids {
    Tetris, Screen_Saver, Browse, Last_Id
};

struct main_menu_items items[] = {
    { Tetris,       "Tetris",       tetris      },
    { Screen_Saver, "Screen Saver", screensaver },
    { Browse,       "Browse",       browse_root },
};

/* Global values for menuing */
int menu_top;
int menu_bottom;
int menu_line_height;
int cursor;

int get_line_height(void)
{
    return menu_line_height;
}

int is_cursor_menu_top(void)
{
    return ((cursor == menu_top) ? 1 : 0);
}

int is_cursor_menu_bottom(void)
{
    return ((cursor == menu_bottom) ? 1 : 0);
}

void put_cursor_menu_top(void)
{
    put_cursor(menu_top);
}

void put_cursor_menu_bottom(void)
{
    put_cursor(menu_bottom);
}

void move_cursor_up(void)
{
    put_cursor(cursor-1);
}

void move_cursor_down(void)
{
    put_cursor(cursor+1);
}

void redraw_cursor(void)
{
    lcd_putsxy(0, cursor*menu_line_height, "-", 0);
}

/* 
 * Move the cursor to a particular id, 
 *   current: where it is now 
 *   target: where you want it to be 
 */
void put_cursor(int target)
{
    lcd_putsxy(0, cursor*menu_line_height, " ",0);
    cursor = target;
    lcd_putsxy(0, cursor*menu_line_height, "-",0);
}

/* We call the function pointer related to the current cursor position */
void execute_menu_item(void)
{
    /* call the proper function for this line */
    items[cursor].function();
}

void add_menu_item(int location, char *string)
{
    lcd_putsxy(MENU_ITEM_Y_LOC, MENU_LINE_HEIGHT*location, string,
               MENU_ITEM_FONT);
    if (location < menu_top)
        menu_top = location;
    if (location > menu_bottom)
        menu_bottom = location;
}

void menu_init(void)
{
    int i = 0;

    menu_top = Tetris;
    menu_bottom = Last_Id-1;
    menu_line_height = MENU_LINE_HEIGHT;
    cursor = menu_top;

    for (i = i; i < Last_Id; i++)
        add_menu_item(items[i].menu_id, (char *) items[i].menu_desc);

    lcd_putsxy(8, 38, "Rockbox!",2);
    redraw_cursor();
}

#endif /* end HAVE_LCD_BITMAP */