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.c55
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 @@
17 * 17 *
18 ****************************************************************************/ 18 ****************************************************************************/
19#include <lcd.h> 19#include <lcd.h>
20#include <limits.h>
20 21
21#include "widgets.h" 22#include "widgets.h"
22 23
@@ -42,6 +43,7 @@ void scrollbar(int x, int y, int width, int height, int items, int min_shown,
42{ 43{
43 int min; 44 int min;
44 int max; 45 int max;
46 int inner_len;
45 int start; 47 int start;
46 int size; 48 int size;
47 49
@@ -82,42 +84,37 @@ void scrollbar(int x, int y, int width, int height, int items, int min_shown,
82 if(max > items) 84 if(max > items)
83 max = items; 85 max = items;
84 86
87 if (orientation == VERTICAL)
88 inner_len = height - 2;
89 else
90 inner_len = width - 2;
91
92 /* avoid overflows */
93 while (items > (INT_MAX / inner_len)) {
94 items >>= 1;
95 min >>= 1;
96 max >>= 1;
97 }
98
85 /* calc start and end of the knob */ 99 /* calc start and end of the knob */
86 if(items > 0 && items > (max - min)) { 100 if(items > 0 && items > (max - min)) {
87 if(orientation == VERTICAL) { 101 size = inner_len * (max - min) / items;
88 size = (height - 2) * (max - min) / items; 102 start = (inner_len - size) * min / (items - (max - min));
89 start = (height - 2 - size) * min / (items - (max - min));
90 }
91 else {
92 size = (width - 2) * (max - min) / items;
93 start = (width - 2 - size) * min / (items - (max - min));
94 }
95 } 103 }
96 else { /* if null draw a full bar */ 104 else { /* if null draw a full bar */
105 size = inner_len;
97 start = 0; 106 start = 0;
98 if(orientation == VERTICAL)
99 size = (height - 2);
100 else
101 size = (width - 2);
102 } 107 }
103 108 /* width of knob is null */
104 /* knob has a width */ 109 if(size == 0) {
105 if(size != 0) { 110 start = (inner_len - 1) * min / items;
106 if(orientation == VERTICAL) 111 size = 1;
107 lcd_fillrect(x + 1, y + start + 1, width - 2, size);
108 else
109 lcd_fillrect(x + start + 1, y + 1, size, height - 2);
110 }
111 else { /* width of knob is null */
112 if(orientation == VERTICAL) {
113 start = (height - 2 - 1) * min / items;
114 lcd_fillrect(x + 1, y + start + 1, width - 2, 1);
115 }
116 else {
117 start = (width - 2 - 1) * min / items;
118 lcd_fillrect(x + start + 1, y + 1, 1, height - 2);
119 }
120 } 112 }
113
114 if(orientation == VERTICAL)
115 lcd_fillrect(x + 1, y + start + 1, width - 2, size);
116 else
117 lcd_fillrect(x + start + 1, y + 1, size, height - 2);
121} 118}
122 119
123/* 120/*