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.c91
1 files changed, 91 insertions, 0 deletions
diff --git a/apps/gui/scrollbar.c b/apps/gui/scrollbar.c
index 73c523f56a..4cf92f4b47 100644
--- a/apps/gui/scrollbar.c
+++ b/apps/gui/scrollbar.c
@@ -21,6 +21,7 @@
21#ifdef HAVE_LCD_BITMAP 21#ifdef HAVE_LCD_BITMAP
22#include "config.h" 22#include "config.h"
23#include "limits.h" 23#include "limits.h"
24#include "bmp.h"
24 25
25void gui_scrollbar_draw(struct screen * screen, int x, int y, 26void gui_scrollbar_draw(struct screen * screen, int x, int y,
26 int width, int height, int items, 27 int width, int height, int items,
@@ -101,4 +102,94 @@ void gui_scrollbar_draw(struct screen * screen, int x, int y,
101 else 102 else
102 screen->fillrect(x + start + 1, y + 1, size, height - 2); 103 screen->fillrect(x + start + 1, y + 1, size, height - 2);
103} 104}
105
106void gui_bitmap_scrollbar_draw(struct screen * screen, struct bitmap bm, int x, int y,
107 int width, int height, int items,
108 int min_shown, int max_shown,
109 enum orientation orientation)
110{
111 int min;
112 int max;
113 int inner_len;
114 int start;
115 int size;
116
117 screen->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
118
119 /* clear pixels in progress bar */
120 screen->fillrect(x, y, width, height);
121
122 /* min should be min */
123 if(min_shown < max_shown) {
124 min = min_shown;
125 max = max_shown;
126 }
127 else {
128 min = max_shown;
129 max = min_shown;
130 }
131
132 /* limit min and max */
133 if(min < 0)
134 min = 0;
135 if(min > items)
136 min = items;
137
138 if(max < 0)
139 max = 0;
140 if(max > items)
141 max = items;
142
143 if (orientation == VERTICAL)
144 inner_len = height;
145 else
146 inner_len = width;
147
148 /* avoid overflows */
149 while (items > (INT_MAX / inner_len)) {
150 items >>= 1;
151 min >>= 1;
152 max >>= 1;
153 }
154
155 /* calc start and end of the knob */
156 if (items > 0 && items > (max - min)) {
157 size = inner_len * (max - min) / items;
158 if (size == 0) { /* width of knob is null */
159 size = 1;
160 start = (inner_len - 1) * min / items;
161 } else {
162 start = (inner_len - size) * min / (items - (max - min));
163 }
164 } else { /* if null draw full bar */
165 size = inner_len;
166 start = 0;
167 }
168
169 screen->set_drawmode(DRMODE_SOLID);
170
171 if(orientation == VERTICAL) {
172#if LCD_DEPTH > 1
173 if (bm.format == FORMAT_MONO)
174#endif
175 screen->mono_bitmap_part(bm.data, 0, 0,
176 bm.width, x, y + start, width, size);
177#if LCD_DEPTH > 1
178 else
179 screen->transparent_bitmap_part((fb_data *)bm.data, 0, 0,
180 bm.width, x, y + start, width, size);
181#endif
182 } else {
183#if LCD_DEPTH > 1
184 if (bm.format == FORMAT_MONO)
185#endif
186 screen->mono_bitmap_part(bm.data, 0, 0,
187 bm.width, x + start, y, size, height);
188#if LCD_DEPTH > 1
189 else
190 screen->transparent_bitmap_part((fb_data *)bm.data, 0, 0,
191 bm.width, x + start, y, size, height);
192#endif
193 }
194}
104#endif /* HAVE_LCD_BITMAP */ 195#endif /* HAVE_LCD_BITMAP */