1
0
Fork 0
forked from len0rd/rockbox

scrollbar(): Code size optimisation; fixed overflow with large parameters (fixes seek position display in video.rock with large files).

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5566 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Jens Arnold 2005-01-16 00:14:55 +00:00
parent 4666f7e0d9
commit 166f7a2fe0

View file

@ -17,6 +17,7 @@
* *
****************************************************************************/ ****************************************************************************/
#include <lcd.h> #include <lcd.h>
#include <limits.h>
#include "widgets.h" #include "widgets.h"
@ -42,6 +43,7 @@ void scrollbar(int x, int y, int width, int height, int items, int min_shown,
{ {
int min; int min;
int max; int max;
int inner_len;
int start; int start;
int size; int size;
@ -82,42 +84,37 @@ void scrollbar(int x, int y, int width, int height, int items, int min_shown,
if(max > items) if(max > items)
max = items; max = items;
/* calc start and end of the knob */ if (orientation == VERTICAL)
if(items > 0 && items > (max - min)) { inner_len = height - 2;
if(orientation == VERTICAL) { else
size = (height - 2) * (max - min) / items; inner_len = width - 2;
start = (height - 2 - size) * min / (items - (max - min));
} /* avoid overflows */
else { while (items > (INT_MAX / inner_len)) {
size = (width - 2) * (max - min) / items; items >>= 1;
start = (width - 2 - size) * min / (items - (max - min)); min >>= 1;
} max >>= 1;
}
else { /* if null draw a full bar */
start = 0;
if(orientation == VERTICAL)
size = (height - 2);
else
size = (width - 2);
} }
/* knob has a width */ /* calc start and end of the knob */
if(size != 0) { if(items > 0 && items > (max - min)) {
if(orientation == VERTICAL) size = inner_len * (max - min) / items;
lcd_fillrect(x + 1, y + start + 1, width - 2, size); start = (inner_len - size) * min / (items - (max - min));
else
lcd_fillrect(x + start + 1, y + 1, size, height - 2);
} }
else { /* width of knob is null */ else { /* if null draw a full bar */
if(orientation == VERTICAL) { size = inner_len;
start = (height - 2 - 1) * min / items; start = 0;
lcd_fillrect(x + 1, y + start + 1, width - 2, 1);
}
else {
start = (width - 2 - 1) * min / items;
lcd_fillrect(x + start + 1, y + 1, 1, height - 2);
}
} }
/* width of knob is null */
if(size == 0) {
start = (inner_len - 1) * min / items;
size = 1;
}
if(orientation == VERTICAL)
lcd_fillrect(x + 1, y + start + 1, width - 2, size);
else
lcd_fillrect(x + start + 1, y + 1, size, height - 2);
} }
/* /*