1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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
31 #include "statusbar.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
;
61 bool statusbar
= global_settings
.statusbar
;
63 display
->has_buttonbar
=false;
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);
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
);
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
);
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
);
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
)
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
)
147 option_select_next(qs
->left_option
);
151 option_select_next(qs
->bottom_option
);
154 case ACTION_QS_RIGHT
:
155 option_select_next(qs
->right_option
);
158 case ACTION_QS_DOWNINV
:
159 option_select_prev(qs
->bottom_option
);
165 bool gui_syncquickscreen_run(struct gui_quickscreen
* qs
, int button_enter
)
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*/
173 gui_syncquickscreen_draw(qs
);
174 gui_syncstatusbar_draw(&statusbars
, true);
176 button
= get_action(CONTEXT_QUICKSCREEN
,TIMEOUT_BLOCK
);
177 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
179 if(gui_quickscreen_do_button(qs
, button
))
184 gui_syncquickscreen_draw(qs
);
186 else if(button
==button_enter
)
189 if((button
== button_enter
) && can_quit
)
192 if(button
==ACTION_STD_CANCEL
)
195 gui_syncstatusbar_draw(&statusbars
, false);
200 #endif /* HAVE_QUICKSCREEN */