HAVE_ADJUSTABLE_CPU_FREQ isn't defined for simulators, so we don't have to check...
[Rockbox.git] / apps / recorder / widgets.c
blob278917da4f31ca3ce672a3b851d3ef29cb503ae4
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Markus Braun
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 ****************************************************************************/
19 #include <lcd.h>
20 #include <limits.h>
22 #include "widgets.h"
24 #ifdef HAVE_LCD_BITMAP
27 * Print a scroll bar
29 void scrollbar(int x, int y, int width, int height, int items, int min_shown,
30 int max_shown, int orientation)
32 int min;
33 int max;
34 int inner_len;
35 int start;
36 int size;
38 /* draw box */
39 lcd_drawrect(x, y, width, height);
41 lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
43 /* clear edge pixels */
44 lcd_drawpixel(x, y);
45 lcd_drawpixel((x + width - 1), y);
46 lcd_drawpixel(x, (y + height - 1));
47 lcd_drawpixel((x + width - 1), (y + height - 1));
49 /* clear pixels in progress bar */
50 lcd_fillrect(x + 1, y + 1, width - 2, height - 2);
52 /* min should be min */
53 if(min_shown < max_shown) {
54 min = min_shown;
55 max = max_shown;
57 else {
58 min = max_shown;
59 max = min_shown;
62 /* limit min and max */
63 if(min < 0)
64 min = 0;
65 if(min > items)
66 min = items;
68 if(max < 0)
69 max = 0;
70 if(max > items)
71 max = items;
73 if (orientation == VERTICAL)
74 inner_len = height - 2;
75 else
76 inner_len = width - 2;
78 /* avoid overflows */
79 while (items > (INT_MAX / inner_len)) {
80 items >>= 1;
81 min >>= 1;
82 max >>= 1;
85 /* calc start and end of the knob */
86 if (items > 0 && items > (max - min)) {
87 size = inner_len * (max - min) / items;
88 if (size == 0) { /* width of knob is null */
89 size = 1;
90 start = (inner_len - 1) * min / items;
91 } else {
92 start = (inner_len - size) * min / (items - (max - min));
94 } else { /* if null draw full bar */
95 size = inner_len;
96 start = 0;
99 lcd_set_drawmode(DRMODE_SOLID);
101 if(orientation == VERTICAL)
102 lcd_fillrect(x + 1, y + start + 1, width - 2, size);
103 else
104 lcd_fillrect(x + start + 1, y + 1, size, height - 2);
108 * Print a checkbox
110 void checkbox(int x, int y, int width, int height, bool checked)
112 /* draw box */
113 lcd_drawrect(x, y, width, height);
115 /* clear inner area */
116 lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
117 lcd_fillrect(x + 1, y + 1, width - 2, height - 2);
118 lcd_set_drawmode(DRMODE_SOLID);
120 if (checked){
121 lcd_drawline(x + 2, y + 2, x + width - 2 - 1 , y + height - 2 - 1);
122 lcd_drawline(x + 2, y + height - 2 - 1, x + width - 2 - 1, y + 2);
126 #endif