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"
45 #ifdef HAVE_LCD_BITMAP
51 #include "statusbar.h"
52 #include "buttonbar.h"
55 struct menu_item
* items
;
56 int (*callback
)(int, int);
58 struct gui_buttonbar buttonbar
;
60 struct gui_synclist synclist
;
65 static struct menu menus
[MAX_MENUS
];
66 static bool inuse
[MAX_MENUS
] = { false };
68 char * menu_get_itemname(int selected_item
, void * data
, char *buffer
)
70 struct menu
*local_menus
=(struct menu
*)data
;
72 return(P2STR(local_menus
->items
[selected_item
].desc
));
75 int menu_find_free(void)
78 /* Tries to find an unused slot to put the new menu */
79 for ( i
=0; i
<MAX_MENUS
; i
++ ) {
85 if ( i
== MAX_MENUS
) {
86 DEBUGF("Out of menus!\n");
92 int menu_init(const struct menu_item
* mitems
, int count
, int (*callback
)(int, int),
93 const char *button1
, const char *button2
, const char *button3
)
95 int menu
=menu_find_free();
96 if(menu
==-1)/* Out of menus */
98 menus
[menu
].items
= (struct menu_item
*)mitems
; /* de-const */
99 gui_synclist_init(&(menus
[menu
].synclist
),
100 &menu_get_itemname
, &menus
[menu
], false, 1);
101 gui_synclist_set_icon_callback(&(menus
[menu
].synclist
), NULL
);
102 gui_synclist_set_nb_items(&(menus
[menu
].synclist
), count
);
103 menus
[menu
].callback
= callback
;
105 gui_buttonbar_init(&(menus
[menu
].buttonbar
));
106 gui_buttonbar_set_display(&(menus
[menu
].buttonbar
), &(screens
[SCREEN_MAIN
]) );
107 gui_buttonbar_set(&(menus
[menu
].buttonbar
), button1
, button2
, button3
);
116 void menu_exit(int m
)
124 gui_buttonbar_draw(&(menus
[m
].buttonbar
));
129 gui_synclist_draw(&(menus
[m
].synclist
));
130 gui_syncstatusbar_draw(&statusbars
, true);
131 menu_talk_selected(m
);
133 key
= get_action(CONTEXT_MAINMENU
,HZ
/2);
135 * "short-circuit" the default keypresses by running the
137 * The callback may return a new key value, often this will be
138 * BUTTON_NONE or the same key value, but it's perfectly legal
139 * to "simulate" key presses by returning another value.
141 if( menus
[m
].callback
!= NULL
)
142 key
= menus
[m
].callback(key
, m
);
143 /* If moved, "say" the entry under the cursor */
144 if(gui_synclist_do_button(&(menus
[m
].synclist
), key
))
145 menu_talk_selected(m
);
148 action_signalscreenchange();
149 return gui_synclist_get_sel_pos(&(menus
[m
].synclist
));
152 case ACTION_STD_CANCEL
:
153 case ACTION_STD_MENU
:
158 if(default_event_handler(key
) == SYS_USB_CONNECTED
)
159 return MENU_ATTACHED_USB
;
162 gui_syncstatusbar_draw(&statusbars
, false);
164 action_signalscreenchange();
165 return MENU_SELECTED_EXIT
;
173 switch (selected
=menu_show(m
))
175 case MENU_SELECTED_EXIT
:
178 case MENU_ATTACHED_USB
:
183 if (menus
[m
].items
[selected
].function
&&
184 menus
[m
].items
[selected
].function())
186 gui_syncstatusbar_draw(&statusbars
, true);
194 * Property function - return the current cursor for "menu"
197 int menu_cursor(int menu
)
199 return gui_synclist_get_sel_pos(&(menus
[menu
].synclist
));
203 * Property function - return the "menu" description at "position"
206 char* menu_description(int menu
, int position
)
208 return P2STR(menus
[menu
].items
[position
].desc
);
212 * Delete the element "position" from the menu items in "menu"
215 void menu_delete(int menu
, int position
)
218 int nb_items
=gui_synclist_get_nb_items(&(menus
[menu
].synclist
));
219 /* copy the menu item from the one below */
220 for( i
= position
; i
< nb_items
- 1; i
++)
221 menus
[menu
].items
[i
] = menus
[menu
].items
[i
+ 1];
223 gui_synclist_del_item(&(menus
[menu
].synclist
));
226 void menu_insert(int menu
, int position
, char *desc
, bool (*function
) (void))
229 int nb_items
=gui_synclist_get_nb_items(&(menus
[menu
].synclist
));
233 /* Move the items below one position forward */
234 for( i
= nb_items
; i
> position
; i
--)
235 menus
[menu
].items
[i
] = menus
[menu
].items
[i
- 1];
237 /* Update the current item */
238 menus
[menu
].items
[position
].desc
= (unsigned char *)desc
;
239 menus
[menu
].items
[position
].function
= function
;
240 gui_synclist_add_item(&(menus
[menu
].synclist
));
244 * Property function - return the "count" of menu items in "menu"
247 int menu_count(int menu
)
249 return gui_synclist_get_nb_items(&(menus
[menu
].synclist
));
253 * Allows a menu item at the current cursor position in "menu"
254 * to be moved up the list
257 bool menu_moveup(int menu
)
259 struct menu_item swap
;
260 int selected
=menu_cursor(menu
);
261 /* can't be the first item ! */
265 /* use a temporary variable to do the swap */
266 swap
= menus
[menu
].items
[selected
- 1];
267 menus
[menu
].items
[selected
- 1] = menus
[menu
].items
[selected
];
268 menus
[menu
].items
[selected
] = swap
;
270 gui_synclist_select_previous(&(menus
[menu
].synclist
));
275 * Allows a menu item at the current cursor position in "menu" to be moved down the list
278 bool menu_movedown(int menu
)
280 struct menu_item swap
;
281 int selected
=menu_cursor(menu
);
282 int nb_items
=gui_synclist_get_nb_items(&(menus
[menu
].synclist
));
284 /* can't be the last item ! */
285 if( selected
== nb_items
- 1)
288 /* use a temporary variable to do the swap */
289 swap
= menus
[menu
].items
[selected
+ 1];
290 menus
[menu
].items
[selected
+ 1] = menus
[menu
].items
[selected
];
291 menus
[menu
].items
[selected
] = swap
;
293 gui_synclist_select_next(&(menus
[menu
].synclist
));
298 * Allows to set the cursor position. Doesn't redraw by itself.
301 void menu_set_cursor(int menu
, int position
)
303 gui_synclist_select_item(&(menus
[menu
].synclist
), position
);
306 void menu_talk_selected(int m
)
308 if(global_settings
.talk_menu
)
310 int selected
=gui_synclist_get_sel_pos(&(menus
[m
].synclist
));
311 int voice_id
= P2ID(menus
[m
].items
[selected
].desc
);
312 if (voice_id
>= 0) /* valid ID given? */
313 talk_id(voice_id
, false); /* say it */
317 void menu_draw(int m
)
319 gui_synclist_draw(&(menus
[m
].synclist
));
322 /* count in letter positions, NOT pixels */
323 void put_cursorxy(int x
, int y
, bool on
)
325 #ifdef HAVE_LCD_BITMAP
329 /* check here instead of at every call (ugly, but cheap) */
330 if (global_settings
.invert_cursor
)
333 lcd_getstringsize((unsigned char *)"A", &fw
, &fh
);
335 ypos
= y
*fh
+ lcd_getymargin();
337 ypos
+= (fh
- 8) / 2;
340 /* place the cursor */
342 #ifdef HAVE_LCD_BITMAP
343 lcd_mono_bitmap(bitmap_icons_6x8
[Icon_Cursor
], xpos
, ypos
, 4, 8);
345 lcd_putc(x
, y
, CURSOR_CHAR
);
349 #if defined(HAVE_LCD_BITMAP)
350 /* I use xy here since it needs to disregard the margins */
351 lcd_set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
352 lcd_fillrect (xpos
, ypos
, 4, 8);
353 lcd_set_drawmode(DRMODE_SOLID
);