copy the images for the skins.
[kugel-rb.git] / apps / gui / buttonbar.c
blob84d49464c0d99515cfd91b85f8824abf130ee723
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) Linus Nielsen Feltzing (2002)
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 2005 Kevin Ferrare :
23 - Multi screen support
24 - Rewrote a lot of code to avoid global vars and make it accept eventually
25 more that 3 buttons on the bar (just the prototype of gui_buttonbar_set
26 and the constant BUTTONBAR_MAX_BUTTONS to modify)
27 2008 Jonathan Gordon
28 - redone to use viewports, items will NOT scroll in their vp.
29 Bar is always drawn at the bottom of the screen. This may be changed later.
30 Callers need to remember to adjust their viewports to not be overwitten
32 #include "config.h"
33 #include "buttonbar.h"
34 #include "viewport.h"
35 #include "lcd.h"
36 #include "font.h"
37 #include "string-extra.h"
38 #include "settings.h"
40 static struct viewport bb_vp[NB_SCREENS];
41 void gui_buttonbar_init(struct gui_buttonbar * buttonbar)
43 int i;
44 gui_buttonbar_unset(buttonbar);
45 FOR_NB_SCREENS(i)
47 viewport_set_defaults(&bb_vp[i], i);
48 bb_vp[i].font = FONT_SYSFIXED;
49 bb_vp[i].y = screens[i].lcdheight - BUTTONBAR_HEIGHT;
50 bb_vp[i].height = BUTTONBAR_HEIGHT;
51 bb_vp[i].drawmode = DRMODE_COMPLEMENT;
55 void gui_buttonbar_set_display(struct gui_buttonbar * buttonbar,
56 struct screen * display)
58 buttonbar->display = display;
61 static void gui_buttonbar_draw_button(struct gui_buttonbar * buttonbar, int num)
63 int button_width;
64 int fh, fw;
65 struct screen * display = buttonbar->display;
66 struct viewport vp = bb_vp[display->screen_type];
68 button_width = display->lcdwidth/BUTTONBAR_MAX_BUTTONS;
69 vp.width = button_width;
70 vp.x = button_width * num;
71 display->set_viewport(&vp);
72 display->fillrect(0, 0, button_width - 1, vp.height);
73 if(buttonbar->caption[num][0] != 0)
75 display->getstringsize(buttonbar->caption[num], &fw, &fh);
76 display->putsxy((button_width - fw)/2,
77 (vp.height-fh)/2, buttonbar->caption[num]);
81 void gui_buttonbar_set(struct gui_buttonbar * buttonbar,
82 const char *caption1,
83 const char *caption2,
84 const char *caption3)
86 gui_buttonbar_unset(buttonbar);
87 if(caption1)
89 strlcpy(buttonbar->caption[0], caption1, BUTTONBAR_CAPTION_LENGTH);
91 if(caption2)
93 strlcpy(buttonbar->caption[1], caption2, BUTTONBAR_CAPTION_LENGTH);
95 if(caption3)
97 strlcpy(buttonbar->caption[2], caption3, BUTTONBAR_CAPTION_LENGTH);
101 void gui_buttonbar_unset(struct gui_buttonbar * buttonbar)
103 int i;
104 for(i = 0;i < BUTTONBAR_MAX_BUTTONS;i++)
105 buttonbar->caption[i][0] = 0;
108 void gui_buttonbar_draw(struct gui_buttonbar * buttonbar)
110 struct screen * display = buttonbar->display;
111 if(!global_settings.buttonbar || !gui_buttonbar_isset(buttonbar))
112 return;
113 int i;
114 display->set_viewport(&bb_vp[display->screen_type]);
115 display->clear_viewport();
116 for(i = 0;i < BUTTONBAR_MAX_BUTTONS;i++)
117 gui_buttonbar_draw_button(buttonbar, i);
118 display->set_viewport(&bb_vp[display->screen_type]);
119 display->update_viewport();
120 display->set_viewport(NULL);
123 bool gui_buttonbar_isset(struct gui_buttonbar * buttonbar)
125 /* If all buttons are unset, the button bar is considered disabled */
126 int i;
127 for(i = 0;i < BUTTONBAR_MAX_BUTTONS;i++)
128 if(buttonbar->caption[i][0] != 0)
129 return true;
130 return false;