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
);
92 #ifdef HAVE_TOUCHSCREEN
93 if (display
->screen_type
== SCREEN_MAIN
)
96 int rect_w
= vp
->width
/2, rect_h
= vp
->height
/2;
97 int old_pattern
= vp
->fg_pattern
;
98 vp
->fg_pattern
= LCD_RGBPACK(0,255,0);
99 display
->drawrect(0, rect_h
, rect_w
, rect_h
);
100 display
->getstringsize(str(LANG_SET_BOOL_YES
), &w
, &h
);
101 display
->putsxy((rect_w
-w
)/2, rect_h
+(rect_h
-h
)/2, str(LANG_SET_BOOL_YES
));
102 vp
->fg_pattern
= LCD_RGBPACK(255,0,0);
103 display
->drawrect(rect_w
, rect_h
, rect_w
, rect_h
);
104 display
->getstringsize(str(LANG_SET_BOOL_NO
), &w
, &h
);
105 display
->putsxy(rect_w
+ (rect_w
-w
)/2, rect_h
+(rect_h
-h
)/2, str(LANG_SET_BOOL_NO
));
106 vp
->fg_pattern
= old_pattern
;
109 /* Space remaining for yes / no text ? */
110 if(line_shift
+2 <= vp_lines
)
112 if(line_shift
+3 <= vp_lines
)
114 display
->puts(0, line_shift
, str(LANG_CONFIRM_WITH_BUTTON
));
115 #ifdef HAVE_LCD_BITMAP
116 display
->puts(0, line_shift
+1, str(LANG_CANCEL_WITH_ANY
));
120 display
->update_viewport();
121 display
->set_viewport(NULL
);
125 * Draws the yesno result
126 * - yn : the yesno structure
127 * - result : the result tha must be displayed :
131 static bool gui_yesno_draw_result(struct gui_yesno
* yn
, enum yesno_res result
)
133 const struct text_message
* message
=yn
->result_message
[result
];
134 struct viewport
*vp
= yn
->vp
;
135 struct screen
* display
=yn
->display
;
138 display
->set_viewport(vp
);
139 display
->clear_viewport();
140 put_message(yn
->display
, message
, 0, viewport_get_nb_lines(vp
));
141 display
->update_viewport();
142 display
->set_viewport(NULL
);
146 enum yesno_res
gui_syncyesno_run(const struct text_message
* main_message
,
147 const struct text_message
* yes_message
,
148 const struct text_message
* no_message
)
152 bool result_displayed
;
153 struct gui_yesno yn
[NB_SCREENS
];
154 struct viewport vp
[NB_SCREENS
];
155 long talked_tick
= 0;
158 yn
[i
].main_message
=main_message
;
159 yn
[i
].result_message
[YESNO_YES
]=yes_message
;
160 yn
[i
].result_message
[YESNO_NO
]=no_message
;
161 yn
[i
].display
=&screens
[i
];
163 #ifdef HAVE_LCD_CHARCELLS
164 /* Quick fix. Viewports should really be enabled proper for charcell */
165 viewport_set_defaults(yn
[i
].vp
, i
);
167 viewportmanager_theme_enable(i
, true, yn
[i
].vp
);
169 screens
[i
].stop_scroll();
170 gui_yesno_draw(&(yn
[i
]));
172 /* make sure to eat any extranous keypresses */
173 while (get_action(CONTEXT_STD
+99, TIMEOUT_NOBLOCK
))
174 action_wait_for_release();
177 /* Repeat the question every 5secs (more or less) */
178 if (global_settings
.talk_menu
179 && (talked_tick
==0 || TIME_AFTER(current_tick
, talked_tick
+HZ
*5)))
181 talked_tick
= current_tick
;
182 talk_text_message(main_message
, false);
184 button
= get_action(CONTEXT_YESNOSCREEN
, HZ
*5);
187 #ifdef HAVE_TOUCHSCREEN
188 case ACTION_TOUCHSCREEN
:
191 if (action_get_touchscreen_press_in_vp(&x
, &y
, yn
[0].vp
) == BUTTON_TOUCHSCREEN
)
193 if (y
> yn
[0].vp
->height
/2)
195 if (x
<= yn
[0].vp
->width
/2)
204 case ACTION_YESNO_ACCEPT
:
208 case SYS_CHARGER_DISCONNECTED
:
209 case SYS_BATTERY_UPDATE
:
210 /* ignore some SYS events that can happen */
213 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
220 result_displayed
=gui_yesno_draw_result(&(yn
[i
]), result
);
222 if (global_settings
.talk_menu
)
224 talk_text_message((result
== YESNO_YES
) ? yes_message
225 : no_message
, false);
226 talk_force_enqueue_next();
233 screens
[i
].scroll_stop(yn
[i
].vp
);
234 viewportmanager_theme_undo(i
, true);
240 /* Function to manipulate all yesno dialogues.
241 This function needs the output text as an argument. */
242 bool yesno_pop(const char* text
)
244 const char *lines
[]={text
};
245 const struct text_message message
={lines
, 1};
246 bool ret
= (gui_syncyesno_run(&message
,NULL
,NULL
)== YESNO_YES
);
248 screens
[i
].clear_viewport();