1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2005 by Kevin Ferrare
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
35 const struct text_message
* main_message
;
36 const struct text_message
* result_message
[2];
39 struct screen
* display
;
42 static void talk_text_message(const struct text_message
* message
, bool enqueue
)
47 for(line
=0; line
<message
->nb_lines
; line
++)
49 long id
= P2ID((unsigned char *)message
->message_lines
[line
]);
59 static int put_message(struct screen
*display
,
60 const struct text_message
* message
,
64 for(i
=0; i
<message
->nb_lines
&& i
+start
<max_y
; i
++)
66 display
->puts_scroll(0, i
+start
,
67 P2STR((unsigned char *)message
->message_lines
[i
]));
74 * - yn : the yesno structure
76 static void gui_yesno_draw(struct gui_yesno
* yn
)
78 struct screen
* display
=yn
->display
;
79 struct viewport
*vp
= yn
->vp
;
80 int nb_lines
, vp_lines
, line_shift
=0;
82 display
->set_viewport(vp
);
83 display
->clear_viewport();
84 nb_lines
= yn
->main_message
->nb_lines
;
85 vp_lines
= viewport_get_nb_lines(vp
);
87 if(nb_lines
+3< vp_lines
)
90 line_shift
+= put_message(display
, yn
->main_message
,
91 line_shift
, vp_lines
);
93 /* Space remaining for yes / no text ? */
94 if(line_shift
+2 <= vp_lines
)
96 if(line_shift
+3 <= vp_lines
)
98 display
->puts(0, line_shift
, str(LANG_CONFIRM_WITH_BUTTON
));
99 #ifdef HAVE_LCD_BITMAP
100 display
->puts(0, line_shift
+1, str(LANG_CANCEL_WITH_ANY
));
103 display
->update_viewport();
104 display
->set_viewport(NULL
);
108 * Draws the yesno result
109 * - yn : the yesno structure
110 * - result : the result tha must be displayed :
114 static bool gui_yesno_draw_result(struct gui_yesno
* yn
, enum yesno_res result
)
116 const struct text_message
* message
=yn
->result_message
[result
];
117 struct viewport
*vp
= yn
->vp
;
118 struct screen
* display
=yn
->display
;
121 display
->set_viewport(vp
);
122 display
->clear_viewport();
123 put_message(yn
->display
, message
, 0, viewport_get_nb_lines(vp
));
124 display
->update_viewport();
125 display
->set_viewport(NULL
);
129 enum yesno_res
gui_syncyesno_run(const struct text_message
* main_message
,
130 const struct text_message
* yes_message
,
131 const struct text_message
* no_message
)
136 bool result_displayed
;
137 struct gui_yesno yn
[NB_SCREENS
];
138 struct viewport vp
[NB_SCREENS
];
139 long talked_tick
= 0;
142 yn
[i
].main_message
=main_message
;
143 yn
[i
].result_message
[YESNO_YES
]=yes_message
;
144 yn
[i
].result_message
[YESNO_NO
]=no_message
;
145 yn
[i
].display
=&screens
[i
];
147 viewport_set_defaults(yn
[i
].vp
, i
);
148 screens
[i
].stop_scroll();
149 gui_yesno_draw(&(yn
[i
]));
153 /* Repeat the question every 5secs (more or less) */
154 if (global_settings
.talk_menu
155 && (talked_tick
==0 || TIME_AFTER(current_tick
, talked_tick
+HZ
*5)))
157 talked_tick
= current_tick
;
158 talk_text_message(main_message
, false);
160 button
= get_action(CONTEXT_YESNOSCREEN
, HZ
*5);
163 case ACTION_YESNO_ACCEPT
:
167 case SYS_CHARGER_DISCONNECTED
:
168 /* ignore some SYS events that can happen */
171 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
178 result_displayed
=gui_yesno_draw_result(&(yn
[i
]), result
);
180 if (global_settings
.talk_menu
)
182 talk_text_message((result
== YESNO_YES
) ? yes_message
183 : no_message
, false);
184 talk_force_enqueue_next();
189 FOR_NB_SCREENS(i
) /* stop scrolling before getting out */
190 screens
[i
].scroll_stop(yn
[i
].vp
);