summaryrefslogtreecommitdiff
path: root/apps/gui/option_select.c
diff options
context:
space:
mode:
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 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2005 by Kevin Ferrare
11 *
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.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#include "option_select.h"
21#include "sprintf.h"
22#include "kernel.h"
23#include "lang.h"
24
25void option_select_init_numeric(struct option_select * opt,
26 const char * title,
27 int init_value,
28 int min_value,
29 int max_value,
30 int step,
31 const char * unit,
32 option_formatter *formatter)
33{
34 opt->title=title;
35 opt->min_value=min_value;
36 opt->max_value=max_value+1;
37 opt->option=init_value;
38 opt->step=step;
39 opt->extra_string=unit;
40 opt->formatter=formatter;
41 opt->items=NULL;
42 opt->limit_loop=false;
43}
44
45void option_select_init_items(struct option_select * opt,
46 const char * title,
47 int selected,
48 const struct opt_items * items,
49 int nb_items)
50{
51 opt->title=title;
52 opt->min_value=0;
53 opt->max_value=nb_items;
54 opt->option=selected;
55 opt->step=1;
56 opt->formatter=NULL;
57 opt->items=items;
58 opt->limit_loop=false;
59}
60
61void option_select_next(struct option_select * opt)
62{
63 if(opt->option + opt->step >= opt->max_value)
64 {
65 if(!opt->limit_loop)
66 {
67 if(opt->option==opt->max_value-1)
68 opt->option=opt->min_value;
69 else
70 opt->option=opt->max_value-1;
71 }
72 }
73 else
74 opt->option+=opt->step;
75}
76
77void option_select_prev(struct option_select * opt)
78{
79 if(opt->option - opt->step < opt->min_value)
80 {
81 if(!opt->limit_loop)
82 {
83 if(opt->option==opt->min_value)
84 opt->option=opt->max_value-1;
85 else
86 opt->option=opt->min_value;
87 }
88 }
89 else
90 opt->option-=opt->step;
91}
92
93const char * option_select_get_text(struct option_select * opt, char * buffer)
94{
95 if(opt->items)
96 return(P2STR(opt->items[opt->option].string));
97 if(!opt->formatter)
98 snprintf(buffer, sizeof buffer,"%d %s", opt->option, opt->extra_string);
99 else
100 opt->formatter(buffer, sizeof buffer, opt->option, opt->extra_string);
101 return(buffer);
102}