summaryrefslogtreecommitdiff
path: root/apps/gui/scrollbar.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/gui/scrollbar.c')
-rw-r--r--apps/gui/scrollbar.c106
1 files changed, 106 insertions, 0 deletions
diff --git a/apps/gui/scrollbar.c b/apps/gui/scrollbar.c
new file mode 100644
index 0000000000..9d5717f1a7
--- /dev/null
+++ b/apps/gui/scrollbar.c
@@ -0,0 +1,106 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) Markus Braun (2002), Kévin FERRARE (2005)
11 *
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.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#include "config.h"
21#include "lcd.h"
22#ifdef HAVE_LCD_BITMAP
23#include "limits.h"
24#include "scrollbar.h"
25#include "screen_access.h"
26
27void gui_scrollbar_draw(struct screen * screen, int x, int y,
28 int width, int height, int items,
29 int min_shown, int max_shown,
30 enum orientation orientation)
31{
32 int min;
33 int max;
34 int inner_len;
35 int start;
36 int size;
37
38 /* draw box */
39 screen->drawrect(x, y, width, height);
40
41 screen->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
42
43 /* clear edge pixels */
44 screen->drawpixel(x, y);
45 screen->drawpixel((x + width - 1), y);
46 screen->drawpixel(x, (y + height - 1));
47 screen->drawpixel((x + width - 1), (y + height - 1));
48
49 /* clear pixels in progress bar */
50 screen->fillrect(x + 1, y + 1, width - 2, height - 2);
51
52 /* min should be min */
53 if(min_shown < max_shown) {
54 min = min_shown;
55 max = max_shown;
56 }
57 else {
58 min = max_shown;
59 max = min_shown;
60 }
61
62 /* limit min and max */
63 if(min < 0)
64 min = 0;
65 if(min > items)
66 min = items;
67
68 if(max < 0)
69 max = 0;
70 if(max > items)
71 max = items;
72
73 if (orientation == VERTICAL)
74 inner_len = height - 2;
75 else
76 inner_len = width - 2;
77
78 /* avoid overflows */
79 while (items > (INT_MAX / inner_len)) {
80 items >>= 1;
81 min >>= 1;
82 max >>= 1;
83 }
84
85 /* calc start and end of the knob */
86 if (items > 0 && items > (max - min)) {
87 size = inner_len * (max - min) / items;
88 if (size == 0) { /* width of knob is null */
89 size = 1;
90 start = (inner_len - 1) * min / items;
91 } else {
92 start = (inner_len - size) * min / (items - (max - min));
93 }
94 } else { /* if null draw full bar */
95 size = inner_len;
96 start = 0;
97 }
98
99 screen->set_drawmode(DRMODE_SOLID);
100
101 if(orientation == VERTICAL)
102 screen->fillrect(x + 1, y + start + 1, width - 2, size);
103 else
104 screen->fillrect(x + start + 1, y + 1, size, height - 2);
105}
106#endif /* HAVE_LCD_BITMAP */