Freeciv-3.2
Loading...
Searching...
No Matches
themecolors.c
Go to the documentation of this file.
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.
7
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***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18/* utility */
19#include "mem.h"
20
21/* client/gui-sdl2 */
22#include "colors.h"
23#include "themespec.h"
24
25#include "themecolors.h"
26
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). */
30struct rgbacolor {
31 int r, g, b, a;
32 struct color *color;
33};
34
38
39static 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",
61
62 "advancedterraindlg_text",
63
64 "citydlg_buy",
65 "citydlg_celeb",
66 "citydlg_corruption",
67 "citydlg_foodperturn",
68 "citydlg_foodstock",
69 "citydlg_food_surplus",
70 "citydlg_frame",
71 "citydlg_gold",
72 "citydlg_granary",
73 "citydlg_growth",
74 "citydlg_happy",
75 "citydlg_impr",
76 "citydlg_infopanel",
77 "citydlg_lux",
78 "citydlg_panel",
79 "citydlg_prod",
80 "citydlg_science",
81 "citydlg_sell",
82 "citydlg_shieldstock",
83 "citydlg_stocks",
84 "citydlg_support",
85 "citydlg_trade",
86 "citydlg_upkeep",
87 "cityrep_foodstock",
88 "cityrep_frame",
89 "cityrep_prod",
90 "cityrep_text",
91 "cityrep_trade",
92 "cma_frame",
93 "cma_text",
94 "connectdlg_frame",
95 "connectdlg_innerframe",
96 "connectdlg_labelframe",
97 "connlistdlg_frame",
98 "diplodlg_meeting_heading_text",
99 "diplodlg_meeting_text",
100 "diplodlg_text",
101 "economydlg_frame",
102 "economydlg_neg_text",
103 "economydlg_text",
104 "helpdlg_frame",
105 "helpdlg_line",
106 "helpdlg_line2",
107 "helpdlg_line3",
108 "helpdlg_text",
109 "joingamedlg_frame",
110 "joingamedlg_text",
111 "mapview_info_frame",
112 "mapview_info_text",
113 "mapview_unitinfo_text",
114 "mapview_unitinfo_veteran_text",
115 "meswin_active_text",
116 "meswin_active_text2",
117 "meswin_frame",
118 "nationdlg_frame",
119 "nationdlg_legend",
120 "nationdlg_text",
121 "newcitydlg_text",
122 "optiondlg_worklistlist_frame",
123 "optiondlg_worklistlist_text",
124 "plrdlg_alliance",
125 "plrdlg_armistice",
126 "plrdlg_ceasefire",
127 "plrdlg_frame",
128 "plrdlg_peace",
129 "plrdlg_text",
130 "plrdlg_war",
131 "plrdlg_war_restricted",
132 "revolutiondlg_text",
133 "sabotagedlg_separator",
134 "sciencedlg_frame",
135 "sciencedlg_med_techicon_bg",
136 "sciencedlg_text",
137 "sellimpr_text",
138 "unitsrep_frame",
139 "unitsrep_text",
140 "unitupgrade_text",
141 "unitdisband_text",
142 "userpasswddlg_frame",
143 "userpasswddlg_text",
144 "wardlg_text",
145 "wldlg_frame",
146};
147
148/************************************************************************/
152{
153 int i;
154 struct theme_color_system *colors = fc_malloc(sizeof(*colors));
155
157 for (i = 0; i < COLOR_THEME_LAST; i++) {
158 colors->colors[i].r
159 = secfile_lookup_int_default(file, 0, "colors.%s0.r", color_names[i]);
160 colors->colors[i].g
161 = secfile_lookup_int_default(file, 0, "colors.%s0.g", color_names[i]);
162 colors->colors[i].b
163 = secfile_lookup_int_default(file, 0, "colors.%s0.b", color_names[i]);
164 colors->colors[i].a
165 = secfile_lookup_int_default(file, 0, "colors.%s0.a", color_names[i]);
166 colors->colors[i].color = NULL;
167 }
168
169 return colors;
170}
171
172/************************************************************************/
176{
177 int i;
178
179 for (i = 0; i < COLOR_THEME_LAST; i++) {
180 if (colors->colors[i].color) {
181 color_free(colors->colors[i].color);
182 }
183 }
184
185 free(colors);
186}
187
188/************************************************************************/
191static struct color *ensure_color_rgba(struct rgbacolor *rgba)
192{
193 if (!rgba->color) {
194 rgba->color = color_alloc_rgba(rgba->r, rgba->g, rgba->b, rgba->a);
195 }
196
197 return rgba->color;
198}
199
200/************************************************************************/
203struct color *theme_get_color(const struct theme *t, enum theme_color color)
204{
206}
char * incite_cost
Definition comments.c:74
void color_free(struct color *color)
Definition colors.c:53
struct color * color_alloc_rgba(int r, int g, int b, int a)
Definition colors.c:64
static struct color * ensure_color_rgba(struct rgbacolor *rgba)
void theme_color_system_free(struct theme_color_system *colors)
static char * color_names[]
Definition themecolors.c:39
struct theme_color_system * theme_color_system_read(struct section_file *file)
struct color * theme_get_color(const struct theme *t, enum theme_color color)
theme_color
Definition themecolors.h:22
@ COLOR_THEME_LAST
struct theme_color_system * theme_get_color_system(const struct theme *t)
Definition themespec.c:1122
#define fc_assert_ret_val(condition, val)
Definition log.h:194
#define fc_malloc(sz)
Definition mem.h:34
int secfile_lookup_int_default(const struct section_file *secfile, int def, const char *path,...)
#define ARRAY_SIZE(x)
Definition shared.h:85
Definition colors.h:21
GdkRGBA color
Definition colors.h:22
struct color * color
Definition themecolors.c:32
struct rgbacolor colors[COLOR_THEME_LAST]
Definition themecolors.c:36