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 /* Boundary check to make sure that height is reasonable, otherwise nothing
99 if ((inner_wd
| inner_ht
) < 0)
102 if (flags
& HORIZONTAL
)
103 inner_len
= inner_wd
;
105 inner_len
= inner_ht
;
107 scrollbar_helper(min_shown
, max_shown
, items
, inner_len
, &size
, &start
);
110 #ifdef HAVE_LCD_COLOR
111 /* must avoid corners if case of (flags & FOREGROUND) */
112 screen
->hline(inner_x
, x
+ inner_wd
, y
);
113 screen
->hline(inner_x
, x
+ inner_wd
, y
+ height
- 1);
114 screen
->vline(x
, inner_y
, y
+ inner_ht
);
115 screen
->vline(x
+ width
- 1, inner_y
, y
+ inner_ht
);
117 screen
->drawrect(x
, y
, width
, height
);
120 screen
->set_drawmode(DRMODE_SOLID
| DRMODE_INVERSEVID
);
122 #ifdef HAVE_LCD_COLOR
123 infill
= flags
& (screen
->depth
> 1 ? INNER_FILL_MASK
: INNER_FILL
);
125 if (!(flags
& FOREGROUND
))
128 /* clear corner pixels */
129 screen
->drawpixel(x
, y
);
130 screen
->drawpixel(x
+ width
- 1, y
);
131 screen
->drawpixel(x
, y
+ height
- 1);
132 screen
->drawpixel(x
+ width
- 1, y
+ height
- 1);
134 #ifdef HAVE_LCD_COLOR
135 if (infill
!= INNER_BGFILL
)
139 if (infill
== INNER_FILL
)
142 /* clear pixels in progress bar */
143 screen
->fillrect(inner_x
, inner_y
, inner_wd
, inner_ht
);
146 screen
->set_drawmode(DRMODE_SOLID
);
148 #ifdef HAVE_LCD_COLOR
149 if (infill
== INNER_BGFILL
)
151 /* fill inner area with current background color */
152 unsigned fg
= screen
->get_foreground();
153 screen
->set_foreground(screen
->get_background());
154 screen
->fillrect(inner_x
, inner_y
, inner_wd
, inner_ht
);
155 screen
->set_foreground(fg
);
159 if (flags
& HORIZONTAL
)
170 screen
->fillrect(inner_x
, inner_y
, inner_wd
, inner_ht
);
173 void gui_bitmap_scrollbar_draw(struct screen
* screen
, struct bitmap bm
, int x
, int y
,
174 int width
, int height
, int items
,
175 int min_shown
, int max_shown
,
182 screen
->set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
184 /* clear pixels in progress bar */
185 screen
->fillrect(x
, y
, width
, height
);
187 if (flags
& HORIZONTAL
)
192 scrollbar_helper(min_shown
, max_shown
, items
, inner_len
, &size
, &start
);
194 screen
->set_drawmode(DRMODE_SOLID
);
196 if (flags
& HORIZONTAL
) {
205 if (bm
.format
== FORMAT_MONO
)
207 screen
->mono_bitmap_part(bm
.data
, 0, 0,
208 bm
.width
, x
, y
, width
, height
);
211 screen
->transparent_bitmap_part((fb_data
*)bm
.data
, 0, 0,
212 STRIDE(screen
->screen_type
,
213 bm
.width
, bm
.height
),
214 x
, y
, width
, height
);
218 void show_busy_slider(struct screen
*s
, int x
, int y
, int width
, int height
)
220 static int start
= 0, dir
= 1;
221 gui_scrollbar_draw(s
, x
, y
, width
, height
, 100,
222 start
, start
+20, HORIZONTAL
);
224 if (s
->screen_type
== SCREEN_MAIN
)
235 #endif /* HAVE_LCD_BITMAP */