diff options
Diffstat (limited to 'apps/gui')
-rw-r--r-- | apps/gui/textarea.c | 12 | ||||
-rw-r--r-- | apps/gui/textarea.h | 16 | ||||
-rw-r--r-- | apps/gui/yesno.c | 96 | ||||
-rw-r--r-- | apps/gui/yesno.h | 91 |
4 files changed, 215 insertions, 0 deletions
diff --git a/apps/gui/textarea.c b/apps/gui/textarea.c index d8e730fdc2..d73f20d0e7 100644 --- a/apps/gui/textarea.c +++ b/apps/gui/textarea.c | |||
@@ -41,6 +41,18 @@ void gui_textarea_update(struct screen * display) | |||
41 | } | 41 | } |
42 | #endif | 42 | #endif |
43 | 43 | ||
44 | int gui_textarea_put_message(struct screen * display, | ||
45 | struct text_message * message, | ||
46 | int ystart) | ||
47 | { | ||
48 | int i; | ||
49 | gui_textarea_clear(display); | ||
50 | for(i=0;i<message->nb_lines && i+ystart<display->nb_lines;i++) | ||
51 | display->puts(0, i+ystart, message->message_lines[i]); | ||
52 | gui_textarea_update(display); | ||
53 | return(i); | ||
54 | } | ||
55 | |||
44 | void gui_textarea_update_nblines(struct screen * display) | 56 | void gui_textarea_update_nblines(struct screen * display) |
45 | { | 57 | { |
46 | #ifdef HAVE_LCD_BITMAP | 58 | #ifdef HAVE_LCD_BITMAP |
diff --git a/apps/gui/textarea.h b/apps/gui/textarea.h index 5249aed7a5..b1af1a5aba 100644 --- a/apps/gui/textarea.h +++ b/apps/gui/textarea.h | |||
@@ -23,6 +23,12 @@ | |||
23 | #include "settings.h" | 23 | #include "settings.h" |
24 | #include "statusbar.h" | 24 | #include "statusbar.h" |
25 | 25 | ||
26 | struct text_message | ||
27 | { | ||
28 | char **message_lines; | ||
29 | int nb_lines; | ||
30 | }; | ||
31 | |||
26 | /* | 32 | /* |
27 | * Clears the area in the screen in which text can be displayed | 33 | * Clears the area in the screen in which text can be displayed |
28 | * and sets the y margin properly | 34 | * and sets the y margin properly |
@@ -46,6 +52,16 @@ extern void gui_textarea_update(struct screen * display); | |||
46 | #endif | 52 | #endif |
47 | 53 | ||
48 | /* | 54 | /* |
55 | * Displays message lines on the given screen | ||
56 | * - display : the screen structure | ||
57 | * - message : the lines to display | ||
58 | * - ystart : the lineon which we start displaying | ||
59 | * returns : the number of lines effectively displayed | ||
60 | */ | ||
61 | extern int gui_textarea_put_message(struct screen * display, | ||
62 | struct text_message * message, | ||
63 | int ystart); | ||
64 | /* | ||
49 | * Compute the number of text lines the display can draw with the current font | 65 | * Compute the number of text lines the display can draw with the current font |
50 | * Also updates the char height and width | 66 | * Also updates the char height and width |
51 | * - display : the screen structure | 67 | * - display : the screen structure |
diff --git a/apps/gui/yesno.c b/apps/gui/yesno.c new file mode 100644 index 0000000000..65f81aaf3e --- /dev/null +++ b/apps/gui/yesno.c | |||
@@ -0,0 +1,96 @@ | |||
1 | #include "yesno.h" | ||
2 | #include "kernel.h" | ||
3 | #include "misc.h" | ||
4 | #include "lang.h" | ||
5 | |||
6 | void gui_yesno_init(struct gui_yesno * yn, | ||
7 | struct text_message * main_message, | ||
8 | struct text_message * yes_message, | ||
9 | struct text_message * no_message) | ||
10 | { | ||
11 | yn->main_message=main_message; | ||
12 | yn->result_message[YESNO_YES]=yes_message; | ||
13 | yn->result_message[YESNO_NO]=no_message; | ||
14 | yn->display=0; | ||
15 | } | ||
16 | |||
17 | void gui_yesno_set_display(struct gui_yesno * yn, | ||
18 | struct screen * display) | ||
19 | { | ||
20 | yn->display=display; | ||
21 | } | ||
22 | |||
23 | void gui_yesno_draw(struct gui_yesno * yn) | ||
24 | { | ||
25 | struct screen * display=yn->display; | ||
26 | int nb_lines, line_shift=0; | ||
27 | #ifdef HAS_LCD_BITMAP | ||
28 | screen_set_xmargin(display, 0); | ||
29 | #endif | ||
30 | gui_textarea_clear(display); | ||
31 | nb_lines=yn->main_message->nb_lines; | ||
32 | |||
33 | if(nb_lines+3<display->nb_lines) | ||
34 | line_shift=1; | ||
35 | nb_lines=gui_textarea_put_message(display, yn->main_message, line_shift); | ||
36 | |||
37 | /* Space remaining for yes / no text ? */ | ||
38 | if(nb_lines+line_shift+2<=display->nb_lines) | ||
39 | { | ||
40 | if(nb_lines+line_shift+3<=display->nb_lines) | ||
41 | nb_lines++; | ||
42 | display->puts(0, nb_lines+line_shift, str(LANG_CONFIRM_WITH_PLAY_RECORDER)); | ||
43 | display->puts(0, nb_lines+line_shift+1, str(LANG_CANCEL_WITH_ANY_RECORDER)); | ||
44 | } | ||
45 | gui_textarea_update(display); | ||
46 | } | ||
47 | |||
48 | bool gui_yesno_draw_result(struct gui_yesno * yn, enum yesno_res result) | ||
49 | { | ||
50 | struct text_message * message=yn->result_message[result]; | ||
51 | if(message==NULL) | ||
52 | return false; | ||
53 | gui_textarea_put_message(yn->display, message, 0); | ||
54 | return(true); | ||
55 | } | ||
56 | |||
57 | enum yesno_res gui_syncyesno_run(struct text_message * main_message, | ||
58 | struct text_message * yes_message, | ||
59 | struct text_message * no_message) | ||
60 | { | ||
61 | int i; | ||
62 | unsigned button; | ||
63 | int result=-1; | ||
64 | bool result_displayed; | ||
65 | struct gui_yesno yn[NB_SCREENS]; | ||
66 | FOR_NB_SCREENS(i) | ||
67 | { | ||
68 | gui_yesno_init(&(yn[i]), main_message, yes_message, no_message); | ||
69 | gui_yesno_set_display(&(yn[i]), &(screens[i])); | ||
70 | gui_yesno_draw(&(yn[i])); | ||
71 | } | ||
72 | while (result==-1) | ||
73 | { | ||
74 | button = button_get(true); | ||
75 | switch (button) | ||
76 | { | ||
77 | case YESNO_OK: | ||
78 | #ifdef TREE_RC_RUN | ||
79 | case YESNO_RC_OK: | ||
80 | #endif | ||
81 | result=YESNO_YES; | ||
82 | break; | ||
83 | |||
84 | default: | ||
85 | if(default_event_handler(button) == SYS_USB_CONNECTED) | ||
86 | return(YESNO_USB); | ||
87 | if(!(button & BUTTON_REL)) | ||
88 | result=YESNO_NO; | ||
89 | } | ||
90 | } | ||
91 | FOR_NB_SCREENS(i) | ||
92 | result_displayed=gui_yesno_draw_result(&(yn[i]), result); | ||
93 | if(result_displayed) | ||
94 | sleep(HZ); | ||
95 | return(result); | ||
96 | } | ||
diff --git a/apps/gui/yesno.h b/apps/gui/yesno.h new file mode 100644 index 0000000000..ac6500daf8 --- /dev/null +++ b/apps/gui/yesno.h | |||
@@ -0,0 +1,91 @@ | |||
1 | #ifndef _GUI_YESNO_H_ | ||
2 | #define _GUI_YESNO_H_ | ||
3 | |||
4 | #include "screen_access.h" | ||
5 | #include "textarea.h" | ||
6 | |||
7 | #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \ | ||
8 | (CONFIG_KEYPAD == IRIVER_H300_PAD) | ||
9 | #define YESNO_OK BUTTON_SELECT | ||
10 | #define YESNO_RC_OK BUTTON_RC_MENU | ||
11 | |||
12 | #elif CONFIG_KEYPAD == RECORDER_PAD | ||
13 | #define YESNO_OK BUTTON_PLAY | ||
14 | #define YESNO_RC_OK BUTTON_RC_PLAY | ||
15 | |||
16 | #elif CONFIG_KEYPAD == PLAYER_PAD | ||
17 | #define YESNO_OK BUTTON_PLAY | ||
18 | #define YESNO_RC_OK BUTTON_RC_PLAY | ||
19 | |||
20 | #elif CONFIG_KEYPAD == ONDIO_PAD | ||
21 | #define YESNO_OK BUTTON_RIGHT | ||
22 | |||
23 | #elif CONFIG_KEYPAD == GMINI100_PAD | ||
24 | #define YESNO_OK BUTTON_PLAY | ||
25 | |||
26 | #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_NANO_PAD) | ||
27 | #define YESNO_OK BUTTON_RIGHT | ||
28 | #endif | ||
29 | enum yesno_res | ||
30 | { | ||
31 | YESNO_YES, | ||
32 | YESNO_NO, | ||
33 | YESNO_USB | ||
34 | }; | ||
35 | |||
36 | struct gui_yesno | ||
37 | { | ||
38 | struct text_message * main_message; | ||
39 | struct text_message * result_message[2]; | ||
40 | |||
41 | struct screen * display; | ||
42 | }; | ||
43 | |||
44 | /* | ||
45 | * Initializes the yesno asker | ||
46 | * - yn : the yesno structure | ||
47 | * - main_message : the question the user has to answer | ||
48 | * - yes_message : message displayed if answer is 'yes' | ||
49 | * - no_message : message displayed if answer is 'no' | ||
50 | */ | ||
51 | extern void gui_yesno_init(struct gui_yesno * yn, | ||
52 | struct text_message * main_message, | ||
53 | struct text_message * yes_message, | ||
54 | struct text_message * no_message); | ||
55 | |||
56 | /* | ||
57 | * Attach the yesno to a screen | ||
58 | * - yn : the yesno structure | ||
59 | * - display : the screen to attach | ||
60 | */ | ||
61 | extern void gui_yesno_set_display(struct gui_yesno * yn, | ||
62 | struct screen * display); | ||
63 | |||
64 | /* | ||
65 | * Draws the yesno | ||
66 | * - yn : the yesno structure | ||
67 | */ | ||
68 | extern void gui_yesno_draw(struct gui_yesno * yn); | ||
69 | |||
70 | /* | ||
71 | * Draws the yesno result | ||
72 | * - yn : the yesno structure | ||
73 | * - result : the result tha must be displayed : | ||
74 | * YESNO_NO if no | ||
75 | * YESNO_YES if yes | ||
76 | */ | ||
77 | extern bool gui_yesno_draw_result(struct gui_yesno * yn, enum yesno_res result); | ||
78 | |||
79 | /* | ||
80 | * Runs the yesno asker : | ||
81 | * it will display the 'main_message' question, and wait for user keypress | ||
82 | * PLAY means yes, other keys means no | ||
83 | * - main_message : the question the user has to answer | ||
84 | * - yes_message : message displayed if answer is 'yes' | ||
85 | * - no_message : message displayed if answer is 'no' | ||
86 | */ | ||
87 | extern enum yesno_res gui_syncyesno_run( | ||
88 | struct text_message * main_message, | ||
89 | struct text_message * yes_message, | ||
90 | struct text_message * no_message); | ||
91 | #endif /* _GUI_YESNO_H_ */ | ||