summaryrefslogtreecommitdiffstats
path: root/apps/gui/option_select.c
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/option_select.c
parent8042640ce967014f10dbc0e3f382cd1876310b66 (diff)
downloadrockbox-74b6af93b1436dc61e8f10b3aff3c79face5faba.tar.gz
rockbox-74b6af93b1436dc61e8f10b3aff3c79face5faba.zip
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/option_select.c')
-rw-r--r--apps/gui/option_select.c102
1 files changed, 102 insertions, 0 deletions
diff --git a/apps/gui/option_select.c b/apps/gui/option_select.c
new file mode 100644
index 0000000000..0e169617c4
--- /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);
+}