diff options
author | Robert Hak <adiamas@rockbox.org> | 2003-08-10 08:58:54 +0000 |
---|---|---|
committer | Robert Hak <adiamas@rockbox.org> | 2003-08-10 08:58:54 +0000 |
commit | 7a38db572ef1d6435d52d66bc169baf6fde3b040 (patch) | |
tree | 231f30585dbe17b81c53511346b843fe7b384456 /apps/recorder/widgets.c | |
parent | 8afb858804c3dbaadf70f84a32f3d9e30b3e7a11 (diff) |
a minor bit of code policing
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3928 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/recorder/widgets.c')
-rw-r--r-- | apps/recorder/widgets.c | 93 |
1 files changed, 33 insertions, 60 deletions
diff --git a/apps/recorder/widgets.c b/apps/recorder/widgets.c index 9ee7dbc66a..99257495cf 100644 --- a/apps/recorder/widgets.c +++ b/apps/recorder/widgets.c @@ -21,26 +21,21 @@ #include "widgets.h" #ifdef HAVE_LCD_BITMAP -/* - * Print a progress bar - */ -void progressbar(int x, int y, int width, int height, int percent, int direction) -{ - int pos; - - /* check position and dimensions */ - if(x < 0) - return; - if(y < 0) - return; - - if(x + width > LCD_WIDTH) - return; +/* Valid dimensions return true, invalid false */ +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; + } - if(y + height > LCD_HEIGHT) - return; + return true; +} +void init_bar(int x, int y, int width, int height) +{ /* draw box */ lcd_drawrect(x, y, width, height); @@ -52,6 +47,21 @@ void progressbar(int x, int y, int width, int height, int percent, int direction /* clear pixels in progress bar */ lcd_clearrect(x + 1, y + 1, width - 2, height - 2); +} + +/* + * Print a progress bar + */ +void progressbar(int x, int y, int width, int height, int percent, + int direction) +{ + int pos; + + /* check position and dimensions */ + if (!valid_dimensions(x, y, width, height)) + return; + + init_bar(x, y, width, height); /* draw bar */ pos = percent; @@ -90,29 +100,10 @@ void slidebar(int x, int y, int width, int height, int percent, int direction) int pos; /* check position and dimensions */ - if(x < 0) - return; - - if(y < 0) - return; - - if(x + width > LCD_WIDTH) - return; - - if(y + height > LCD_HEIGHT) + if (!valid_dimensions(x, y, width, height)) return; - /* draw box */ - lcd_drawrect(x, y, width, height); - - /* clear edge pixels */ - lcd_clearpixel(x, y); - lcd_clearpixel((x + width - 1), y); - lcd_clearpixel(x, (y + height - 1)); - lcd_clearpixel((x + width - 1), (y + height - 1)); - - /* clear pixels in progress bar */ - lcd_clearrect(x + 1, y + 1, width - 2, height - 2); + init_bar(x, y, width, height); /* draw knob */ pos = percent; @@ -147,7 +138,8 @@ void slidebar(int x, int y, int width, int height, int percent, int direction) /* * Print a scroll bar */ -void scrollbar(int x, int y, int width, int height, int items, int min_shown, int max_shown, int orientation) +void scrollbar(int x, int y, int width, int height, int items, int min_shown, + int max_shown, int orientation) { int min; int max; @@ -155,29 +147,10 @@ void scrollbar(int x, int y, int width, int height, int items, int min_shown, in int size; /* check position and dimensions */ - if(x < 0) - return; - - if(y < 0) + if (!valid_dimensions(x, y, width, height)) return; - if(x + width > LCD_WIDTH) - return; - - if(y + height > LCD_HEIGHT) - return; - - /* draw box */ - lcd_drawrect(x, y, width, height); - - /* clear edge pixels */ - lcd_clearpixel(x, y); - lcd_clearpixel((x + width - 1), y); - lcd_clearpixel(x, (y + height - 1)); - lcd_clearpixel((x + width - 1), (y + height - 1)); - - /* clear pixels in progress bar */ - lcd_clearrect(x + 1, y + 1, width - 2, height - 2); + init_bar(x, y, width, height); /* min should be min */ if(min_shown < max_shown) { |