1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 Robert E. Hak
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
21 - Multi screen support
22 - Rewrote/removed a lot of code now useless with the new gui API
30 #include "backlight.h"
44 #ifdef HAVE_LCD_BITMAP
50 #include "statusbar.h"
51 #include "buttonbar.h"
54 struct menu_item
* items
;
55 int (*callback
)(int, int);
57 struct gui_buttonbar buttonbar
;
59 struct gui_synclist synclist
;
64 static struct menu menus
[MAX_MENUS
];
65 static bool inuse
[MAX_MENUS
] = { false };
67 char * menu_get_itemname(int selected_item
, void * data
, char *buffer
)
69 struct menu
*local_menus
=(struct menu
*)data
;
71 return(P2STR(local_menus
->items
[selected_item
].desc
));
74 int menu_find_free(void)
77 /* Tries to find an unused slot to put the new menu */
78 for ( i
=0; i
<MAX_MENUS
; i
++ ) {
84 if ( i
== MAX_MENUS
) {
85 DEBUGF("Out of menus!\n");
91 int menu_init(const struct menu_item
* mitems
, int count
, int (*callback
)(int, int),
92 const char *button1
, const char *button2
, const char *button3
)
94 int menu
=menu_find_free();
95 if(menu
==-1)/* Out of menus */
97 menus
[menu
].items
= (struct menu_item
*)mitems
; /* de-const */
98 gui_synclist_init(&(menus
[menu
].synclist
),
99 &menu_get_itemname
, &menus
[menu
]);
100 gui_synclist_set_icon_callback(&(menus
[menu
].synclist
), NULL
);
101 gui_synclist_set_nb_items(&(menus
[menu
].synclist
), count
);
102 menus
[menu
].callback
= callback
;
104 gui_buttonbar_init(&(menus
[menu
].buttonbar
));
105 gui_buttonbar_set_display(&(menus
[menu
].buttonbar
), &(screens
[SCREEN_MAIN
]) );
106 gui_buttonbar_set(&(menus
[menu
].buttonbar
), button1
, button2
, button3
);
115 void menu_exit(int m
)
123 gui_buttonbar_draw(&(menus
[m
].buttonbar
));
128 gui_synclist_draw(&(menus
[m
].synclist
));
129 gui_syncstatusbar_draw(&statusbars
, true);
130 menu_talk_selected(m
);
132 key
= button_get_w_tmo(HZ
/2);
134 * "short-circuit" the default keypresses by running the
136 * The callback may return a new key value, often this will be
137 * BUTTON_NONE or the same key value, but it's perfectly legal
138 * to "simulate" key presses by returning another value.
140 if( menus
[m
].callback
!= NULL
)
141 key
= menus
[m
].callback(key
, m
);
142 /* If moved, "say" the entry under the cursor */
143 if(gui_synclist_do_button(&(menus
[m
].synclist
), key
))
144 menu_talk_selected(m
);
153 #ifdef MENU_RC_ENTER2
156 return gui_synclist_get_sel_pos(&(menus
[m
].synclist
));
163 #ifdef MENU_EXIT_MENU
169 #ifdef MENU_RC_EXIT_MENU
170 case MENU_RC_EXIT_MENU
:
176 if(default_event_handler(key
) == SYS_USB_CONNECTED
)
177 return MENU_ATTACHED_USB
;
180 gui_syncstatusbar_draw(&statusbars
, false);
182 return MENU_SELECTED_EXIT
;
190 switch (selected
=menu_show(m
))
192 case MENU_SELECTED_EXIT
:
195 case MENU_ATTACHED_USB
:
200 if (menus
[m
].items
[selected
].function
&&
201 menus
[m
].items
[selected
].function())
203 gui_syncstatusbar_draw(&statusbars
, true);
211 * Property function - return the current cursor for "menu"
214 int menu_cursor(int menu
)
216 return gui_synclist_get_sel_pos(&(menus
[menu
].synclist
));
220 * Property function - return the "menu" description at "position"
223 char* menu_description(int menu
, int position
)
225 return P2STR(menus
[menu
].items
[position
].desc
);
229 * Delete the element "position" from the menu items in "menu"
232 void menu_delete(int menu
, int position
)
235 int nb_items
=gui_synclist_get_nb_items(&(menus
[menu
].synclist
));
236 /* copy the menu item from the one below */
237 for( i
= position
; i
< nb_items
- 1; i
++)
238 menus
[menu
].items
[i
] = menus
[menu
].items
[i
+ 1];
240 gui_synclist_del_item(&(menus
[menu
].synclist
));
243 void menu_insert(int menu
, int position
, char *desc
, bool (*function
) (void))
246 int nb_items
=gui_synclist_get_nb_items(&(menus
[menu
].synclist
));
250 /* Move the items below one position forward */
251 for( i
= nb_items
; i
> position
; i
--)
252 menus
[menu
].items
[i
] = menus
[menu
].items
[i
- 1];
254 /* Update the current item */
255 menus
[menu
].items
[position
].desc
= (unsigned char *)desc
;
256 menus
[menu
].items
[position
].function
= function
;
257 gui_synclist_add_item(&(menus
[menu
].synclist
));
261 * Property function - return the "count" of menu items in "menu"
264 int menu_count(int menu
)
266 return gui_synclist_get_nb_items(&(menus
[menu
].synclist
));
270 * Allows a menu item at the current cursor position in "menu"
271 * to be moved up the list
274 bool menu_moveup(int menu
)
276 struct menu_item swap
;
277 int selected
=menu_cursor(menu
);
278 /* can't be the first item ! */
282 /* use a temporary variable to do the swap */
283 swap
= menus
[menu
].items
[selected
- 1];
284 menus
[menu
].items
[selected
- 1] = menus
[menu
].items
[selected
];
285 menus
[menu
].items
[selected
] = swap
;
287 gui_synclist_select_previous(&(menus
[menu
].synclist
));
292 * Allows a menu item at the current cursor position in "menu" to be moved down the list
295 bool menu_movedown(int menu
)
297 struct menu_item swap
;
298 int selected
=menu_cursor(menu
);
299 int nb_items
=gui_synclist_get_nb_items(&(menus
[menu
].synclist
));
301 /* can't be the last item ! */
302 if( selected
== nb_items
- 1)
305 /* use a temporary variable to do the swap */
306 swap
= menus
[menu
].items
[selected
+ 1];
307 menus
[menu
].items
[selected
+ 1] = menus
[menu
].items
[selected
];
308 menus
[menu
].items
[selected
] = swap
;
310 gui_synclist_select_next(&(menus
[menu
].synclist
));
315 * Allows to set the cursor position. Doesn't redraw by itself.
318 void menu_set_cursor(int menu
, int position
)
320 gui_synclist_select_item(&(menus
[menu
].synclist
), position
);
323 void menu_talk_selected(int m
)
325 if(global_settings
.talk_menu
)
327 int selected
=gui_synclist_get_sel_pos(&(menus
[m
].synclist
));
328 int voice_id
= P2ID(menus
[m
].items
[selected
].desc
);
329 if (voice_id
>= 0) /* valid ID given? */
330 talk_id(voice_id
, false); /* say it */
334 void menu_draw(int m
)
336 gui_synclist_draw(&(menus
[m
].synclist
));
339 /* count in letter positions, NOT pixels */
340 void put_cursorxy(int x
, int y
, bool on
)
342 #ifdef HAVE_LCD_BITMAP
346 /* check here instead of at every call (ugly, but cheap) */
347 if (global_settings
.invert_cursor
)
350 lcd_getstringsize((unsigned char *)"A", &fw
, &fh
);
352 ypos
= y
*fh
+ lcd_getymargin();
354 ypos
+= (fh
- 8) / 2;
357 /* place the cursor */
359 #ifdef HAVE_LCD_BITMAP
360 lcd_mono_bitmap(bitmap_icons_6x8
[Icon_Cursor
], xpos
, ypos
, 4, 8);
362 lcd_putc(x
, y
, CURSOR_CHAR
);
366 #if defined(HAVE_LCD_BITMAP)
367 /* I use xy here since it needs to disregard the margins */
368 lcd_set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
369 lcd_fillrect (xpos
, ypos
, 4, 8);
370 lcd_set_drawmode(DRMODE_SOLID
);