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
)
153 bool result_displayed
;
154 struct gui_yesno yn
[NB_SCREENS
];
155 struct viewport vp
[NB_SCREENS
];
156 long talked_tick
= 0;
159 yn
[i
].main_message
=main_message
;
160 yn
[i
].result_message
[YESNO_YES
]=yes_message
;
161 yn
[i
].result_message
[YESNO_NO
]=no_message
;
162 yn
[i
].display
=&screens
[i
];
164 #ifdef HAVE_LCD_CHARCELLS
165 /* Quick fix. Viewports should really be enabled proper for charcell */
166 viewport_set_defaults(yn
[i
].vp
, i
);
168 viewportmanager_theme_enable(i
, true, yn
[i
].vp
);
170 screens
[i
].stop_scroll();
171 gui_yesno_draw(&(yn
[i
]));
175 /* Repeat the question every 5secs (more or less) */
176 if (global_settings
.talk_menu
177 && (talked_tick
==0 || TIME_AFTER(current_tick
, talked_tick
+HZ
*5)))
179 talked_tick
= current_tick
;
180 talk_text_message(main_message
, false);
182 button
= get_action(CONTEXT_YESNOSCREEN
, HZ
*5);
185 #ifdef HAVE_TOUCHSCREEN
186 case ACTION_TOUCHSCREEN
:
189 if (action_get_touchscreen_press_in_vp(&x
, &y
, yn
[0].vp
) == BUTTON_TOUCHSCREEN
)
191 if (y
> yn
[0].vp
->height
/2)
193 if (x
<= yn
[0].vp
->width
/2)
202 case ACTION_YESNO_ACCEPT
:
206 case SYS_CHARGER_DISCONNECTED
:
207 /* ignore some SYS events that can happen */
210 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
217 result_displayed
=gui_yesno_draw_result(&(yn
[i
]), result
);
219 if (global_settings
.talk_menu
)
221 talk_text_message((result
== YESNO_YES
) ? yes_message
222 : no_message
, false);
223 talk_force_enqueue_next();
230 screens
[i
].scroll_stop(yn
[i
].vp
);
231 viewportmanager_theme_undo(i
, true);