summaryrefslogtreecommitdiff
path: root/apps/recorder/widgets.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/recorder/widgets.c')
-rw-r--r--apps/recorder/widgets.c93
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) {