remove the need for action_signalscreenchange().
[Rockbox.git] / apps / gui / quickscreen.c
blob008c6fa721973a044f54e46c4e12d230d810cb63
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2005 by Kevin Ferrare
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include "quickscreen.h"
22 #ifdef HAVE_QUICKSCREEN
24 #include <stdio.h>
25 #include "system.h"
26 #include "icons.h"
27 #include "textarea.h"
28 #include "font.h"
29 #include "kernel.h"
30 #include "misc.h"
31 #include "statusbar.h"
32 #include "action.h"
34 void gui_quickscreen_init(struct gui_quickscreen * qs,
35 struct option_select *left_option,
36 struct option_select *bottom_option,
37 struct option_select *right_option,
38 quickscreen_callback callback)
40 qs->left_option=left_option;
41 qs->bottom_option=bottom_option;
42 qs->right_option=right_option;
43 qs->callback=callback;
47 * Draws the quickscreen on a given screen
48 * - qs : the quickscreen
49 * - display : the screen to draw on
51 static void gui_quickscreen_draw(struct gui_quickscreen * qs, struct screen * display)
53 #define PUTS_CENTER (display->height/2/font_h)
54 #define PUTS_BOTTOM (display->height/font_h)
55 #define PUTSXY_CENTER (display->height/2)
56 #define PUTSXY_BOTTOM (display->height)
58 const unsigned char *option;
59 const unsigned char *title;
60 int w, font_h;
61 bool statusbar = global_settings.statusbar;
62 #ifdef HAS_BUTTONBAR
63 display->has_buttonbar=false;
64 #endif
65 gui_textarea_clear(display);
66 if (display->height / display->char_height < 7) /* we need at leats 7 lines */
68 display->setfont(FONT_SYSFIXED);
70 display->getstringsize("A", NULL, &font_h);
72 /* Displays the first line of text */
73 option=(unsigned char *)option_select_get_text(qs->left_option);
74 title=(unsigned char *)qs->left_option->title;
75 display->puts_scroll(2, PUTS_CENTER-4+!statusbar, title);
76 display->puts_scroll(2, PUTS_CENTER-3+!statusbar, option);
77 display->mono_bitmap(bitmap_icons_7x8[Icon_FastBackward], 1,
78 PUTSXY_CENTER-(font_h*3), 7, 8);
80 /* Displays the second line of text */
81 option=(unsigned char *)option_select_get_text(qs->right_option);
82 title=(unsigned char *)qs->right_option->title;
83 display->getstringsize(title, &w, NULL);
84 if(w > display->width - 8)
86 display->puts_scroll(2, PUTS_CENTER-2+!statusbar, title);
87 display->mono_bitmap(bitmap_icons_7x8[Icon_FastForward], 1,
88 PUTSXY_CENTER-font_h, 7, 8);
90 else
92 display->putsxy(display->width - w - 12, PUTSXY_CENTER-font_h, title);
93 display->mono_bitmap(bitmap_icons_7x8[Icon_FastForward],
94 display->width - 8, PUTSXY_CENTER-font_h, 7, 8);
96 display->getstringsize(option, &w, NULL);
97 if(w > display->width)
98 display->puts_scroll(0, PUTS_CENTER-1+!statusbar, option);
99 else
100 display->putsxy(display->width -w-12, PUTSXY_CENTER, option);
102 /* Displays the third line of text */
103 option=(unsigned char *)option_select_get_text(qs->bottom_option);
104 title=(unsigned char *)qs->bottom_option->title;
106 display->getstringsize(title, &w, NULL);
107 if(w > display->width)
108 display->puts_scroll(0, PUTS_BOTTOM-4+!statusbar, title);
109 else
110 display->putsxy(display->width/2-w/2, PUTSXY_BOTTOM-(font_h*3), title);
112 display->getstringsize(option, &w, NULL);
113 if(w > display->width)
114 display->puts_scroll(0, PUTS_BOTTOM-3+!statusbar, option);
115 else
116 display->putsxy(display->width/2-w/2, PUTSXY_BOTTOM-(font_h*2), option);
117 display->mono_bitmap(bitmap_icons_7x8[Icon_DownArrow], display->width/2-4,
118 PUTSXY_BOTTOM-font_h, 7, 8);
120 gui_textarea_update(display);
121 display->setfont(FONT_UI);
125 * Draws the quickscreen on all available screens
126 * - qs : the quickscreen
128 static void gui_syncquickscreen_draw(struct gui_quickscreen * qs)
130 int i;
131 FOR_NB_SCREENS(i)
132 gui_quickscreen_draw(qs, &screens[i]);
136 * Does the actions associated to the given button if any
137 * - qs : the quickscreen
138 * - button : the key we are going to analyse
139 * returns : true if the button corresponded to an action, false otherwise
141 static bool gui_quickscreen_do_button(struct gui_quickscreen * qs, int button)
144 switch(button)
146 case ACTION_QS_LEFT:
147 option_select_next(qs->left_option);
148 return(true);
150 case ACTION_QS_DOWN:
151 option_select_next(qs->bottom_option);
152 return(true);
154 case ACTION_QS_RIGHT:
155 option_select_next(qs->right_option);
156 return(true);
158 case ACTION_QS_DOWNINV:
159 option_select_prev(qs->bottom_option);
160 return(true);
162 return(false);
165 bool gui_syncquickscreen_run(struct gui_quickscreen * qs, int button_enter)
167 int button;
168 /* To quit we need either :
169 * - a second press on the button that made us enter
170 * - an action taken while pressing the enter button,
171 * then release the enter button*/
172 bool can_quit=false;
173 gui_syncquickscreen_draw(qs);
174 gui_syncstatusbar_draw(&statusbars, true);
175 while (true) {
176 button = get_action(CONTEXT_QUICKSCREEN,TIMEOUT_BLOCK);
177 if(default_event_handler(button) == SYS_USB_CONNECTED)
178 return(true);
179 if(gui_quickscreen_do_button(qs, button))
181 can_quit=true;
182 if(qs->callback)
183 qs->callback(qs);
184 gui_syncquickscreen_draw(qs);
186 else if(button==button_enter)
187 can_quit=true;
189 if((button == button_enter) && can_quit)
190 break;
192 if(button==ACTION_STD_CANCEL)
193 break;
195 gui_syncstatusbar_draw(&statusbars, false);
197 return false;
200 #endif /* HAVE_QUICKSCREEN */