From 6f4c6ed99007f89099b74bfbb95f5ca58b0ead3c Mon Sep 17 00:00:00 2001 From: Stéphane Doyon Date: Wed, 7 Nov 2007 01:37:00 +0000 Subject: Straighten out voicing of yesno dialogs. Make it so gui_syncyesno_run() does not modify the text_messages passed as argument, simplify the code and even reduce size a bit. The key is to support voicing at the level of the text_message itself. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15505 a1c6a512-1295-4272-9138-f99709370657 --- apps/gui/textarea.c | 20 +++++++++++++++++++- apps/gui/textarea.h | 6 ++++++ apps/gui/yesno.c | 34 +++------------------------------- 3 files changed, 28 insertions(+), 32 deletions(-) diff --git a/apps/gui/textarea.c b/apps/gui/textarea.c index 0dd063c493..b30667df4e 100644 --- a/apps/gui/textarea.c +++ b/apps/gui/textarea.c @@ -19,6 +19,8 @@ #include "textarea.h" #include "font.h" +#include "lang.h" +#include "talk.h" void gui_textarea_clear(struct screen * display) { @@ -51,7 +53,8 @@ int gui_textarea_put_message(struct screen * display, int i; gui_textarea_clear(display); for(i=0;inb_lines && i+ystartnb_lines;i++) - display->puts_scroll(0, i+ystart, (unsigned char *)message->message_lines[i]); + display->puts_scroll(0, i+ystart, P2STR((unsigned char *)message-> + message_lines[i])); gui_textarea_update(display); return(i); } @@ -74,3 +77,18 @@ void gui_textarea_update_nblines(struct screen * display) #endif display->nb_lines = height / display->char_height; } + +void talk_text_message(struct text_message * message, bool enqueue) +{ + int line; + if(message) + for(line=0; linenb_lines; line++) + { + long id = P2ID((unsigned char *)message->message_lines[line]); + if(id>=0) + { + talk_id(id, enqueue); + enqueue = true; + } + } +} diff --git a/apps/gui/textarea.h b/apps/gui/textarea.h index 413169db24..765add084a 100644 --- a/apps/gui/textarea.h +++ b/apps/gui/textarea.h @@ -59,6 +59,12 @@ extern int gui_textarea_put_message(struct screen * display, */ extern void gui_textarea_update_nblines(struct screen * display); +/* + * Speak a text_message. The message's lines may be virtual pointers + * representing language / voicefont IDs (see settings.h). + */ +extern void talk_text_message(struct text_message * message, bool enqueue); + #ifdef HAVE_LCD_BITMAP /* * Compute the number of pixels from which text can be displayed diff --git a/apps/gui/yesno.c b/apps/gui/yesno.c index 4e86b017ca..891e73809b 100644 --- a/apps/gui/yesno.c +++ b/apps/gui/yesno.c @@ -101,25 +101,6 @@ static bool gui_yesno_draw_result(struct gui_yesno * yn, enum yesno_res result) #include "debug.h" -/* Processes a text_message whose lines may be virtual pointers - representing language / voicefont IDs (see settings.h). Copies out - the IDs to the ids array, which is of length maxlen, and replaces - the pointers in the text_message with the actual language strings. - The ids array is terminated with the TALK_FINAL_ID sentinel - element. */ -static void extract_talk_ids(struct text_message *m, long *ids, int maxlen) -{ - int line, i=0; - if(m) - for(line=0; linenb_lines; line++) { - long id = P2ID((unsigned char *)m->message_lines[line]); - if(id>=0 && imessage_lines[line] = (char *)P2STR((unsigned char *)m->message_lines[line]); - } - ids[i] = TALK_FINAL_ID; -} - enum yesno_res gui_syncyesno_run(struct text_message * main_message, struct text_message * yes_message, struct text_message * no_message) @@ -129,13 +110,7 @@ enum yesno_res gui_syncyesno_run(struct text_message * main_message, int result=-1; bool result_displayed; struct gui_yesno yn[NB_SCREENS]; - long voice_ids[5]; long talked_tick = 0; - /* The text messages may contain virtual pointers to IDs (see - settings.h) instead of plain strings. Copy the IDs out so we - can speak them, and unwrap the actual language strings. */ - extract_talk_ids(main_message, voice_ids, - sizeof(voice_ids)/sizeof(voice_ids[0])); FOR_NB_SCREENS(i) { gui_yesno_init(&(yn[i]), main_message, yes_message, no_message); @@ -149,7 +124,7 @@ enum yesno_res gui_syncyesno_run(struct text_message * main_message, && (talked_tick==0 || TIME_AFTER(current_tick, talked_tick+HZ*5))) { talked_tick = current_tick; - talk_idarray(voice_ids, false); + talk_text_message(main_message, false); } button = get_action(CONTEXT_YESNOSCREEN, HZ*5); switch (button) @@ -168,16 +143,13 @@ enum yesno_res gui_syncyesno_run(struct text_message * main_message, } } - /* extract_talk_ids also converts ID to STR */ - extract_talk_ids((result == YESNO_YES) ? yes_message : no_message, - voice_ids, sizeof(voice_ids)/sizeof(voice_ids[0])); - FOR_NB_SCREENS(i) result_displayed=gui_yesno_draw_result(&(yn[i]), result); if (global_settings.talk_menu) { - talk_idarray(voice_ids, false); + talk_text_message((result == YESNO_YES) ? yes_message + : no_message, false); talk_force_enqueue_next(); } if(result_displayed) -- cgit v1.2.3