Freeciv-3.3
Loading...
Searching...
No Matches
colors_common.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 "log.h"
20#include "shared.h"
21
22/* common */
23#include "player.h"
24#include "rgbcolor.h"
25
26/* client/include */
27#include "colors_g.h"
28
29/* client */
30#include "tilespec.h"
31
32#include "colors_common.h"
33
36};
37
38/************************************************************************/
45{
46 struct color_system *colors = fc_malloc(sizeof(*colors));
48
49 colors->stdcolors = fc_calloc(COLOR_LAST, sizeof(*colors->stdcolors));
50
53 struct rgbcolor *prgbcolor = NULL;
54
55 if (rgbcolor_load(file, &prgbcolor, "colors.%s0",
57 *(colors->stdcolors + stdcolor) = prgbcolor;
58 } else {
60 *(colors->stdcolors + stdcolor) = rgbcolor_new(0, 0, 0);
61 }
62 }
63
64 return colors;
65}
66
67/************************************************************************/
70void color_system_free(struct color_system *colors)
71{
73
77 }
78
79 free(colors->stdcolors);
80
81 free(colors);
82}
83
84/************************************************************************/
87struct color *ensure_color(struct rgbcolor *rgb)
88{
90
91 if (!rgb->color) {
92 rgb->color = color_alloc(rgb->r, rgb->g, rgb->b);
93 }
94 return rgb->color;
95}
96
97/************************************************************************/
100struct color *get_color(const struct tileset *t, enum color_std stdcolor)
101{
102 struct color_system *colors = get_color_system(t);
103
104 fc_assert_ret_val(colors != NULL, NULL);
105
106 return ensure_color(*(colors->stdcolors + stdcolor));
107}
108
109/************************************************************************/
113bool player_has_color(const struct player *pplayer)
114{
115 fc_assert_ret_val(pplayer != NULL, FALSE);
116
117 return pplayer->rgb != NULL;
118}
119
120/************************************************************************/
125struct color *get_player_color(const struct tileset *t,
126 const struct player *pplayer)
127{
128 fc_assert_ret_val(pplayer != NULL, NULL);
129 fc_assert_ret_val(pplayer->rgb != NULL, NULL);
130
131 return ensure_color(pplayer->rgb);
132}
133
134/************************************************************************/
137struct color *get_terrain_color(const struct tileset *t,
138 const struct terrain *pterrain)
139{
140 fc_assert_ret_val(pterrain != NULL, NULL);
141 fc_assert_ret_val(pterrain->rgb != NULL, NULL);
142
143 return ensure_color(pterrain->rgb);
144}
145
146/************************************************************************/
151 struct color **candidates, int ncandidates)
152{
154 int i;
155 struct color *best = NULL;
156
159
160 for (i = 0; i < ncandidates; i++) {
162 int diff = ABS(sbright - cbright);
163
164 if (best == NULL || diff > bestdiff) {
165 best = candidates[i];
166 bestdiff = diff;
167 }
168 }
169
170 return best;
171}
void color_system_free(struct color_system *colors)
struct color * color_best_contrast(struct color *subject, struct color **candidates, int ncandidates)
struct color * get_player_color(const struct tileset *t, const struct player *pplayer)
struct color_system * color_system_read(struct section_file *file)
struct color * ensure_color(struct rgbcolor *rgb)
bool player_has_color(const struct player *pplayer)
struct color * get_color(const struct tileset *t, enum color_std stdcolor)
struct color * get_terrain_color(const struct tileset *t, const struct terrain *pterrain)
char * incite_cost
Definition comments.c:74
struct color * color_alloc(int r, int g, int b)
Definition colors.c:38
int color_brightness_score(struct color *pcolor)
Definition colors.c:62
#define fc_assert_ret_val(condition, val)
Definition log.h:194
#define log_error(message,...)
Definition log.h:103
#define fc_calloc(n, esz)
Definition mem.h:38
#define fc_malloc(sz)
Definition mem.h:34
const char * secfile_error(void)
void rgbcolor_destroy(struct rgbcolor *prgbcolor)
Definition rgbcolor.c:74
bool rgbcolor_load(struct section_file *file, struct rgbcolor **prgbcolor, char *path,...)
Definition rgbcolor.c:90
struct rgbcolor * rgbcolor_new(int r, int g, int b)
Definition rgbcolor.c:34
#define ABS(x)
Definition shared.h:61
struct rgbcolor ** stdcolors
Definition colors.h:21
struct rgbcolor * rgb
Definition player.h:312
int g
Definition rgbcolor.h:34
struct color * color
Definition rgbcolor.h:35
int b
Definition rgbcolor.h:34
int r
Definition rgbcolor.h:34
struct rgbcolor * rgb
Definition terrain.h:154
#define FALSE
Definition support.h:47
struct color_system * get_color_system(const struct tileset *t)
Definition tilespec.c:7100