Update Beast installation instructions to use beastpatcher and remove instructions...
[kugel-rb.git] / apps / gui / scrollbar.c
blob0cb3602d11185a7a2345f134162143d50f2de26a
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) Markus Braun (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 #include "scrollbar.h"
23 #ifdef HAVE_LCD_BITMAP
24 #include "config.h"
25 #include "limits.h"
26 #include "bmp.h"
28 /* calculates the start and size of the knob */
29 static void scrollbar_helper(int min_shown, int max_shown, int items,
30 int inner_len, int *size, int *start)
32 int min, max, range;
34 /* min should be min */
35 if(min_shown < max_shown) {
36 min = min_shown;
37 max = max_shown;
39 else {
40 min = max_shown;
41 max = min_shown;
44 /* limit min and max */
45 if(min < 0)
46 min = 0;
47 if(min > items)
48 min = items;
50 if(max < 0)
51 max = 0;
52 if(max > items)
53 max = items;
55 range = max - min;
57 /* avoid overflows */
58 while (items > (INT_MAX / inner_len)) {
59 items >>= 1;
60 range >>= 1;
63 /* calc start and end of the knob */
64 if (items > 0 && items > range) {
65 *size = inner_len * range / items;
66 if (*size == 0) { /* width of knob is null */
67 *size = 1;
68 *start = (inner_len - 1) * min / items;
69 } else {
70 *start = (inner_len - *size) * min / (items - range);
72 } else { /* if null draw full bar */
73 *size = inner_len;
74 *start = 0;
77 return;
80 void gui_scrollbar_draw(struct screen * screen, int x, int y,
81 int width, int height, int items,
82 int min_shown, int max_shown,
83 unsigned flags)
85 int inner_x, inner_y, inner_wd, inner_ht, inner_len;
86 int start, size;
87 #ifdef HAVE_LCD_COLOR
88 int infill;
89 #endif
91 inner_x = x + 1;
92 inner_y = y + 1;
93 inner_wd = width - 2;
94 inner_ht = height - 2;
96 if (flags & HORIZONTAL)
97 inner_len = inner_wd;
98 else
99 inner_len = inner_ht;
101 scrollbar_helper(min_shown, max_shown, items, inner_len, &size, &start);
103 /* draw box */
104 #ifdef HAVE_LCD_COLOR
105 /* must avoid corners if case of (flags & FOREGROUND) */
106 screen->hline(inner_x, x + inner_wd, y);
107 screen->hline(inner_x, x + inner_wd, y + height - 1);
108 screen->vline(x, inner_y, y + inner_ht);
109 screen->vline(x + width - 1, inner_y, y + inner_ht);
110 #else
111 screen->drawrect(x, y, width, height);
112 #endif
114 screen->set_drawmode(DRMODE_SOLID | DRMODE_INVERSEVID);
116 #ifdef HAVE_LCD_COLOR
117 infill = flags & (screen->depth > 1 ? INNER_FILL_MASK : INNER_FILL);
119 if (!(flags & FOREGROUND))
121 #endif
122 /* clear corner pixels */
123 screen->drawpixel(x, y);
124 screen->drawpixel(x + width - 1, y);
125 screen->drawpixel(x, y + height - 1);
126 screen->drawpixel(x + width - 1, y + height - 1);
128 #ifdef HAVE_LCD_COLOR
129 if (infill != INNER_BGFILL)
130 infill = INNER_FILL;
133 if (infill == INNER_FILL)
134 #endif
136 /* clear pixels in progress bar */
137 screen->fillrect(inner_x, inner_y, inner_wd, inner_ht);
140 screen->set_drawmode(DRMODE_SOLID);
142 #ifdef HAVE_LCD_COLOR
143 if (infill == INNER_BGFILL)
145 /* fill inner area with current background color */
146 unsigned fg = screen->get_foreground();
147 screen->set_foreground(screen->get_background());
148 screen->fillrect(inner_x, inner_y, inner_wd, inner_ht);
149 screen->set_foreground(fg);
151 #endif
153 if (flags & HORIZONTAL)
155 inner_x += start;
156 inner_wd = size;
158 else
160 inner_y += start;
161 inner_ht = size;
164 screen->fillrect(inner_x, inner_y, inner_wd, inner_ht);
167 void gui_bitmap_scrollbar_draw(struct screen * screen, struct bitmap bm, int x, int y,
168 int width, int height, int items,
169 int min_shown, int max_shown,
170 unsigned flags)
172 int start;
173 int size;
174 int inner_len;
176 screen->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
178 /* clear pixels in progress bar */
179 screen->fillrect(x, y, width, height);
181 if (flags & HORIZONTAL)
182 inner_len = width;
183 else
184 inner_len = height;
186 scrollbar_helper(min_shown, max_shown, items, inner_len, &size, &start);
188 screen->set_drawmode(DRMODE_SOLID);
190 if (flags & HORIZONTAL) {
191 #if LCD_DEPTH > 1
192 if (bm.format == FORMAT_MONO)
193 #endif
194 screen->mono_bitmap_part(bm.data, 0, 0,
195 bm.width, x + start, y, size, height);
196 #if LCD_DEPTH > 1
197 else
198 screen->transparent_bitmap_part((fb_data *)bm.data, 0, 0,
199 bm.width, x + start, y, size, height);
200 #endif
201 } else {
202 #if LCD_DEPTH > 1
203 if (bm.format == FORMAT_MONO)
204 #endif
205 screen->mono_bitmap_part(bm.data, 0, 0,
206 bm.width, x, y + start, width, size);
207 #if LCD_DEPTH > 1
208 else
209 screen->transparent_bitmap_part((fb_data *)bm.data, 0, 0,
210 bm.width, x, y + start, width, size);
211 #endif
215 void show_busy_slider(struct screen *s, int x, int y, int width, int height)
217 static int start = 0, dir = 1;
218 gui_scrollbar_draw(s, x, y, width, height, 100,
219 start, start+20, HORIZONTAL);
220 #if NB_SCREENS > 1
221 if (s->screen_type == SCREEN_MAIN)
223 #endif
224 start += (dir*2);
225 if (start > 79)
226 dir = -1;
227 else if (start < 1)
228 dir = 1;
229 #if NB_SCREENS > 1
231 #endif
234 #endif /* HAVE_LCD_BITMAP */