diff options
author | Teruaki Kawashima <teru@rockbox.org> | 2010-02-11 14:18:31 +0000 |
---|---|---|
committer | Teruaki Kawashima <teru@rockbox.org> | 2010-02-11 14:18:31 +0000 |
commit | 1549b19d9e686433de8f1feadaa980dc13d63019 (patch) | |
tree | 9c1042ad065bf8b8a2d6da504bca542d5c4e8631 | |
parent | ad2ee3094ff48e8ae578a4327c936286e6005b38 (diff) | |
download | rockbox-1549b19d9e686433de8f1feadaa980dc13d63019.tar.gz rockbox-1549b19d9e686433de8f1feadaa980dc13d63019.zip |
color_picker: a bit of rework for color_picker.
* don't call display->getcharheight() so often, store the value to char_height and use it instead.
* replay title_height by char_height, they should be the same.
* fix spaces.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24595 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/gui/color_picker.c | 131 | ||||
-rw-r--r-- | apps/gui/color_picker.h | 4 | ||||
-rw-r--r-- | apps/plugin.h | 4 |
3 files changed, 66 insertions, 73 deletions
diff --git a/apps/gui/color_picker.c b/apps/gui/color_picker.c index f8caf4d38f..044edd7789 100644 --- a/apps/gui/color_picker.c +++ b/apps/gui/color_picker.c | |||
@@ -155,13 +155,13 @@ static void draw_screen(struct screen *display, char *title, | |||
155 | unsigned text_color = LCD_BLACK; | 155 | unsigned text_color = LCD_BLACK; |
156 | unsigned background_color = LCD_WHITE; | 156 | unsigned background_color = LCD_WHITE; |
157 | char buf[32]; | 157 | char buf[32]; |
158 | int i, text_x, y, line_height; | 158 | int i, char_height, line_height; |
159 | int text_top; | 159 | int max_label_width; |
160 | int text_x, text_top; | ||
160 | int slider_x, slider_width; | 161 | int slider_x, slider_width; |
161 | bool display_three_rows; | 162 | bool display_three_rows; |
162 | int max_label_width; | ||
163 | struct viewport vp; | 163 | struct viewport vp; |
164 | 164 | ||
165 | viewport_set_defaults(&vp, display->screen_type); | 165 | viewport_set_defaults(&vp, display->screen_type); |
166 | display->set_viewport(&vp); | 166 | display->set_viewport(&vp); |
167 | 167 | ||
@@ -173,30 +173,30 @@ static void draw_screen(struct screen *display, char *title, | |||
173 | background_color = display->get_background(); | 173 | background_color = display->get_background(); |
174 | } | 174 | } |
175 | 175 | ||
176 | max_label_width = label_get_max_width(display); | ||
177 | |||
178 | /* Draw title string */ | 176 | /* Draw title string */ |
179 | set_drawinfo(display, DRMODE_SOLID, text_color, background_color); | 177 | set_drawinfo(display, DRMODE_SOLID, text_color, background_color); |
180 | vp.flags |= VP_FLAG_ALIGN_CENTER; | 178 | vp.flags |= VP_FLAG_ALIGN_CENTER; |
181 | display->getstringsize(title, NULL, &y); | ||
182 | display->putsxy(0, MARGIN_TOP, title); | 179 | display->putsxy(0, MARGIN_TOP, title); |
183 | 180 | ||
184 | /* Get slider positions and top starting position */ | 181 | /* Get slider positions and top starting position */ |
185 | text_top = MARGIN_TOP + y + TITLE_MARGIN_BOTTOM + SELECTOR_TB_MARGIN; | 182 | max_label_width = label_get_max_width(display); |
183 | char_height = display->getcharheight(); | ||
184 | text_top = MARGIN_TOP + char_height + | ||
185 | TITLE_MARGIN_BOTTOM + SELECTOR_TB_MARGIN; | ||
186 | text_x = SELECTOR_WIDTH; | 186 | text_x = SELECTOR_WIDTH; |
187 | slider_x = text_x + max_label_width + SLIDER_TEXT_MARGIN; | 187 | slider_x = text_x + max_label_width + SLIDER_TEXT_MARGIN; |
188 | slider_width = vp.width - slider_x*2 - max_label_width; | 188 | slider_width = vp.width - slider_x*2 - max_label_width; |
189 | line_height = display->getcharheight() + 2*SELECTOR_TB_MARGIN; | 189 | line_height = char_height + 2*SELECTOR_TB_MARGIN; |
190 | 190 | ||
191 | /* Find out if there's enough room for three sliders or just | 191 | /* Find out if there's enough room for three sliders or just |
192 | enough to display the selected slider - calculate total height | 192 | enough to display the selected slider - calculate total height |
193 | of display with three sliders present */ | 193 | of display with three sliders present */ |
194 | display_three_rows = | 194 | display_three_rows = |
195 | vp.height >= | 195 | vp.height >= |
196 | text_top + line_height*3 + /* Title + 3 sliders */ | 196 | text_top + line_height*3 + /* Title + 3 sliders */ |
197 | SWATCH_TOP_MARGIN + /* at least 2 lines */ | 197 | SWATCH_TOP_MARGIN + /* at least 2 lines */ |
198 | display->getcharheight()*2 + /* + margins for bottom */ | 198 | char_height*2 + /* + margins for bottom */ |
199 | MARGIN_BOTTOM; /* colored rectangle */ | 199 | MARGIN_BOTTOM; /* colored rectangle */ |
200 | 200 | ||
201 | for (i = 0; i < 3; i++) | 201 | for (i = 0; i < 3; i++) |
202 | { | 202 | { |
@@ -207,8 +207,7 @@ static void draw_screen(struct screen *display, char *title, | |||
207 | 207 | ||
208 | if (i == row) | 208 | if (i == row) |
209 | { | 209 | { |
210 | set_drawinfo(display, DRMODE_SOLID, text_color, | 210 | set_drawinfo(display, DRMODE_SOLID, text_color, background_color); |
211 | background_color); | ||
212 | 211 | ||
213 | if (global_settings.cursor_style != 0) | 212 | if (global_settings.cursor_style != 0) |
214 | { | 213 | { |
@@ -216,8 +215,7 @@ static void draw_screen(struct screen *display, char *title, | |||
216 | display->fillrect(0, | 215 | display->fillrect(0, |
217 | text_top - SELECTOR_TB_MARGIN, | 216 | text_top - SELECTOR_TB_MARGIN, |
218 | vp.width, | 217 | vp.width, |
219 | display->getcharheight() + | 218 | char_height + SELECTOR_TB_MARGIN*2); |
220 | SELECTOR_TB_MARGIN*2); | ||
221 | 219 | ||
222 | if (display->depth < 16) | 220 | if (display->depth < 16) |
223 | { | 221 | { |
@@ -228,13 +226,11 @@ static void draw_screen(struct screen *display, char *title, | |||
228 | else if (display_three_rows) | 226 | else if (display_three_rows) |
229 | { | 227 | { |
230 | /* Draw "> <" around sliders */ | 228 | /* Draw "> <" around sliders */ |
231 | int top = text_top + (display->getcharheight() - | 229 | int top = text_top + (char_height - SELECTOR_HEIGHT) / 2; |
232 | SELECTOR_HEIGHT) / 2; | ||
233 | screen_put_iconxy(display, 0, top, Icon_Cursor); | 230 | screen_put_iconxy(display, 0, top, Icon_Cursor); |
234 | screen_put_iconxy(display, | 231 | screen_put_iconxy(display, |
235 | vp.width - | 232 | vp.width - SELECTOR_WIDTH, |
236 | get_icon_width(display->screen_type), | 233 | top, Icon_Cursor); |
237 | top, Icon_Cursor); | ||
238 | } | 234 | } |
239 | 235 | ||
240 | if (display->depth >= 16) | 236 | if (display->depth >= 16) |
@@ -261,15 +257,15 @@ static void draw_screen(struct screen *display, char *title, | |||
261 | display->putsxy(text_x, text_top, buf); | 257 | display->putsxy(text_x, text_top, buf); |
262 | 258 | ||
263 | /* Draw scrollbar */ | 259 | /* Draw scrollbar */ |
264 | gui_scrollbar_draw(display, /* screen */ | 260 | gui_scrollbar_draw(display, /* screen */ |
265 | slider_x, /* x */ | 261 | slider_x, /* x */ |
266 | text_top + display->getcharheight() / 4,/* y */ | 262 | text_top + char_height / 4, /* y */ |
267 | slider_width, /* width */ | 263 | slider_width, /* width */ |
268 | display->getcharheight() / 2, /* height */ | 264 | char_height / 2, /* height */ |
269 | rgb_max[i], /* items */ | 265 | rgb_max[i], /* items */ |
270 | 0, /* min_shown */ | 266 | 0, /* min_shown */ |
271 | rgb->rgb_val[i], /* max_shown */ | 267 | rgb->rgb_val[i], /* max_shown */ |
272 | sb_flags); /* flags */ | 268 | sb_flags); /* flags */ |
273 | 269 | ||
274 | /* Advance to next line */ | 270 | /* Advance to next line */ |
275 | text_top += line_height; | 271 | text_top += line_height; |
@@ -287,7 +283,7 @@ static void draw_screen(struct screen *display, char *title, | |||
287 | int height = vp.height - top - MARGIN_BOTTOM; | 283 | int height = vp.height - top - MARGIN_BOTTOM; |
288 | 284 | ||
289 | /* Only draw if room */ | 285 | /* Only draw if room */ |
290 | if (height >= display->getcharheight() + 2) | 286 | if (height >= char_height + 2) |
291 | { | 287 | { |
292 | /* draw the big rectangle */ | 288 | /* draw the big rectangle */ |
293 | display->set_foreground(rgb->color); | 289 | display->set_foreground(rgb->color); |
@@ -296,67 +292,61 @@ static void draw_screen(struct screen *display, char *title, | |||
296 | /* Draw RGB: #rrggbb in middle of swatch */ | 292 | /* Draw RGB: #rrggbb in middle of swatch */ |
297 | set_drawinfo(display, DRMODE_FG, get_black_or_white(rgb), | 293 | set_drawinfo(display, DRMODE_FG, get_black_or_white(rgb), |
298 | background_color); | 294 | background_color); |
299 | display->getstringsize(buf, NULL, &y); | ||
300 | 295 | ||
301 | display->putsxy(0, top + (height - y) / 2, buf); | 296 | display->putsxy(0, top + (height - char_height) / 2, buf); |
302 | 297 | ||
303 | /* Draw border around the rect */ | 298 | /* Draw border around the rect */ |
304 | set_drawinfo(display, DRMODE_SOLID, text_color, | 299 | set_drawinfo(display, DRMODE_SOLID, text_color, background_color); |
305 | background_color); | ||
306 | display->drawrect(text_x, top, width, height); | 300 | display->drawrect(text_x, top, width, height); |
307 | } | 301 | } |
308 | } | 302 | } |
309 | else | 303 | else |
310 | { | 304 | { |
311 | /* Display RGB value only centered on remaining display if room */ | 305 | /* Display RGB value only centered on remaining display if room */ |
312 | display->getstringsize(buf, NULL, &y); | 306 | int top = text_top + SWATCH_TOP_MARGIN; |
313 | i = text_top + SWATCH_TOP_MARGIN; | 307 | int height = vp.height - top - MARGIN_BOTTOM; |
314 | 308 | ||
315 | if (i + y <= display->getheight() - MARGIN_BOTTOM) | 309 | if (height >= char_height) |
316 | { | 310 | { |
317 | set_drawinfo(display, DRMODE_SOLID, text_color, background_color); | 311 | set_drawinfo(display, DRMODE_SOLID, text_color, background_color); |
318 | display->putsxy(0, (i + vp.height - MARGIN_BOTTOM - y) / 2, buf); | 312 | display->putsxy(0, top + (height - char_height) / 2, buf); |
319 | } | 313 | } |
320 | } | 314 | } |
321 | 315 | ||
322 | display->setfont(FONT_UI); | ||
323 | |||
324 | display->update_viewport(); | 316 | display->update_viewport(); |
325 | display->set_viewport(NULL); | 317 | display->set_viewport(NULL); |
326 | /* Be sure screen mode is reset */ | ||
327 | set_drawinfo(display, DRMODE_SOLID, text_color, background_color); | ||
328 | } | 318 | } |
329 | 319 | ||
330 | #ifdef HAVE_TOUCHSCREEN | 320 | #ifdef HAVE_TOUCHSCREEN |
331 | static int touchscreen_slider(struct screen *display, | 321 | static int touchscreen_slider(struct screen *display, |
332 | struct rgb_pick *rgb, | 322 | struct rgb_pick *rgb, |
333 | const char* title, | ||
334 | int *selected_slider) | 323 | int *selected_slider) |
335 | { | 324 | { |
336 | short x,y; | 325 | short x, y; |
337 | int text_top, slider_x, slider_width, title_height; | 326 | int char_height, line_height; |
338 | int button; | ||
339 | bool display_three_rows; | ||
340 | int max_label_width; | 327 | int max_label_width; |
341 | int pressed_slider; | 328 | int text_top, slider_x, slider_width; |
329 | bool display_three_rows; | ||
330 | int button; | ||
331 | int pressed_slider; | ||
342 | struct viewport vp; | 332 | struct viewport vp; |
343 | int line_height; | ||
344 | 333 | ||
345 | viewport_set_defaults(&vp, display->screen_type); | 334 | viewport_set_defaults(&vp, display->screen_type); |
335 | display->set_viewport(&vp); | ||
346 | 336 | ||
347 | max_label_width = label_get_max_width(display); | ||
348 | display->getstringsize(title, NULL, &title_height); | ||
349 | button = action_get_touchscreen_press_in_vp(&x, &y, &vp); | 337 | button = action_get_touchscreen_press_in_vp(&x, &y, &vp); |
350 | if (button == ACTION_UNKNOWN || button == BUTTON_NONE) | 338 | if (button == ACTION_UNKNOWN || button == BUTTON_NONE) |
351 | return ACTION_NONE; | 339 | return ACTION_NONE; |
352 | /* Get slider positions and top starting position | 340 | /* Get slider positions and top starting position |
353 | * need vp.y here, because of the statusbar, since touchscreen | 341 | * need vp.y here, because of the statusbar, since touchscreen |
354 | * coordinates are absolute */ | 342 | * coordinates are absolute */ |
355 | text_top = MARGIN_TOP + title_height + TITLE_MARGIN_BOTTOM + | 343 | max_label_width = label_get_max_width(display); |
356 | SELECTOR_TB_MARGIN; | 344 | char_height = display->getcharheight(); |
345 | text_top = MARGIN_TOP + char_height + | ||
346 | TITLE_MARGIN_BOTTOM + SELECTOR_TB_MARGIN; | ||
357 | slider_x = SELECTOR_WIDTH + max_label_width + SLIDER_TEXT_MARGIN; | 347 | slider_x = SELECTOR_WIDTH + max_label_width + SLIDER_TEXT_MARGIN; |
358 | slider_width = vp.width - slider_x*2 - max_label_width; | 348 | slider_width = vp.width - slider_x*2 - max_label_width; |
359 | line_height = display->getcharheight() + 2*SELECTOR_TB_MARGIN; | 349 | line_height = char_height + 2*SELECTOR_TB_MARGIN; |
360 | 350 | ||
361 | /* same logic as in draw_screen */ | 351 | /* same logic as in draw_screen */ |
362 | /* Find out if there's enough room for three sliders or just | 352 | /* Find out if there's enough room for three sliders or just |
@@ -364,23 +354,27 @@ static int touchscreen_slider(struct screen *display, | |||
364 | of display with three sliders present */ | 354 | of display with three sliders present */ |
365 | display_three_rows = | 355 | display_three_rows = |
366 | vp.height >= | 356 | vp.height >= |
367 | text_top + title_height*3 + /* Title + 3 sliders */ | 357 | text_top + line_height*3 + /* Title + 3 sliders */ |
368 | SWATCH_TOP_MARGIN + /* at least 2 lines */ | 358 | SWATCH_TOP_MARGIN + /* at least 2 lines */ |
369 | display->getcharheight()*2 + /* + margins for bottom */ | 359 | char_height*2 + /* + margins for bottom */ |
370 | MARGIN_BOTTOM; /* colored rectangle */ | 360 | MARGIN_BOTTOM; /* colored rectangle */ |
361 | |||
362 | display->set_viewport(NULL); | ||
371 | 363 | ||
372 | if (y < text_top) | 364 | if (y < text_top) |
373 | { | 365 | { |
374 | if (button == BUTTON_REL) | 366 | if (button == BUTTON_REL) |
375 | return ACTION_STD_CANCEL; | 367 | return ACTION_STD_CANCEL; |
368 | else | ||
369 | return ACTION_NONE; | ||
376 | } | 370 | } |
377 | 371 | ||
378 | vp.y += text_top; | 372 | if (y >= text_top + line_height * (display_three_rows ? 3:1)) |
379 | vp.height = line_height * (display_three_rows ? 3:1); | ||
380 | if (!viewport_point_within_vp(&vp, x, y)) | ||
381 | { /* touching the color area means accept */ | 373 | { /* touching the color area means accept */ |
382 | if (button == BUTTON_REL) | 374 | if (button == BUTTON_REL) |
383 | return ACTION_STD_OK; | 375 | return ACTION_STD_OK; |
376 | else | ||
377 | return ACTION_NONE; | ||
384 | } | 378 | } |
385 | /* y is relative to the original viewport */ | 379 | /* y is relative to the original viewport */ |
386 | pressed_slider = (y - text_top)/line_height; | 380 | pressed_slider = (y - text_top)/line_height; |
@@ -388,8 +382,7 @@ static int touchscreen_slider(struct screen *display, | |||
388 | *selected_slider = pressed_slider; | 382 | *selected_slider = pressed_slider; |
389 | /* add max_label_width to overcome integer division limits, | 383 | /* add max_label_width to overcome integer division limits, |
390 | * cap value later since that may lead to an overflow */ | 384 | * cap value later since that may lead to an overflow */ |
391 | if (x < slider_x+(slider_width+max_label_width) && | 385 | if (x < slider_x + (slider_width+max_label_width) && x > slider_x) |
392 | x > slider_x) | ||
393 | { | 386 | { |
394 | char computed_val; | 387 | char computed_val; |
395 | x -= slider_x; | 388 | x -= slider_x; |
@@ -407,8 +400,8 @@ static int touchscreen_slider(struct screen *display, | |||
407 | color is a pointer to the colour (in native format) to modify | 400 | color is a pointer to the colour (in native format) to modify |
408 | set banned_color to -1 to allow all | 401 | set banned_color to -1 to allow all |
409 | ***********/ | 402 | ***********/ |
410 | bool set_color(struct screen *display, char *title, unsigned *color, | 403 | bool set_color(struct screen *display, char *title, |
411 | unsigned banned_color) | 404 | unsigned *color, unsigned banned_color) |
412 | { | 405 | { |
413 | int exit = 0, slider = 0; | 406 | int exit = 0, slider = 0; |
414 | struct rgb_pick rgb; | 407 | struct rgb_pick rgb; |
@@ -436,7 +429,7 @@ bool set_color(struct screen *display, char *title, unsigned *color, | |||
436 | #ifdef HAVE_TOUCHSCREEN | 429 | #ifdef HAVE_TOUCHSCREEN |
437 | if (button == ACTION_TOUCHSCREEN | 430 | if (button == ACTION_TOUCHSCREEN |
438 | && display->screen_type == SCREEN_MAIN) | 431 | && display->screen_type == SCREEN_MAIN) |
439 | button = touchscreen_slider(display, &rgb, title, &slider); | 432 | button = touchscreen_slider(display, &rgb, &slider); |
440 | #endif | 433 | #endif |
441 | 434 | ||
442 | switch (button) | 435 | switch (button) |
diff --git a/apps/gui/color_picker.h b/apps/gui/color_picker.h index 8122b72a11..6993b5fcaf 100644 --- a/apps/gui/color_picker.h +++ b/apps/gui/color_picker.h | |||
@@ -22,7 +22,7 @@ | |||
22 | 22 | ||
23 | #ifdef HAVE_LCD_COLOR /* this file is a bit useless on non color lcds.. */ | 23 | #ifdef HAVE_LCD_COLOR /* this file is a bit useless on non color lcds.. */ |
24 | 24 | ||
25 | bool set_color(struct screen *display, char *title, unsigned *color, | 25 | bool set_color(struct screen *display, char *title, |
26 | unsigned banned_color); | 26 | unsigned *color, unsigned banned_color); |
27 | 27 | ||
28 | #endif | 28 | #endif |
diff --git a/apps/plugin.h b/apps/plugin.h index 70a3fa2a1b..e5766c68b5 100644 --- a/apps/plugin.h +++ b/apps/plugin.h | |||
@@ -686,8 +686,8 @@ struct plugin_api { | |||
686 | bool (*set_bool)(const char* string, const bool* variable ); | 686 | bool (*set_bool)(const char* string, const bool* variable ); |
687 | 687 | ||
688 | #ifdef HAVE_LCD_COLOR | 688 | #ifdef HAVE_LCD_COLOR |
689 | bool (*set_color)(struct screen *display, char *title, unsigned *color, | 689 | bool (*set_color)(struct screen *display, char *title, |
690 | unsigned banned_color); | 690 | unsigned *color, unsigned banned_color); |
691 | #endif | 691 | #endif |
692 | /* action handling */ | 692 | /* action handling */ |
693 | int (*get_custom_action)(int context,int timeout, | 693 | int (*get_custom_action)(int context,int timeout, |