diff options
author | Thomas Martitz <kugel@rockbox.org> | 2009-09-05 18:52:44 +0000 |
---|---|---|
committer | Thomas Martitz <kugel@rockbox.org> | 2009-09-05 18:52:44 +0000 |
commit | 4034e0b47fbc91cb530e9621cc6be243c071597c (patch) | |
tree | 0cd7e950eb5a42558e84ab26fdadd42e6d09fc50 /apps | |
parent | dee9277a09428f9fa75231892d60df42eeffc6b5 (diff) | |
download | rockbox-4034e0b47fbc91cb530e9621cc6be243c071597c.tar.gz rockbox-4034e0b47fbc91cb530e9621cc6be243c071597c.zip |
Put the quickscreen viewports onto the stack (saving a tiny bit of ram), and simplify the preparing and drawing functions a bit.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22634 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r-- | apps/gui/quickscreen.c | 134 |
1 files changed, 64 insertions, 70 deletions
diff --git a/apps/gui/quickscreen.c b/apps/gui/quickscreen.c index 7b042aa078..3eab14c5b5 100644 --- a/apps/gui/quickscreen.c +++ b/apps/gui/quickscreen.c | |||
@@ -40,8 +40,6 @@ | |||
40 | #include "option_select.h" | 40 | #include "option_select.h" |
41 | #include "debug.h" | 41 | #include "debug.h" |
42 | 42 | ||
43 | static struct viewport vps[NB_SCREENS][QUICKSCREEN_ITEM_COUNT]; | ||
44 | static struct viewport vp_icons[NB_SCREENS]; | ||
45 | /* 1 top, 1 bottom, 2 on either side, 1 for the icons | 43 | /* 1 top, 1 bottom, 2 on either side, 1 for the icons |
46 | * if enough space, top and bottom have 2 lines */ | 44 | * if enough space, top and bottom have 2 lines */ |
47 | #define MIN_LINES 5 | 45 | #define MIN_LINES 5 |
@@ -52,14 +50,12 @@ static struct viewport vp_icons[NB_SCREENS]; | |||
52 | #define CENTER_ICONAREA_SIZE (MARGIN+8*2) | 50 | #define CENTER_ICONAREA_SIZE (MARGIN+8*2) |
53 | 51 | ||
54 | static void quickscreen_fix_viewports(struct gui_quickscreen *qs, | 52 | static void quickscreen_fix_viewports(struct gui_quickscreen *qs, |
55 | struct screen *display, | 53 | struct screen *display, |
56 | struct viewport *parent) | 54 | struct viewport *parent, |
55 | struct viewport | ||
56 | vps[QUICKSCREEN_ITEM_COUNT], | ||
57 | struct viewport *vp_icons) | ||
57 | { | 58 | { |
58 | #ifdef HAVE_REMOTE_LCD | ||
59 | int screen = display->screen_type; | ||
60 | #else | ||
61 | const int screen = 0; | ||
62 | #endif | ||
63 | int char_height, width, pad = 0; | 59 | int char_height, width, pad = 0; |
64 | int left_width, right_width, vert_lines; | 60 | int left_width, right_width, vert_lines; |
65 | unsigned char *s; | 61 | unsigned char *s; |
@@ -74,36 +70,36 @@ static void quickscreen_fix_viewports(struct gui_quickscreen *qs, | |||
74 | char_height = parent->height/nb_lines; | 70 | char_height = parent->height/nb_lines; |
75 | 71 | ||
76 | /* center the icons VP first */ | 72 | /* center the icons VP first */ |
77 | vp_icons[screen] = *parent; | 73 | *vp_icons = *parent; |
78 | vp_icons[screen].width = CENTER_ICONAREA_SIZE; /* abosulte smallest allowed */ | 74 | vp_icons->width = CENTER_ICONAREA_SIZE; /* abosulte smallest allowed */ |
79 | vp_icons[screen].x = parent->x; | 75 | vp_icons->x = parent->x; |
80 | vp_icons[screen].x += (parent->width-CENTER_ICONAREA_SIZE)/2; | 76 | vp_icons->x += (parent->width-CENTER_ICONAREA_SIZE)/2; |
81 | 77 | ||
82 | 78 | ||
83 | vps[screen][QUICKSCREEN_BOTTOM] = *parent; | 79 | vps[QUICKSCREEN_BOTTOM] = *parent; |
84 | vps[screen][QUICKSCREEN_TOP] = *parent; | 80 | vps[QUICKSCREEN_TOP] = *parent; |
85 | /* depending on the space the top/buttom items use 1 or 2 lines */ | 81 | /* depending on the space the top/buttom items use 1 or 2 lines */ |
86 | if (nb_lines < MIN_LINES) | 82 | if (nb_lines < MIN_LINES) |
87 | vert_lines = 1; | 83 | vert_lines = 1; |
88 | else | 84 | else |
89 | vert_lines = 2; | 85 | vert_lines = 2; |
90 | vps[screen][QUICKSCREEN_TOP].y = parent->y; | 86 | vps[QUICKSCREEN_TOP].y = parent->y; |
91 | vps[screen][QUICKSCREEN_TOP].height = vps[screen][QUICKSCREEN_BOTTOM].height | 87 | vps[QUICKSCREEN_TOP].height = vps[QUICKSCREEN_BOTTOM].height |
92 | = vert_lines*char_height; | 88 | = vert_lines*char_height; |
93 | vps[screen][QUICKSCREEN_BOTTOM].y | 89 | vps[QUICKSCREEN_BOTTOM].y |
94 | = parent->y + parent->height - vps[screen][QUICKSCREEN_BOTTOM].height; | 90 | = parent->y + parent->height - vps[QUICKSCREEN_BOTTOM].height; |
95 | 91 | ||
96 | /* enough space vertically, so put a nice margin */ | 92 | /* enough space vertically, so put a nice margin */ |
97 | if (nb_lines >= MAX_NEEDED_LINES) | 93 | if (nb_lines >= MAX_NEEDED_LINES) |
98 | { | 94 | { |
99 | vps[screen][QUICKSCREEN_TOP].y += MARGIN; | 95 | vps[QUICKSCREEN_TOP].y += MARGIN; |
100 | vps[screen][QUICKSCREEN_BOTTOM].y -= MARGIN; | 96 | vps[QUICKSCREEN_BOTTOM].y -= MARGIN; |
101 | } | 97 | } |
102 | 98 | ||
103 | vp_icons[screen].y = vps[screen][QUICKSCREEN_TOP].y | 99 | vp_icons->y = vps[QUICKSCREEN_TOP].y |
104 | + vps[screen][QUICKSCREEN_TOP].height; | 100 | + vps[QUICKSCREEN_TOP].height; |
105 | vp_icons[screen].height = parent->height - vp_icons[screen].y; | 101 | vp_icons->height = parent->height - vp_icons->y; |
106 | vp_icons[screen].height -= parent->height - vps[screen][QUICKSCREEN_BOTTOM].y; | 102 | vp_icons->height -= parent->height - vps[QUICKSCREEN_BOTTOM].y; |
107 | 103 | ||
108 | /* adjust the left/right items widths to fit the screen nicely */ | 104 | /* adjust the left/right items widths to fit the screen nicely */ |
109 | s = P2STR(ID2P(qs->items[QUICKSCREEN_LEFT]->lang_id)); | 105 | s = P2STR(ID2P(qs->items[QUICKSCREEN_LEFT]->lang_id)); |
@@ -112,47 +108,47 @@ static void quickscreen_fix_viewports(struct gui_quickscreen *qs, | |||
112 | right_width = display->getstringsize(s, NULL, NULL); | 108 | right_width = display->getstringsize(s, NULL, NULL); |
113 | 109 | ||
114 | width = MAX(left_width, right_width); | 110 | width = MAX(left_width, right_width); |
115 | if (width*2 + vp_icons[screen].width > parent->width) | 111 | if (width*2 + vp_icons->width > parent->width) |
116 | { /* crop text viewports */ | 112 | { /* crop text viewports */ |
117 | width = (parent->width - vp_icons[screen].width)/2; | 113 | width = (parent->width - vp_icons->width)/2; |
118 | } | 114 | } |
119 | else | 115 | else |
120 | { /* add more gap in icons vp */ | 116 | { /* add more gap in icons vp */ |
121 | int excess = parent->width - vp_icons[screen].width - width*2; | 117 | int excess = parent->width - vp_icons->width - width*2; |
122 | if (excess > MARGIN*4) | 118 | if (excess > MARGIN*4) |
123 | { | 119 | { |
124 | pad = MARGIN; | 120 | pad = MARGIN; |
125 | excess -= MARGIN*2; | 121 | excess -= MARGIN*2; |
126 | } | 122 | } |
127 | vp_icons[screen].x -= excess/2; | 123 | vp_icons->x -= excess/2; |
128 | vp_icons[screen].width += excess; | 124 | vp_icons->width += excess; |
129 | } | 125 | } |
130 | 126 | ||
131 | vps[screen][QUICKSCREEN_LEFT] = *parent; | 127 | vps[QUICKSCREEN_LEFT] = *parent; |
132 | vps[screen][QUICKSCREEN_LEFT].x = parent->x + pad; | 128 | vps[QUICKSCREEN_LEFT].x = parent->x + pad; |
133 | vps[screen][QUICKSCREEN_LEFT].width = width; | 129 | vps[QUICKSCREEN_LEFT].width = width; |
134 | 130 | ||
135 | vps[screen][QUICKSCREEN_RIGHT] = *parent; | 131 | vps[QUICKSCREEN_RIGHT] = *parent; |
136 | vps[screen][QUICKSCREEN_RIGHT].x = parent->x + parent->width - width - pad; | 132 | vps[QUICKSCREEN_RIGHT].x = parent->x + parent->width - width - pad; |
137 | vps[screen][QUICKSCREEN_RIGHT].width = width; | 133 | vps[QUICKSCREEN_RIGHT].width = width; |
138 | 134 | ||
139 | vps[screen][QUICKSCREEN_LEFT].height = vps[screen][QUICKSCREEN_RIGHT].height | 135 | vps[QUICKSCREEN_LEFT].height = vps[QUICKSCREEN_RIGHT].height |
140 | = 2*char_height; | 136 | = 2*char_height; |
141 | 137 | ||
142 | vps[screen][QUICKSCREEN_LEFT].y = vps[screen][QUICKSCREEN_RIGHT].y | 138 | vps[QUICKSCREEN_LEFT].y = vps[QUICKSCREEN_RIGHT].y |
143 | = parent->y + (parent->height/2) - char_height; | 139 | = parent->y + (parent->height/2) - char_height; |
144 | 140 | ||
145 | /* shrink the icons vp by a few pixels if there is room so the arrows | 141 | /* shrink the icons vp by a few pixels if there is room so the arrows |
146 | aren't drawn right next to the text */ | 142 | aren't drawn right next to the text */ |
147 | if (vp_icons[screen].width > CENTER_ICONAREA_SIZE*2) | 143 | if (vp_icons->width > CENTER_ICONAREA_SIZE*2) |
148 | { | 144 | { |
149 | vp_icons[screen].width -= CENTER_ICONAREA_SIZE*2/3; | 145 | vp_icons->width -= CENTER_ICONAREA_SIZE*2/3; |
150 | vp_icons[screen].x += CENTER_ICONAREA_SIZE*2/6; | 146 | vp_icons->x += CENTER_ICONAREA_SIZE*2/6; |
151 | } | 147 | } |
152 | if (vp_icons[screen].height > CENTER_ICONAREA_SIZE*2) | 148 | if (vp_icons->height > CENTER_ICONAREA_SIZE*2) |
153 | { | 149 | { |
154 | vp_icons[screen].height -= CENTER_ICONAREA_SIZE*2/3; | 150 | vp_icons->height -= CENTER_ICONAREA_SIZE*2/3; |
155 | vp_icons[screen].y += CENTER_ICONAREA_SIZE*2/6; | 151 | vp_icons->y += CENTER_ICONAREA_SIZE*2/6; |
156 | } | 152 | } |
157 | } | 153 | } |
158 | 154 | ||
@@ -184,16 +180,12 @@ static void quickscreen_draw_text(const char *s, int item, bool title, | |||
184 | display->putsxy(x, line*h, s); | 180 | display->putsxy(x, line*h, s); |
185 | } | 181 | } |
186 | 182 | ||
187 | static void gui_quickscreen_draw(struct gui_quickscreen *qs, | 183 | static void gui_quickscreen_draw(const struct gui_quickscreen *qs, |
188 | struct screen *display, | 184 | struct screen *display, |
189 | struct viewport *parent) | 185 | struct viewport *parent, |
186 | struct viewport vps[QUICKSCREEN_ITEM_COUNT], | ||
187 | struct viewport *vp_icons) | ||
190 | { | 188 | { |
191 | #ifdef HAVE_REMOTE_LCD | ||
192 | int screen = display->screen_type; | ||
193 | #else | ||
194 | const int screen = 0; | ||
195 | #endif | ||
196 | |||
197 | int i; | 189 | int i; |
198 | char buf[MAX_PATH]; | 190 | char buf[MAX_PATH]; |
199 | unsigned const char *title, *value; | 191 | unsigned const char *title, *value; |
@@ -205,8 +197,8 @@ static void gui_quickscreen_draw(struct gui_quickscreen *qs, | |||
205 | { | 197 | { |
206 | if (!qs->items[i]) | 198 | if (!qs->items[i]) |
207 | continue; | 199 | continue; |
208 | display->set_viewport(&vps[screen][i]); | 200 | display->set_viewport(&vps[i]); |
209 | display->scroll_stop(&vps[screen][i]); | 201 | display->scroll_stop(&vps[i]); |
210 | 202 | ||
211 | title = P2STR(ID2P(qs->items[i]->lang_id)); | 203 | title = P2STR(ID2P(qs->items[i]->lang_id)); |
212 | setting = qs->items[i]->setting; | 204 | setting = qs->items[i]->setting; |
@@ -214,33 +206,33 @@ static void gui_quickscreen_draw(struct gui_quickscreen *qs, | |||
214 | value = option_get_valuestring((struct settings_list*)qs->items[i], | 206 | value = option_get_valuestring((struct settings_list*)qs->items[i], |
215 | buf, MAX_PATH, temp); | 207 | buf, MAX_PATH, temp); |
216 | 208 | ||
217 | if (vps[screen][i].height < display->getcharheight()*2) | 209 | if (vps[i].height < display->getcharheight()*2) |
218 | { | 210 | { |
219 | char text[MAX_PATH]; | 211 | char text[MAX_PATH]; |
220 | snprintf(text, MAX_PATH, "%s: %s", title, value); | 212 | snprintf(text, MAX_PATH, "%s: %s", title, value); |
221 | quickscreen_draw_text(text, i, true, display, &vps[screen][i]); | 213 | quickscreen_draw_text(text, i, true, display, &vps[i]); |
222 | } | 214 | } |
223 | else | 215 | else |
224 | { | 216 | { |
225 | quickscreen_draw_text(title, i, true, display, &vps[screen][i]); | 217 | quickscreen_draw_text(title, i, true, display, &vps[i]); |
226 | quickscreen_draw_text(value, i, false, display, &vps[screen][i]); | 218 | quickscreen_draw_text(value, i, false, display, &vps[i]); |
227 | } | 219 | } |
228 | display->update_viewport(); | 220 | display->update_viewport(); |
229 | } | 221 | } |
230 | /* draw the icons */ | 222 | /* draw the icons */ |
231 | display->set_viewport(&vp_icons[screen]); | 223 | display->set_viewport(vp_icons); |
232 | 224 | ||
233 | display->mono_bitmap(bitmap_icons_7x8[Icon_UpArrow], | 225 | display->mono_bitmap(bitmap_icons_7x8[Icon_UpArrow], |
234 | (vp_icons[screen].width/2) - 4, 0, 7, 8); | 226 | (vp_icons->width/2) - 4, 0, 7, 8); |
235 | display->mono_bitmap(bitmap_icons_7x8[Icon_FastForward], | 227 | display->mono_bitmap(bitmap_icons_7x8[Icon_FastForward], |
236 | vp_icons[screen].width - 8, | 228 | vp_icons->width - 8, |
237 | (vp_icons[screen].height/2) - 4, 7, 8); | 229 | (vp_icons->height/2) - 4, 7, 8); |
238 | display->mono_bitmap(bitmap_icons_7x8[Icon_FastBackward], 0, | 230 | display->mono_bitmap(bitmap_icons_7x8[Icon_FastBackward], 0, |
239 | (vp_icons[screen].height/2) - 4, 7, 8); | 231 | (vp_icons->height/2) - 4, 7, 8); |
240 | 232 | ||
241 | display->mono_bitmap(bitmap_icons_7x8[Icon_DownArrow], | 233 | display->mono_bitmap(bitmap_icons_7x8[Icon_DownArrow], |
242 | (vp_icons[screen].width/2) - 4, | 234 | (vp_icons->width/2) - 4, |
243 | vp_icons[screen].height - 8, 7, 8); | 235 | vp_icons->height - 8, 7, 8); |
244 | 236 | ||
245 | display->set_viewport(parent); | 237 | display->set_viewport(parent); |
246 | display->update_viewport(); | 238 | display->update_viewport(); |
@@ -318,7 +310,9 @@ static int quickscreen_touchscreen_button(void) | |||
318 | static bool gui_syncquickscreen_run(struct gui_quickscreen * qs, int button_enter) | 310 | static bool gui_syncquickscreen_run(struct gui_quickscreen * qs, int button_enter) |
319 | { | 311 | { |
320 | int button, i, j; | 312 | int button, i, j; |
321 | struct viewport vp[NB_SCREENS]; | 313 | struct viewport parent[NB_SCREENS]; |
314 | struct viewport vps[NB_SCREENS][QUICKSCREEN_ITEM_COUNT]; | ||
315 | struct viewport vp_icons[NB_SCREENS]; | ||
322 | bool changed = false; | 316 | bool changed = false; |
323 | /* To quit we need either : | 317 | /* To quit we need either : |
324 | * - a second press on the button that made us enter | 318 | * - a second press on the button that made us enter |
@@ -329,9 +323,9 @@ static bool gui_syncquickscreen_run(struct gui_quickscreen * qs, int button_ente | |||
329 | { | 323 | { |
330 | screens[i].set_viewport(NULL); | 324 | screens[i].set_viewport(NULL); |
331 | screens[i].stop_scroll(); | 325 | screens[i].stop_scroll(); |
332 | viewport_set_defaults(&vp[i], i); | 326 | viewport_set_defaults(&parent[i], i); |
333 | quickscreen_fix_viewports(qs, &screens[i], &vp[i]); | 327 | quickscreen_fix_viewports(qs, &screens[i], &parent[i], vps[i], &vp_icons[i]); |
334 | gui_quickscreen_draw(qs, &screens[i], &vp[i]); | 328 | gui_quickscreen_draw(qs, &screens[i], &parent[i], vps[i], &vp_icons[i]); |
335 | } | 329 | } |
336 | /* Announce current selection on entering this screen. This is all | 330 | /* Announce current selection on entering this screen. This is all |
337 | queued up, but can be interrupted as soon as a setting is | 331 | queued up, but can be interrupted as soon as a setting is |
@@ -354,7 +348,7 @@ static bool gui_syncquickscreen_run(struct gui_quickscreen * qs, int button_ente | |||
354 | changed = true; | 348 | changed = true; |
355 | can_quit=true; | 349 | can_quit=true; |
356 | FOR_NB_SCREENS(i) | 350 | FOR_NB_SCREENS(i) |
357 | gui_quickscreen_draw(qs, &screens[i], &vp[i]); | 351 | gui_quickscreen_draw(qs, &screens[i], &parent[i], vps[i],&vp_icons[i]); |
358 | if (qs->callback) | 352 | if (qs->callback) |
359 | qs->callback(qs); | 353 | qs->callback(qs); |
360 | } | 354 | } |