When mixer is not available, recommend SDL2_mixer instead of SDL1.2 mixer
[freeciv.git] / client / gui-sdl / themecolors.c
blob313538e0e5ef824f3fc41fca606c447a53957306
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)
6 any later version.
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 ***********************************************************************/
14 #ifdef HAVE_CONFIG_H
15 #include <fc_config.h>
16 #endif
18 /* utility */
19 #include "mem.h"
21 /* client/gui-sdl */
22 #include "colors.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). */
30 struct rgbacolor {
31 int r, g, b, a;
32 struct color *color;
35 struct theme_color_system {
36 struct rgbacolor colors[COLOR_THEME_LAST];
39 static char *color_names[] = {
40 "background",
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",
48 "editfield_caret",
49 "label_bar",
50 "quick_info_bg",
51 "quick_info_frame",
52 "quick_info_text",
53 "selectionrectangle",
54 "text",
55 "themelabel2_bg",
56 "widget_normal_text",
57 "widget_selected_text",
58 "widget_pressed_text",
59 "widget_disabled_text",
60 "window_titlebar_separator",
62 "advancedterraindlg_text",
65 "citydlg_buy",
66 "citydlg_celeb",
67 "citydlg_corruption",
68 "citydlg_foodperturn",
69 "citydlg_foodstock",
70 "citydlg_food_surplus",
71 "citydlg_frame",
72 "citydlg_gold",
73 "citydlg_granary",
74 "citydlg_growth",
75 "citydlg_happy",
76 "citydlg_impr",
77 "citydlg_infopanel",
78 "citydlg_lux",
79 "citydlg_panel",
80 "citydlg_prod",
81 "citydlg_science",
82 "citydlg_sell",
83 "citydlg_shieldstock",
84 "citydlg_stocks",
85 "citydlg_support",
86 "citydlg_trade",
87 "citydlg_upkeep",
88 "cityrep_foodstock",
89 "cityrep_frame",
90 "cityrep_prod",
91 "cityrep_text",
92 "cityrep_trade",
93 "cma_frame",
94 "cma_text",
95 "connectdlg_frame",
96 "connectdlg_innerframe",
97 "connectdlg_labelframe",
98 "connlistdlg_frame",
99 "diplodlg_meeting_heading_text",
100 "diplodlg_meeting_text",
101 "diplodlg_text",
102 "economydlg_frame",
103 "economydlg_neg_text",
104 "economydlg_text",
105 "helpdlg_frame",
106 "helpdlg_line",
107 "helpdlg_line2",
108 "helpdlg_line3",
109 "helpdlg_text",
110 "joingamedlg_frame",
111 "joingamedlg_text",
112 "mapview_info_frame",
113 "mapview_info_text",
114 "mapview_unitinfo_text",
115 "mapview_unitinfo_veteran_text",
116 "meswin_active_text",
117 "meswin_active_text2",
118 "meswin_frame",
119 "nationdlg_frame",
120 "nationdlg_legend",
121 "nationdlg_text",
122 "newcitydlg_text",
123 "optiondlg_worklistlist_frame",
124 "optiondlg_worklistlist_text",
125 "plrdlg_alliance",
126 "plrdlg_armistice",
127 "plrdlg_ceasefire",
128 "plrdlg_frame",
129 "plrdlg_peace",
130 "plrdlg_text",
131 "plrdlg_war",
132 "plrdlg_war_restricted",
133 "revolutiondlg_text",
134 "sabotagedlg_separator",
135 "sciencedlg_frame",
136 "sciencedlg_med_techicon_bg",
137 "sciencedlg_text",
138 "sellimpr_text",
139 "unitsrep_frame",
140 "unitsrep_text",
141 "unitupgrade_text",
142 "unitdisband_text",
143 "userpasswddlg_frame",
144 "userpasswddlg_text",
145 "wardlg_text",
146 "wldlg_frame",
149 struct theme_color_system *theme_color_system_read(struct section_file *file)
151 int i;
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++) {
156 colors->colors[i].r
157 = secfile_lookup_int_default(file, 0, "colors.%s0.r", color_names[i]);
158 colors->colors[i].g
159 = secfile_lookup_int_default(file, 0, "colors.%s0.g", color_names[i]);
160 colors->colors[i].b
161 = secfile_lookup_int_default(file, 0, "colors.%s0.b", color_names[i]);
162 colors->colors[i].a
163 = secfile_lookup_int_default(file, 0, "colors.%s0.a", color_names[i]);
164 colors->colors[i].color = NULL;
167 return colors;
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)
175 int i;
177 for (i = 0; i < COLOR_THEME_LAST; i++) {
178 if (colors->colors[i].color) {
179 color_free(colors->colors[i].color);
183 free(colors);
186 /****************************************************************************
187 Return the RGBA color, allocating it if necessary.
188 ****************************************************************************/
189 static struct color *ensure_color_rgba(struct rgbacolor *rgba)
191 if (!rgba->color) {
192 rgba->color = color_alloc_rgba(rgba->r, rgba->g, rgba->b, rgba->a);
194 return rgba->color;
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]);