[Freeciv-Dev] (PR#14866) gui-sdl: theme colors patch
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=14866 >
This patch adds support for color descriptions to the gui-sdl theme
system. The code is derived from colors_common.c, so there's nearly no
difference to the tileset color system except the use of RGBA colors. A
sample colors.themespec file is attached.
Index: client/gui-sdl/citydlg.c
===================================================================
--- client/gui-sdl/citydlg.c (Revision 11348)
+++ client/gui-sdl/citydlg.c (Arbeitskopie)
@@ -32,20 +32,21 @@
#include <SDL/SDL.h>
#include "city.h"
+#include "civclient.h"
+#include "climisc.h"
+#include "climap.h"
#include "fcintl.h"
#include "game.h"
#include "map.h"
#include "improvement.h"
#include "log.h"
-#include "gui_mem.h"
-
#include "packets.h"
#include "player.h"
#include "shared.h"
#include "support.h"
+#include "text.h"
-#include "civclient.h"
#include "cityrep.h"
#include "cma_fe.h"
#include "colors.h"
@@ -55,28 +56,24 @@
#include "graphics.h"
#include "gui_main.h"
#include "gui_id.h"
+#include "gui_mem.h"
#include "gui_string.h"
#include "gui_stuff.h"
+#include "gui_tilespec.h"
#include "gui_zoom.h"
#include "happiness.h"
#include "helpdlg.h"
#include "inputdlg.h"
#include "mapctrl.h"
#include "mapview.h"
+#include "menu.h"
+#include "optiondlg.h"
#include "options.h"
#include "repodlgs.h"
+#include "themecolors.h"
#include "tilespec.h"
-#include "climisc.h"
-#include "climap.h"
#include "wldlg.h"
-#include "gui_tilespec.h"
-#include "text.h"
-#include "optiondlg.h"
-#include "menu.h"
-
-/*#include "cityicon.ico"*/
-
#include "citydlg.h"
/* ============================================================= */
@@ -604,7 +601,7 @@
/* create window background */
resize_window(pWindow, NULL,
- get_game_colorRGB(COLOR_STD_BACKGROUND_BROWN), ww,
+ get_game_colorRGB(COLOR_THEME_BACKGROUND_BROWN), ww,
WINDOW_TILE_HIGH + adj_size(2) + FRAME_WH + (i * hh) +
pWindow->prev->size.h + adj_size(5));
@@ -1282,7 +1279,7 @@
}
resize_window(pWindow, NULL,
- get_game_colorRGB(COLOR_STD_BACKGROUND_BROWN),
+ get_game_colorRGB(COLOR_THEME_BACKGROUND_BROWN),
ww + DOUBLE_FRAME_WH, hh + FRAME_WH + 5);
/* setup rest of widgets */
@@ -1478,7 +1475,7 @@
/* create window background */
resize_window(pWindow, NULL,
- get_game_colorRGB(COLOR_STD_BACKGROUND_BROWN),
+ get_game_colorRGB(COLOR_THEME_BACKGROUND_BROWN),
pWindow->size.w, pWindow->size.h);
/* enable widgets */
@@ -2563,7 +2560,7 @@
my_snprintf(cBuf, sizeof(cBuf), _("City map"));
pStr = create_str16_from_char(cBuf, adj_font(11));
- pStr->fgcol = *get_game_colorRGB(COLOR_STD_CITY_GOLD);
+ pStr->fgcol = *get_game_colorRGB(COLOR_THEME_CITY_GOLD);
pStr->style |= TTF_STYLE_BOLD;
pBuf = create_text_surf_from_str16(pStr);
@@ -2578,7 +2575,7 @@
my_snprintf(cBuf, sizeof(cBuf), _("Citizens"));
copy_chars_to_string16(pStr, cBuf);
- pStr->fgcol = *get_game_colorRGB(COLOR_STD_CITY_LUX);
+ pStr->fgcol = *get_game_colorRGB(COLOR_THEME_CITY_LUX);
pBuf = create_text_surf_from_str16(pStr);
@@ -2592,7 +2589,7 @@
my_snprintf(cBuf, sizeof(cBuf), _("City Improvements"));
copy_chars_to_string16(pStr, cBuf);
- pStr->fgcol = *get_game_colorRGB(COLOR_STD_CITY_GOLD);
+ pStr->fgcol = *get_game_colorRGB(COLOR_THEME_CITY_GOLD);
pBuf = create_text_surf_from_str16(pStr);
@@ -2645,7 +2642,7 @@
pCity->surplus[O_FOOD]);
copy_chars_to_string16(pStr, cBuf);
- pStr->fgcol = *get_game_colorRGB(COLOR_STD_CITY_FOOD_SURPLUS);
+ pStr->fgcol = *get_game_colorRGB(COLOR_THEME_CITY_FOOD_SURPLUS);
pBuf = create_text_surf_from_str16(pStr);
@@ -2694,7 +2691,7 @@
pCity->prod[O_SHIELD] + pCity->waste[O_SHIELD]);
copy_chars_to_string16(pStr, cBuf);
- pStr->fgcol = *get_game_colorRGB(COLOR_STD_CITY_PROD);
+ pStr->fgcol = *get_game_colorRGB(COLOR_THEME_CITY_PROD);
pBuf = create_text_surf_from_str16(pStr);
@@ -2739,7 +2736,7 @@
pCity->prod[O_SHIELD] + pCity->waste[O_SHIELD] -
pCity->surplus[O_SHIELD]);
copy_chars_to_string16(pStr, cBuf);
- pStr->fgcol = *get_game_colorRGB(COLOR_STD_CITY_SUPPORT);
+ pStr->fgcol = *get_game_colorRGB(COLOR_THEME_CITY_SUPPORT);
pBuf = create_text_surf_from_str16(pStr);
@@ -2776,7 +2773,7 @@
pCity->surplus[O_TRADE]);
copy_chars_to_string16(pStr, cBuf);
- pStr->fgcol = *get_game_colorRGB(COLOR_STD_CITY_TRADE);
+ pStr->fgcol = *get_game_colorRGB(COLOR_THEME_CITY_TRADE);
pBuf = create_text_surf_from_str16(pStr);
@@ -2849,7 +2846,7 @@
pCity->surplus[O_GOLD], pCity->prod[O_GOLD]);
copy_chars_to_string16(pStr, cBuf);
- pStr->fgcol = *get_game_colorRGB(COLOR_STD_CITY_GOLD);
+ pStr->fgcol = *get_game_colorRGB(COLOR_THEME_CITY_GOLD);
pBuf = create_text_surf_from_str16(pStr);
@@ -2896,7 +2893,7 @@
pCity->prod[O_GOLD] - pCity->surplus[O_GOLD]);
copy_chars_to_string16(pStr, cBuf);
- pStr->fgcol = *get_game_colorRGB(COLOR_STD_CITY_UNKEEP);
+ pStr->fgcol = *get_game_colorRGB(COLOR_THEME_CITY_UPKEEP);
pBuf = create_text_surf_from_str16(pStr);
@@ -2935,7 +2932,7 @@
pCity->prod[O_SCIENCE]);
copy_chars_to_string16(pStr, cBuf);
- pStr->fgcol = *get_game_colorRGB(COLOR_STD_CITY_SCIENCE);
+ pStr->fgcol = *get_game_colorRGB(COLOR_THEME_CITY_SCIENCE);
pBuf = create_text_surf_from_str16(pStr);
@@ -2975,7 +2972,7 @@
pCity->prod[O_LUXURY]);
copy_chars_to_string16(pStr, cBuf);
- pStr->fgcol = *get_game_colorRGB(COLOR_STD_CITY_LUX);
+ pStr->fgcol = *get_game_colorRGB(COLOR_THEME_CITY_LUX);
pBuf = create_text_surf_from_str16(pStr);
@@ -3341,7 +3338,7 @@
}
copy_chars_to_string16(pStr, cBuf);
- pStr->fgcol = *get_game_colorRGB(COLOR_STD_CITY_LUX);
+ pStr->fgcol = *get_game_colorRGB(COLOR_THEME_CITY_LUX);
pBuf = create_text_surf_from_str16(pStr);
Index: client/gui-sdl/optiondlg.c
===================================================================
--- client/gui-sdl/optiondlg.c (Revision 11348)
+++ client/gui-sdl/optiondlg.c (Arbeitskopie)
@@ -55,6 +55,7 @@
#include "wldlg.h"
#include "colors.h"
#include "connectdlg.h"
+#include "themecolors.h"
#include "optiondlg.h"
#include "options.h"
@@ -261,7 +262,7 @@
/* No more worklist slots free. */
if (j == MAX_NUM_WORKLISTS) {
set_wstate(pWidget, FC_WS_DISABLED);
- pWidget->string16->fgcol = *(get_game_colorRGB(COLOR_STD_DISABLED));
+ pWidget->string16->fgcol = *(get_game_colorRGB(COLOR_THEME_DISABLED));
}
Index: client/gui-sdl/mapview.c
===================================================================
--- client/gui-sdl/mapview.c (Revision 11348)
+++ client/gui-sdl/mapview.c (Arbeitskopie)
@@ -169,13 +169,16 @@
/**************************************************************************
Draw a filled-in colored rectangle onto the mapview or citydialog canvas.
**************************************************************************/
-void canvas_put_rectangle(struct canvas *pcanvas,
- struct color *pcolor,
- int canvas_x, int canvas_y, int width, int height)
+void canvas_put_rectangle(struct canvas *pcanvas, struct color *pcolor,
+ int canvas_x, int canvas_y, int width, int height)
{
SDL_Rect dst = {canvas_x, canvas_y, width, height};
- SDL_FillRect(pcanvas->surf, &dst,
- get_game_color(pcolor, pcanvas->surf));
+
+ SDL_FillRect(pcanvas->surf, &dst, SDL_MapRGBA(pcanvas->surf->format,
+ pcolor->color->r,
+ pcolor->color->g,
+ pcolor->color->b,
+ pcolor->color->unused));
}
/**************************************************************************
@@ -186,7 +189,11 @@
int dx, int dy)
{
putline(pcanvas->surf, start_x, start_y, start_x + dx, start_y + dy,
- get_game_color(pcolor, pcanvas->surf));
+ SDL_MapRGBA(pcanvas->surf->format,
+ pcolor->color->r,
+ pcolor->color->g,
+ pcolor->color->b,
+ pcolor->color->unused));
}
/****************************************************************************
@@ -197,8 +204,13 @@
int canvas_x, int canvas_y)
{
SDL_Rect dst = {canvas_x, canvas_y, GET_SURF(psprite)->w,
- GET_SURF(psprite)->h};
- SDL_FillRect(pcanvas->surf, &dst, get_game_color(pcolor, pcanvas->surf));
+ GET_SURF(psprite)->h};
+
+ SDL_FillRect(pcanvas->surf, &dst, SDL_MapRGBA(pcanvas->surf->format,
+ pcolor->color->r,
+ pcolor->color->g,
+ pcolor->color->b,
+ pcolor->color->unused));
}
void canvas_fog_sprite_area(struct canvas *pcanvas, struct sprite *psprite,
Index: client/gui-sdl/gui_tilespec.c
===================================================================
--- client/gui-sdl/gui_tilespec.c (Revision 11348)
+++ client/gui-sdl/gui_tilespec.c (Arbeitskopie)
@@ -47,7 +47,7 @@
#ifdef SMALL_SCREEN
#define load_GUI_surface(pSpr, pStruct, pSurf, tag) \
do { \
- pSpr = themeset_lookup_sprite_tag_alt(themeset, tag, "", TRUE, "", ""); \
+ pSpr = theme_lookup_sprite_tag_alt(theme, tag, "", TRUE, "", ""); \
pStruct->pSurf = (pSpr ? GET_SURF(pSpr) : NULL); \
assert(pStruct->pSurf != NULL); \
pStruct->pSurf = ZoomSurface(pStruct->pSurf, 0.5, 0.5, 0); \
@@ -56,7 +56,7 @@
#else
#define load_GUI_surface(pSpr, pStruct, pSurf, tag) \
do { \
- pSpr = themeset_lookup_sprite_tag_alt(themeset, tag, "", TRUE, "", ""); \
+ pSpr = theme_lookup_sprite_tag_alt(theme, tag, "", TRUE, "", ""); \
pStruct->pSurf = (pSpr ? GET_SURF(pSpr) : NULL); \
assert(pStruct->pSurf != NULL); \
pSpr->psurface = NULL; \
@@ -207,8 +207,8 @@
...
**************************************************************************/
void tilespec_setup_city_gfx(void) {
- struct sprite *pSpr = themeset_lookup_sprite_tag_alt(
- themeset, "theme.city", "", TRUE, "", "");
+ struct sprite *pSpr = theme_lookup_sprite_tag_alt(
+ theme, "theme.city", "", TRUE, "", "");
pCity_Surf = (pSpr ? adj_surf(GET_SURF(pSpr)) : NULL);
@@ -337,7 +337,7 @@
pTheme = MALLOC(sizeof(struct Theme));
- if(!themeset_lookup_sprite_tag_alt(themeset, "theme.tech_tree", "", FALSE,
"", "")) {
+ if(!theme_lookup_sprite_tag_alt(theme, "theme.tech_tree", "", FALSE, "",
"")) {
freelog(LOG_FATAL, "Your current tileset don't contains ""all"" GUI theme
graphic\n"
"Please use other tileset with ""full"" GUI graphic pack (use -t tileset
options)\n"
"If you don't have any tileset with SDLClient GUI theme then go to
freeciv\n"
Index: client/gui-sdl/repodlgs.c
===================================================================
--- client/gui-sdl/repodlgs.c (Revision 11348)
+++ client/gui-sdl/repodlgs.c (Arbeitskopie)
@@ -59,6 +59,8 @@
#include "mapview.h"
#include "mapctrl.h"
+#include "themecolors.h"
+
#include "repodlgs_common.h"
#include "repodlgs.h"
@@ -262,7 +264,7 @@
(pUnitsDlg->pEndWidgetList->size.h - hh) / 2;
resize_window(pWindow, NULL,
- get_game_colorRGB(COLOR_STD_BACKGROUND_BROWN),
+ get_game_colorRGB(COLOR_THEME_BACKGROUND_BROWN),
ww + DOUBLE_FRAME_WH, hh);
/* setup rest of widgets */
@@ -1548,7 +1550,7 @@
(pEconomyDlg->pEndWidgetList->size.h - hh) / 2;
resize_window(pWindow, NULL,
- get_game_colorRGB(COLOR_STD_BACKGROUND_BROWN),
+ get_game_colorRGB(COLOR_THEME_BACKGROUND_BROWN),
ww + DOUBLE_FRAME_WH, hh);
/* setup rest of widgets */
Index: client/gui-sdl/themes.c
===================================================================
--- client/gui-sdl/themes.c (Revision 11348)
+++ client/gui-sdl/themes.c (Arbeitskopie)
@@ -34,12 +34,12 @@
char buf[strlen(directory) + strlen("/") + strlen(theme_name) +
strlen("/theme") + 1];
/* free previous loaded theme, if any */
- themeset_free(themeset);
+ theme_free(theme);
my_snprintf(buf, sizeof(buf), "%s/%s/theme", directory, theme_name);
themespec_try_read(buf);
- themeset_load_tiles(themeset);
+ theme_load_sprites(theme);
}
/*****************************************************************************
@@ -47,7 +47,7 @@
*****************************************************************************/
void gui_clear_theme(void)
{
- themeset_free(themeset);
+ theme_free(theme);
load_theme(GUI_SDL_DEFAULT_THEME);
}
Index: client/gui-sdl/gui_stuff.c
===================================================================
--- client/gui-sdl/gui_stuff.c (Revision 11348)
+++ client/gui-sdl/gui_stuff.c (Arbeitskopie)
@@ -43,6 +43,7 @@
#include "gui_main.h"
#include "mapview.h"
#include "log.h"
+#include "themecolors.h"
#include "gui_id.h"
#include "gui_stuff.h"
@@ -687,12 +688,12 @@
/*SDL_SetAlpha(pText, 0x0, 0x0);*/
pWidget->string16->fgcol = color;
- color = *get_game_colorRGB(COLOR_STD_QUICK_INFO);
+ color = *get_game_colorRGB(COLOR_THEME_QUICK_INFO);
color.unused = 150;
pBcgd = create_filled_surface(pText->w + adj_size(10), pText->h +
adj_size(6), SDL_SWSURFACE,
- get_game_colorRGB(COLOR_STD_QUICK_INFO));
+ get_game_colorRGB(COLOR_THEME_QUICK_INFO));
/* callculate start position */
@@ -2858,7 +2859,7 @@
}
if (state == FC_WS_DISABLED) {
- SDL_Color c = *get_game_colorRGB(COLOR_STD_DISABLED);
+ SDL_Color c = *get_game_colorRGB(COLOR_THEME_DISABLED);
putframe(pIcon->dst, dest.x + 1, dest.y + 1,
dest.x + dest.w + adj_size(2), dest.y + dest.h + adj_size(2),
SDL_MapRGBA(pIcon->dst->format, c.r, c.g, c.b, c.unused));
Index: client/gui-sdl/cma_fe.c
===================================================================
--- client/gui-sdl/cma_fe.c (Revision 11348)
+++ client/gui-sdl/cma_fe.c (Arbeitskopie)
@@ -38,6 +38,7 @@
#include "gui_tilespec.h"
#include "gui_stuff.h"
#include "mapview.h"
+#include "themecolors.h"
#include "cma_fec.h"
#include "cma_fe.h"
@@ -338,7 +339,7 @@
pWindow->size.y = pWidget->size.y - (hh + FRAME_WH);
resize_window(pWindow, NULL,
- get_game_colorRGB(COLOR_STD_BACKGROUND_BROWN),
+ get_game_colorRGB(COLOR_THEME_BACKGROUND_BROWN),
ww + DOUBLE_FRAME_WH, hh + FRAME_WH);
/* setup rest of widgets */
Index: client/gui-sdl/themespec.c
===================================================================
--- client/gui-sdl/themespec.c (Revision 11348)
+++ client/gui-sdl/themespec.c (Arbeitskopie)
@@ -13,7 +13,7 @@
/**********************************************************************
Functions for handling the themespec files which describe
- the files and contents of themesets.
+ the files and contents of themes.
original author: David Pfitzner <dwp@xxxxxxxxxxxxxx>
***********************************************************************/
@@ -51,6 +51,7 @@
#include "themes_common.h"
#include "themespec.h"
+#include "themecolors.h"
#include "gui_tilespec.h"
@@ -105,7 +106,7 @@
TYPED_LIST_ITERATE(struct small_sprite, list, pitem)
#define small_sprite_list_iterate_end LIST_ITERATE_END
-struct themeset {
+struct theme {
char name[512];
int priority;
@@ -121,9 +122,11 @@
struct hash_table *sprite_hash;
/* struct named_sprites sprites;*/
+
+ struct theme_color_system *color_system;
};
-struct themeset *themeset;
+struct theme *theme;
#define THEMESPEC_CAPSTR "+themespec3 duplicates_ok"
/*
@@ -132,7 +135,7 @@
* +themespec3 - basic format; required
*
* duplicates_ok - we can handle existence of duplicate tags
- * (lattermost tag which appears is used; themesets which
+ * (lattermost tag which appears is used; themes which
* have duplicates should specify "+duplicates_ok")
*/
@@ -144,9 +147,9 @@
/****************************************************************************
- Return the name of the given themeset.
+ Return the name of the given theme.
****************************************************************************/
-const char *themeset_get_name(const struct themeset *t)
+const char *theme_get_name(const struct theme *t)
{
return t->name;
}
@@ -156,7 +159,7 @@
file can be found. (It is left up to the GUI code to load and unload this
file.)
****************************************************************************/
-const char *themeset_main_intro_filename(const struct themeset *t)
+const char *theme_main_intro_filename(const struct theme *t)
{
return t->main_intro_filename;
}
@@ -166,7 +169,7 @@
file can be found. (It is left up to the GUI code to load and unload this
file.)
****************************************************************************/
-const char *themeset_mini_intro_filename(const struct themeset *t)
+const char *theme_mini_intro_filename(const struct theme *t)
{
return t->minimap_intro_filename;
}
@@ -174,9 +177,9 @@
/**************************************************************************
Initialize.
**************************************************************************/
-static struct themeset *themeset_new(void)
+static struct theme *theme_new(void)
{
- struct themeset *t = fc_calloc(1, sizeof(*t));
+ struct theme *t = fc_calloc(1, sizeof(*t));
t->specfiles = specfile_list_new();
t->small_sprites = small_sprite_list_new();
@@ -184,38 +187,38 @@
}
/**********************************************************************
- Returns a static list of themesets available on the system by
+ Returns a static list of themes available on the system by
searching all data directories for files matching THEMESPEC_SUFFIX.
The list is NULL-terminated.
***********************************************************************/
-const char **get_themeset_list(void)
+const char **get_theme_list(void)
{
- static const char **themesets = NULL;
+ static const char **themes = NULL;
- if (!themesets) {
+ if (!themes) {
/* Note: this means you must restart the client after installing a new
- themeset. */
+ theme. */
char **list = datafilelist(THEMESPEC_SUFFIX);
int i, count = 0;
for (i = 0; list[i]; i++) {
- struct themeset *t = themeset_read_toplevel(list[i]);
+ struct theme *t = theme_read_toplevel(list[i]);
if (t) {
- themesets = fc_realloc(themesets, (count + 1) * sizeof(*themesets));
- themesets[count] = list[i];
+ themes = fc_realloc(themes, (count + 1) * sizeof(*themes));
+ themes[count] = list[i];
count++;
- themeset_free(t);
+ theme_free(t);
} else {
free(list[i]);
}
}
- themesets = fc_realloc(themesets, (count + 1) * sizeof(*themesets));
- themesets[count] = NULL;
+ themes = fc_realloc(themes, (count + 1) * sizeof(*themes));
+ themes[count] = NULL;
}
- return themesets;
+ return themes;
}
/**********************************************************************
@@ -225,13 +228,13 @@
Falls back to default if can't find specified name;
dies if can't find default.
***********************************************************************/
-static char *themespec_fullname(const char *themeset_name)
+static char *themespec_fullname(const char *theme_name)
{
- if (themeset_name) {
- char fname[strlen(themeset_name) + strlen(THEMESPEC_SUFFIX) + 1], *dname;
+ if (theme_name) {
+ char fname[strlen(theme_name) + strlen(THEMESPEC_SUFFIX) + 1], *dname;
my_snprintf(fname, sizeof(fname),
- "%s%s", themeset_name, THEMESPEC_SUFFIX);
+ "%s%s", theme_name, THEMESPEC_SUFFIX);
/* dname = datafilename(fname);*/
dname = fname;
@@ -282,7 +285,7 @@
See themespec_read_toplevel().
***********************************************************************/
-static void themeset_free_toplevel(struct themeset *t)
+static void theme_free_toplevel(struct theme *t)
{
if (t->main_intro_filename) {
free(t->main_intro_filename);
@@ -292,16 +295,21 @@
free(t->minimap_intro_filename);
t->minimap_intro_filename = NULL;
}
+
+ if (t->color_system) {
+ theme_color_system_free(t->color_system);
+ t->color_system = NULL;
+ }
}
/**************************************************************************
Clean up.
**************************************************************************/
-void themeset_free(struct themeset *t)
+void theme_free(struct theme *t)
{
if (t) {
- themeset_free_tiles(t);
- themeset_free_toplevel(t);
+ theme_free_sprites(t);
+ theme_free_toplevel(t);
specfile_list_free(t->specfiles);
small_sprite_list_free(t->small_sprites);
free(t);
@@ -312,37 +320,37 @@
/**********************************************************************
Read a new themespec in when first starting the game.
- Call this function with the (guessed) name of the themeset, when
+ Call this function with the (guessed) name of the theme, when
starting the client.
***********************************************************************/
-void themespec_try_read(const char *themeset_name)
+void themespec_try_read(const char *theme_name)
{
- if (!(themeset = themeset_read_toplevel(themeset_name))) {
+ if (!(theme = theme_read_toplevel(theme_name))) {
char **list = datafilelist(THEMESPEC_SUFFIX);
int i;
for (i = 0; list[i]; i++) {
- struct themeset *t = themeset_read_toplevel(list[i]);
+ struct theme *t = theme_read_toplevel(list[i]);
if (t) {
- if (!themeset || t->priority > themeset->priority) {
- themeset = t;
+ if (!theme || t->priority > theme->priority) {
+ theme = t;
} else {
- themeset_free(t);
+ theme_free(t);
}
}
free(list[i]);
}
free(list);
- if (!themeset) {
- freelog(LOG_FATAL, _("No usable default themeset found, aborting!"));
+ if (!theme) {
+ freelog(LOG_FATAL, _("No usable default theme found, aborting!"));
exit(EXIT_FAILURE);
}
- freelog(LOG_NORMAL, _("Trying \"%s\" themeset."), themeset->name);
+ freelog(LOG_NORMAL, _("Trying \"%s\" theme."), theme->name);
}
-/* sz_strlcpy(default_themeset_name, themeset_get_name(themeset));*/
+/* sz_strlcpy(default_theme_name, theme_get_name(theme));*/
}
/**********************************************************************
@@ -350,24 +358,24 @@
Unlike the initial reading code, which reads pieces one at a time,
this gets rid of the old data and reads in the new all at once. If the
- new themeset fails to load the old themeset may be reloaded; otherwise the
- client will exit. If a NULL name is given the current themeset will be
+ new theme fails to load the old theme may be reloaded; otherwise the
+ client will exit. If a NULL name is given the current theme will be
reread.
It will also call the necessary functions to redraw the graphics.
***********************************************************************/
-void themespec_reread(const char *new_themeset_name)
+void themespec_reread(const char *new_theme_name)
{
struct tile *center_tile;
enum client_states state = get_client_state();
- const char *name = new_themeset_name ? new_themeset_name : themeset->name;
- char themeset_name[strlen(name) + 1], old_name[strlen(themeset->name) + 1];
+ const char *name = new_theme_name ? new_theme_name : theme->name;
+ char theme_name[strlen(name) + 1], old_name[strlen(theme->name) + 1];
/* Make local copies since these values may be freed down below */
- sz_strlcpy(themeset_name, name);
- sz_strlcpy(old_name, themeset->name);
+ sz_strlcpy(theme_name, name);
+ sz_strlcpy(old_name, theme->name);
- freelog(LOG_NORMAL, "Loading themeset %s.", themeset_name);
+ freelog(LOG_NORMAL, "Loading theme %s.", theme_name);
/* Step 0: Record old data.
*
@@ -379,20 +387,20 @@
*
* We free all old data in preparation for re-reading it.
*/
- themeset_free_tiles(themeset);
- themeset_free_toplevel(themeset);
+ theme_free_sprites(theme);
+ theme_free_toplevel(theme);
/* Step 2: Read.
*
- * We read in the new themeset. This should be pretty straightforward.
+ * We read in the new theme. This should be pretty straightforward.
*/
- if (!(themeset = themeset_read_toplevel(themeset_name))) {
- if (!(themeset = themeset_read_toplevel(old_name))) {
- die("Failed to re-read the currently loaded themeset.");
+ if (!(theme = theme_read_toplevel(theme_name))) {
+ if (!(theme = theme_read_toplevel(old_name))) {
+ die("Failed to re-read the currently loaded theme.");
}
}
-/* sz_strlcpy(default_themeset_name, themeset->name);*/
- themeset_load_tiles(themeset);
+/* sz_strlcpy(default_theme_name, theme->name);*/
+ theme_load_sprites(theme);
/* Step 3: Setup
*
@@ -406,7 +414,7 @@
*
* The below code just does things straightforwardly, by setting up
* each possible sprite again. Hopefully it catches everything, and
- * doesn't mess up too badly if we change themesets while not connected
+ * doesn't mess up too badly if we change themes while not connected
* to a server.
*/
if (state < CLIENT_GAME_RUNNING_STATE) {
@@ -425,7 +433,7 @@
}
popdown_all_game_dialogs();
generate_citydlg_dimensions();
-/* themeset_changed();*/
+/* theme_changed();*/
can_slide = FALSE;
center_tile_mapcanvas(center_tile);
/* update_map_cavnas_visible forces a full redraw. Otherwise with fast
@@ -515,7 +523,7 @@
positions of the sprites in the big_sprite are saved in the
small_sprite structs.
**************************************************************************/
-static void scan_specfile(struct themeset *t, struct specfile *sf,
+static void scan_specfile(struct theme *t, struct specfile *sf,
bool duplicates_ok)
{
struct section_file the_file, *file = &the_file;
@@ -683,7 +691,7 @@
Sets global variables, including tile sizes and full names for
intro files.
***********************************************************************/
-struct themeset *themeset_read_toplevel(const char *themeset_name)
+struct theme *theme_read_toplevel(const char *theme_name)
{
struct section_file the_file, *file = &the_file;
char *fname, *c;
@@ -692,11 +700,11 @@
char **spec_filenames;
char *file_capstr;
bool duplicates_ok;
- struct themeset *t = themeset_new();
+ struct theme *t = theme_new();
- fname = themespec_fullname(themeset_name);
+ fname = themespec_fullname(theme_name);
if (!fname) {
- themeset_free(t);
+ theme_free(t);
return NULL;
}
freelog(LOG_VERBOSE, "themespec file is %s", fname);
@@ -705,7 +713,7 @@
freelog(LOG_ERROR, _("Could not open \"%s\"."), fname);
section_file_free(file);
free(fname);
- themeset_free(t);
+ theme_free(t);
return NULL;
}
@@ -713,7 +721,7 @@
THEMESPEC_CAPSTR, fname)) {
section_file_free(file);
free(fname);
- themeset_free(t);
+ theme_free(t);
return NULL;
}
@@ -722,7 +730,7 @@
(void) section_file_lookup(file, "themespec.name"); /* currently unused */
- sz_strlcpy(t->name, themeset_name);
+ sz_strlcpy(t->name, theme_name);
t->priority = secfile_lookup_int(file, "themespec.priority");
c = secfile_lookup_str(file, "themespec.main_intro_file");
@@ -739,7 +747,7 @@
freelog(LOG_ERROR, "No theme graphics files specified in \"%s\"", fname);
section_file_free(file);
free(fname);
- themeset_free(t);
+ theme_free(t);
return NULL;
}
@@ -756,7 +764,7 @@
if (!dname) {
section_file_free(file);
free(fname);
- themeset_free(t);
+ theme_free(t);
return NULL;
}
sf->file_name = mystrdup(dname);
@@ -766,6 +774,8 @@
}
free(spec_filenames);
+ t->color_system = theme_color_system_read(file);
+
section_file_check_unused(file, fname);
section_file_free(file);
@@ -781,7 +791,7 @@
counter is increased. Can return NULL if the sprite couldn't be
loaded.
**************************************************************************/
-static struct sprite *load_sprite(struct themeset *t, const char *tag_name)
+static struct sprite *load_sprite(struct theme *t, const char *tag_name)
{
/* Lookup information about where the sprite is found. */
struct small_sprite *ss = hash_lookup_data(t->sprite_hash, tag_name);
@@ -831,7 +841,7 @@
Unloads the sprite. Decrease the reference counter. If the last
reference is removed the sprite is freed.
**************************************************************************/
-static void unload_sprite(struct themeset *t, const char *tag_name)
+static void unload_sprite(struct theme *t, const char *tag_name)
{
struct small_sprite *ss = hash_lookup_data(t->sprite_hash, tag_name);
@@ -877,7 +887,7 @@
#define SET_SPRITE_ALT_OPT(field, tag, alt) \
do { \
- t->sprites.field = themeset_lookup_sprite_tag_alt(t, tag, alt, FALSE,
\
+ t->sprites.field = theme_lookup_sprite_tag_alt(t, tag, alt, FALSE, \
"sprite", #field); \
} while (FALSE)
@@ -885,7 +895,7 @@
Initialize 'sprites' structure based on hardwired tags which the
client always requires.
***********************************************************************/
-static void themeset_lookup_sprite_tags(struct themeset *t)
+static void theme_lookup_sprite_tags(struct theme *t)
{
/* the 'sprites' structure is currently not used, for now we call some
* functions in gui_tilespec.c instead */
@@ -901,7 +911,7 @@
call. This saves a fair amount of memory, but it will take extra time
the next time we start loading sprites again.
**************************************************************************/
-static void finish_loading_sprites(struct themeset *t)
+static void finish_loading_sprites(struct theme *t)
{
specfile_list_iterate(t->specfiles, sf) {
if (sf->big_sprite) {
@@ -916,9 +926,9 @@
to sprites. Also sets up and populates sprite_hash, and calls func
to initialize 'sprites' structure.
***********************************************************************/
-void themeset_load_tiles(struct themeset *t)
+void theme_load_sprites(struct theme *t)
{
- themeset_lookup_sprite_tags(t);
+ theme_lookup_sprite_tags(t);
finish_loading_sprites(t);
}
@@ -926,7 +936,7 @@
Lookup sprite to match tag, or else to match alt if don't find,
or else return NULL, and emit log message.
***********************************************************************/
-struct sprite* themeset_lookup_sprite_tag_alt(struct themeset *t,
+struct sprite* theme_lookup_sprite_tag_alt(struct theme *t,
const char *tag, const char *alt,
bool required, const char *what,
const char *name)
@@ -976,7 +986,7 @@
This patch unloads all sprites from the sprite hash (the hash itself
is left intact).
****************************************************************************/
-static void unload_all_sprites(struct themeset *t)
+static void unload_all_sprites(struct theme *t)
{
if (t->sprite_hash) {
int i, entries = hash_num_entries(t->sprite_hash);
@@ -995,7 +1005,7 @@
/**********************************************************************
...
***********************************************************************/
-void themeset_free_tiles(struct themeset *t)
+void theme_free_sprites(struct theme *t)
{
int i;
@@ -1050,3 +1060,11 @@
tilespec_free_theme();
tilespec_free_city_icons();
}
+
+/****************************************************************************
+ Return the theme's color system.
+****************************************************************************/
+struct theme_color_system *theme_get_color_system(const struct theme *t)
+{
+ return t->color_system;
+}
Index: client/gui-sdl/cityrep.c
===================================================================
--- client/gui-sdl/cityrep.c (Revision 11348)
+++ client/gui-sdl/cityrep.c (Arbeitskopie)
@@ -35,6 +35,7 @@
#include "citydlg.h"
#include "cityrepdata.h"
#include "clinet.h"
+#include "cma_fe.h"
#include "graphics.h"
#include "gui_string.h"
#include "gui_stuff.h"
@@ -44,16 +45,15 @@
#include "gui_zoom.h"
#include "colors.h"
#include "wldlg.h"
-
#include "mapview.h"
#include "mapctrl.h"
#include "optiondlg.h"
#include "options.h"
#include "repodlgs.h"
#include "climisc.h"
+#include "themecolors.h"
#include "cityrep.h"
-#include "cma_fe.h"
static struct ADVANCED_DLG *pCityRep = NULL;
@@ -257,13 +257,13 @@
(WF_DRAW_THEME_TRANSPARENT|WF_SELLECT_WITHOUT_BAR));
if (city_unhappy(pCity)) {
- pBuf->string16->fgcol = *get_game_colorRGB(COLOR_STD_CITY_TRADE);
+ pBuf->string16->fgcol = *get_game_colorRGB(COLOR_THEME_CITY_TRADE);
} else {
if (city_celebrating(pCity)) {
- pBuf->string16->fgcol = *get_game_colorRGB(COLOR_STD_CITY_CELEB);
+ pBuf->string16->fgcol = *get_game_colorRGB(COLOR_THEME_CITY_CELEB);
} else {
if (city_happy(pCity)) {
- pBuf->string16->fgcol = *get_game_colorRGB(COLOR_STD_CITY_HAPPY);
+ pBuf->string16->fgcol = *get_game_colorRGB(COLOR_THEME_CITY_HAPPY);
}
}
}
@@ -321,7 +321,7 @@
my_snprintf(cBuf, sizeof(cBuf), "%d", pCity->surplus[O_FOOD]);
pStr = create_str16_from_char(cBuf, adj_font(10));
pStr->style |= SF_CENTER;
- pStr->fgcol = *get_game_colorRGB(COLOR_STD_CITY_FOOD_SURPLUS);
+ pStr->fgcol = *get_game_colorRGB(COLOR_THEME_CITY_FOOD_SURPLUS);
pBuf = create_iconlabel(NULL, pWindow->dst, pStr,
WF_DRAW_THEME_TRANSPARENT);
if(count > 9 * COL) {
@@ -363,7 +363,7 @@
my_snprintf(cBuf, sizeof(cBuf), "%d", pCity->surplus[O_TRADE]);
pStr = create_str16_from_char(cBuf, adj_font(10));
pStr->style |= SF_CENTER;
- pStr->fgcol = *get_game_colorRGB(COLOR_STD_CITY_TRADE);
+ pStr->fgcol = *get_game_colorRGB(COLOR_THEME_CITY_TRADE);
pBuf = create_iconlabel(NULL, pWindow->dst, pStr,
WF_DRAW_THEME_TRANSPARENT);
if(count > 9 * COL) {
@@ -390,7 +390,7 @@
my_snprintf(cBuf, sizeof(cBuf), "%d", pCity->surplus[O_GOLD]);
pStr = create_str16_from_char(cBuf, adj_font(10));
pStr->style |= SF_CENTER;
- pStr->fgcol = *get_game_colorRGB(COLOR_STD_CITY_GOLD);
+ pStr->fgcol = *get_game_colorRGB(COLOR_THEME_CITY_GOLD);
pBuf = create_iconlabel(NULL, pWindow->dst, pStr,
WF_DRAW_THEME_TRANSPARENT);
if(count > 9 * COL) {
@@ -404,7 +404,7 @@
my_snprintf(cBuf, sizeof(cBuf), "%d", pCity->prod[O_SCIENCE]);
pStr = create_str16_from_char(cBuf, adj_font(10));
pStr->style |= SF_CENTER;
- pStr->fgcol = *get_game_colorRGB(COLOR_STD_CITY_SCIENCE);
+ pStr->fgcol = *get_game_colorRGB(COLOR_THEME_CITY_SCIENCE);
pBuf = create_iconlabel(NULL, pWindow->dst, pStr,
WF_DRAW_THEME_TRANSPARENT);
if(count > 9 * COL) {
@@ -418,7 +418,7 @@
my_snprintf(cBuf, sizeof(cBuf), "%d", pCity->prod[O_LUXURY]);
pStr = create_str16_from_char(cBuf, adj_font(10));
pStr->style |= SF_CENTER;
- pStr->fgcol = *get_game_colorRGB(COLOR_STD_CITY_LUX);
+ pStr->fgcol = *get_game_colorRGB(COLOR_THEME_CITY_LUX);
pBuf = create_iconlabel(NULL, pWindow->dst, pStr,
WF_DRAW_THEME_TRANSPARENT);
if(count > 9 * COL) {
@@ -433,7 +433,7 @@
pCity->prod[O_SHIELD] + pCity->waste[O_SHIELD]);
pStr = create_str16_from_char(cBuf, adj_font(10));
pStr->style |= SF_CENTER;
- pStr->fgcol = *get_game_colorRGB(COLOR_STD_CITY_PROD);
+ pStr->fgcol = *get_game_colorRGB(COLOR_THEME_CITY_PROD);
pBuf = create_iconlabel(NULL, pWindow->dst, pStr,
WF_DRAW_THEME_TRANSPARENT);
if(count > 9 * COL) {
@@ -461,7 +461,7 @@
pCity->prod[O_SHIELD] + pCity->waste[O_SHIELD] -
pCity->surplus[O_SHIELD]);
pStr = create_str16_from_char(cBuf, adj_font(10));
pStr->style |= SF_CENTER;
- pStr->fgcol = *get_game_colorRGB(COLOR_STD_CITY_SUPPORT);
+ pStr->fgcol = *get_game_colorRGB(COLOR_THEME_CITY_SUPPORT);
pBuf = create_iconlabel(NULL, pWindow->dst, pStr,
WF_DRAW_THEME_TRANSPARENT);
if(count > 9 * COL) {
@@ -475,7 +475,7 @@
my_snprintf(cBuf, sizeof(cBuf), "%d", pCity->surplus[O_SHIELD]);
pStr = create_str16_from_char(cBuf, adj_font(10));
pStr->style |= SF_CENTER;
- pStr->fgcol = *get_game_colorRGB(COLOR_STD_CITY_TRADE);
+ pStr->fgcol = *get_game_colorRGB(COLOR_THEME_CITY_TRADE);
pBuf = create_iconlabel(NULL, pWindow->dst, pStr,
WF_DRAW_THEME_TRANSPARENT);
if(count > 9 * COL) {
@@ -700,7 +700,7 @@
(pIcons->pBIG_Luxury->w + adj_size(6)) + adj_size(4);
dst.h = h - WINDOW_TILE_HIGH - adj_size(2) - FRAME_WH - adj_size(32);
- color = *get_game_colorRGB(COLOR_STD_CITY_TRADE);
+ color = *get_game_colorRGB(COLOR_THEME_CITY_TRADE);
color.unused = 96;
SDL_FillRectAlpha(pWindow->theme, &dst, &color);
@@ -739,7 +739,7 @@
(pIcons->pBIG_Shield_Surplus->w + adj_size(6)) + adj_size(4);
dst.h = h - WINDOW_TILE_HIGH - adj_size(2) - FRAME_WH - adj_size(32);
- color = *get_game_colorRGB(COLOR_STD_CITY_PROD);
+ color = *get_game_colorRGB(COLOR_THEME_CITY_PROD);
color.unused = 96;
SDL_FillRectAlpha(pWindow->theme, &dst, &color);
@@ -910,13 +910,13 @@
/* city name status */
if (city_unhappy(pCity)) {
- pWidget->string16->fgcol = *get_game_colorRGB(COLOR_STD_CITY_TRADE);
+ pWidget->string16->fgcol = *get_game_colorRGB(COLOR_THEME_CITY_TRADE);
} else {
if (city_celebrating(pCity)) {
- pWidget->string16->fgcol = *get_game_colorRGB(COLOR_STD_CITY_CELEB);
+ pWidget->string16->fgcol = *get_game_colorRGB(COLOR_THEME_CITY_CELEB);
} else {
if (city_happy(pCity)) {
- pWidget->string16->fgcol = *get_game_colorRGB(COLOR_STD_CITY_HAPPY);
+ pWidget->string16->fgcol = *get_game_colorRGB(COLOR_THEME_CITY_HAPPY);
}
}
}
Index: client/gui-sdl/themespec.h
===================================================================
--- client/gui-sdl/themespec.h (Revision 11348)
+++ client/gui-sdl/themespec.h (Arbeitskopie)
@@ -13,7 +13,7 @@
/**********************************************************************
Reading and using the themespec files, which describe
- the files and contents of themesets.
+ the files and contents of themes.
***********************************************************************/
#ifndef FC__THEMESPEC_H
#define FC__THEMESPEC_H
@@ -24,29 +24,32 @@
struct sprite; /* opaque; gui-dep */
-struct themeset;
+struct theme;
-extern struct themeset *themeset;
+extern struct theme *theme;
-const char **get_themeset_list(void);
+const char **get_theme_list(void);
-struct themeset *themeset_read_toplevel(const char *themeset_name);
-void themeset_free(struct themeset *themeset);
-void themeset_load_tiles(struct themeset *t);
-void themeset_free_tiles(struct themeset *t);
+struct theme *theme_read_toplevel(const char *theme_name);
+void theme_free(struct theme *theme);
+void theme_load_sprites(struct theme *t);
+void theme_free_sprites(struct theme *t);
-void themespec_try_read(const char *themeset_name);
-void themespec_reread(const char *themeset_name);
+void themespec_try_read(const char *theme_name);
+void themespec_reread(const char *theme_name);
void themespec_reread_callback(struct client_option *option);
-struct sprite* themeset_lookup_sprite_tag_alt(struct themeset *t,
+struct sprite* theme_lookup_sprite_tag_alt(struct theme *t,
const char *tag, const char *alt,
bool required, const char *what,
const char *name);
-/* Themeset accessor functions. */
-const char *themeset_get_name(const struct themeset *t);
-const char *themeset_main_intro_filename(const struct themeset *t);
-const char *themeset_mini_intro_filename(const struct themeset *t);
+struct theme_color_system;
+struct theme_color_system *theme_get_color_system(const struct theme *t);
+/* theme accessor functions. */
+const char *theme_get_name(const struct theme *t);
+const char *theme_main_intro_filename(const struct theme *t);
+const char *theme_mini_intro_filename(const struct theme *t);
+
#endif /* FC__THEMESPEC_H */
Index: client/gui-sdl/dialogs.c
===================================================================
--- client/gui-sdl/dialogs.c (Revision 11348)
+++ client/gui-sdl/dialogs.c (Arbeitskopie)
@@ -80,6 +80,7 @@
#include "tilespec.h"
#include "text.h"
#include "movement.h"
+#include "themecolors.h"
#include "dialogs.h"
@@ -323,7 +324,7 @@
pWindow->size.y = (Main.screen->h - h) / 2;
resize_window(pWindow, NULL,
- get_game_colorRGB(COLOR_STD_BACKGROUND_BROWN), w, h);
+ get_game_colorRGB(COLOR_THEME_BACKGROUND_BROWN), w, h);
dst.x = (pWindow->size.w - pHeadline->w) / 2;
dst.y = WINDOW_TILE_HIGH + adj_size(11);
@@ -506,7 +507,7 @@
}
resize_window(pWindow, NULL,
- get_game_colorRGB(COLOR_STD_BACKGROUND_BROWN),
+ get_game_colorRGB(COLOR_THEME_BACKGROUND_BROWN),
ww + DOUBLE_FRAME_WH, hh);
/* setup rest of widgets */
@@ -1004,7 +1005,7 @@
put_window_near_map_tile(pWindow, pWindow->size.w, pWindow->size.h, ptile);
resize_window(pWindow, NULL,
- get_game_colorRGB(COLOR_STD_BACKGROUND_BROWN),
+ get_game_colorRGB(COLOR_THEME_BACKGROUND_BROWN),
pWindow->size.w, pWindow->size.h);
/* ------------------------ */
@@ -3987,7 +3988,7 @@
pWindow->size.y = (pWindow->dst->h - h) / 2;
resize_window(pWindow, NULL,
- get_game_colorRGB(COLOR_STD_BACKGROUND_BROWN), w, h);
+ get_game_colorRGB(COLOR_THEME_BACKGROUND_BROWN), w, h);
area.x = adj_size(10);
area.y = WINDOW_TILE_HIGH + adj_size(10);
Index: client/gui-sdl/themecolors.c
===================================================================
--- client/gui-sdl/themecolors.c (Revision 0)
+++ client/gui-sdl/themecolors.c (Revision 0)
@@ -0,0 +1,116 @@
+/**********************************************************************
+ Freeciv - Copyright (C) 2005 - The Freeciv Project
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+***********************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <assert.h>
+
+#include "hash.h"
+#include "log.h"
+#include "shared.h"
+
+#include "player.h"
+
+#include "colors_g.h"
+
+#include "colors.h"
+#include "themespec.h"
+
+#include "themecolors.h"
+
+/* An RGBAcolor contains the R,G,B,A bitvalues for a color. The color itself
+ * holds the color structure for this color but may be NULL (it's allocated
+ * on demand at runtime). */
+struct rgbacolor {
+ int r, g, b, a;
+ struct color *color;
+};
+
+struct theme_color_system {
+ struct rgbacolor colors[(THEME_COLOR_LAST - COLOR_LAST)];
+};
+
+static char *color_names[] = {
+ "background_brown",
+ "quick_info",
+ "disabled",
+ "city_prod",
+ "city_support",
+ "city_trade",
+ "city_gold",
+ "city_lux",
+ "city_food_surplus",
+ "city_upkeep",
+ "city_science",
+ "city_happy",
+ "city_celeb",
+ "red_disabled"
+};
+
+struct theme_color_system *theme_color_system_read(struct section_file *file)
+{
+ int i;
+ struct theme_color_system *colors = fc_malloc(sizeof(*colors));
+
+ assert(ARRAY_SIZE(color_names) == (THEME_COLOR_LAST - COLOR_LAST));
+ for (i = 0; i < (THEME_COLOR_LAST - COLOR_LAST); i++) {
+ colors->colors[i].r
+ = secfile_lookup_int(file, "colors.%s0.r", color_names[i]);
+ colors->colors[i].g
+ = secfile_lookup_int(file, "colors.%s0.g", color_names[i]);
+ colors->colors[i].b
+ = secfile_lookup_int(file, "colors.%s0.b", color_names[i]);
+ colors->colors[i].a
+ = secfile_lookup_int(file, "colors.%s0.a", color_names[i]);
+ colors->colors[i].color = NULL;
+ }
+
+ return colors;
+}
+
+/****************************************************************************
+ Called when the client first starts to free any allocated colors.
+****************************************************************************/
+void theme_color_system_free(struct theme_color_system *colors)
+{
+ int i;
+
+ for (i = 0; i < (THEME_COLOR_LAST - COLOR_LAST); i++) {
+ if (colors->colors[i].color) {
+ color_free(colors->colors[i].color);
+ }
+ }
+
+ free(colors);
+}
+
+/****************************************************************************
+ Return the RGBA color, allocating it if necessary.
+****************************************************************************/
+static struct color *ensure_color(struct rgbacolor *rgba)
+{
+ if (!rgba->color) {
+ rgba->color = color_alloc_rgba(rgba->r, rgba->g, rgba->b, rgba->a);
+ }
+ return rgba->color;
+}
+
+/****************************************************************************
+ Return a pointer to the given "theme" color.
+****************************************************************************/
+struct color *theme_get_color(const struct theme *t, enum theme_color color)
+{
+ return ensure_color(&theme_get_color_system(t)->colors[color]);
+}
Index: client/gui-sdl/themecolors.h
===================================================================
--- client/gui-sdl/themecolors.h (Revision 0)
+++ client/gui-sdl/themecolors.h (Revision 0)
@@ -0,0 +1,55 @@
+/**********************************************************************
+ Freeciv - Copyright (C) 2005 - The Freeciv Project
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+***********************************************************************/
+
+#ifndef FC__THEMECOLORS_H
+#define FC__THEMECOLORS_H
+
+#include "registry.h"
+
+#include "fc_types.h"
+
+#include "colors_common.h"
+
+/* The color system is designed on the assumption that almost, but
+ * not quite, all displays will be truecolor. */
+
+enum theme_color {
+ COLOR_THEME_BACKGROUND_BROWN = COLOR_LAST, /* Background2 (brown) */
+ COLOR_THEME_QUICK_INFO, /* Quick info Background color */
+ COLOR_THEME_DISABLED, /* disable color */
+ COLOR_THEME_CITY_PROD, /* city production color */
+ COLOR_THEME_CITY_SUPPORT, /* city units support color */
+ COLOR_THEME_CITY_TRADE, /* city trade color */
+ COLOR_THEME_CITY_GOLD, /* city gold color */
+ COLOR_THEME_CITY_LUX, /* city luxuries color */
+ COLOR_THEME_CITY_FOOD_SURPLUS, /* city food surplus color */
+ COLOR_THEME_CITY_UPKEEP, /* city upkeep color */
+ COLOR_THEME_CITY_SCIENCE, /* city science color */
+ COLOR_THEME_CITY_HAPPY, /* city happy color */
+ COLOR_THEME_CITY_CELEB, /* city celebrating color */
+ COLOR_THEME_RED_DISABLED, /* player at war but can't meet or get intel.
data */
+ THEME_COLOR_LAST
+};
+
+struct color;
+struct theme_color_system;
+struct theme;
+
+struct color *theme_get_color(const struct theme *t, enum theme_color color);
+
+/* Functions used by the theme to allocate the color system. */
+struct theme_color_system *theme_color_system_read(struct section_file *file);
+
+void theme_color_system_free(struct theme_color_system *colors);
+
+#endif /* FC__THEMECOLORS_H */
Index: client/gui-sdl/diplodlg.c
===================================================================
--- client/gui-sdl/diplodlg.c (Revision 11348)
+++ client/gui-sdl/diplodlg.c (Arbeitskopie)
@@ -42,6 +42,7 @@
#include "colors.h"
#include "log.h"
#include "dialogs_g.h"
+#include "themecolors.h"
#include "diplodlg.h"
@@ -780,7 +781,7 @@
pWindow->size.y = (Main.screen->h - hh) / 2;
resize_window(pWindow, NULL,
- get_game_colorRGB(COLOR_STD_BACKGROUND_BROWN), ww, hh);
+ get_game_colorRGB(COLOR_THEME_BACKGROUND_BROWN), ww, hh);
setup_vertical_widgets_position(1,
pWindow->size.x + FRAME_WH + adj_size(2), pWindow->size.y +
WINDOW_TILE_HIGH + adj_size(2),
@@ -910,7 +911,7 @@
pWindow->size.y = (Main.screen->h - hh) / 2;
resize_window(pWindow, NULL,
- get_game_colorRGB(COLOR_STD_BACKGROUND_BROWN), ww, hh);
+ get_game_colorRGB(COLOR_THEME_BACKGROUND_BROWN), ww, hh);
pBuf = pWindow->prev;
pBuf->size.x = pWindow->size.x + adj_size(20);
@@ -1145,7 +1146,7 @@
pWindow->size.y = (Main.screen->h - hh) / 2;
resize_window(pWindow, NULL,
- get_game_colorRGB(COLOR_STD_BACKGROUND_BROWN), ww, hh);
+ get_game_colorRGB(COLOR_THEME_BACKGROUND_BROWN), ww, hh);
/* setup rest of widgets */
/* label */
@@ -1334,7 +1335,7 @@
pWindow->size.y = (Main.screen->h - hh) / 2;
resize_window(pWindow, NULL,
- get_game_colorRGB(COLOR_STD_BACKGROUND_BROWN), ww, hh);
+ get_game_colorRGB(COLOR_THEME_BACKGROUND_BROWN), ww, hh);
/* setup rest of widgets */
/* label */
Index: client/gui-sdl/graphics.c
===================================================================
--- client/gui-sdl/graphics.c (Revision 11348)
+++ client/gui-sdl/graphics.c (Arbeitskopie)
@@ -3416,8 +3416,8 @@
{
SDL_Surface *pLogo;
- SDL_Surface *pLogo_Surf = adj_surf(GET_SURF(themeset_lookup_sprite_tag_alt(
- themeset, "theme.logo", "", TRUE, "", "")));
+ SDL_Surface *pLogo_Surf = adj_surf(GET_SURF(theme_lookup_sprite_tag_alt(
+ theme, "theme.logo", "", TRUE, "", "")));
assert(pLogo_Surf != NULL);
pLogo = SDL_CreateRGBSurface(SDL_SWSURFACE,
pLogo_Surf->w, pLogo_Surf->h,
Index: client/gui-sdl/colors.c
===================================================================
--- client/gui-sdl/colors.c (Revision 11348)
+++ client/gui-sdl/colors.c (Arbeitskopie)
@@ -29,74 +29,39 @@
#include "mem.h"
#include "log.h"
+#include "themespec.h"
+#include "themecolors.h"
+
#include "colors.h"
-/*
- r, g, b, a
-*/
-static SDL_Color SDLClient_standard_rgba_colors[SDLCLIENT_STD_COLOR_LAST -
- COLOR_LAST] = {
- {72, 61, 139, 255}, /* race14 */
- {100, 149, 237, 255}, /* race15 */
- {255, 228, 181, 255}, /* race16 */
- {112, 128, 144, 255}, /* race17 */
- {143, 188, 143, 255}, /* race18 */
- {93, 71, 139, 255}, /* race19 */
- {255, 114, 86, 255}, /* race20 */
- {205, 205, 180, 255}, /* race21 */
- {238, 99, 99, 255}, /* race22 */
- {154, 205, 50, 255}, /* race23 */
- {250, 128, 114, 255}, /* race24 */
- {205, 198, 115, 255}, /* race25 */
- {238, 92, 66, 255}, /* race26 */
- {191, 62, 255, 255}, /* race27 */
- {127, 255, 212, 255}, /* race28 */
- {0, 191, 255, 255}, /* race29 */
- {255, 222, 173, 255}, /* race30 */
- {65, 105, 225, 255}, /* race31 */
- {0, 128, 0, 255}, /* Ground (green) fogged */
- {138, 114, 82, 255}, /* Background2 (brown) */
- {190, 190, 190, 255}, /* Grid line color */
- {0, 150, 0, 150}, /* Quick info (green) */
- {0, 0, 0, 96}, /* FOG OF WAR color */
- {90, 90, 90, 255}, /* disable color */
- {125, 170, 220, 255}, /* city production color */
- {20, 210, 200, 255}, /* city units support color */
- {226, 82, 13, 255}, /* city trade color */
- {220, 186, 60, 255}, /* city gold color */
- {238, 156, 7, 255}, /* city luxuries color */
- {105, 190, 90, 255}, /* city food surplus color */
- {12, 18, 108, 255}, /* city unkeep color */
- {212, 172, 206, 255}, /* city science color */
- {255, 255, 0, 255}, /* city happy color */
- {190, 115, 5, 255}, /* city celebrating color */
- {128, 0, 0, 255} /* player at war but can't meet or get intel.
data */
-};
-
/**************************************************************************
...
**************************************************************************/
SDL_Color * get_game_colorRGB(enum color_std color_offset)
{
if (color_offset >= COLOR_LAST) {
- return &SDLClient_standard_rgba_colors[color_offset - COLOR_LAST];
+ return theme_get_color(theme, (color_offset - COLOR_LAST))->color;
+ } else {
+ return get_color(tileset, color_offset)->color;
}
- return get_color(tileset, color_offset)->color;
}
/**************************************************************************
...
**************************************************************************/
-Uint32 get_game_color(struct color *pcolor , SDL_Surface *pDest)
-{
- if (pcolor)
+struct color *color_alloc_rgba(int r, int g, int b, int a) {
- return SDL_MapRGBA(pDest->format, pcolor->color->r, pcolor->color->g,
- pcolor->color->b, pcolor->color->unused);
+ struct color *result = fc_malloc(sizeof(*result));
+
+ SDL_Color *pcolor = fc_malloc(sizeof(*pcolor));
+ pcolor->r = r;
+ pcolor->g = g;
+ pcolor->b = b;
+ pcolor->unused = a;
+
+ result->color = pcolor;
- else
- return 0;
-
+ return result;
}
struct color *color_alloc(int r, int g, int b) {
Index: client/gui-sdl/mapctrl.c
===================================================================
--- client/gui-sdl/mapctrl.c (Revision 11348)
+++ client/gui-sdl/mapctrl.c (Arbeitskopie)
@@ -69,6 +69,7 @@
#include "plrdlg.h"
#include "overview_common.h"
#include "log.h"
+#include "themecolors.h"
#include "mapctrl.h"
@@ -996,7 +997,7 @@
resize_window(pWindow, NULL,
- get_game_colorRGB(COLOR_STD_BACKGROUND_BROWN), w, h);
+ get_game_colorRGB(COLOR_THEME_BACKGROUND_BROWN), w, h);
/* width left button */
pBuf = pWindow->prev;
Index: client/gui-sdl/graphics.h
===================================================================
--- client/gui-sdl/graphics.h (Revision 11348)
+++ client/gui-sdl/graphics.h (Arbeitskopie)
@@ -330,4 +330,23 @@
} \
} while(0)
+/* Blend the RGB values of two pixels based on a source alpha value */
+#define ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB) \
+do { \
+ dR = (((sR-dR)*(A))>>8)+dR; \
+ dG = (((sG-dG)*(A))>>8)+dG; \
+ dB = (((sB-dB)*(A))>>8)+dB; \
+} while(0)
+
+#define ALPHA_BLEND128(sR, sG, sB, dR, dG, dB) \
+do { \
+ Uint32 __Src = (sR << 16 | sG << 8 | sB); \
+ Uint32 __Dst = (dR << 16 | dG << 8 | dB); \
+ __Dst = ((((__Src & 0x00fefefe) + (__Dst & 0x00fefefe)) >> 1)
\
+ + (__Src & __Dst & 0x00010101)) | 0xFF000000; \
+ dR = (__Dst >> 16) & 0xFF; \
+ dG = (__Dst >> 8 ) & 0xFF; \
+ dB = (__Dst ) & 0xFF; \
+} while(0)
+
#endif /* FC__GRAPHICS_H */
Index: client/gui-sdl/colors.h
===================================================================
--- client/gui-sdl/colors.h (Revision 11348)
+++ client/gui-sdl/colors.h (Arbeitskopie)
@@ -22,71 +22,15 @@
#ifndef FC__COLORS_H
#define FC__COLORS_H
+#include <SDL/SDL.h>
+
#include "colors_g.h"
struct color {
SDL_Color *color;
};
-enum SDLClient_std_color {
- COLOR_STD_RACE14 = COLOR_LAST,
- COLOR_STD_RACE15,
- COLOR_STD_RACE16,
- COLOR_STD_RACE17,
- COLOR_STD_RACE18,
- COLOR_STD_RACE19,
- COLOR_STD_RACE20,
- COLOR_STD_RACE21,
- COLOR_STD_RACE22,
- COLOR_STD_RACE23,
- COLOR_STD_RACE24,
- COLOR_STD_RACE25,
- COLOR_STD_RACE26,
- COLOR_STD_RACE27,
- COLOR_STD_RACE28,
- COLOR_STD_RACE29,
- COLOR_STD_RACE30,
- COLOR_STD_RACE31,
- COLOR_STD_GROUND_FOGED,
- COLOR_STD_BACKGROUND_BROWN, /* Background2 (brown) */
- COLOR_STD_GRID, /* Grid line color */
- COLOR_STD_QUICK_INFO, /* Quick info Background color */
- COLOR_STD_FOG_OF_WAR, /* FOG OF WAR color */
- COLOR_STD_DISABLED, /* disable color */
- COLOR_STD_CITY_PROD, /* city production color */
- COLOR_STD_CITY_SUPPORT, /* city units support color */
- COLOR_STD_CITY_TRADE, /* city trade color */
- COLOR_STD_CITY_GOLD, /* city gold color */
- COLOR_STD_CITY_LUX, /* city luxuries color */
- COLOR_STD_CITY_FOOD_SURPLUS, /* city food surplus color */
- COLOR_STD_CITY_UNKEEP, /* city unkeep color */
- COLOR_STD_CITY_SCIENCE, /* city science color */
- COLOR_STD_CITY_HAPPY, /* city happy color */
- COLOR_STD_CITY_CELEB, /* city celebrating color */
- COLOR_STD_RED_DISABLED, /* player at war but can't meet or get intel.
data */
- SDLCLIENT_STD_COLOR_LAST
-};
-
+struct color *color_alloc_rgba(int r, int g, int b, int a);
SDL_Color * get_game_colorRGB(Uint32 color_offset);
-Uint32 get_game_color(struct color *pcolor, SDL_Surface *pDest);
-/* Blend the RGB values of two pixels based on a source alpha value */
-#define ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB) \
-do { \
- dR = (((sR-dR)*(A))>>8)+dR; \
- dG = (((sG-dG)*(A))>>8)+dG; \
- dB = (((sB-dB)*(A))>>8)+dB; \
-} while(0)
-
-#define ALPHA_BLEND128(sR, sG, sB, dR, dG, dB) \
-do { \
- Uint32 __Src = (sR << 16 | sG << 8 | sB); \
- Uint32 __Dst = (dR << 16 | dG << 8 | dB); \
- __Dst = ((((__Src & 0x00fefefe) + (__Dst & 0x00fefefe)) >> 1)
\
- + (__Src & __Dst & 0x00010101)) | 0xFF000000; \
- dR = (__Dst >> 16) & 0xFF; \
- dG = (__Dst >> 8 ) & 0xFF; \
- dB = (__Dst ) & 0xFF; \
-} while(0)
-
#endif /* FC__COLORS_H */
Index: client/gui-sdl/helpdlg.c
===================================================================
--- client/gui-sdl/helpdlg.c (Revision 11348)
+++ client/gui-sdl/helpdlg.c (Arbeitskopie)
@@ -51,6 +51,7 @@
#include "tilespec.h"
#include "gui_tilespec.h"
#include "repodlgs.h"
+#include "themecolors.h"
#include "helpdlg.h"
@@ -1113,7 +1114,7 @@
set_wstate(pBuf, FC_WS_NORMAL);
if (is_wonder(imp))
{
- pBuf->string16->fgcol = *get_game_colorRGB(COLOR_STD_CITY_LUX);
+ pBuf->string16->fgcol = *get_game_colorRGB(COLOR_THEME_CITY_LUX);
}
pBuf->action = change_impr_callback;
pBuf->ID = MAX_ID - imp;
Index: client/gui-sdl/plrdlg.c
===================================================================
--- client/gui-sdl/plrdlg.c (Revision 11348)
+++ client/gui-sdl/plrdlg.c (Arbeitskopie)
@@ -47,6 +47,8 @@
#include "colors.h"
#include "mapview.h"
#include "diplodlg.h"
+#include "themecolors.h"
+
#include "plrdlg.h"
#ifndef M_PI
@@ -283,7 +285,7 @@
break;
case DS_ALLIANCE:
if (SDL_Client_Flags & CF_DRAW_PLAYERS_ALLIANCE_STATUS) {
- c = *get_game_colorRGB(COLOR_STD_CITY_GOLD);
+ c = *get_game_colorRGB(COLOR_THEME_CITY_GOLD);
putline(pPlayer1->dst, x0, y0, x1, y1,
SDL_MapRGBA(pPlayer1->dst->format, c.r, c.g, c.b,
c.unused));
}
@@ -497,7 +499,7 @@
pStr->fgcol = (SDL_Color){0, 200, 0, 255};
break;
case DS_ALLIANCE:
- pStr->fgcol = *(get_game_colorRGB(COLOR_STD_CITY_GOLD));
+ pStr->fgcol = *(get_game_colorRGB(COLOR_THEME_CITY_GOLD));
break;
default:
/* no contact */
@@ -693,7 +695,7 @@
set_wstate(pBuf, FC_WS_NORMAL);
pBuf->string16->fgcol = (SDL_Color){255, 0, 0, 255};
} else {
- pBuf->string16->fgcol =
*(get_game_colorRGB(COLOR_STD_RED_DISABLED));
+ pBuf->string16->fgcol =
*(get_game_colorRGB(COLOR_THEME_RED_DISABLED));
}
break;
case DS_CEASEFIRE:
@@ -705,11 +707,11 @@
set_wstate(pBuf, FC_WS_NORMAL);
break;
case DS_ALLIANCE:
- pBuf->string16->fgcol = *(get_game_colorRGB(COLOR_STD_CITY_GOLD));
+ pBuf->string16->fgcol = *(get_game_colorRGB(COLOR_THEME_CITY_GOLD));
set_wstate(pBuf, FC_WS_NORMAL);
break;
case DS_NO_CONTACT:
- pBuf->string16->fgcol = *(get_game_colorRGB(COLOR_STD_DISABLED));
+ pBuf->string16->fgcol = *(get_game_colorRGB(COLOR_THEME_DISABLED));
break;
default:
set_wstate(pBuf, FC_WS_NORMAL);
Index: client/gui-sdl/wldlg.c
===================================================================
--- client/gui-sdl/wldlg.c (Revision 11348)
+++ client/gui-sdl/wldlg.c (Arbeitskopie)
@@ -35,7 +35,7 @@
#include "fcintl.h"
#include "game.h"
-
+#include "citydlg.h"
#include "graphics.h"
#include "gui_id.h"
#include "gui_main.h"
@@ -55,10 +55,11 @@
#include "climisc.h"
#include "clinet.h"
#include "log.h"
+#include "themecolors.h"
#include "wldlg.h"
-#include "citydlg.h"
+
#define TARGETS_COL 4
#define TARGETS_ROW 4
@@ -1613,7 +1614,7 @@
dst.w = adj_size(130);
dst.h = adj_size(145);
- c = *get_game_colorRGB(COLOR_STD_BACKGROUND_BROWN);
+ c = *get_game_colorRGB(COLOR_THEME_BACKGROUND_BROWN);
SDL_FillRect(pWindow->theme, &dst,
SDL_MapRGBA(pWindow->theme->format, c.r, c.g, c.b, c.unused));
@@ -1637,7 +1638,7 @@
dst.w = adj_size(130);
dst.h = adj_size(99);
- c = *get_game_colorRGB(COLOR_STD_BACKGROUND_BROWN);
+ c = *get_game_colorRGB(COLOR_THEME_BACKGROUND_BROWN);
SDL_FillRect(pWindow->theme, &dst,
SDL_MapRGBA(pWindow->theme->format, c.r, c.g, c.b, c.unused));
Index: client/gui-sdl/Makefile.am
===================================================================
--- client/gui-sdl/Makefile.am (Revision 11348)
+++ client/gui-sdl/Makefile.am (Arbeitskopie)
@@ -81,8 +81,11 @@
resources.h \
spaceshipdlg.c \
spaceshipdlg.h \
+ themecolors.c \
+ themecolors.h \
themes.c \
themespec.c \
+ themespec.h \
wldlg.c \
wldlg.h \
gui_string.c \
[colors]
background_brown = {"r", "g", "b", "a"
138, 114, 82, 255
}
quick_info = {"r", "g", "b", "a"
0, 150, 0, 150
}
disabled = {"r", "g", "b", "a"
90, 90, 90, 255
}
city_prod = {"r", "g", "b", "a"
125, 170, 220, 255
}
city_support = {"r", "g", "b", "a"
20, 210, 200, 255
}
city_trade = {"r", "g", "b", "a"
226, 82, 13, 255
}
city_gold = {"r", "g", "b", "a"
220, 186, 60, 255
}
city_lux = {"r", "g", "b", "a"
238, 156, 7, 255
}
city_food_surplus = {"r", "g", "b", "a"
105, 190, 90, 255
}
city_upkeep = {"r", "g", "b", "a"
12, 18, 108, 255
}
city_science = {"r", "g", "b", "a"
212, 172, 206, 255
}
city_happy = {"r", "g", "b", "a"
255, 255, 0, 255
}
city_celeb = {"r", "g", "b", "a"
190, 115, 5, 255
}
red_disabled = {"r", "g", "b", "a"
128, 0, 0, 255
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#14866) gui-sdl: theme colors patch,
Christian Prochaska <=
|
|