From a6eb0f6669c26a99cb634702351c0757c4aea0b0 Mon Sep 17 00:00:00 2001 From: Jens Arnold Date: Tue, 23 Aug 2005 22:06:15 +0000 Subject: Widgets: Reduced code size by not checking coordinate boundaries, as current lcd code handles clipping. Optimised calculation of scrollbar know position/size. Always clear inner part of checkbox. Removed old progressbar/slidebar direction enum. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7394 a1c6a512-1295-4272-9138-f99709370657 --- apps/recorder/widgets.c | 56 ++++++++++++++----------------------------------- apps/recorder/widgets.h | 8 ------- 2 files changed, 16 insertions(+), 48 deletions(-) (limited to 'apps/recorder') diff --git a/apps/recorder/widgets.c b/apps/recorder/widgets.c index 09daf87fd3..480592bf7d 100644 --- a/apps/recorder/widgets.c +++ b/apps/recorder/widgets.c @@ -23,18 +23,6 @@ #ifdef HAVE_LCD_BITMAP -/* Valid dimensions return true, invalid false */ -static bool valid_dimensions(int x, int y, int width, int height) -{ - if((x < 0) || (x + width > LCD_WIDTH) || - (y < 0) || (y + height > LCD_HEIGHT)) - { - return false; - } - - return true; -} - /* * Print a scroll bar */ @@ -47,10 +35,6 @@ void scrollbar(int x, int y, int width, int height, int items, int min_shown, int start; int size; - /* check position and dimensions */ - if (!valid_dimensions(x, y, width, height)) - return; - /* draw box */ lcd_drawrect(x, y, width, height); @@ -66,7 +50,7 @@ void scrollbar(int x, int y, int width, int height, int items, int min_shown, lcd_fillrect(x + 1, y + 1, width - 2, height - 2); /* min should be min */ - if(min_shown < max_shown) { + if(min_shown < max_shown) { min = min_shown; max = max_shown; } @@ -90,7 +74,7 @@ void scrollbar(int x, int y, int width, int height, int items, int min_shown, inner_len = height - 2; else inner_len = width - 2; - + /* avoid overflows */ while (items > (INT_MAX / inner_len)) { items >>= 1; @@ -99,19 +83,18 @@ void scrollbar(int x, int y, int width, int height, int items, int min_shown, } /* calc start and end of the knob */ - if(items > 0 && items > (max - min)) { + if (items > 0 && items > (max - min)) { size = inner_len * (max - min) / items; - start = (inner_len - size) * min / (items - (max - min)); - } - else { /* if null draw a full bar */ + if (size == 0) { /* width of knob is null */ + size = 1; + start = (inner_len - 1) * min / items; + } else { + start = (inner_len - size) * min / (items - (max - min)); + } + } else { /* if null draw full bar */ size = inner_len; start = 0; } - /* width of knob is null */ - if(size == 0) { - start = (inner_len - 1) * min / items; - size = 1; - } lcd_set_drawmode(DRMODE_SOLID); @@ -126,24 +109,17 @@ void scrollbar(int x, int y, int width, int height, int items, int min_shown, */ void checkbox(int x, int y, int width, int height, bool checked) { - /* check position and dimensions */ - if((x < 0) || (x + width > LCD_WIDTH) || - (y < 0) || (y + height > LCD_HEIGHT) || - (width < 4 ) || (height < 4 )) - { - return; - } - + /* draw box */ lcd_drawrect(x, y, width, height); + /* clear inner area */ + lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); + lcd_fillrect(x + 1, y + 1, width - 2, height - 2); + lcd_set_drawmode(DRMODE_SOLID); + if (checked){ lcd_drawline(x + 2, y + 2, x + width - 2 - 1 , y + height - 2 - 1); lcd_drawline(x + 2, y + height - 2 - 1, x + width - 2 - 1, y + 2); - } else { - /* be sure to clear box */ - lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); - lcd_fillrect(x + 1, y + 1, width - 2, height - 2); - lcd_set_drawmode(DRMODE_SOLID); } } diff --git a/apps/recorder/widgets.h b/apps/recorder/widgets.h index 44d849b628..78684c8f23 100644 --- a/apps/recorder/widgets.h +++ b/apps/recorder/widgets.h @@ -21,14 +21,6 @@ #include #ifdef HAVE_LCD_BITMAP -/* Directions for progressbar and slidebar */ -enum { - Grow_Right = 0, - Grow_Left, - Grow_Down, - Grow_Up -}; - /* Orientation for scrollbar */ enum { VERTICAL = 0, -- cgit v1.2.3