diff options
author | Thomas Martitz <kugel@rockbox.org> | 2009-09-13 13:40:58 +0000 |
---|---|---|
committer | Thomas Martitz <kugel@rockbox.org> | 2009-09-13 13:40:58 +0000 |
commit | c0f1c49178b4c205e1c990ea2fb25a417305528c (patch) | |
tree | 637fdedd15f2119125cdaa257fbf7798e8687e74 | |
parent | 541dd6fda5ae93073a0b9c499f62af2cf46f3529 (diff) | |
download | rockbox-c0f1c49178b4c205e1c990ea2fb25a417305528c.tar.gz rockbox-c0f1c49178b4c205e1c990ea2fb25a417305528c.zip |
Get rid of some of the code duplication from checkwps, it still duplicates a lot though.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22695 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/gui/viewport.c | 106 | ||||
-rw-r--r-- | apps/gui/viewport.h | 44 | ||||
-rw-r--r-- | firmware/export/font.h | 2 | ||||
-rw-r--r-- | tools/checkwps/SOURCES | 1 | ||||
-rw-r--r-- | tools/checkwps/checkwps.c | 120 | ||||
-rw-r--r-- | tools/checkwps/checkwps.h | 2 |
6 files changed, 83 insertions, 192 deletions
diff --git a/apps/gui/viewport.c b/apps/gui/viewport.c index 06caa2379d..ff3a110936 100644 --- a/apps/gui/viewport.c +++ b/apps/gui/viewport.c | |||
@@ -24,18 +24,10 @@ | |||
24 | #include "lcd.h" | 24 | #include "lcd.h" |
25 | #include "lcd-remote.h" | 25 | #include "lcd-remote.h" |
26 | #include "font.h" | 26 | #include "font.h" |
27 | #include "sprintf.h" | ||
28 | #include "string.h" | ||
29 | #include "settings.h" | ||
30 | #include "kernel.h" | ||
31 | #include "system.h" | ||
32 | #include "misc.h" | ||
33 | #include "viewport.h" | 27 | #include "viewport.h" |
34 | #include "statusbar.h" | ||
35 | #include "screen_access.h" | 28 | #include "screen_access.h" |
36 | #include "appevents.h" | 29 | #include "settings.h" |
37 | 30 | #include "misc.h" | |
38 | |||
39 | 31 | ||
40 | /*some short cuts for fg/bg/line selector handling */ | 32 | /*some short cuts for fg/bg/line selector handling */ |
41 | #ifdef HAVE_LCD_COLOR | 33 | #ifdef HAVE_LCD_COLOR |
@@ -54,6 +46,17 @@ | |||
54 | #define BG_FALLBACK LCD_DEFAULT_BG | 46 | #define BG_FALLBACK LCD_DEFAULT_BG |
55 | #endif | 47 | #endif |
56 | 48 | ||
49 | /* all below isn't needed for pc tools (i.e. checkwps/wps editor) | ||
50 | * only viewport_parse_viewport() is */ | ||
51 | #ifndef __PCTOOL__ | ||
52 | #include "sprintf.h" | ||
53 | #include "string.h" | ||
54 | #include "kernel.h" | ||
55 | #include "system.h" | ||
56 | #include "statusbar.h" | ||
57 | #include "appevents.h" | ||
58 | |||
59 | |||
57 | static int statusbar_enabled = 0; | 60 | static int statusbar_enabled = 0; |
58 | 61 | ||
59 | #ifdef HAVE_LCD_BITMAP | 62 | #ifdef HAVE_LCD_BITMAP |
@@ -295,12 +298,55 @@ bool viewport_ui_vp_get_state(enum screen_type screen) | |||
295 | return ui_vp_info.active[screen]; | 298 | return ui_vp_info.active[screen]; |
296 | } | 299 | } |
297 | 300 | ||
301 | /* | ||
302 | * (re)parse the UI vp from the settings | ||
303 | * - Returns | ||
304 | * 0 if no UI vp is used at all | ||
305 | * else the bit for the screen (1<<screen) is set | ||
306 | */ | ||
307 | static unsigned viewport_init_ui_vp(void) | ||
308 | { | ||
309 | int screen; | ||
310 | unsigned ret = 0; | ||
311 | char *setting; | ||
312 | FOR_NB_SCREENS(screen) | ||
313 | { | ||
314 | #ifdef HAVE_REMOTE_LCD | ||
315 | if ((screen == SCREEN_REMOTE)) | ||
316 | setting = global_settings.remote_ui_vp_config; | ||
317 | else | ||
318 | #endif | ||
319 | setting = global_settings.ui_vp_config; | ||
320 | |||
321 | |||
322 | if (!(viewport_parse_viewport(&custom_vp[screen], screen, | ||
323 | setting, ','))) | ||
324 | viewport_set_fullscreen(&custom_vp[screen], screen); | ||
325 | else | ||
326 | ret |= BIT_N(screen); | ||
327 | } | ||
328 | return ret; | ||
329 | } | ||
330 | |||
331 | #ifdef HAVE_TOUCHSCREEN | ||
332 | /* check if a point (x and y coordinates) are within a viewport */ | ||
333 | bool viewport_point_within_vp(const struct viewport *vp, int x, int y) | ||
334 | { | ||
335 | bool is_x = (x >= vp->x && x < (vp->x + vp->width)); | ||
336 | bool is_y = (y >= vp->y && y < (vp->y + vp->height)); | ||
337 | return (is_x && is_y); | ||
338 | } | ||
339 | #endif /* HAVE_TOUCHSCREEN */ | ||
340 | #endif /* HAVE_LCD_BITMAP */ | ||
341 | #endif /* __PCTOOL__ */ | ||
342 | |||
298 | #ifdef HAVE_LCD_COLOR | 343 | #ifdef HAVE_LCD_COLOR |
299 | #define ARG_STRING(_depth) ((_depth) == 2 ? "dddddgg":"dddddcc") | 344 | #define ARG_STRING(_depth) ((_depth) == 2 ? "dddddgg":"dddddcc") |
300 | #else | 345 | #else |
301 | #define ARG_STRING(_depth) "dddddgg" | 346 | #define ARG_STRING(_depth) "dddddgg" |
302 | #endif | 347 | #endif |
303 | 348 | ||
349 | #ifdef HAVE_LCD_BITMAP | ||
304 | const char* viewport_parse_viewport(struct viewport *vp, | 350 | const char* viewport_parse_viewport(struct viewport *vp, |
305 | enum screen_type screen, | 351 | enum screen_type screen, |
306 | const char *bufptr, | 352 | const char *bufptr, |
@@ -386,44 +432,4 @@ const char* viewport_parse_viewport(struct viewport *vp, | |||
386 | 432 | ||
387 | return ptr; | 433 | return ptr; |
388 | } | 434 | } |
389 | |||
390 | /* | ||
391 | * (re)parse the UI vp from the settings | ||
392 | * - Returns | ||
393 | * 0 if no UI vp is used at all | ||
394 | * else the bit for the screen (1<<screen) is set | ||
395 | */ | ||
396 | static unsigned viewport_init_ui_vp(void) | ||
397 | { | ||
398 | int screen; | ||
399 | unsigned ret = 0; | ||
400 | char *setting; | ||
401 | FOR_NB_SCREENS(screen) | ||
402 | { | ||
403 | #ifdef HAVE_REMOTE_LCD | ||
404 | if ((screen == SCREEN_REMOTE)) | ||
405 | setting = global_settings.remote_ui_vp_config; | ||
406 | else | ||
407 | #endif | 435 | #endif |
408 | setting = global_settings.ui_vp_config; | ||
409 | |||
410 | |||
411 | if (!(viewport_parse_viewport(&custom_vp[screen], screen, | ||
412 | setting, ','))) | ||
413 | viewport_set_fullscreen(&custom_vp[screen], screen); | ||
414 | else | ||
415 | ret |= BIT_N(screen); | ||
416 | } | ||
417 | return ret; | ||
418 | } | ||
419 | |||
420 | #ifdef HAVE_TOUCHSCREEN | ||
421 | /* check if a point (x and y coordinates) are within a viewport */ | ||
422 | bool viewport_point_within_vp(const struct viewport *vp, int x, int y) | ||
423 | { | ||
424 | bool is_x = (x >= vp->x && x < (vp->x + vp->width)); | ||
425 | bool is_y = (y >= vp->y && y < (vp->y + vp->height)); | ||
426 | return (is_x && is_y); | ||
427 | } | ||
428 | #endif /* HAVE_TOUCHSCREEN */ | ||
429 | #endif /* HAVE_LCD_BITMAP */ | ||
diff --git a/apps/gui/viewport.h b/apps/gui/viewport.h index d431766ab5..9cabc00468 100644 --- a/apps/gui/viewport.h +++ b/apps/gui/viewport.h | |||
@@ -66,6 +66,7 @@ void viewport_set_defaults(struct viewport *vp, enum screen_type screen); | |||
66 | #define VP_SB_IGNORE_SETTING(screen) BIT_N(4+screen) | 66 | #define VP_SB_IGNORE_SETTING(screen) BIT_N(4+screen) |
67 | #define VP_SB_ALLSCREENS (VP_SB_ONSCREEN(0)|VP_SB_ONSCREEN(1)) | 67 | #define VP_SB_ALLSCREENS (VP_SB_ONSCREEN(0)|VP_SB_ONSCREEN(1)) |
68 | 68 | ||
69 | #ifndef __PCTOOL__ | ||
69 | /* | 70 | /* |
70 | * Initialize the viewportmanager, which in turns initializes the UI vp and | 71 | * Initialize the viewportmanager, which in turns initializes the UI vp and |
71 | * statusbar stuff | 72 | * statusbar stuff |
@@ -86,25 +87,6 @@ void viewport_set_fullscreen(struct viewport *vp, enum screen_type screen); | |||
86 | #ifdef HAVE_LCD_BITMAP | 87 | #ifdef HAVE_LCD_BITMAP |
87 | 88 | ||
88 | /* | 89 | /* |
89 | * Parse a viewport definition (vp_def), which looks like: | ||
90 | * | ||
91 | * Screens with depth > 1: | ||
92 | * X|Y|width|height|font|foregorund color|background color | ||
93 | * Screens with depth = 1: | ||
94 | * X|Y|width|height|font | ||
95 | * | ||
96 | * | is a separator and can be specified via the parameter | ||
97 | * | ||
98 | * Returns the pointer to the char after the last character parsed | ||
99 | * if everything went OK or NULL if an error happened (some values | ||
100 | * not specified in the definition) | ||
101 | */ | ||
102 | const char* viewport_parse_viewport(struct viewport *vp, | ||
103 | enum screen_type screen, | ||
104 | const char *vp_def, | ||
105 | const char separator); | ||
106 | |||
107 | /* | ||
108 | * Returns a pointer to the current viewport | 90 | * Returns a pointer to the current viewport |
109 | * - That could be the UI vp, or a viewport passed to do_menu() or the like | 91 | * - That could be the UI vp, or a viewport passed to do_menu() or the like |
110 | */ | 92 | */ |
@@ -129,4 +111,28 @@ bool viewport_point_within_vp(const struct viewport *vp, int x, int y); | |||
129 | #define viewport_set_current_vp(a) | 111 | #define viewport_set_current_vp(a) |
130 | #define viewport_get_current_vp() NULL | 112 | #define viewport_get_current_vp() NULL |
131 | #endif | 113 | #endif |
114 | |||
115 | #endif /* __PCTOOL__ */ | ||
116 | |||
117 | #ifdef HAVE_LCD_BITMAP | ||
118 | |||
119 | /* | ||
120 | * Parse a viewport definition (vp_def), which looks like: | ||
121 | * | ||
122 | * Screens with depth > 1: | ||
123 | * X|Y|width|height|font|foregorund color|background color | ||
124 | * Screens with depth = 1: | ||
125 | * X|Y|width|height|font | ||
126 | * | ||
127 | * | is a separator and can be specified via the parameter | ||
128 | * | ||
129 | * Returns the pointer to the char after the last character parsed | ||
130 | * if everything went OK or NULL if an error happened (some values | ||
131 | * not specified in the definition) | ||
132 | */ | ||
133 | const char* viewport_parse_viewport(struct viewport *vp, | ||
134 | enum screen_type screen, | ||
135 | const char *vp_def, | ||
136 | const char separator); | ||
137 | #endif /* HAVE_LCD_BITMAP */ | ||
132 | #endif /* __VIEWPORT_H__ */ | 138 | #endif /* __VIEWPORT_H__ */ |
diff --git a/firmware/export/font.h b/firmware/export/font.h index d17fa18b8b..75b012d722 100644 --- a/firmware/export/font.h +++ b/firmware/export/font.h | |||
@@ -62,13 +62,11 @@ | |||
62 | * must be available at system startup. | 62 | * must be available at system startup. |
63 | * Fonts are specified in firmware/font.c. | 63 | * Fonts are specified in firmware/font.c. |
64 | */ | 64 | */ |
65 | #ifndef __PCTOOL__ | ||
66 | enum { | 65 | enum { |
67 | FONT_SYSFIXED, /* system fixed pitch font*/ | 66 | FONT_SYSFIXED, /* system fixed pitch font*/ |
68 | FONT_UI, /* system porportional font*/ | 67 | FONT_UI, /* system porportional font*/ |
69 | MAXFONTS | 68 | MAXFONTS |
70 | }; | 69 | }; |
71 | #endif | ||
72 | 70 | ||
73 | /* | 71 | /* |
74 | * .fnt loadable font file format definition | 72 | * .fnt loadable font file format definition |
diff --git a/tools/checkwps/SOURCES b/tools/checkwps/SOURCES index 80b2f76510..4afa5587e1 100644 --- a/tools/checkwps/SOURCES +++ b/tools/checkwps/SOURCES | |||
@@ -7,4 +7,5 @@ checkwps.c | |||
7 | 7 | ||
8 | #ifdef HAVE_LCD_BITMAP | 8 | #ifdef HAVE_LCD_BITMAP |
9 | ../../apps/recorder/bmp.c | 9 | ../../apps/recorder/bmp.c |
10 | ../../apps/gui/viewport.c | ||
10 | #endif | 11 | #endif |
diff --git a/tools/checkwps/checkwps.c b/tools/checkwps/checkwps.c index 6e985195fb..079454def1 100644 --- a/tools/checkwps/checkwps.c +++ b/tools/checkwps/checkwps.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include "wps.h" | 28 | #include "wps.h" |
29 | #include "wps_internals.h" | 29 | #include "wps_internals.h" |
30 | #include "settings.h" | 30 | #include "settings.h" |
31 | #include "viewport.h" | ||
31 | 32 | ||
32 | bool debug_wps = true; | 33 | bool debug_wps = true; |
33 | int wps_verbose_level = 0; | 34 | int wps_verbose_level = 0; |
@@ -294,125 +295,6 @@ struct skin_viewport* find_viewport(char label, struct wps_data *data) | |||
294 | return NULL; | 295 | return NULL; |
295 | } | 296 | } |
296 | 297 | ||
297 | /* From viewport.c & misc.h */ | ||
298 | #define LIST_VALUE_PARSED(setvals, position) ((setvals) & BIT_N(position)) | ||
299 | |||
300 | /*some short cuts for fg/bg/line selector handling */ | ||
301 | #ifdef HAVE_LCD_COLOR | ||
302 | #define LINE_SEL_FROM_SETTINGS(vp) \ | ||
303 | do { \ | ||
304 | vp->lss_pattern = global_settings.lss_color; \ | ||
305 | vp->lse_pattern = global_settings.lse_color; \ | ||
306 | vp->lst_pattern = global_settings.lst_color; \ | ||
307 | } while (0) | ||
308 | #define FG_FALLBACK global_settings.fg_color | ||
309 | #define BG_FALLBACK global_settings.bg_color | ||
310 | #else | ||
311 | /* mono/greyscale doesn't have most of the above */ | ||
312 | #define LINE_SEL_FROM_SETTINGS(vp) | ||
313 | #define FG_FALLBACK LCD_DEFAULT_FG | ||
314 | #define BG_FALLBACK LCD_DEFAULT_BG | ||
315 | #endif | ||
316 | |||
317 | #ifdef HAVE_LCD_COLOR | ||
318 | #define ARG_STRING(_depth) ((_depth) == 2 ? "dddddgg":"dddddcc") | ||
319 | #else | ||
320 | #define ARG_STRING(_depth) "dddddgg" | ||
321 | #endif | ||
322 | |||
323 | extern const char* parse_list(const char *fmt, uint32_t *set_vals, | ||
324 | const char sep, const char* str, ...); | ||
325 | |||
326 | const char* viewport_parse_viewport(struct viewport *vp, | ||
327 | enum screen_type screen, | ||
328 | const char *bufptr, | ||
329 | const char separator) | ||
330 | { | ||
331 | /* parse the list to the viewport struct */ | ||
332 | const char *ptr = bufptr; | ||
333 | int depth; | ||
334 | uint32_t set = 0; | ||
335 | |||
336 | enum { | ||
337 | PL_X = 0, | ||
338 | PL_Y, | ||
339 | PL_WIDTH, | ||
340 | PL_HEIGHT, | ||
341 | PL_FONT, | ||
342 | PL_FG, | ||
343 | PL_BG, | ||
344 | }; | ||
345 | |||
346 | /* Work out the depth of this display */ | ||
347 | depth = screens[screen].depth; | ||
348 | #if (LCD_DEPTH == 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 1) | ||
349 | if (depth == 1) | ||
350 | { | ||
351 | #ifdef HAVE_LCD_BITMAP | ||
352 | if (!(ptr = parse_list("ddddd", &set, separator, ptr, | ||
353 | &vp->x, &vp->y, &vp->width, &vp->height, &vp->font))) | ||
354 | return NULL; | ||
355 | #endif | ||
356 | } | ||
357 | else | ||
358 | #endif | ||
359 | #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1) | ||
360 | if (depth >= 2) | ||
361 | { | ||
362 | if (!(ptr = parse_list(ARG_STRING(depth), &set, separator, ptr, | ||
363 | &vp->x, &vp->y, &vp->width, &vp->height, &vp->font, | ||
364 | &vp->fg_pattern,&vp->bg_pattern))) | ||
365 | return NULL; | ||
366 | } | ||
367 | else | ||
368 | #endif | ||
369 | {} | ||
370 | #undef ARG_STRING | ||
371 | |||
372 | /* X and Y *must* be set */ | ||
373 | if (!LIST_VALUE_PARSED(set, PL_X) || !LIST_VALUE_PARSED(set, PL_Y)) | ||
374 | return NULL; | ||
375 | |||
376 | /* fix defaults */ | ||
377 | if (!LIST_VALUE_PARSED(set, PL_WIDTH)) | ||
378 | vp->width = screens[screen].lcdwidth - vp->x; | ||
379 | if (!LIST_VALUE_PARSED(set, PL_HEIGHT)) | ||
380 | vp->height = screens[screen].lcdheight - vp->y; | ||
381 | |||
382 | #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1) | ||
383 | if (!LIST_VALUE_PARSED(set, PL_FG)) | ||
384 | vp->fg_pattern = FG_FALLBACK; | ||
385 | if (!LIST_VALUE_PARSED(set, PL_BG)) | ||
386 | vp->bg_pattern = BG_FALLBACK; | ||
387 | #endif /* LCD_DEPTH > 1 || LCD_REMOTE_DEPTH > 1 */ | ||
388 | |||
389 | LINE_SEL_FROM_SETTINGS(vp); | ||
390 | |||
391 | /* Validate the viewport dimensions - we know that the numbers are | ||
392 | non-negative integers, ignore bars and assume the viewport takes them | ||
393 | * into account */ | ||
394 | if ((vp->x >= screens[screen].lcdwidth) || | ||
395 | ((vp->x + vp->width) > screens[screen].lcdwidth) || | ||
396 | (vp->y >= screens[screen].lcdheight) || | ||
397 | ((vp->y + vp->height) > screens[screen].lcdheight)) | ||
398 | { | ||
399 | return NULL; | ||
400 | } | ||
401 | |||
402 | #ifdef HAVE_LCD_BITMAP | ||
403 | /* Default to using the user font if the font was an invalid number or '-'*/ | ||
404 | if (((vp->font != FONT_SYSFIXED) && (vp->font != FONT_UI)) | ||
405 | || !LIST_VALUE_PARSED(set, PL_FONT) | ||
406 | ) | ||
407 | vp->font = FONT_UI; | ||
408 | |||
409 | /* Set the defaults for fields not user-specified */ | ||
410 | vp->drawmode = DRMODE_SOLID; | ||
411 | #endif | ||
412 | |||
413 | return ptr; | ||
414 | } | ||
415 | |||
416 | int main(int argc, char **argv) | 298 | int main(int argc, char **argv) |
417 | { | 299 | { |
418 | int res; | 300 | int res; |
diff --git a/tools/checkwps/checkwps.h b/tools/checkwps/checkwps.h index 1032cca246..dd7da32776 100644 --- a/tools/checkwps/checkwps.h +++ b/tools/checkwps/checkwps.h | |||
@@ -25,8 +25,6 @@ | |||
25 | #include <stdlib.h> | 25 | #include <stdlib.h> |
26 | #include <stdbool.h> | 26 | #include <stdbool.h> |
27 | 27 | ||
28 | #define FONT_SYSFIXED 0 | ||
29 | #define FONT_UI 1 | ||
30 | #define SYSFONT_HEIGHT 8 | 28 | #define SYSFONT_HEIGHT 8 |
31 | 29 | ||
32 | #ifndef MIN | 30 | #ifndef MIN |