webperimental: Mountain vision bonus.
[freeciv.git] / client / gui-sdl2 / colors.c
blobbd250ee934070e381ef6d2be0e32193383ef69ce
1 /***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
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 /***********************************************************************
15 colors.c - description
16 -------------------
17 begin : Mon Jul 15 2002
18 copyright : (C) 2002 by Rafał Bursig
19 email : Rafał Bursig <bursig@poczta.fm>
20 ***********************************************************************/
22 #ifdef HAVE_CONFIG_H
23 #include <fc_config.h>
24 #endif
26 /* SDL2 */
27 #ifdef SDL2_PLAIN_INCLUDE
28 #include <SDL.h>
29 #else /* SDL2_PLAIN_INCLUDE */
30 #include <SDL2/SDL.h>
31 #endif /* SDL2_PLAIN_INCLUDE */
33 /* client */
34 #include "tilespec.h"
36 /* gui-sdl2 */
37 #include "themespec.h"
39 #include "colors.h"
41 /**************************************************************************
42 Get color from theme.
43 **************************************************************************/
44 SDL_Color *get_theme_color(enum theme_color themecolor)
46 return theme_get_color(theme, themecolor)->color;
49 /**************************************************************************
50 Get color for some game object instance.
51 **************************************************************************/
52 SDL_Color *get_game_color(enum color_std stdcolor)
54 return get_color(tileset, stdcolor)->color;
57 /****************************************************************************
58 Allocate a color with alpha channel and return a pointer to it. Alpha
59 channel is not really used yet.
60 ****************************************************************************/
61 struct color *color_alloc_rgba(int r, int g, int b, int a)
63 struct color *result = fc_malloc(sizeof(*result));
64 SDL_Color *pcolor = fc_malloc(sizeof(*pcolor));
66 pcolor->r = r;
67 pcolor->g = g;
68 pcolor->b = b;
69 pcolor->a = a;
71 result->color = pcolor;
73 return result;
76 /****************************************************************************
77 Allocate a solid color and return a pointer to it.
78 ****************************************************************************/
79 struct color *color_alloc(int r, int g, int b)
81 struct color *result = fc_malloc(sizeof(*result));
82 SDL_Color *pcolor = fc_malloc(sizeof(*pcolor));
84 pcolor->r = r;
85 pcolor->g = g;
86 pcolor->b = b;
87 pcolor->a = 255;
89 result->color = pcolor;
91 return result;
94 /****************************************************************************
95 Free resources allocated for color.
96 ****************************************************************************/
97 void color_free(struct color *pcolor)
99 if (!pcolor) {
100 return;
103 if (pcolor->color) {
104 free(pcolor->color);
107 free(pcolor);
110 /****************************************************************************
111 Return a number indicating the perceptual brightness of this color
112 relative to others (larger is brighter).
113 ****************************************************************************/
114 int color_brightness_score(struct color *pcolor)
116 struct rgbcolor *prgb = rgbcolor_new(pcolor->color->r,
117 pcolor->color->g,
118 pcolor->color->b);
119 int score = rgbcolor_brightness_score(prgb);
121 rgbcolor_destroy(prgb);
122 return score;