Reorder some operands to increase frequency of multiply early termination on TDMI...
[kugel-rb.git] / apps / gui / buttonbar.c
blobabf1800bb2d66e8055348bb030ebe7aeb27a5981
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.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 strncpy(buttonbar->caption[0], caption1, 7);
90 buttonbar->caption[0][7] = 0;
92 if(caption2)
94 strncpy(buttonbar->caption[1], caption2, 7);
95 buttonbar->caption[1][7] = 0;
97 if(caption3)
99 strncpy(buttonbar->caption[2], caption3, 7);
100 buttonbar->caption[2][7] = 0;
104 void gui_buttonbar_unset(struct gui_buttonbar * buttonbar)
106 int i;
107 for(i = 0;i < BUTTONBAR_MAX_BUTTONS;i++)
108 buttonbar->caption[i][0] = 0;
111 void gui_buttonbar_draw(struct gui_buttonbar * buttonbar)
113 struct screen * display = buttonbar->display;
114 if(!global_settings.buttonbar || !gui_buttonbar_isset(buttonbar))
115 return;
116 int i;
117 display->set_viewport(&bb_vp[display->screen_type]);
118 display->clear_viewport();
119 for(i = 0;i < BUTTONBAR_MAX_BUTTONS;i++)
120 gui_buttonbar_draw_button(buttonbar, i);
121 display->set_viewport(&bb_vp[display->screen_type]);
122 display->update_viewport();
123 display->set_viewport(NULL);
126 bool gui_buttonbar_isset(struct gui_buttonbar * buttonbar)
128 /* If all buttons are unset, the button bar is considered disabled */
129 int i;
130 for(i = 0;i < BUTTONBAR_MAX_BUTTONS;i++)
131 if(buttonbar->caption[i][0] != 0)
132 return true;
133 return false;