2005-11-22 03:38:07 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 by Kevin Ferrare
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "quickscreen.h"
|
2006-04-10 03:51:17 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_QUICKSCREEN
|
2005-11-22 03:38:07 +00:00
|
|
|
|
2006-03-12 23:45:40 +00:00
|
|
|
#include <stdio.h>
|
2006-01-21 23:43:57 +00:00
|
|
|
#include "system.h"
|
2005-11-22 03:38:07 +00:00
|
|
|
#include "icons.h"
|
|
|
|
#include "textarea.h"
|
|
|
|
#include "font.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "statusbar.h"
|
2006-08-15 12:27:07 +00:00
|
|
|
#include "action.h"
|
2005-11-22 03:38:07 +00:00
|
|
|
|
|
|
|
void gui_quickscreen_init(struct gui_quickscreen * qs,
|
|
|
|
struct option_select *left_option,
|
|
|
|
struct option_select *bottom_option,
|
|
|
|
struct option_select *right_option,
|
|
|
|
quickscreen_callback callback)
|
|
|
|
{
|
|
|
|
qs->left_option=left_option;
|
|
|
|
qs->bottom_option=bottom_option;
|
|
|
|
qs->right_option=right_option;
|
|
|
|
qs->callback=callback;
|
|
|
|
}
|
|
|
|
|
2007-03-11 21:48:20 +00:00
|
|
|
/*
|
|
|
|
* Draws the quickscreen on a given screen
|
|
|
|
* - qs : the quickscreen
|
|
|
|
* - display : the screen to draw on
|
|
|
|
*/
|
|
|
|
static void gui_quickscreen_draw(struct gui_quickscreen * qs, struct screen * display)
|
2005-11-22 03:38:07 +00:00
|
|
|
{
|
2006-04-11 06:38:10 +00:00
|
|
|
#define PUTS_CENTER (display->height/2/font_h)
|
|
|
|
#define PUTS_BOTTOM (display->height/font_h)
|
|
|
|
#define PUTSXY_CENTER (display->height/2)
|
|
|
|
#define PUTSXY_BOTTOM (display->height)
|
|
|
|
|
2005-12-05 23:37:14 +00:00
|
|
|
const unsigned char *option;
|
|
|
|
const unsigned char *title;
|
2006-04-11 06:38:10 +00:00
|
|
|
int w, font_h;
|
2006-04-02 10:41:16 +00:00
|
|
|
bool statusbar = global_settings.statusbar;
|
2005-11-22 03:38:07 +00:00
|
|
|
#ifdef HAS_BUTTONBAR
|
|
|
|
display->has_buttonbar=false;
|
|
|
|
#endif
|
|
|
|
gui_textarea_clear(display);
|
2007-03-04 13:04:15 +00:00
|
|
|
if (display->height / display->char_height < 7) /* we need at leats 7 lines */
|
|
|
|
{
|
|
|
|
display->setfont(FONT_SYSFIXED);
|
|
|
|
}
|
2006-04-11 06:38:10 +00:00
|
|
|
display->getstringsize("A", NULL, &font_h);
|
2005-11-22 03:38:07 +00:00
|
|
|
|
2006-03-12 23:45:40 +00:00
|
|
|
/* Displays the first line of text */
|
2007-05-24 19:03:26 +00:00
|
|
|
option=(unsigned char *)option_select_get_text(qs->left_option);
|
2006-03-12 23:45:40 +00:00
|
|
|
title=(unsigned char *)qs->left_option->title;
|
2006-04-11 06:38:10 +00:00
|
|
|
display->puts_scroll(2, PUTS_CENTER-4+!statusbar, title);
|
|
|
|
display->puts_scroll(2, PUTS_CENTER-3+!statusbar, option);
|
|
|
|
display->mono_bitmap(bitmap_icons_7x8[Icon_FastBackward], 1,
|
|
|
|
PUTSXY_CENTER-(font_h*3), 7, 8);
|
2005-11-22 03:38:07 +00:00
|
|
|
|
2006-03-12 23:45:40 +00:00
|
|
|
/* Displays the second line of text */
|
2007-05-24 19:03:26 +00:00
|
|
|
option=(unsigned char *)option_select_get_text(qs->right_option);
|
2006-03-12 23:45:40 +00:00
|
|
|
title=(unsigned char *)qs->right_option->title;
|
2006-04-11 06:38:10 +00:00
|
|
|
display->getstringsize(title, &w, NULL);
|
2006-04-04 07:01:24 +00:00
|
|
|
if(w > display->width - 8)
|
2006-04-02 10:41:16 +00:00
|
|
|
{
|
2006-04-11 06:38:10 +00:00
|
|
|
display->puts_scroll(2, PUTS_CENTER-2+!statusbar, title);
|
|
|
|
display->mono_bitmap(bitmap_icons_7x8[Icon_FastForward], 1,
|
|
|
|
PUTSXY_CENTER-font_h, 7, 8);
|
2006-04-02 10:41:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-04-11 06:38:10 +00:00
|
|
|
display->putsxy(display->width - w - 12, PUTSXY_CENTER-font_h, title);
|
2006-04-10 03:51:17 +00:00
|
|
|
display->mono_bitmap(bitmap_icons_7x8[Icon_FastForward],
|
2006-04-11 06:38:10 +00:00
|
|
|
display->width - 8, PUTSXY_CENTER-font_h, 7, 8);
|
2006-04-02 10:41:16 +00:00
|
|
|
}
|
|
|
|
display->getstringsize(option, &w, NULL);
|
2006-04-04 07:01:24 +00:00
|
|
|
if(w > display->width)
|
2006-04-11 06:38:10 +00:00
|
|
|
display->puts_scroll(0, PUTS_CENTER-1+!statusbar, option);
|
2006-04-02 10:41:16 +00:00
|
|
|
else
|
2006-04-11 06:38:10 +00:00
|
|
|
display->putsxy(display->width -w-12, PUTSXY_CENTER, option);
|
2006-04-02 10:41:16 +00:00
|
|
|
|
|
|
|
/* Displays the third line of text */
|
2007-05-24 19:03:26 +00:00
|
|
|
option=(unsigned char *)option_select_get_text(qs->bottom_option);
|
2006-04-02 10:41:16 +00:00
|
|
|
title=(unsigned char *)qs->bottom_option->title;
|
|
|
|
|
|
|
|
display->getstringsize(title, &w, NULL);
|
2006-04-04 07:01:24 +00:00
|
|
|
if(w > display->width)
|
2006-04-11 06:38:10 +00:00
|
|
|
display->puts_scroll(0, PUTS_BOTTOM-4+!statusbar, title);
|
2006-04-02 10:41:16 +00:00
|
|
|
else
|
2006-04-11 06:38:10 +00:00
|
|
|
display->putsxy(display->width/2-w/2, PUTSXY_BOTTOM-(font_h*3), title);
|
2006-04-02 10:41:16 +00:00
|
|
|
|
|
|
|
display->getstringsize(option, &w, NULL);
|
2006-04-04 07:01:24 +00:00
|
|
|
if(w > display->width)
|
2006-04-11 06:38:10 +00:00
|
|
|
display->puts_scroll(0, PUTS_BOTTOM-3+!statusbar, option);
|
2006-04-02 10:41:16 +00:00
|
|
|
else
|
2006-04-11 06:38:10 +00:00
|
|
|
display->putsxy(display->width/2-w/2, PUTSXY_BOTTOM-(font_h*2), option);
|
|
|
|
display->mono_bitmap(bitmap_icons_7x8[Icon_DownArrow], display->width/2-4,
|
|
|
|
PUTSXY_BOTTOM-font_h, 7, 8);
|
2005-11-22 03:38:07 +00:00
|
|
|
|
|
|
|
gui_textarea_update(display);
|
2005-11-22 21:55:05 +00:00
|
|
|
display->setfont(FONT_UI);
|
2005-11-22 03:38:07 +00:00
|
|
|
}
|
|
|
|
|
2007-03-11 21:48:20 +00:00
|
|
|
/*
|
|
|
|
* Draws the quickscreen on all available screens
|
|
|
|
* - qs : the quickscreen
|
|
|
|
*/
|
|
|
|
static void gui_syncquickscreen_draw(struct gui_quickscreen * qs)
|
2005-11-22 03:38:07 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
gui_quickscreen_draw(qs, &screens[i]);
|
|
|
|
}
|
|
|
|
|
2007-03-11 21:48:20 +00:00
|
|
|
/*
|
|
|
|
* Does the actions associated to the given button if any
|
|
|
|
* - qs : the quickscreen
|
|
|
|
* - button : the key we are going to analyse
|
|
|
|
* returns : true if the button corresponded to an action, false otherwise
|
|
|
|
*/
|
|
|
|
static bool gui_quickscreen_do_button(struct gui_quickscreen * qs, int button)
|
2005-11-22 03:38:07 +00:00
|
|
|
{
|
2006-03-12 23:45:40 +00:00
|
|
|
|
2005-11-22 03:38:07 +00:00
|
|
|
switch(button)
|
|
|
|
{
|
2006-08-15 12:27:07 +00:00
|
|
|
case ACTION_QS_LEFT:
|
2005-11-22 03:38:07 +00:00
|
|
|
option_select_next(qs->left_option);
|
|
|
|
return(true);
|
|
|
|
|
2006-08-15 12:27:07 +00:00
|
|
|
case ACTION_QS_DOWN:
|
2005-11-22 03:38:07 +00:00
|
|
|
option_select_next(qs->bottom_option);
|
|
|
|
return(true);
|
|
|
|
|
2006-08-15 12:27:07 +00:00
|
|
|
case ACTION_QS_RIGHT:
|
2005-11-22 03:38:07 +00:00
|
|
|
option_select_next(qs->right_option);
|
|
|
|
return(true);
|
|
|
|
|
2006-08-15 12:27:07 +00:00
|
|
|
case ACTION_QS_DOWNINV:
|
2005-11-22 03:38:07 +00:00
|
|
|
option_select_prev(qs->bottom_option);
|
|
|
|
return(true);
|
|
|
|
}
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
2005-11-22 21:55:05 +00:00
|
|
|
bool gui_syncquickscreen_run(struct gui_quickscreen * qs, int button_enter)
|
2005-11-22 03:38:07 +00:00
|
|
|
{
|
2006-08-15 12:27:07 +00:00
|
|
|
int button;
|
2005-11-22 21:55:05 +00:00
|
|
|
/* To quit we need either :
|
|
|
|
* - a second press on the button that made us enter
|
|
|
|
* - an action taken while pressing the enter button,
|
|
|
|
* then release the enter button*/
|
|
|
|
bool can_quit=false;
|
2005-11-22 03:38:07 +00:00
|
|
|
gui_syncquickscreen_draw(qs);
|
2005-11-25 21:22:28 +00:00
|
|
|
gui_syncstatusbar_draw(&statusbars, true);
|
2006-08-15 12:27:07 +00:00
|
|
|
action_signalscreenchange();
|
2005-11-22 03:38:07 +00:00
|
|
|
while (true) {
|
2006-08-15 12:27:07 +00:00
|
|
|
button = get_action(CONTEXT_QUICKSCREEN,TIMEOUT_BLOCK);
|
2005-11-24 00:33:00 +00:00
|
|
|
if(default_event_handler(button) == SYS_USB_CONNECTED)
|
2005-11-22 03:38:07 +00:00
|
|
|
return(true);
|
2005-11-24 00:33:00 +00:00
|
|
|
if(gui_quickscreen_do_button(qs, button))
|
2005-11-22 03:38:07 +00:00
|
|
|
{
|
2005-11-22 21:55:05 +00:00
|
|
|
can_quit=true;
|
2005-11-22 03:38:07 +00:00
|
|
|
if(qs->callback)
|
|
|
|
qs->callback(qs);
|
|
|
|
gui_syncquickscreen_draw(qs);
|
|
|
|
}
|
2006-08-15 12:27:07 +00:00
|
|
|
else if(button==button_enter)
|
2005-11-22 21:55:05 +00:00
|
|
|
can_quit=true;
|
2006-08-15 12:27:07 +00:00
|
|
|
|
|
|
|
if((button == button_enter) && can_quit)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if(button==ACTION_STD_CANCEL)
|
|
|
|
break;
|
|
|
|
|
2005-11-22 03:38:07 +00:00
|
|
|
gui_syncstatusbar_draw(&statusbars, false);
|
|
|
|
}
|
2006-08-15 12:27:07 +00:00
|
|
|
action_signalscreenchange();
|
|
|
|
return false;
|
2005-11-22 03:38:07 +00:00
|
|
|
}
|
|
|
|
|
2006-04-10 03:51:17 +00:00
|
|
|
#endif /* HAVE_QUICKSCREEN */
|
2005-11-22 03:38:07 +00:00
|
|
|
|