summaryrefslogtreecommitdiff
path: root/apps/gui
diff options
context:
space:
mode:
authorKevin Ferrare <kevin@rockbox.org>2005-11-22 03:38:07 +0000
committerKevin Ferrare <kevin@rockbox.org>2005-11-22 03:38:07 +0000
commit74b6af93b1436dc61e8f10b3aff3c79face5faba (patch)
treef5d17c6b0adb9f6cc448a112b309a6dff7451a76 /apps/gui
parent8042640ce967014f10dbc0e3f382cd1876310b66 (diff)
downloadrockbox-74b6af93b1436dc61e8f10b3aff3c79face5faba.zip
rockbox-74b6af93b1436dc61e8f10b3aff3c79face5faba.tar.gz
rockbox-74b6af93b1436dc61e8f10b3aff3c79face5faba.tar.bz2
rockbox-74b6af93b1436dc61e8f10b3aff3c79face5faba.tar.xz
Added multi-screen support for quickscreen (mostly rewritten from scratch) and USB screen ; just looking at the hour makes me think it could be buggy
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8039 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/gui')
-rw-r--r--apps/gui/gwps-common.c2
-rw-r--r--apps/gui/gwps.c4
-rw-r--r--apps/gui/gwps.h1
-rw-r--r--apps/gui/option_select.c102
-rw-r--r--apps/gui/option_select.h119
-rw-r--r--apps/gui/quickscreen.c179
-rw-r--r--apps/gui/quickscreen.h114
-rw-r--r--apps/gui/select.c78
-rw-r--r--apps/gui/select.h33
-rw-r--r--apps/gui/statusbar.h5
10 files changed, 541 insertions, 96 deletions
diff --git a/apps/gui/gwps-common.c b/apps/gui/gwps-common.c
index 16f3a6f..4eee5f7 100644
--- a/apps/gui/gwps-common.c
+++ b/apps/gui/gwps-common.c
@@ -61,7 +61,7 @@ static void gui_wps_statusbar_draw(struct gui_wps *wps, bool force)
{
bool draw = global_settings.statusbar;
if(wps->data->wps_sb_tag
- && gui_wps->data->show_sb_on_wps)
+ && wps->data->show_sb_on_wps)
draw = true;
else if(wps->data->wps_sb_tag)
draw = false;
diff --git a/apps/gui/gwps.c b/apps/gui/gwps.c
index a937507..52340e6 100644
--- a/apps/gui/gwps.c
+++ b/apps/gui/gwps.c
@@ -509,7 +509,7 @@ long gui_wps_show(void)
#ifdef WPS_RC_QUICK
case WPS_RC_QUICK:
#endif
- if (quick_screen(CONTEXT_WPS, WPS_QUICK))
+ if (quick_screen_quick())
return SYS_USB_CONNECTED;
restore = true;
lastbutton = 0;
@@ -518,7 +518,7 @@ long gui_wps_show(void)
/* screen settings */
#ifdef BUTTON_F3
case BUTTON_F3:
- if (quick_screen(CONTEXT_WPS, BUTTON_F3))
+ if (quick_screen_f3())
return SYS_USB_CONNECTED;
restore = true;
break;
diff --git a/apps/gui/gwps.h b/apps/gui/gwps.h
index dfae7c3..66199bc 100644
--- a/apps/gui/gwps.h
+++ b/apps/gui/gwps.h
@@ -68,6 +68,7 @@
#define WPS_RC_BROWSE (BUTTON_RC_MENU | BUTTON_REL)
#define WPS_RC_BROWSE_PRE BUTTON_RC_MENU
#define WPS_RC_CONTEXT (BUTTON_RC_MENU | BUTTON_REPEAT)
+#define WPS_RC_QUICK (BUTTON_RC_MODE | BUTTON_REPEAT)
#elif CONFIG_KEYPAD == RECORDER_PAD
#define WPS_NEXT (BUTTON_RIGHT | BUTTON_REL)
diff --git a/apps/gui/option_select.c b/apps/gui/option_select.c
new file mode 100644
index 0000000..0e16961
--- /dev/null
+++ b/apps/gui/option_select.c
@@ -0,0 +1,102 @@
+/***************************************************************************
+ * __________ __ ___.
+ * 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 "option_select.h"
+#include "sprintf.h"
+#include "kernel.h"
+#include "lang.h"
+
+void option_select_init_numeric(struct option_select * opt,
+ const char * title,
+ int init_value,
+ int min_value,
+ int max_value,
+ int step,
+ const char * unit,
+ option_formatter *formatter)
+{
+ opt->title=title;
+ opt->min_value=min_value;
+ opt->max_value=max_value+1;
+ opt->option=init_value;
+ opt->step=step;
+ opt->extra_string=unit;
+ opt->formatter=formatter;
+ opt->items=NULL;
+ opt->limit_loop=false;
+}
+
+void option_select_init_items(struct option_select * opt,
+ const char * title,
+ int selected,
+ const struct opt_items * items,
+ int nb_items)
+{
+ opt->title=title;
+ opt->min_value=0;
+ opt->max_value=nb_items;
+ opt->option=selected;
+ opt->step=1;
+ opt->formatter=NULL;
+ opt->items=items;
+ opt->limit_loop=false;
+}
+
+void option_select_next(struct option_select * opt)
+{
+ if(opt->option + opt->step >= opt->max_value)
+ {
+ if(!opt->limit_loop)
+ {
+ if(opt->option==opt->max_value-1)
+ opt->option=opt->min_value;
+ else
+ opt->option=opt->max_value-1;
+ }
+ }
+ else
+ opt->option+=opt->step;
+}
+
+void option_select_prev(struct option_select * opt)
+{
+ if(opt->option - opt->step < opt->min_value)
+ {
+ if(!opt->limit_loop)
+ {
+ if(opt->option==opt->min_value)
+ opt->option=opt->max_value-1;
+ else
+ opt->option=opt->min_value;
+ }
+ }
+ else
+ opt->option-=opt->step;
+}
+
+const char * option_select_get_text(struct option_select * opt, char * buffer)
+{
+ if(opt->items)
+ return(P2STR(opt->items[opt->option].string));
+ if(!opt->formatter)
+ snprintf(buffer, sizeof buffer,"%d %s", opt->option, opt->extra_string);
+ else
+ opt->formatter(buffer, sizeof buffer, opt->option, opt->extra_string);
+ return(buffer);
+}
diff --git a/apps/gui/option_select.h b/apps/gui/option_select.h
new file mode 100644
index 0000000..c6a5e19
--- /dev/null
+++ b/apps/gui/option_select.h
@@ -0,0 +1,119 @@
+/***************************************************************************
+ * __________ __ ___.
+ * 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_OPTION_SELECT_H_
+#define _GUI_OPTION_SELECT_H_
+#include "settings.h"
+
+typedef void option_formatter(char* dest, int dest_length,
+ int variable, const char* unit);
+
+struct option_select
+{
+ 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 */
+ option_formatter *formatter;
+ const struct opt_items * items;
+ bool limit_loop;
+};
+
+/*
+ * Initializes an option containing a numeric values
+ * - title : the title of the option
+ * - init_value : the initial value the number will be
+ * - min_value, max_value : bounds to the value
+ * - step : the ammount you want to add / withdraw to the initial number
+ * each time a key is pressed
+ * - unit : the unit in which the value is (ex "s", "bytes", ...)
+ * - formatter : a callback function that generates a string
+ * from the number it gets
+ */
+extern void option_select_init_numeric(struct option_select * opt,
+ const char * title,
+ int init_value,
+ int min_value,
+ int max_value,
+ int step,
+ const char * unit,
+ option_formatter *formatter);
+
+/*
+ * Initializes an option containing a list of choices
+ * - title : the title of the option
+ * - selected : the initially selected item
+ * - items : the list of items, defined in settings.h
+ * - nb_items : the number of items in the 'items' list
+ */
+extern void option_select_init_items(struct option_select * opt,
+ const char * title,
+ int selected,
+ const struct opt_items * items,
+ int nb_items);
+
+/*
+ * Gets the selected option
+ * - opt : the option struct
+ * - buffer : a buffer to eventually format the option
+ * Returns the selected option
+ */
+extern const char * option_select_get_text(struct option_select * opt, char * buffer);
+
+/*
+ * Selects the next value
+ * - opt : the option struct
+ */
+extern void option_select_next(struct option_select * opt);
+
+/*
+ * Selects the previous value
+ * - opt : the option struct
+ */
+extern void option_select_prev(struct option_select * opt);
+
+/*
+ * Returns the selected number
+ * - opt : the option struct
+ */
+#define option_select_get_selected(_opt) \
+ (_opt)->option
+
+/*
+ * Returns the title
+ * - opt : the option struct
+ */
+#define option_select_get_title(_opt) \
+ (_opt)->title
+
+/*
+ * Tells the option selector wether it should stop when reaching the min/max value
+ * or should continue (by going to max/min)
+ * - opt : the option struct
+ * - scroll :
+ * - true : stops when reaching min/max
+ * - false : continues to go to max/min when reaching min/max
+ */
+#define option_select_limit_loop(_opt, loop) \
+ (_opt)->limit_loop=loop
+
+#endif /* _GUI_OPTION_SELECT_H_ */
diff --git a/apps/gui/quickscreen.c b/apps/gui/quickscreen.c
new file mode 100644
index 0000000..760c1bd
--- /dev/null
+++ b/apps/gui/quickscreen.c
@@ -0,0 +1,179 @@
+/***************************************************************************
+ * __________ __ ___.
+ * 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 "quickscreen.h"
+#ifdef HAS_QUICKSCREEN
+
+#include "icons.h"
+#include "textarea.h"
+#include "font.h"
+#include "kernel.h"
+#include "misc.h"
+#include "statusbar.h"
+
+void gui_quickscreen_init(struct gui_quickscreen * qs,
+ struct option_select *left_option,
+ struct option_select *bottom_option,
+ struct option_select *right_option,
+ char * left_right_title,
+ quickscreen_callback callback)
+{
+ qs->left_option=left_option;
+ qs->bottom_option=bottom_option;
+ qs->right_option=right_option;
+ qs->left_right_title=left_right_title;
+ qs->callback=callback;
+}
+
+void gui_quickscreen_draw(struct gui_quickscreen * qs, struct screen * display)
+{
+ int w,h;
+ char buffer[30];
+ const char * option;
+ const char * title;
+#ifdef HAS_BUTTONBAR
+ display->has_buttonbar=false;
+#endif
+ gui_textarea_clear(display);
+ display->getstringsize("M",&w,&h);
+ /* Displays the icons */
+ display->mono_bitmap(bitmap_icons_7x8[Icon_FastBackward],
+ display->width/2 - 16,
+ display->height/2 - 4, 7, 8);
+ display->mono_bitmap(bitmap_icons_7x8[Icon_DownArrow],
+ display->width/2 - 3,
+ display->height - h*3, 7, 8);
+ display->mono_bitmap(bitmap_icons_7x8[Icon_FastForward],
+ display->width/2 + 8,
+ display->height/2 - 4, 7, 8);
+ display->setfont(FONT_SYSFIXED);
+
+ /* Displays the left's text */
+ title=option_select_get_title(qs->left_option);
+ option=option_select_get_text(qs->left_option, buffer);
+ display->putsxy(0, display->height/2 - h*2, title);
+ display->putsxy(0, display->height/2 - h, qs->left_right_title);
+ display->putsxy(0, display->height/2, option);
+
+ /* Displays the bottom's text */
+ title=option_select_get_title(qs->bottom_option);
+ option=option_select_get_text(qs->bottom_option, buffer);
+ display->getstringsize(title, &w, &h);
+ display->putsxy((display->width-w)/2, display->height - h*2, title);
+ display->getstringsize(option, &w, &h);
+ display->putsxy((display->width-w)/2, display->height - h, option);
+
+ /* Displays the right's text */
+ title=option_select_get_title(qs->right_option);
+ option=option_select_get_text(qs->right_option, buffer);
+ display->getstringsize(title,&w,&h);
+ display->putsxy(display->width - w, display->height/2 - h*2, title);
+ display->getstringsize(qs->left_right_title,&w,&h);
+ display->putsxy(display->width - w, display->height/2 - h, qs->left_right_title);
+ display->getstringsize(option,&w,&h);
+ display->putsxy(display->width - w, display->height/2, option);
+
+ gui_textarea_update(display);
+ lcd_setfont(FONT_UI);
+}
+
+void gui_syncquickscreen_draw(struct gui_quickscreen * qs)
+{
+ int i;
+ FOR_NB_SCREENS(i)
+ gui_quickscreen_draw(qs, &screens[i]);
+}
+
+bool gui_quickscreen_do_button(struct gui_quickscreen * qs, int button)
+{
+ switch(button)
+ {
+ case QUICKSCREEN_LEFT :
+ case QUICKSCREEN_LEFT | BUTTON_REPEAT :
+#ifdef QUICKSCREEN_RC_LEFT
+ case QUICKSCREEN_RC_LEFT :
+ case QUICKSCREEN_RC_LEFT | BUTTON_REPEAT :
+#endif
+ option_select_next(qs->left_option);
+ return(true);
+
+ case QUICKSCREEN_BOTTOM :
+ case QUICKSCREEN_BOTTOM | BUTTON_REPEAT :
+#ifdef QUICKSCREEN_RC_BOTTOM
+ case QUICKSCREEN_RC_BOTTOM :
+ case QUICKSCREEN_RC_BOTTOM | BUTTON_REPEAT :
+#endif
+ option_select_next(qs->bottom_option);
+ return(true);
+
+ case QUICKSCREEN_RIGHT :
+ case QUICKSCREEN_RIGHT | BUTTON_REPEAT :
+#ifdef QUICKSCREEN_RC_RIGHT
+ case QUICKSCREEN_RC_RIGHT :
+ case QUICKSCREEN_RC_RIGHT | BUTTON_REPEAT :
+#endif
+ option_select_next(qs->right_option);
+ return(true);
+
+ case QUICKSCREEN_BOTTOM_INV :
+ case QUICKSCREEN_BOTTOM_INV | BUTTON_REPEAT :
+#ifdef QUICKSCREEN_RC_BOTTOM_INV
+ case QUICKSCREEN_RC_BOTTOM_INV :
+ case QUICKSCREEN_RC_BOTTOM_INV | BUTTON_REPEAT :
+#endif
+ option_select_prev(qs->bottom_option);
+ return(true);
+ }
+ return(false);
+}
+
+bool gui_syncquickscreen_run(struct gui_quickscreen * qs)
+{
+ int key;
+ gui_syncquickscreen_draw(qs);
+ while (true) {
+ key = button_get(true);
+ if(default_event_handler(key) == SYS_USB_CONNECTED)
+ return(true);
+ if(gui_quickscreen_do_button(qs, key))
+ {
+ if(qs->callback)
+ qs->callback(qs);
+ gui_syncquickscreen_draw(qs);
+ }
+ else if(key==QUICKSCREEN_QUIT
+#ifdef QUICKSCREEN_QUIT
+ || key==QUICKSCREEN_QUIT
+#endif
+#ifdef QUICKSCREEN_QUIT2
+ || key==QUICKSCREEN_QUIT2
+#endif
+#if QUICKSCREEN_RC_QUIT
+ || key==QUICKSCREEN_RC_QUIT
+#endif
+ )
+ {
+ return(false);
+ }
+ gui_syncstatusbar_draw(&statusbars, false);
+ }
+}
+
+#endif /* HAS_QUICKSCREEN */
+
diff --git a/apps/gui/quickscreen.h b/apps/gui/quickscreen.h
new file mode 100644
index 0000000..09a0390
--- /dev/null
+++ b/apps/gui/quickscreen.h
@@ -0,0 +1,114 @@
+/***************************************************************************
+ * __________ __ ___.
+ * 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 "button.h"
+#include "config.h"
+#if (CONFIG_KEYPAD == RECORDER_PAD) || (CONFIG_KEYPAD == IRIVER_H100_PAD) ||\
+ (CONFIG_KEYPAD == IRIVER_H300_PAD)
+
+#ifndef _GUI_QUICKSCREEN_H_
+#define _GUI_QUICKSCREEN_H_
+
+#define HAS_QUICKSCREEN
+
+#include "option_select.h"
+#include "screen_access.h"
+
+#define QUICKSCREEN_LEFT BUTTON_LEFT
+#define QUICKSCREEN_BOTTOM BUTTON_DOWN
+#define QUICKSCREEN_BOTTOM_INV BUTTON_UP
+#define QUICKSCREEN_RIGHT BUTTON_RIGHT
+
+#if CONFIG_KEYPAD == RECORDER_PAD
+#define QUICKSCREEN_QUIT BUTTON_F2
+#define QUICKSCREEN_QUIT2 BUTTON_F3
+#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
+#define QUICKSCREEN_QUIT BUTTON_MODE
+#define QUICKSCREEN_QUIT2 BUTTON_OFF
+#define QUICKSCREEN_RC_QUIT BUTTON_RC_MODE
+#ifdef CONFIG_REMOTE_KEYPAD
+#define QUICKSCREEN_RC_LEFT BUTTON_RC_REW
+#define QUICKSCREEN_RC_BOTTOM BUTTON_RC_VOL_DOWN
+#define QUICKSCREEN_RC_BOTTOM_INV BUTTON_RC_VOL_UP
+#define QUICKSCREEN_RC_RIGHT BUTTON_RC_FF
+#endif
+
+#endif
+
+struct gui_quickscreen;
+/*
+ * Callback function called each time the quickscreen gets modified
+ * - qs : the quickscreen that did the modification
+ */
+typedef void (quickscreen_callback)(struct gui_quickscreen * qs);
+
+struct gui_quickscreen
+{
+ struct option_select *left_option;
+ struct option_select *bottom_option;
+ struct option_select *right_option;
+ char * left_right_title;
+ quickscreen_callback *callback;
+};
+
+/*
+ * Initializes a quickscreen
+ * - qs : the quickscreen
+ * - left_option, bottom_option, right_option : a list of choices
+ * for each option
+ * - left_right_title : the 2nd line of the title
+ * on the left and on the right
+ * - callback : a callback function called each time the quickscreen
+ * gets modified
+ */
+void gui_quickscreen_init(struct gui_quickscreen * qs,
+ struct option_select *left_option,
+ struct option_select *bottom_option,
+ struct option_select *right_option,
+ char * left_right_title,
+ quickscreen_callback *callback);
+/*
+ * Draws the quickscreen on a given screen
+ * - qs : the quickscreen
+ * - display : the screen to draw on
+ */
+void gui_quickscreen_draw(struct gui_quickscreen * qs, struct screen * display);
+
+/*
+ * Does the actions associated to the given button if any
+ * - qs : the quickscreen
+ * - button : the key we are going to analyse
+ * returns : true if the button corresponded to an action, false otherwise
+ */
+bool gui_quickscreen_do_button(struct gui_quickscreen * qs, int button);
+
+/*
+ * Draws the quickscreen on all available screens
+ * - qs : the quickscreen
+ */
+void gui_syncquickscreen_draw(struct gui_quickscreen * qs);
+
+/*
+ * Runs the quickscreen on all available screens
+ * - qs : the quickscreen
+ * returns : true if usb was connected, false otherwise
+ */
+bool gui_syncquickscreen_run(struct gui_quickscreen * qs);
+
+#endif /*_GUI_QUICK_SCREEN_H_*/
+#endif /* CONFIG_KEYPAD */
diff --git a/apps/gui/select.c b/apps/gui/select.c
index 5cde812..b632177 100644
--- a/apps/gui/select.c
+++ b/apps/gui/select.c
@@ -21,9 +21,9 @@
#include "lang.h"
#include "textarea.h"
-#include "sprintf.h"
-#include "kernel.h"
#include "screen_access.h"
+#include "kernel.h"
+
void gui_select_init_numeric(struct gui_select * select,
const char * title,
@@ -32,23 +32,12 @@ void gui_select_init_numeric(struct gui_select * select,
int max_value,
int step,
const char * unit,
- void (*formatter)(char* dest,
- int dest_length,
- int variable,
- const char* unit)
- )
+ option_formatter *formatter)
{
select->canceled=false;
select->validated=false;
- select->title=title;
- select->min_value=min_value;
- select->max_value=max_value+1;
- select->option=init_value;
- select->step=step;
- select->extra_string=unit;
- select->formatter=formatter;
- select->items=NULL;
- select->limit_loop=false;
+ option_select_init_numeric(&select->options, title, init_value,
+ min_value, max_value, step, unit, formatter);
}
void gui_select_init_items(struct gui_select * select,
@@ -59,69 +48,22 @@ void gui_select_init_items(struct gui_select * select,
{
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;
- select->limit_loop=false;
-}
-
-void gui_select_next(struct gui_select * select)
-{
- if(select->option + select->step >= select->max_value)
- {
- if(!select->limit_loop)
- {
- if(select->option==select->max_value-1)
- select->option=select->min_value;
- else
- select->option=select->max_value-1;
- }
- }
- else
- select->option+=select->step;
-}
-
-void gui_select_prev(struct gui_select * select)
-{
- if(select->option - select->step < select->min_value)
- {
- if(!select->limit_loop)
- {
- if(select->option==select->min_value)
- select->option=select->max_value-1;
- else
- select->option=select->min_value;
- }
- }
- else
- select->option-=select->step;
+ option_select_init_items(&select->options, title, selected, items, nb_items);
}
void gui_select_draw(struct gui_select * select, struct screen * display)
{
+ char buffer[30];
+ const char * selected=option_select_get_text(&(select->options), buffer);
#ifdef HAVE_LCD_BITMAP
screen_set_xmargin(display, 0);
#endif
gui_textarea_clear(display);
- display->puts_scroll(0, 0, select->title);
+ display->puts_scroll(0, 0, option_select_get_title(&(select->options)));
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);
- }
+ display->puts_scroll(0, 1, selected);
gui_textarea_update(display);
}
diff --git a/apps/gui/select.h b/apps/gui/select.h
index bc14af4..2799d80 100644
--- a/apps/gui/select.h
+++ b/apps/gui/select.h
@@ -21,6 +21,7 @@
#define _GUI_SELECT_H_
#include "screen_access.h"
#include "settings.h"
+#include "option_select.h"
#if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
(CONFIG_KEYPAD == IRIVER_H300_PAD)
@@ -83,19 +84,7 @@ 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;
- bool limit_loop;
+ struct option_select options;
};
/*
@@ -116,10 +105,7 @@ extern void gui_select_init_numeric(struct gui_select * select,
int max_value,
int step,
const char * unit,
- void (*formatter)(char* dest,
- int dest_length,
- int variable,
- const char* unit));
+ option_formatter *formatter);
/*
@@ -140,13 +126,15 @@ extern void gui_select_init_items(struct gui_select * select,
* Selects the next value
* - select : the select struct
*/
-extern void gui_select_next(struct gui_select * select);
+#define gui_select_next(select) \
+ option_select_next(&(select->options))
/*
* Selects the previous value
* - select : the select struct
*/
-extern void gui_select_prev(struct gui_select * select);
+#define gui_select_prev(select) \
+ option_select_prev(&(select->options))
/*
* Draws the select on the given screen
@@ -159,9 +147,8 @@ extern void gui_select_draw(struct gui_select * select, struct screen * display)
* Returns the selected value
* - select : the select struct
*/
-#define gui_select_get_selected(select) \
- (select)->option
-
+#define gui_select_get_selected(_sel_) \
+ option_select_get_selected(&((_sel_)->options))
/*
* Cancels the select
* - select : the select struct
@@ -199,7 +186,7 @@ extern void gui_select_draw(struct gui_select * select, struct screen * display)
* - false : continues to go to max/min when reaching min/max
*/
#define gui_select_limit_loop(select, loop) \
- (select)->limit_loop=loop
+ option_select_limit_loop(&((select)->options), loop)
/*
* Draws the select on all the screens
diff --git a/apps/gui/statusbar.h b/apps/gui/statusbar.h
index e7fe92e..816205e 100644
--- a/apps/gui/statusbar.h
+++ b/apps/gui/statusbar.h
@@ -85,8 +85,9 @@ extern void gui_statusbar_init(struct gui_statusbar * bar);
* - bar : the statusbar structure
* - display : the screen to attach
*/
-#define gui_statusbar_set_screen(gui_statusbar, screen) \
- (gui_statusbar)->display = screen
+#define gui_statusbar_set_screen(gui_statusbar, _display) \
+ (gui_statusbar)->display = (_display);
+
/*
* Draws the status bar on the attached screen