1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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
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
)
34 /* min should be min */
35 if(min_shown
< max_shown
) {
44 /* limit min and max */
58 while (items
> (INT_MAX
/ inner_len
)) {
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 */
68 *start
= (inner_len
- 1) * min
/ items
;
70 *start
= (inner_len
- *size
) * min
/ (items
- range
);
72 } else { /* if null draw full bar */
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
,
85 int inner_x
, inner_y
, inner_wd
, inner_ht
, inner_len
;
94 inner_ht
= height
- 2;
96 if (flags
& HORIZONTAL
)
101 scrollbar_helper(min_shown
, max_shown
, items
, inner_len
, &size
, &start
);
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
);
111 screen
->drawrect(x
, y
, width
, height
);
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
))
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
)
133 if (infill
== INNER_FILL
)
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
);
153 if (flags
& HORIZONTAL
)
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
,
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
)
186 scrollbar_helper(min_shown
, max_shown
, items
, inner_len
, &size
, &start
);
188 screen
->set_drawmode(DRMODE_SOLID
);
190 if (flags
& HORIZONTAL
) {
192 if (bm
.format
== FORMAT_MONO
)
194 screen
->mono_bitmap_part(bm
.data
, 0, 0,
195 bm
.width
, x
+ start
, y
, size
, height
);
198 screen
->transparent_bitmap_part((fb_data
*)bm
.data
, 0, 0,
199 bm
.width
, x
+ start
, y
, size
, height
);
203 if (bm
.format
== FORMAT_MONO
)
205 screen
->mono_bitmap_part(bm
.data
, 0, 0,
206 bm
.width
, x
, y
+ start
, width
, size
);
209 screen
->transparent_bitmap_part((fb_data
*)bm
.data
, 0, 0,
210 bm
.width
, x
, y
+ start
, width
, size
);
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
);
221 if (s
->screen_type
== SCREEN_MAIN
)
234 #endif /* HAVE_LCD_BITMAP */