summaryrefslogtreecommitdiff
path: root/apps/menu.c
blob: 5c8356c93af7b6279fc26fde3537e9ae4f618682 (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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/***************************************************************************
 *             __________               __   ___.
 *   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 "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 show_logo(void)
{
  unsigned char buffer[112 * 8];

  int failure;
  int width=0;
  int height=0;

  failure = read_bmp_file("/rockbox112.bmp", &width, &height, buffer);

  debugf("read_bmp_file() returned %d, width %d height %d\n",
         failure, width, height);

  if(!failure) {
    int i;
    int eline;
    for(i=0, eline=0; i< height; i+=8, eline++) {
      int x,y;
      
      /* the bitmap function doesn't work with full-height bitmaps
         so we "stripe" the logo output */

      lcd_bitmap(&buffer[eline*width], 0, 24+i, width,
                 (height-i)>8?8:height-i, false);
      
#if 0
      /* for screen output debugging */
      for(y=0; y<8 && (i+y < height); y++) {
        for(x=0; x < width; x++) {

          if(buffer[eline*width + x] & (1<<y)) {
            printf("*");
          }
          else
            printf(" ");
        }
        printf("\n");
      }
#endif
    }

    lcd_update();
  }

}

void menu_init(void)
{
    menu_top = Tetris;
    menu_bottom = Last_Id-1;
    menu_line_height = MENU_LINE_HEIGHT;
    cursor = menu_top;
}

void menu_draw(void)
{
    int i = 0;

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

    show_logo();
    redraw_cursor();
}

#endif /* end HAVE_LCD_BITMAP */