implement smooth seeking acceleration for audio playback and mpegplayer
[Rockbox.git] / apps / gui / buttonbar.c
blobce03c82a696fa4c4ccab3a6c67041387533d9f28
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) Linus Nielsen Feltzing (2002)
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 2005 Kevin Ferrare :
21 - Multi screen support
22 - Rewrote a lot of code to avoid global vars and make it accept eventually
23 more that 3 buttons on the bar (just the prototype of gui_buttonbar_set
24 and the constant BUTTONBAR_MAX_BUTTONS to modify)
25 2008 Jonathan Gordon
26 - redone to use viewports, items will NOT scroll in their vp.
27 Bar is always drawn at the bottom of the screen. This may be changed later.
28 Callers need to remember to adjust their viewports to not be overwitten
30 #include "config.h"
31 #include "buttonbar.h"
32 #include "viewport.h"
33 #include "lcd.h"
34 #include "font.h"
35 #include "string.h"
36 #include "settings.h"
38 static struct viewport bb_vp[NB_SCREENS];
39 void gui_buttonbar_init(struct gui_buttonbar * buttonbar)
41 int i;
42 gui_buttonbar_unset(buttonbar);
43 FOR_NB_SCREENS(i)
45 viewport_set_defaults(&bb_vp[i], i);
46 bb_vp[i].font = FONT_SYSFIXED;
47 bb_vp[i].y = screens[i].height - BUTTONBAR_HEIGHT;
48 bb_vp[i].height = BUTTONBAR_HEIGHT;
49 bb_vp[i].drawmode = DRMODE_COMPLEMENT;
53 void gui_buttonbar_set_display(struct gui_buttonbar * buttonbar,
54 struct screen * display)
56 buttonbar->display = display;
59 static void gui_buttonbar_draw_button(struct gui_buttonbar * buttonbar, int num)
61 int button_width;
62 int fh, fw;
63 struct screen * display = buttonbar->display;
64 struct viewport vp = bb_vp[display->screen_type];
66 button_width = display->width/BUTTONBAR_MAX_BUTTONS;
67 vp.width = button_width;
68 vp.x = button_width * num;
69 display->set_viewport(&vp);
70 display->fillrect(0, 0, button_width - 1, vp.height);
71 if(buttonbar->caption[num][0] != 0)
73 display->getstringsize(buttonbar->caption[num], &fw, &fh);
74 display->putsxy((button_width - fw)/2,
75 (vp.height-fh)/2, buttonbar->caption[num]);
79 void gui_buttonbar_set(struct gui_buttonbar * buttonbar,
80 const char *caption1,
81 const char *caption2,
82 const char *caption3)
84 gui_buttonbar_unset(buttonbar);
85 if(caption1)
87 strncpy(buttonbar->caption[0], caption1, 7);
88 buttonbar->caption[0][7] = 0;
90 if(caption2)
92 strncpy(buttonbar->caption[1], caption2, 7);
93 buttonbar->caption[1][7] = 0;
95 if(caption3)
97 strncpy(buttonbar->caption[2], caption3, 7);
98 buttonbar->caption[2][7] = 0;
102 void gui_buttonbar_unset(struct gui_buttonbar * buttonbar)
104 int i;
105 for(i = 0;i < BUTTONBAR_MAX_BUTTONS;i++)
106 buttonbar->caption[i][0] = 0;
109 void gui_buttonbar_draw(struct gui_buttonbar * buttonbar)
111 struct screen * display = buttonbar->display;
112 if(!global_settings.buttonbar || !gui_buttonbar_isset(buttonbar))
113 return;
114 int i;
115 display->set_viewport(&bb_vp[display->screen_type]);
116 display->clear_viewport();
117 for(i = 0;i < BUTTONBAR_MAX_BUTTONS;i++)
118 gui_buttonbar_draw_button(buttonbar, i);
119 display->set_viewport(&bb_vp[display->screen_type]);
120 display->update_viewport();
121 display->set_viewport(NULL);
124 bool gui_buttonbar_isset(struct gui_buttonbar * buttonbar)
126 /* If all buttons are unset, the button bar is considered disabled */
127 int i;
128 for(i = 0;i < BUTTONBAR_MAX_BUTTONS;i++)
129 if(buttonbar->caption[i][0] != 0)
130 return true;
131 return false;