1 /****************************************************************************
2 Freeciv - Copyright (C) 2010 - The Freeciv Team
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 ****************************************************************************/
13 #ifndef FC__RGBCOLOR_H
14 #define FC__RGBCOLOR_H
18 #endif /* __cplusplus */
25 /* Used for the color system in the client and the definition of the terrain
26 * colors used in the overview/map images. The values are read from the
30 /* An RGBcolor contains the R,G,B bitvalues for a color. The color itself
31 * holds the color structure for this color but may be NULL (it's allocated
32 * on demand at runtime). */
38 /* get 'struct color_list' and related functions: */
39 #define SPECLIST_TAG rgbcolor
40 #define SPECLIST_TYPE struct rgbcolor
43 #define rgbcolor_list_iterate(rgbcolorlist, prgbcolor) \
44 TYPED_LIST_ITERATE(struct rgbcolor, rgbcolorlist, prgbcolor)
45 #define rgbcolor_list_iterate_end LIST_ITERATE_END
47 /* Check the RGB color values. If a value is not in the interval [0, 255]
48 * clip it to the interval boundaries. */
49 #define CHECK_RGBCOLOR(_str, _c, _colorname) \
51 int _color_save = _c; \
53 _c = CLIP(0, _c, 255); \
54 if (_c != _color_save) { \
55 log_error("Invalid value for '%s' in color definition '%s' (%d). " \
56 "Setting it to '%d'.", _colorname, _str, _color_save, _c); \
59 #define rgbcolor_check(_str, _r, _g, _b) \
61 CHECK_RGBCOLOR(_str, _r, "red"); \
62 CHECK_RGBCOLOR(_str, _g, "green"); \
63 CHECK_RGBCOLOR(_str, _b, "blue"); \
66 struct rgbcolor
*rgbcolor_new(int r
, int g
, int b
);
67 struct rgbcolor
*rgbcolor_copy(const struct rgbcolor
*prgbcolor
);
68 bool rgbcolors_are_equal(const struct rgbcolor
*c1
, const struct rgbcolor
*c2
);
69 void rgbcolor_destroy(struct rgbcolor
*prgbcolor
);
71 bool rgbcolor_load(struct section_file
*file
, struct rgbcolor
**prgbcolor
,
73 fc__attribute((__format__ (__printf__
, 3, 4)));
74 void rgbcolor_save(struct section_file
*file
,
75 const struct rgbcolor
*prgbcolor
, char *path
, ...)
76 fc__attribute((__format__ (__printf__
, 3, 4)));
78 bool rgbcolor_to_hex(const struct rgbcolor
*prgbcolor
, char *hex
,
80 bool rgbcolor_from_hex(struct rgbcolor
**prgbcolor
, const char *hex
);
82 int rgbcolor_brightness_score(struct rgbcolor
*prgbcolor
);
86 #endif /* __cplusplus */
88 #endif /* FC__RGBCOLOR_H */