2005-10-28 00:00:00 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
2005-10-30 01:24:35 +00:00
|
|
|
* Copyright (C) Linus Nielsen Feltzing (2002)
|
2005-10-28 00:00:00 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2005-10-30 01:24:35 +00:00
|
|
|
/*
|
|
|
|
2005 Kevin Ferrare :
|
|
|
|
- Multi screen support
|
|
|
|
- Rewrote a lot of code to avoid global vars and make it accept eventually
|
|
|
|
more that 3 buttons on the bar (just the prototype of gui_buttonbar_set
|
|
|
|
and the constant BUTTONBAR_MAX_BUTTONS to modify)
|
2008-05-29 08:59:57 +00:00
|
|
|
2008 Jonathan Gordon
|
|
|
|
- redone to use viewports, items will NOT scroll in their vp.
|
|
|
|
Bar is always drawn at the bottom of the screen. This may be changed later.
|
|
|
|
Callers need to remember to adjust their viewports to not be overwitten
|
2005-10-30 01:24:35 +00:00
|
|
|
*/
|
2005-10-28 00:00:00 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include "buttonbar.h"
|
2008-05-29 08:59:57 +00:00
|
|
|
#include "viewport.h"
|
2005-10-28 00:00:00 +00:00
|
|
|
#include "lcd.h"
|
|
|
|
#include "font.h"
|
|
|
|
#include "string.h"
|
|
|
|
#include "settings.h"
|
|
|
|
|
2008-05-29 08:59:57 +00:00
|
|
|
static struct viewport bb_vp[NB_SCREENS];
|
2005-10-28 00:00:00 +00:00
|
|
|
void gui_buttonbar_init(struct gui_buttonbar * buttonbar)
|
|
|
|
{
|
2008-05-29 08:59:57 +00:00
|
|
|
int i;
|
2005-10-28 00:00:00 +00:00
|
|
|
gui_buttonbar_unset(buttonbar);
|
2008-05-29 08:59:57 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
{
|
|
|
|
viewport_set_defaults(&bb_vp[i], i);
|
|
|
|
bb_vp[i].font = FONT_SYSFIXED;
|
|
|
|
bb_vp[i].y = screens[i].height - BUTTONBAR_HEIGHT;
|
|
|
|
bb_vp[i].height = BUTTONBAR_HEIGHT;
|
|
|
|
bb_vp[i].drawmode = DRMODE_COMPLEMENT;
|
|
|
|
}
|
2005-10-28 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void gui_buttonbar_set_display(struct gui_buttonbar * buttonbar,
|
|
|
|
struct screen * display)
|
|
|
|
{
|
|
|
|
buttonbar->display = display;
|
|
|
|
}
|
|
|
|
|
2006-12-25 14:01:47 +00:00
|
|
|
static void gui_buttonbar_draw_button(struct gui_buttonbar * buttonbar, int num)
|
2005-10-28 00:00:00 +00:00
|
|
|
{
|
2008-05-29 08:59:57 +00:00
|
|
|
int button_width;
|
|
|
|
int fh, fw;
|
2005-10-28 00:00:00 +00:00
|
|
|
struct screen * display = buttonbar->display;
|
2008-05-29 08:59:57 +00:00
|
|
|
struct viewport vp = bb_vp[display->screen_type];
|
2005-10-28 00:00:00 +00:00
|
|
|
|
|
|
|
button_width = display->width/BUTTONBAR_MAX_BUTTONS;
|
2008-05-29 08:59:57 +00:00
|
|
|
vp.width = button_width;
|
|
|
|
vp.x = button_width * num;
|
|
|
|
display->set_viewport(&vp);
|
|
|
|
display->fillrect(0, 0, button_width - 1, vp.height);
|
2005-10-28 00:00:00 +00:00
|
|
|
if(buttonbar->caption[num][0] != 0)
|
|
|
|
{
|
2008-05-29 08:59:57 +00:00
|
|
|
display->getstringsize(buttonbar->caption[num], &fw, &fh);
|
|
|
|
display->putsxy((button_width - fw)/2,
|
|
|
|
(vp.height-fh)/2, buttonbar->caption[num]);
|
2005-10-28 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void gui_buttonbar_set(struct gui_buttonbar * buttonbar,
|
|
|
|
const char *caption1,
|
|
|
|
const char *caption2,
|
|
|
|
const char *caption3)
|
|
|
|
{
|
|
|
|
gui_buttonbar_unset(buttonbar);
|
|
|
|
if(caption1)
|
|
|
|
{
|
|
|
|
strncpy(buttonbar->caption[0], caption1, 7);
|
|
|
|
buttonbar->caption[0][7] = 0;
|
|
|
|
}
|
|
|
|
if(caption2)
|
|
|
|
{
|
|
|
|
strncpy(buttonbar->caption[1], caption2, 7);
|
|
|
|
buttonbar->caption[1][7] = 0;
|
|
|
|
}
|
|
|
|
if(caption3)
|
|
|
|
{
|
|
|
|
strncpy(buttonbar->caption[2], caption3, 7);
|
|
|
|
buttonbar->caption[2][7] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void gui_buttonbar_unset(struct gui_buttonbar * buttonbar)
|
|
|
|
{
|
|
|
|
int i;
|
2005-10-28 23:52:49 +00:00
|
|
|
for(i = 0;i < BUTTONBAR_MAX_BUTTONS;i++)
|
2005-10-28 00:00:00 +00:00
|
|
|
buttonbar->caption[i][0] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gui_buttonbar_draw(struct gui_buttonbar * buttonbar)
|
|
|
|
{
|
|
|
|
struct screen * display = buttonbar->display;
|
2008-05-29 08:59:57 +00:00
|
|
|
if(!global_settings.buttonbar || !gui_buttonbar_isset(buttonbar))
|
2005-10-30 22:34:51 +00:00
|
|
|
return;
|
2005-10-28 00:00:00 +00:00
|
|
|
int i;
|
2008-05-29 08:59:57 +00:00
|
|
|
display->set_viewport(&bb_vp[display->screen_type]);
|
|
|
|
display->clear_viewport();
|
2005-10-28 23:52:49 +00:00
|
|
|
for(i = 0;i < BUTTONBAR_MAX_BUTTONS;i++)
|
2005-10-28 00:00:00 +00:00
|
|
|
gui_buttonbar_draw_button(buttonbar, i);
|
2008-05-29 08:59:57 +00:00
|
|
|
display->set_viewport(&bb_vp[display->screen_type]);
|
|
|
|
display->update_viewport();
|
|
|
|
display->set_viewport(NULL);
|
2005-10-28 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool gui_buttonbar_isset(struct gui_buttonbar * buttonbar)
|
|
|
|
{
|
|
|
|
/* If all buttons are unset, the button bar is considered disabled */
|
|
|
|
int i;
|
2005-10-28 23:52:49 +00:00
|
|
|
for(i = 0;i < BUTTONBAR_MAX_BUTTONS;i++)
|
2005-10-30 22:34:51 +00:00
|
|
|
if(buttonbar->caption[i][0] != 0)
|
2005-10-28 00:00:00 +00:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|