diff options
| author | Kevin Ferrare <kevin@rockbox.org> | 2005-11-04 07:18:36 +0000 |
|---|---|---|
| committer | Kevin Ferrare <kevin@rockbox.org> | 2005-11-04 07:18:36 +0000 |
| commit | cbbdc95d9ccb5dc678daa9e22aeed81dfe72ef8e (patch) | |
| tree | e7ce1fc3e7b7e0a935470d76e934599000886afd /apps/gui | |
| parent | 12a4ba0d76cff7976055819965ae1a8e92a502bd (diff) | |
| download | rockbox-cbbdc95d9ccb5dc678daa9e22aeed81dfe72ef8e.zip rockbox-cbbdc95d9ccb5dc678daa9e22aeed81dfe72ef8e.tar.gz rockbox-cbbdc95d9ccb5dc678daa9e22aeed81dfe72ef8e.tar.bz2 rockbox-cbbdc95d9ccb5dc678daa9e22aeed81dfe72ef8e.tar.xz | |
Fixed a bug in the multi-screen menus, the statusbar wasn't refreshed when coming from some custom wps that erases it ; Initial support for options in the menus
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7747 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/gui')
| -rw-r--r-- | apps/gui/select.c | 143 | ||||
| -rw-r--r-- | apps/gui/select.h | 130 |
2 files changed, 273 insertions, 0 deletions
diff --git a/apps/gui/select.c b/apps/gui/select.c new file mode 100644 index 0000000..88ebfb4 --- /dev/null +++ b/apps/gui/select.c @@ -0,0 +1,143 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2005 by Kevin Ferrare + * + * 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 "select.h" + +#include "lang.h" +#include "textarea.h" +#include "sprintf.h" +#include "kernel.h" +#include "screen_access.h" + +void gui_select_init_numeric(struct gui_select * select, + const char * title, + int init_value, + int min_value, + int max_value, + int step, + const char * unit, + void (*formatter)(char* dest, + int dest_length, + int variable, + const char* unit) + ) +{ + select->canceled=false; + select->validated=false; + select->title=title; + select->min_value=min_value; + select->max_value=max_value; + select->option=init_value; + select->step=step; + select->extra_string=unit; + select->formatter=formatter; + select->items=NULL; +} + +void gui_select_init_items(struct gui_select * select, + const char * title, + int selected, + const struct opt_items * items, + int nb_items) +{ + select->canceled=false; + select->validated=false; + select->title=title; + select->min_value=0; + select->max_value=nb_items; + select->option=selected; + select->step=1; + select->formatter=NULL; + select->items=items; +} +//FIXME: si step>1, mettre d'abord au plus grand, ensuite passerau plus petit +void gui_select_next(struct gui_select * select) +{ + select->option+=select->step; + if(select->option >= select->max_value) + select->option=select->min_value; +} + +void gui_select_prev(struct gui_select * select) +{ + select->option-=select->step; + if(select->option < select->min_value) + select->option=select->max_value-1; +} + +void gui_select_draw(struct gui_select * select, struct screen * display) +{ + screen_set_xmargin(display, 0); + gui_textarea_clear(display); + display->puts_scroll(0, 0, select->title); + + if(gui_select_is_canceled(select)) + display->puts_scroll(0, 0, str(LANG_MENU_SETTING_CANCEL)); + if(select->items) + display->puts_scroll(0, 1, P2STR(select->items[select->option].string)); + else + { + char buffer[30]; + if(!select->formatter) + snprintf(buffer, sizeof buffer,"%d %s", select->option, select->extra_string); + else + select->formatter(buffer, sizeof buffer, select->option, select->extra_string); + display->puts_scroll(0, 1, buffer); + } + gui_textarea_update(display); +} + +void gui_syncselect_draw(struct gui_select * select) +{ + int i; + for(i=0;i<NB_SCREENS;i++) + gui_select_draw(select, &(screens[i])); +} + +bool gui_syncselect_do_button(struct gui_select * select, int button) +{ + bool moved=false; + switch(button) + { + case SELECT_INC : + case SELECT_INC | BUTTON_REPEAT : + gui_select_next(select); + moved=true; + break; + case SELECT_DEC : + case SELECT_DEC | BUTTON_REPEAT : + gui_select_prev(select); + moved=true; + break; + case SELECT_OK : +#ifdef SELECT_OK2 + case SELECT_OK2 : +#endif + gui_select_validate(select); + break; + case SELECT_CANCEL : + case SELECT_CANCEL2 : + gui_select_cancel(select); + gui_syncselect_draw(select); + sleep(HZ/2); + break; + } + return(moved); +} + diff --git a/apps/gui/select.h b/apps/gui/select.h new file mode 100644 index 0000000..f222964 --- /dev/null +++ b/apps/gui/select.h @@ -0,0 +1,130 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2005 by Kevin Ferrare + * + * 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. + * + ****************************************************************************/ + + +#ifndef _GUI_SELECT_H_ +#define _GUI_SELECT_H_ +#include "screen_access.h" +#include "settings.h" + +#if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \ + (CONFIG_KEYPAD == IRIVER_H300_PAD) +#define SELECT_INC BUTTON_UP +#define SELECT_DEC BUTTON_DOWN +#define SELECT_OK BUTTON_SELECT +#define SELECT_OK2 BUTTON_LEFT +#define SELECT_CANCEL BUTTON_OFF +#define SELECT_CANCEL2 BUTTON_MODE + +#elif CONFIG_KEYPAD == RECORDER_PAD +#define SELECT_INC BUTTON_UP +#define SELECT_DEC BUTTON_DOWN +#define SELECT_OK BUTTON_PLAY +#define SELECT_OK2 BUTTON_LEFT +#define SELECT_CANCEL BUTTON_OFF +#define SELECT_CANCEL2 BUTTON_F1 + +#elif CONFIG_KEYPAD == PLAYER_PAD +#define SELECT_INC BUTTON_RIGHT +#define SELECT_DEC BUTTON_LEFT +#define SELECT_OK BUTTON_PLAY +#define SELECT_CANCEL BUTTON_STOP +#define SELECT_CANCEL2 BUTTON_MENU + +#elif CONFIG_KEYPAD == ONDIO_PAD +#define SELECT_INC BUTTON_UP +#define SELECT_DEC BUTTON_DOWN +#define SELECT_OK BUTTON_RIGHT +#define SELECT_OK2 BUTTON_LEFT +#define SELECT_CANCEL BUTTON_MENU +#define SELECT_CANCEL2 BUTTON_OFF + +#elif CONFIG_KEYPAD == GMINI100_PAD +#define SELECT_INC BUTTON_UP +#define SELECT_DEC BUTTON_DOWN +#define SELECT_OK BUTTON_PLAY +#define SELECT_OK2 BUTTON_LEFT +#define SELECT_CANCEL BUTTON_OFF +#define SELECT_CANCEL2 BUTTON_MENU + +#endif + +struct gui_select +{ + bool canceled; + bool validated; + const char * title; + int min_value; + int max_value; + int step; + int option; + const char * extra_string; + /* In the case the option is a number */ + void (*formatter)(char* dest, + int dest_length, + int variable, + const char* unit); + const struct opt_items * items; +}; + +extern void gui_select_init_numeric(struct gui_select * select, + const char * title, + int init_value, + int min_value, + int max_value, + int step, + const char * unit, + void (*formatter)(char* dest, + int dest_length, + int variable, + const char* unit)); + +extern void gui_select_init_items(struct gui_select * select, + const char * title, + int selected, + const struct opt_items * items, + int nb_items + ); + +extern void gui_select_next(struct gui_select * select); + +extern void gui_select_prev(struct gui_select * select); + +extern void gui_select_draw(struct gui_select * select, struct screen * display); + +#define gui_select_get_selected(select) \ + (select)->option + +#define gui_select_cancel(select) \ + (select)->canceled=true + +#define gui_select_is_canceled(select) \ + (select)->canceled + +#define gui_select_validate(select) \ + (select)->validated=true + +#define gui_select_is_validated(select) \ + (select)->validated + +extern void gui_syncselect_draw(struct gui_select * select); + +extern bool gui_syncselect_do_button(struct gui_select * select, int button); + +#endif /* _GUI_SELECT_H_ */ |