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 const unsigned char *option
;
54 const unsigned char *title
;
56 bool statusbar
= global_settings
.statusbar
;
58 display
->has_buttonbar
=false;
60 gui_textarea_clear(display
);
61 if (display
->height
/ display
->char_height
< 7) /* we need at leats 7 lines */
63 display
->setfont(FONT_SYSFIXED
);
65 display
->getstringsize("A", NULL
, &font_h
);
67 /* do these calculations once */
68 const unsigned int puts_center
= display
->height
/2/font_h
;
69 const unsigned int puts_bottom
= display
->height
/font_h
;
70 const unsigned int putsxy_center
= display
->height
/2;
71 const unsigned int putsxy_bottom
= display
->height
;
73 /* Displays the first line of text */
74 option
=(unsigned char *)option_select_get_text(qs
->left_option
);
75 title
=(unsigned char *)qs
->left_option
->title
;
76 display
->puts_scroll(2, puts_center
-4+!statusbar
, title
);
77 display
->puts_scroll(2, puts_center
-3+!statusbar
, option
);
78 display
->mono_bitmap(bitmap_icons_7x8
[Icon_FastBackward
], 1,
79 putsxy_center
-(font_h
*3), 7, 8);
81 /* Displays the second line of text */
82 option
=(unsigned char *)option_select_get_text(qs
->right_option
);
83 title
=(unsigned char *)qs
->right_option
->title
;
84 display
->getstringsize(title
, &w
, NULL
);
85 if(w
> display
->width
- 8)
87 display
->puts_scroll(2, puts_center
-2+!statusbar
, title
);
88 display
->mono_bitmap(bitmap_icons_7x8
[Icon_FastForward
], 1,
89 putsxy_center
-font_h
, 7, 8);
93 display
->putsxy(display
->width
- w
- 12, putsxy_center
-font_h
, title
);
94 display
->mono_bitmap(bitmap_icons_7x8
[Icon_FastForward
],
95 display
->width
- 8, putsxy_center
-font_h
, 7, 8);
97 display
->getstringsize(option
, &w
, NULL
);
98 if(w
> display
->width
)
99 display
->puts_scroll(0, puts_center
-1+!statusbar
, option
);
101 display
->putsxy(display
->width
-w
-12, putsxy_center
, option
);
103 /* Displays the third line of text */
104 option
=(unsigned char *)option_select_get_text(qs
->bottom_option
);
105 title
=(unsigned char *)qs
->bottom_option
->title
;
107 display
->getstringsize(title
, &w
, NULL
);
108 if(w
> display
->width
)
109 display
->puts_scroll(0, puts_bottom
-4+!statusbar
, title
);
111 display
->putsxy(display
->width
/2-w
/2, putsxy_bottom
-(font_h
*3), title
);
113 display
->getstringsize(option
, &w
, NULL
);
114 if(w
> display
->width
)
115 display
->puts_scroll(0, puts_bottom
-3+!statusbar
, option
);
117 display
->putsxy(display
->width
/2-w
/2, putsxy_bottom
-(font_h
*2), option
);
118 display
->mono_bitmap(bitmap_icons_7x8
[Icon_DownArrow
], display
->width
/2-4,
119 putsxy_bottom
-font_h
, 7, 8);
121 gui_textarea_update(display
);
122 display
->setfont(FONT_UI
);
126 * Draws the quickscreen on all available screens
127 * - qs : the quickscreen
129 static void gui_syncquickscreen_draw(struct gui_quickscreen
* qs
)
133 gui_quickscreen_draw(qs
, &screens
[i
]);
137 * Does the actions associated to the given button if any
138 * - qs : the quickscreen
139 * - button : the key we are going to analyse
140 * returns : true if the button corresponded to an action, false otherwise
142 static bool gui_quickscreen_do_button(struct gui_quickscreen
* qs
, int button
)
148 option_select_next(qs
->left_option
);
152 option_select_next(qs
->bottom_option
);
155 case ACTION_QS_RIGHT
:
156 option_select_next(qs
->right_option
);
159 case ACTION_QS_DOWNINV
:
160 option_select_prev(qs
->bottom_option
);
166 bool gui_syncquickscreen_run(struct gui_quickscreen
* qs
, int button_enter
)
169 /* To quit we need either :
170 * - a second press on the button that made us enter
171 * - an action taken while pressing the enter button,
172 * then release the enter button*/
174 gui_syncquickscreen_draw(qs
);
175 gui_syncstatusbar_draw(&statusbars
, true);
177 button
= get_action(CONTEXT_QUICKSCREEN
,TIMEOUT_BLOCK
);
178 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
180 if(gui_quickscreen_do_button(qs
, button
))
185 gui_syncquickscreen_draw(qs
);
187 else if(button
==button_enter
)
190 if((button
== button_enter
) && can_quit
)
193 if(button
==ACTION_STD_CANCEL
)
196 gui_syncstatusbar_draw(&statusbars
, false);
201 #endif /* HAVE_QUICKSCREEN */