diff options
-rw-r--r-- | apps/gui/option_select.c | 46 | ||||
-rw-r--r-- | apps/gui/option_select.h | 33 | ||||
-rw-r--r-- | apps/gui/quickscreen.c | 10 |
3 files changed, 11 insertions, 78 deletions
diff --git a/apps/gui/option_select.c b/apps/gui/option_select.c index 045f5570c4..d4fb225a59 100644 --- a/apps/gui/option_select.c +++ b/apps/gui/option_select.c | |||
@@ -22,26 +22,6 @@ | |||
22 | #include "kernel.h" | 22 | #include "kernel.h" |
23 | #include "lang.h" | 23 | #include "lang.h" |
24 | 24 | ||
25 | void 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=true; | ||
43 | } | ||
44 | |||
45 | void option_select_init_items(struct option_select * opt, | 25 | void option_select_init_items(struct option_select * opt, |
46 | const char * title, | 26 | const char * title, |
47 | int selected, | 27 | int selected, |
@@ -52,31 +32,25 @@ void option_select_init_items(struct option_select * opt, | |||
52 | opt->min_value=0; | 32 | opt->min_value=0; |
53 | opt->max_value=nb_items; | 33 | opt->max_value=nb_items; |
54 | opt->option=selected; | 34 | opt->option=selected; |
55 | opt->step=1; | ||
56 | opt->formatter=NULL; | ||
57 | opt->items=items; | 35 | opt->items=items; |
58 | opt->limit_loop=false; | ||
59 | } | 36 | } |
60 | 37 | ||
61 | void option_select_next(struct option_select * opt) | 38 | void option_select_next(struct option_select * opt) |
62 | { | 39 | { |
63 | if(opt->option + opt->step >= opt->max_value) | 40 | if(opt->option + 1 >= opt->max_value) |
64 | { | 41 | { |
65 | if(!opt->limit_loop) | ||
66 | { | ||
67 | if(opt->option==opt->max_value-1) | 42 | if(opt->option==opt->max_value-1) |
68 | opt->option=opt->min_value; | 43 | opt->option=opt->min_value; |
69 | else | 44 | else |
70 | opt->option=opt->max_value-1; | 45 | opt->option=opt->max_value-1; |
71 | } | ||
72 | } | 46 | } |
73 | else | 47 | else |
74 | opt->option+=opt->step; | 48 | opt->option+=1; |
75 | } | 49 | } |
76 | 50 | ||
77 | void option_select_prev(struct option_select * opt) | 51 | void option_select_prev(struct option_select * opt) |
78 | { | 52 | { |
79 | if(opt->option - opt->step < opt->min_value) | 53 | if(opt->option - 1 < opt->min_value) |
80 | { | 54 | { |
81 | /* the dissimilarity to option_select_next() arises from the | 55 | /* the dissimilarity to option_select_next() arises from the |
82 | * sleep timer problem (bug #5000 and #5001): | 56 | * sleep timer problem (bug #5000 and #5001): |
@@ -85,21 +59,15 @@ void option_select_prev(struct option_select * opt) | |||
85 | * We need to be able to set timer to 0 (= Off) nevertheless. */ | 59 | * We need to be able to set timer to 0 (= Off) nevertheless. */ |
86 | if(opt->option!=opt->min_value) | 60 | if(opt->option!=opt->min_value) |
87 | opt->option=opt->min_value; | 61 | opt->option=opt->min_value; |
88 | else if(!opt->limit_loop) | 62 | else |
89 | opt->option=opt->max_value-1; | 63 | opt->option=opt->max_value-1; |
90 | } | 64 | } |
91 | else | 65 | else |
92 | opt->option-=opt->step; | 66 | opt->option-=1; |
93 | } | 67 | } |
94 | 68 | ||
95 | const char * option_select_get_text(struct option_select * opt, char * buffer, | 69 | const char * option_select_get_text(struct option_select * opt/*, char * buffer, |
96 | int buffersize) | 70 | int buffersize*/) |
97 | { | 71 | { |
98 | if(opt->items) | ||
99 | return(P2STR(opt->items[opt->option].string)); | 72 | return(P2STR(opt->items[opt->option].string)); |
100 | if(!opt->formatter) | ||
101 | snprintf(buffer, buffersize,"%d %s", opt->option, opt->extra_string); | ||
102 | else | ||
103 | opt->formatter(buffer, buffersize, opt->option, opt->extra_string); | ||
104 | return(buffer); | ||
105 | } | 73 | } |
diff --git a/apps/gui/option_select.h b/apps/gui/option_select.h index 6adbe1e720..e2ae31a848 100644 --- a/apps/gui/option_select.h +++ b/apps/gui/option_select.h | |||
@@ -21,44 +21,16 @@ | |||
21 | #define _GUI_OPTION_SELECT_H_ | 21 | #define _GUI_OPTION_SELECT_H_ |
22 | #include "settings.h" | 22 | #include "settings.h" |
23 | 23 | ||
24 | typedef void option_formatter(char* dest, int dest_length, | ||
25 | int variable, const char* unit); | ||
26 | |||
27 | struct option_select | 24 | struct option_select |
28 | { | 25 | { |
29 | const char * title; | 26 | const char * title; |
30 | int min_value; | 27 | int min_value; |
31 | int max_value; | 28 | int max_value; |
32 | int step; | ||
33 | int option; | 29 | int option; |
34 | const char * extra_string; | ||
35 | /* In the case the option is a number */ | ||
36 | option_formatter *formatter; | ||
37 | const struct opt_items * items; | 30 | const struct opt_items * items; |
38 | bool limit_loop; | ||
39 | }; | 31 | }; |
40 | 32 | ||
41 | /* | 33 | /* |
42 | * Initializes an option containing a numeric values | ||
43 | * - title : the title of the option | ||
44 | * - init_value : the initial value the number will be | ||
45 | * - min_value, max_value : bounds to the value | ||
46 | * - step : the ammount you want to add / withdraw to the initial number | ||
47 | * each time a key is pressed | ||
48 | * - unit : the unit in which the value is (ex "s", "bytes", ...) | ||
49 | * - formatter : a callback function that generates a string | ||
50 | * from the number it gets | ||
51 | */ | ||
52 | extern void option_select_init_numeric(struct option_select * opt, | ||
53 | const char * title, | ||
54 | int init_value, | ||
55 | int min_value, | ||
56 | int max_value, | ||
57 | int step, | ||
58 | const char * unit, | ||
59 | option_formatter *formatter); | ||
60 | |||
61 | /* | ||
62 | * Initializes an option containing a list of choices | 34 | * Initializes an option containing a list of choices |
63 | * - title : the title of the option | 35 | * - title : the title of the option |
64 | * - selected : the initially selected item | 36 | * - selected : the initially selected item |
@@ -74,12 +46,9 @@ extern void option_select_init_items(struct option_select * opt, | |||
74 | /* | 46 | /* |
75 | * Gets the selected option | 47 | * Gets the selected option |
76 | * - opt : the option struct | 48 | * - opt : the option struct |
77 | * - buffer : a buffer to eventually format the option | ||
78 | * Returns the selected option | 49 | * Returns the selected option |
79 | */ | 50 | */ |
80 | extern const char * option_select_get_text(struct option_select * opt, | 51 | extern const char * option_select_get_text(struct option_select * opt); |
81 | char * buffer, | ||
82 | int buffersize); | ||
83 | 52 | ||
84 | /* | 53 | /* |
85 | * Selects the next value | 54 | * Selects the next value |
diff --git a/apps/gui/quickscreen.c b/apps/gui/quickscreen.c index cda6e7aa51..310d48041f 100644 --- a/apps/gui/quickscreen.c +++ b/apps/gui/quickscreen.c | |||
@@ -55,7 +55,6 @@ static void gui_quickscreen_draw(struct gui_quickscreen * qs, struct screen * di | |||
55 | #define PUTSXY_CENTER (display->height/2) | 55 | #define PUTSXY_CENTER (display->height/2) |
56 | #define PUTSXY_BOTTOM (display->height) | 56 | #define PUTSXY_BOTTOM (display->height) |
57 | 57 | ||
58 | char buffer[30]; | ||
59 | const unsigned char *option; | 58 | const unsigned char *option; |
60 | const unsigned char *title; | 59 | const unsigned char *title; |
61 | int w, font_h; | 60 | int w, font_h; |
@@ -71,8 +70,7 @@ static void gui_quickscreen_draw(struct gui_quickscreen * qs, struct screen * di | |||
71 | display->getstringsize("A", NULL, &font_h); | 70 | display->getstringsize("A", NULL, &font_h); |
72 | 71 | ||
73 | /* Displays the first line of text */ | 72 | /* Displays the first line of text */ |
74 | option=(unsigned char *)option_select_get_text(qs->left_option, buffer, | 73 | option=(unsigned char *)option_select_get_text(qs->left_option); |
75 | sizeof buffer); | ||
76 | title=(unsigned char *)qs->left_option->title; | 74 | title=(unsigned char *)qs->left_option->title; |
77 | display->puts_scroll(2, PUTS_CENTER-4+!statusbar, title); | 75 | display->puts_scroll(2, PUTS_CENTER-4+!statusbar, title); |
78 | display->puts_scroll(2, PUTS_CENTER-3+!statusbar, option); | 76 | display->puts_scroll(2, PUTS_CENTER-3+!statusbar, option); |
@@ -80,8 +78,7 @@ static void gui_quickscreen_draw(struct gui_quickscreen * qs, struct screen * di | |||
80 | PUTSXY_CENTER-(font_h*3), 7, 8); | 78 | PUTSXY_CENTER-(font_h*3), 7, 8); |
81 | 79 | ||
82 | /* Displays the second line of text */ | 80 | /* Displays the second line of text */ |
83 | option=(unsigned char *)option_select_get_text(qs->right_option, buffer, | 81 | option=(unsigned char *)option_select_get_text(qs->right_option); |
84 | sizeof buffer); | ||
85 | title=(unsigned char *)qs->right_option->title; | 82 | title=(unsigned char *)qs->right_option->title; |
86 | display->getstringsize(title, &w, NULL); | 83 | display->getstringsize(title, &w, NULL); |
87 | if(w > display->width - 8) | 84 | if(w > display->width - 8) |
@@ -103,8 +100,7 @@ static void gui_quickscreen_draw(struct gui_quickscreen * qs, struct screen * di | |||
103 | display->putsxy(display->width -w-12, PUTSXY_CENTER, option); | 100 | display->putsxy(display->width -w-12, PUTSXY_CENTER, option); |
104 | 101 | ||
105 | /* Displays the third line of text */ | 102 | /* Displays the third line of text */ |
106 | option=(unsigned char *)option_select_get_text(qs->bottom_option, buffer, | 103 | option=(unsigned char *)option_select_get_text(qs->bottom_option); |
107 | sizeof buffer); | ||
108 | title=(unsigned char *)qs->bottom_option->title; | 104 | title=(unsigned char *)qs->bottom_option->title; |
109 | 105 | ||
110 | display->getstringsize(title, &w, NULL); | 106 | display->getstringsize(title, &w, NULL); |