Freeciv-3.1: /fast/freeciv/nightly/S3_1/client/gui-sdl2/themecolors.c Source File

Freeciv-3.1

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). */
30 struct rgbacolor {
31 int r, g, b, a;
32 struct color *color;
33};
34
35 struct theme_color_system {
36 struct rgbacolor colors[COLOR_THEME_LAST];
37};
38
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",
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/************************************************************************/
151 struct theme_color_system *theme_color_system_read(struct section_file *file)
152{
153 int i;
154 struct theme_color_system *colors = fc_malloc(sizeof(*colors));
155
156 fc_assert_ret_val(ARRAY_SIZE(color_names) == COLOR_THEME_LAST, NULL);
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/************************************************************************/
175 void theme_color_system_free(struct theme_color_system *colors)
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/************************************************************************/
191 static 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/************************************************************************/
203 struct color *theme_get_color(const struct theme *t, enum theme_color color)
204{
205 return ensure_color_rgba(&theme_get_color_system(t)->colors[color]);
206}
color_free
void color_free(struct color *color)
Definition colors.c:53
color_alloc_rgba
struct color * color_alloc_rgba(int r, int g, int b, int a)
Definition colors.c:61
colors.h
fc_assert_ret_val
#define fc_assert_ret_val(condition, val)
Definition log.h:194
mem.h
fc_malloc
#define fc_malloc(sz)
Definition mem.h:34
secfile_lookup_int_default
int secfile_lookup_int_default(const struct section_file *secfile, int def, const char *path,...)
Definition registry_ini.c:1937
ARRAY_SIZE
#define ARRAY_SIZE(x)
Definition shared.h:85
color
Definition colors.h:20
rgbacolor
Definition themecolors.c:30
rgbacolor::g
int g
Definition themecolors.c:31
rgbacolor::b
int b
Definition themecolors.c:31
rgbacolor::color
struct color * color
Definition themecolors.c:32
rgbacolor::r
int r
Definition themecolors.c:31
rgbacolor::a
int a
Definition themecolors.c:31
section_file
Definition section_file.h:36
theme_color_system
Definition themecolors.c:35
theme_color_system::colors
struct rgbacolor colors[COLOR_THEME_LAST]
Definition themecolors.c:36
theme
Definition themespec.c:133
ensure_color_rgba
static struct color * ensure_color_rgba(struct rgbacolor *rgba)
Definition themecolors.c:191
theme_color_system_free
void theme_color_system_free(struct theme_color_system *colors)
Definition themecolors.c:175
color_names
static char * color_names[]
Definition themecolors.c:39
theme_color_system_read
struct theme_color_system * theme_color_system_read(struct section_file *file)
Definition themecolors.c:151
theme_get_color
struct color * theme_get_color(const struct theme *t, enum theme_color color)
Definition themecolors.c:203
themecolors.h
theme_color
theme_color
Definition themecolors.h:22
COLOR_THEME_LAST
@ COLOR_THEME_LAST
Definition themecolors.h:129
theme_get_color_system
struct theme_color_system * theme_get_color_system(const struct theme *t)
Definition themespec.c:1124
themespec.h