summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2005-08-23 22:06:15 +0000
committerJens Arnold <amiconn@rockbox.org>2005-08-23 22:06:15 +0000
commita6eb0f6669c26a99cb634702351c0757c4aea0b0 (patch)
tree761cd5f6ac231154bb88f5404ca8917316fe3f42
parenta5600672eda13c5fd55ed47abc6f0a54974c66c1 (diff)
downloadrockbox-a6eb0f6669c26a99cb634702351c0757c4aea0b0.tar.gz
rockbox-a6eb0f6669c26a99cb634702351c0757c4aea0b0.zip
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
-rw-r--r--apps/recorder/widgets.c56
-rw-r--r--apps/recorder/widgets.h8
2 files changed, 16 insertions, 48 deletions
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 @@
23 23
24#ifdef HAVE_LCD_BITMAP 24#ifdef HAVE_LCD_BITMAP
25 25
26/* Valid dimensions return true, invalid false */
27static bool valid_dimensions(int x, int y, int width, int height)
28{
29 if((x < 0) || (x + width > LCD_WIDTH) ||
30 (y < 0) || (y + height > LCD_HEIGHT))
31 {
32 return false;
33 }
34
35 return true;
36}
37
38/* 26/*
39 * Print a scroll bar 27 * Print a scroll bar
40 */ 28 */
@@ -47,10 +35,6 @@ void scrollbar(int x, int y, int width, int height, int items, int min_shown,
47 int start; 35 int start;
48 int size; 36 int size;
49 37
50 /* check position and dimensions */
51 if (!valid_dimensions(x, y, width, height))
52 return;
53
54 /* draw box */ 38 /* draw box */
55 lcd_drawrect(x, y, width, height); 39 lcd_drawrect(x, y, width, height);
56 40
@@ -66,7 +50,7 @@ void scrollbar(int x, int y, int width, int height, int items, int min_shown,
66 lcd_fillrect(x + 1, y + 1, width - 2, height - 2); 50 lcd_fillrect(x + 1, y + 1, width - 2, height - 2);
67 51
68 /* min should be min */ 52 /* min should be min */
69 if(min_shown < max_shown) { 53 if(min_shown < max_shown) {
70 min = min_shown; 54 min = min_shown;
71 max = max_shown; 55 max = max_shown;
72 } 56 }
@@ -90,7 +74,7 @@ void scrollbar(int x, int y, int width, int height, int items, int min_shown,
90 inner_len = height - 2; 74 inner_len = height - 2;
91 else 75 else
92 inner_len = width - 2; 76 inner_len = width - 2;
93 77
94 /* avoid overflows */ 78 /* avoid overflows */
95 while (items > (INT_MAX / inner_len)) { 79 while (items > (INT_MAX / inner_len)) {
96 items >>= 1; 80 items >>= 1;
@@ -99,19 +83,18 @@ void scrollbar(int x, int y, int width, int height, int items, int min_shown,
99 } 83 }
100 84
101 /* calc start and end of the knob */ 85 /* calc start and end of the knob */
102 if(items > 0 && items > (max - min)) { 86 if (items > 0 && items > (max - min)) {
103 size = inner_len * (max - min) / items; 87 size = inner_len * (max - min) / items;
104 start = (inner_len - size) * min / (items - (max - min)); 88 if (size == 0) { /* width of knob is null */
105 } 89 size = 1;
106 else { /* if null draw a full bar */ 90 start = (inner_len - 1) * min / items;
91 } else {
92 start = (inner_len - size) * min / (items - (max - min));
93 }
94 } else { /* if null draw full bar */
107 size = inner_len; 95 size = inner_len;
108 start = 0; 96 start = 0;
109 } 97 }
110 /* width of knob is null */
111 if(size == 0) {
112 start = (inner_len - 1) * min / items;
113 size = 1;
114 }
115 98
116 lcd_set_drawmode(DRMODE_SOLID); 99 lcd_set_drawmode(DRMODE_SOLID);
117 100
@@ -126,24 +109,17 @@ void scrollbar(int x, int y, int width, int height, int items, int min_shown,
126 */ 109 */
127void checkbox(int x, int y, int width, int height, bool checked) 110void checkbox(int x, int y, int width, int height, bool checked)
128{ 111{
129 /* check position and dimensions */ 112 /* draw box */
130 if((x < 0) || (x + width > LCD_WIDTH) ||
131 (y < 0) || (y + height > LCD_HEIGHT) ||
132 (width < 4 ) || (height < 4 ))
133 {
134 return;
135 }
136
137 lcd_drawrect(x, y, width, height); 113 lcd_drawrect(x, y, width, height);
138 114
115 /* clear inner area */
116 lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
117 lcd_fillrect(x + 1, y + 1, width - 2, height - 2);
118 lcd_set_drawmode(DRMODE_SOLID);
119
139 if (checked){ 120 if (checked){
140 lcd_drawline(x + 2, y + 2, x + width - 2 - 1 , y + height - 2 - 1); 121 lcd_drawline(x + 2, y + 2, x + width - 2 - 1 , y + height - 2 - 1);
141 lcd_drawline(x + 2, y + height - 2 - 1, x + width - 2 - 1, y + 2); 122 lcd_drawline(x + 2, y + height - 2 - 1, x + width - 2 - 1, y + 2);
142 } else {
143 /* be sure to clear box */
144 lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
145 lcd_fillrect(x + 1, y + 1, width - 2, height - 2);
146 lcd_set_drawmode(DRMODE_SOLID);
147 } 123 }
148} 124}
149 125
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 @@
21#include <lcd.h> 21#include <lcd.h>
22 22
23#ifdef HAVE_LCD_BITMAP 23#ifdef HAVE_LCD_BITMAP
24/* Directions for progressbar and slidebar */
25enum {
26 Grow_Right = 0,
27 Grow_Left,
28 Grow_Down,
29 Grow_Up
30};
31
32/* Orientation for scrollbar */ 24/* Orientation for scrollbar */
33enum { 25enum {
34 VERTICAL = 0, 26 VERTICAL = 0,