1 /**********************************************************************
2 Freeciv - Copyright (C) 2005 - The Freeciv Project
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 ***********************************************************************/
15 #include <fc_config.h>
23 #include "themespec.h"
25 #include "themecolors.h"
27 /* An RGBAcolor contains the R,G,B,A bitvalues for a color. The color itself
28 * holds the color structure for this color but may be NULL (it's allocated
29 * on demand at runtime). */
35 struct theme_color_system
{
36 struct rgbacolor colors
[COLOR_THEME_LAST
];
39 static char *color_names
[] = {
41 "checkbox_label_text",
42 "custom_widget_normal_text",
43 "custom_widget_selected_frame",
44 "custom_widget_selected_text",
45 "custom_widget_pressed_frame",
46 "custom_widget_pressed_text",
47 "custom_widget_disabled_text",
57 "widget_selected_text",
58 "widget_pressed_text",
59 "widget_disabled_text",
60 "window_titlebar_separator",
62 "advancedterraindlg_text",
68 "citydlg_foodperturn",
70 "citydlg_food_surplus",
83 "citydlg_shieldstock",
96 "connectdlg_innerframe",
97 "connectdlg_labelframe",
99 "diplodlg_meeting_heading_text",
100 "diplodlg_meeting_text",
103 "economydlg_neg_text",
112 "mapview_info_frame",
114 "mapview_unitinfo_text",
115 "mapview_unitinfo_veteran_text",
116 "meswin_active_text",
117 "meswin_active_text2",
123 "optiondlg_worklistlist_frame",
124 "optiondlg_worklistlist_text",
132 "plrdlg_war_restricted",
133 "revolutiondlg_text",
134 "sabotagedlg_separator",
136 "sciencedlg_med_techicon_bg",
143 "userpasswddlg_frame",
144 "userpasswddlg_text",
149 struct theme_color_system
*theme_color_system_read(struct section_file
*file
)
152 struct theme_color_system
*colors
= fc_malloc(sizeof(*colors
));
154 fc_assert_ret_val(ARRAY_SIZE(color_names
) == COLOR_THEME_LAST
, NULL
);
155 for (i
= 0; i
< COLOR_THEME_LAST
; i
++) {
157 = secfile_lookup_int_default(file
, 0, "colors.%s0.r", color_names
[i
]);
159 = secfile_lookup_int_default(file
, 0, "colors.%s0.g", color_names
[i
]);
161 = secfile_lookup_int_default(file
, 0, "colors.%s0.b", color_names
[i
]);
163 = secfile_lookup_int_default(file
, 0, "colors.%s0.a", color_names
[i
]);
164 colors
->colors
[i
].color
= NULL
;
170 /****************************************************************************
171 Called when the client first starts to free any allocated colors.
172 ****************************************************************************/
173 void theme_color_system_free(struct theme_color_system
*colors
)
177 for (i
= 0; i
< COLOR_THEME_LAST
; i
++) {
178 if (colors
->colors
[i
].color
) {
179 color_free(colors
->colors
[i
].color
);
186 /****************************************************************************
187 Return the RGBA color, allocating it if necessary.
188 ****************************************************************************/
189 static struct color
*ensure_color_rgba(struct rgbacolor
*rgba
)
192 rgba
->color
= color_alloc_rgba(rgba
->r
, rgba
->g
, rgba
->b
, rgba
->a
);
197 /****************************************************************************
198 Return a pointer to the given "theme" color.
199 ****************************************************************************/
200 struct color
*theme_get_color(const struct theme
*t
, enum theme_color color
)
202 return ensure_color_rgba(&theme_get_color_system(t
)->colors
[color
]);