1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
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)
27 #include "buttonbar.h"
36 void gui_buttonbar_init(struct gui_buttonbar
* buttonbar
)
38 gui_buttonbar_unset(buttonbar
);
41 void gui_buttonbar_set_display(struct gui_buttonbar
* buttonbar
,
42 struct screen
* display
)
44 buttonbar
->display
= display
;
47 static void gui_buttonbar_draw_button(struct gui_buttonbar
* buttonbar
, int num
)
49 int xpos
, ypos
, button_width
, text_width
;
51 struct screen
* display
= buttonbar
->display
;
52 display
->getstringsize("M", NULL
, &fh
);
54 button_width
= display
->width
/BUTTONBAR_MAX_BUTTONS
;
55 xpos
= num
* button_width
;
56 ypos
= display
->height
- fh
;
58 if(buttonbar
->caption
[num
][0] != 0)
61 text_width
= display
->getstringsize(buttonbar
->caption
[num
], NULL
, NULL
);
62 display
->putsxy(xpos
+ (button_width
- text_width
)/2,
63 ypos
, buttonbar
->caption
[num
]);
66 display
->set_drawmode(DRMODE_COMPLEMENT
);
67 display
->fillrect(xpos
, ypos
, button_width
- 1, fh
);
68 display
->set_drawmode(DRMODE_SOLID
);
71 void gui_buttonbar_set(struct gui_buttonbar
* buttonbar
,
76 gui_buttonbar_unset(buttonbar
);
79 strncpy(buttonbar
->caption
[0], caption1
, 7);
80 buttonbar
->caption
[0][7] = 0;
84 strncpy(buttonbar
->caption
[1], caption2
, 7);
85 buttonbar
->caption
[1][7] = 0;
89 strncpy(buttonbar
->caption
[2], caption3
, 7);
90 buttonbar
->caption
[2][7] = 0;
94 void gui_buttonbar_unset(struct gui_buttonbar
* buttonbar
)
97 for(i
= 0;i
< BUTTONBAR_MAX_BUTTONS
;i
++)
98 buttonbar
->caption
[i
][0] = 0;
101 void gui_buttonbar_draw(struct gui_buttonbar
* buttonbar
)
103 struct screen
* display
= buttonbar
->display
;
104 screen_has_buttonbar(display
, gui_buttonbar_isset(buttonbar
));
105 if(!global_settings
.buttonbar
|| !display
->has_buttonbar
)
108 display
->setfont(FONT_SYSFIXED
);
110 display
->set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
111 display
->fillrect(0, display
->height
- BUTTONBAR_HEIGHT
,
112 display
->width
, BUTTONBAR_HEIGHT
);
113 display
->set_drawmode(DRMODE_SOLID
);
115 for(i
= 0;i
< BUTTONBAR_MAX_BUTTONS
;i
++)
116 gui_buttonbar_draw_button(buttonbar
, i
);
117 display
->update_rect(0, display
->height
- BUTTONBAR_HEIGHT
,
118 display
->width
, BUTTONBAR_HEIGHT
);
119 display
->setfont(FONT_UI
);
122 bool gui_buttonbar_isset(struct gui_buttonbar
* buttonbar
)
124 /* If all buttons are unset, the button bar is considered disabled */
126 for(i
= 0;i
< BUTTONBAR_MAX_BUTTONS
;i
++)
127 if(buttonbar
->caption
[i
][0] != 0)
132 #endif /* HAS_BUTTONBAR */