* removed some more unused stuff in the simulator makefile
[kugel-rb.git] / apps / recorder / widgets.c
blob4008d2b4c2d1beebd6fe438727c636f492728e96
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: not checked in
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>
21 #include "widgets.h"
23 #ifdef HAVE_LCD_BITMAP
25 /* Valid dimensions return true, invalid false */
26 bool valid_dimensions(int x, int y, int width, int height)
28 if((x < 0) || (x + width > LCD_WIDTH) ||
29 (y < 0) || (y + height > LCD_HEIGHT))
31 return false;
34 return true;
37 void init_bar(int x, int y, int width, int height)
39 /* draw box */
40 lcd_drawrect(x, y, width, height);
42 /* clear edge pixels */
43 lcd_clearpixel(x, y);
44 lcd_clearpixel((x + width - 1), y);
45 lcd_clearpixel(x, (y + height - 1));
46 lcd_clearpixel((x + width - 1), (y + height - 1));
48 /* clear pixels in progress bar */
49 lcd_clearrect(x + 1, y + 1, width - 2, height - 2);
53 * Print a progress bar
55 void progressbar(int x, int y, int width, int height, int percent,
56 int direction)
58 int pos;
60 /* check position and dimensions */
61 if (!valid_dimensions(x, y, width, height))
62 return;
64 init_bar(x, y, width, height);
66 /* draw bar */
67 pos = percent;
68 if(pos < 0)
69 pos = 0;
70 if(pos > 100)
71 pos = 100;
73 switch (direction)
75 case Grow_Right:
76 pos=(width - 2) * pos / 100;
77 lcd_fillrect(x + 1, y + 1, pos, height - 2);
78 break;
79 case Grow_Left:
80 pos=(width - 2) * (100 - pos) / 100;
81 lcd_fillrect(x + pos, y + 1, width - 1 - pos, height - 2);
82 break;
83 case Grow_Down:
84 pos=(height - 2) * pos / 100;
85 lcd_fillrect(x + 1, y + 1, width - 2, pos);
86 break;
87 case Grow_Up:
88 pos=(height - 2) * (100 - pos) / 100;
89 lcd_fillrect(x + 1, y + pos, width - 2, height - 1 - pos);
90 break;
96 * Print a slidebar bar
98 void slidebar(int x, int y, int width, int height, int percent, int direction)
100 int pos;
102 /* check position and dimensions */
103 if (!valid_dimensions(x, y, width, height))
104 return;
106 init_bar(x, y, width, height);
108 /* draw knob */
109 pos = percent;
110 if(pos < 0)
111 pos = 0;
112 if(pos > 100)
113 pos = 100;
115 switch (direction)
117 case Grow_Right:
118 pos = (width - height) * pos / 100;
119 break;
120 case Grow_Left:
121 pos=(width - height) * (100 - pos) / 100;
122 break;
123 case Grow_Down:
124 pos=(height - width) * pos / 100;
125 break;
126 case Grow_Up:
127 pos=(height - width) * (100 - pos) / 100;
128 break;
131 if(direction == Grow_Left || direction == Grow_Right)
132 lcd_fillrect(x + pos + 1, y + 1, height - 2, height - 2);
133 else
134 lcd_fillrect(x + 1, y + pos + 1, width - 2, width - 2);
139 * Print a scroll bar
141 void scrollbar(int x, int y, int width, int height, int items, int min_shown,
142 int max_shown, int orientation)
144 int min;
145 int max;
146 int start;
147 int size;
149 /* check position and dimensions */
150 if (!valid_dimensions(x, y, width, height))
151 return;
153 init_bar(x, y, width, height);
155 /* min should be min */
156 if(min_shown < max_shown) {
157 min = min_shown;
158 max = max_shown;
160 else {
161 min = max_shown;
162 max = min_shown;
165 /* limit min and max */
166 if(min < 0)
167 min = 0;
168 if(min > items)
169 min = items;
171 if(max < 0)
172 max = 0;
173 if(max > items)
174 max = items;
176 /* calc start and end of the knob */
177 if(items > 0 && items > (max - min)) {
178 if(orientation == VERTICAL) {
179 size = (height - 2) * (max - min) / items;
180 start = (height - 2 - size) * min / (items - (max - min));
182 else {
183 size = (width - 2) * (max - min) / items;
184 start = (width - 2 - size) * min / (items - (max - min));
187 else { /* if null draw a full bar */
188 start = 0;
189 if(orientation == VERTICAL)
190 size = (height - 2);
191 else
192 size = (width - 2);
195 /* knob has a width */
196 if(size != 0) {
197 if(orientation == VERTICAL)
198 lcd_fillrect(x + 1, y + start + 1, width - 2, size);
199 else
200 lcd_fillrect(x + start + 1, y + 1, size, height - 2);
202 else { /* width of knob is null */
203 if(orientation == VERTICAL) {
204 start = (height - 2 - 1) * min / items;
205 lcd_fillrect(x + 1, y + start + 1, width - 2, 1);
207 else {
208 start = (width - 2 - 1) * min / items;
209 lcd_fillrect(x + start + 1, y + 1, 1, height - 2);
215 * Print a checkbox
217 void checkbox(int x, int y, int width, int height, bool checked)
219 /* check position and dimensions */
220 if((x < 0) || (x + width > LCD_WIDTH) ||
221 (y < 0) || (y + height > LCD_HEIGHT) ||
222 (width < 4 ) || (height < 4 ))
224 return;
227 lcd_drawrect(x, y, width, height);
229 if (checked){
230 lcd_drawline(x + 2, y + 2, x + width - 2 - 1 , y + height - 2 - 1);
231 lcd_drawline(x + 2, y + height - 2 - 1, x + width - 2 - 1, y + 2);
232 } else {
233 /* be sure to clear box */
234 lcd_clearrect(x + 1, y + 1, width - 2, height - 2);
238 #endif