1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
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)
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
33 #include "buttonbar.h"
40 static struct viewport bb_vp
[NB_SCREENS
];
41 void gui_buttonbar_init(struct gui_buttonbar
* buttonbar
)
44 gui_buttonbar_unset(buttonbar
);
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
)
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
,
86 gui_buttonbar_unset(buttonbar
);
89 strlcpy(buttonbar
->caption
[0], caption1
, BUTTONBAR_CAPTION_LENGTH
);
93 strlcpy(buttonbar
->caption
[1], caption2
, BUTTONBAR_CAPTION_LENGTH
);
97 strlcpy(buttonbar
->caption
[2], caption3
, BUTTONBAR_CAPTION_LENGTH
);
101 void gui_buttonbar_unset(struct gui_buttonbar
* buttonbar
)
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
))
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 */
127 for(i
= 0;i
< BUTTONBAR_MAX_BUTTONS
;i
++)
128 if(buttonbar
->caption
[i
][0] != 0)