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
;
91 if (flags
& INVERTFILL
)
93 min_shown
= items
- max_shown
;
100 inner_ht
= height
- 2;
102 /* Boundary check to make sure that height is reasonable, otherwise nothing
105 if ((inner_wd
| inner_ht
) < 0)
108 if (flags
& HORIZONTAL
)
109 inner_len
= inner_wd
;
111 inner_len
= inner_ht
;
113 scrollbar_helper(min_shown
, max_shown
, items
, inner_len
, &size
, &start
);
116 #ifdef HAVE_LCD_COLOR
117 /* must avoid corners if case of (flags & FOREGROUND) */
118 screen
->hline(inner_x
, x
+ inner_wd
, y
);
119 screen
->hline(inner_x
, x
+ inner_wd
, y
+ height
- 1);
120 screen
->vline(x
, inner_y
, y
+ inner_ht
);
121 screen
->vline(x
+ width
- 1, inner_y
, y
+ inner_ht
);
123 screen
->drawrect(x
, y
, width
, height
);
126 screen
->set_drawmode(DRMODE_SOLID
| DRMODE_INVERSEVID
);
128 #ifdef HAVE_LCD_COLOR
129 infill
= flags
& (screen
->depth
> 1 ? INNER_FILL_MASK
: INNER_FILL
);
131 if (!(flags
& FOREGROUND
))
134 /* clear corner pixels */
135 screen
->drawpixel(x
, y
);
136 screen
->drawpixel(x
+ width
- 1, y
);
137 screen
->drawpixel(x
, y
+ height
- 1);
138 screen
->drawpixel(x
+ width
- 1, y
+ height
- 1);
140 #ifdef HAVE_LCD_COLOR
141 if (infill
!= INNER_BGFILL
)
145 if (infill
== INNER_FILL
)
148 /* clear pixels in progress bar */
149 screen
->fillrect(inner_x
, inner_y
, inner_wd
, inner_ht
);
152 screen
->set_drawmode(DRMODE_SOLID
);
154 if (flags
& INNER_NOFILL
)
157 #ifdef HAVE_LCD_COLOR
158 if (infill
== INNER_BGFILL
)
160 /* fill inner area with current background color */
161 unsigned fg
= screen
->get_foreground();
162 screen
->set_foreground(screen
->get_background());
163 screen
->fillrect(inner_x
, inner_y
, inner_wd
, inner_ht
);
164 screen
->set_foreground(fg
);
168 if (flags
& HORIZONTAL
)
179 screen
->fillrect(inner_x
, inner_y
, inner_wd
, inner_ht
);
182 void gui_bitmap_scrollbar_draw(struct screen
* screen
, struct bitmap
*bm
, int x
, int y
,
183 int width
, int height
, int items
,
184 int min_shown
, int max_shown
,
190 int startx
= 0, starty
= 0;
192 screen
->set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
194 /* clear pixels in progress bar */
195 if ((flags
&DONT_CLEAR_EXCESS
) == 0)
196 screen
->fillrect(x
, y
, width
, height
);
198 screen
->set_drawmode(DRMODE_SOLID
);
200 if (flags
& INNER_NOFILL
)
203 if (flags
& INVERTFILL
)
205 min_shown
= items
- max_shown
;
209 if (flags
& HORIZONTAL
)
214 scrollbar_helper(min_shown
, max_shown
, items
, inner_len
, &size
, &start
);
216 if (flags
& HORIZONTAL
) {
219 if (flags
& INVERTFILL
)
224 if (flags
& INVERTFILL
)
228 if (bm
->width
< startx
)
230 else if (bm
->width
< startx
+ width
)
231 width
= bm
->width
- startx
;
232 if (bm
->height
< starty
)
234 else if (bm
->height
< starty
+ height
)
235 height
= bm
->height
- starty
;
238 if (bm
->format
== FORMAT_MONO
)
240 screen
->mono_bitmap_part(bm
->data
, startx
, starty
,
241 bm
->width
, x
, y
, width
, height
);
244 screen
->transparent_bitmap_part((fb_data
*)bm
->data
, startx
, starty
,
245 STRIDE(screen
->screen_type
,
246 bm
->width
, bm
->height
),
247 x
, y
, width
, height
);
251 void show_busy_slider(struct screen
*s
, int x
, int y
, int width
, int height
)
253 static int start
= 0, dir
= 1;
254 gui_scrollbar_draw(s
, x
, y
, width
, height
, 100,
255 start
, start
+20, HORIZONTAL
);
257 if (s
->screen_type
== SCREEN_MAIN
)
268 #endif /* HAVE_LCD_BITMAP */