Index: theme_engine.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/utility/ftwl/theme_engine.c,v retrieving revision 1.2 diff -u -r1.2 theme_engine.c --- theme_engine.c 29 Jul 2004 10:09:49 -0000 1.2 +++ theme_engine.c 29 Jul 2004 10:37:00 -0000 @@ -59,11 +59,13 @@ static char *current_theme; static char current_res[30]; +static int theme_bytes_per_pixel; /************************************************************************* - ... + Initialize theme engine and look for theme directory containing the + given example file. *************************************************************************/ -void te_init(const char *theme) +void te_init(const char *theme, char *example_file) { struct ct_size size; be_screen_get_size(&size); @@ -73,8 +75,8 @@ my_snprintf(current_res, sizeof(current_res), "%dx%d", size.width, size.height); - my_snprintf(filename, sizeof(filename), "themes/%s/%s/mapview.screen", - current_theme, current_res); + my_snprintf(filename, sizeof(filename), "themes/%s/%s/%s", + current_theme, current_res, example_file); if (!datafilename(filename)) { freelog(LOG_FATAL, "ERROR: There is no theme '%s' in resolution '%s'.", current_theme, current_res); @@ -83,11 +85,19 @@ } /************************************************************************* + Initialize colour model from a palette file. +*************************************************************************/ +void te_init_colormodel(struct section_file *file) +{ + theme_bytes_per_pixel = secfile_lookup_int(file, "meta.bpp") / 8; +} + +/************************************************************************* ... *************************************************************************/ struct Sprite *te_load_gfx(const char *filename) { - const int prefixes=6; + const int prefixes = 6; char prefix[prefixes][512]; int i; @@ -100,12 +110,10 @@ my_snprintf(prefix[4], sizeof(prefix[4]), "themes/"); my_snprintf(prefix[5], sizeof(prefix[5]), "%s", ""); - //printf("searching for '%s' in:\n",filename); for (i = 0; i < prefixes; i++) { char fullname[512]; char *tmp; - //printf(" '%s'\n",prefix[i]); my_snprintf(fullname, sizeof(fullname), "%s%s", prefix[i], filename); tmp = datafilename(fullname); @@ -123,15 +131,15 @@ *************************************************************************/ static bool str_color_to_be_color(be_color *col, const char *s) { - int values[3]; + int values[theme_bytes_per_pixel]; int i; - if (strlen(s) != 9 || s[0] != '#') { + if (strlen(s) != (theme_bytes_per_pixel * 2 + 1) || s[0] != '#') { return FALSE; } s++; - for (i = 0; i < 3; i++) { + for (i = 0; i < theme_bytes_per_pixel; i++) { char b[3]; int scanned; @@ -143,6 +151,7 @@ assert(scanned == 1); s += 2; } + /* FIXME: this needs to be generalized for other bitdepths */ *col = be_get_color(values[0], values[1], values[2]); return TRUE; } Index: theme_engine.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/utility/ftwl/theme_engine.h,v retrieving revision 1.1 diff -u -r1.1 theme_engine.h --- theme_engine.h 22 Jul 2004 20:00:55 -0000 1.1 +++ theme_engine.h 29 Jul 2004 10:37:00 -0000 @@ -36,7 +36,8 @@ struct keybinding_list *keybindings; }; -void te_init(const char *theme); +void te_init(const char *theme, char *example_file); +void te_init_colormodel(struct section_file *file); struct section_file *te_open_themed_file(const char *name); struct te_screen *te_get_screen(struct sw_widget *parent_window, const char *screen_name,