diff options
author | Jens Arnold <amiconn@rockbox.org> | 2005-01-16 00:14:55 +0000 |
---|---|---|
committer | Jens Arnold <amiconn@rockbox.org> | 2005-01-16 00:14:55 +0000 |
commit | 166f7a2fe015dda37b3b1fa7a7070189493cde05 (patch) | |
tree | 928737f36eb62813c175745ee575db644b991858 /apps/recorder | |
parent | 4666f7e0d9abc96fefa57838452bec1e321ef3e0 (diff) | |
download | rockbox-166f7a2fe015dda37b3b1fa7a7070189493cde05.tar.gz rockbox-166f7a2fe015dda37b3b1fa7a7070189493cde05.zip |
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
Diffstat (limited to 'apps/recorder')
-rw-r--r-- | apps/recorder/widgets.c | 55 |
1 files changed, 26 insertions, 29 deletions
diff --git a/apps/recorder/widgets.c b/apps/recorder/widgets.c index 7ac647024a..5c608bcb6b 100644 --- a/apps/recorder/widgets.c +++ b/apps/recorder/widgets.c @@ -17,6 +17,7 @@ * ****************************************************************************/ #include <lcd.h> +#include <limits.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 max; + int inner_len; int start; int size; @@ -82,42 +84,37 @@ void scrollbar(int x, int y, int width, int height, int items, int min_shown, if(max > items) max = items; + if (orientation == VERTICAL) + inner_len = height - 2; + else + inner_len = width - 2; + + /* avoid overflows */ + while (items > (INT_MAX / inner_len)) { + items >>= 1; + min >>= 1; + max >>= 1; + } + /* calc start and end of the knob */ if(items > 0 && items > (max - min)) { - if(orientation == VERTICAL) { - size = (height - 2) * (max - min) / items; - start = (height - 2 - size) * min / (items - (max - min)); - } - else { - size = (width - 2) * (max - min) / items; - start = (width - 2 - size) * min / (items - (max - min)); - } + size = inner_len * (max - min) / items; + start = (inner_len - size) * min / (items - (max - min)); } else { /* if null draw a full bar */ + size = inner_len; start = 0; - if(orientation == VERTICAL) - size = (height - 2); - else - size = (width - 2); } - - /* knob has a width */ - if(size != 0) { - if(orientation == VERTICAL) - lcd_fillrect(x + 1, y + start + 1, width - 2, size); - else - lcd_fillrect(x + start + 1, y + 1, size, height - 2); - } - else { /* width of knob is null */ - if(orientation == VERTICAL) { - start = (height - 2 - 1) * min / items; - 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); } /* |