Freeciv-3.2
Loading...
Searching...
No Matches
colors.c
Go to the documentation of this file.
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.
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/***********************************************************************
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***********************************************************************/
21
22#ifdef HAVE_CONFIG_H
23#include <fc_config.h>
24#endif
25
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 */
32
33/* common */
34#include "rgbcolor.h"
35
36/* client */
37#include "tilespec.h"
38
39/* gui-sdl2 */
40#include "themespec.h"
41
42#include "colors.h"
43
44/**********************************************************************/
51
52/**********************************************************************/
59
60/**********************************************************************/
64struct color *color_alloc_rgba(int r, int g, int b, int a)
65{
66 struct color *result = fc_malloc(sizeof(*result));
67 SDL_Color *pcolor = fc_malloc(sizeof(*pcolor));
68
69 pcolor->r = r;
70 pcolor->g = g;
71 pcolor->b = b;
72 pcolor->a = a;
73
74 result->color = pcolor;
75
76 return result;
77}
78
79/**********************************************************************/
82struct color *color_alloc(int r, int g, int b)
83{
84 struct color *result = fc_malloc(sizeof(*result));
85 SDL_Color *pcolor = fc_malloc(sizeof(*pcolor));
86
87 pcolor->r = r;
88 pcolor->g = g;
89 pcolor->b = b;
90 pcolor->a = 255;
91
92 result->color = pcolor;
93
94 return result;
95}
96
97/**********************************************************************/
101{
102 if (!pcolor) {
103 return;
104 }
105
106 if (pcolor->color) {
107 free(pcolor->color);
108 }
109
110 free(pcolor);
111}
112
113/**********************************************************************/
118{
119 struct rgbcolor *prgb = rgbcolor_new(pcolor->color->r,
120 pcolor->color->g,
121 pcolor->color->b);
122 int score = rgbcolor_brightness_score(prgb);
123
125 return score;
126}
struct canvas int int int int struct sprite *sprite struct canvas struct color * pcolor
Definition canvas_g.h:56
struct color * get_color(const struct tileset *t, enum color_std stdcolor)
char * incite_cost
Definition comments.c:74
struct color * color_alloc(int r, int g, int b)
Definition colors.c:38
void color_free(struct color *color)
Definition colors.c:53
int color_brightness_score(struct color *pcolor)
Definition colors.c:62
struct color * color_alloc_rgba(int r, int g, int b, int a)
Definition colors.c:64
SDL_Color * get_theme_color(enum theme_color themecolor)
Definition colors.c:47
SDL_Color * get_game_color(enum color_std stdcolor)
Definition colors.c:55
struct color * theme_get_color(const struct theme *t, enum theme_color color)
theme_color
Definition themecolors.h:22
struct theme * active_theme
Definition themespec.c:154
#define fc_malloc(sz)
Definition mem.h:34
void rgbcolor_destroy(struct rgbcolor *prgbcolor)
Definition rgbcolor.c:74
struct rgbcolor * rgbcolor_new(int r, int g, int b)
Definition rgbcolor.c:34
int rgbcolor_brightness_score(struct rgbcolor *prgbcolor)
Definition rgbcolor.c:196
Definition colors.h:21
int g
Definition colors.h:21
GdkRGBA color
Definition colors.h:22
int r
Definition colors.h:21
int b
Definition colors.h:21