From 7a38db572ef1d6435d52d66bc169baf6fde3b040 Mon Sep 17 00:00:00 2001 From: Robert Hak Date: Sun, 10 Aug 2003 08:58:54 +0000 Subject: a minor bit of code policing git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3928 a1c6a512-1295-4272-9138-f99709370657 --- apps/recorder/widgets.c | 93 ++++++++++++++++++------------------------------- 1 file changed, 33 insertions(+), 60 deletions(-) (limited to 'apps') 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) { -- cgit v1.2.3