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/* SDL3 */
27#include <SDL3/SDL.h>
28
29/* common */
30#include "rgbcolor.h"
31
32/* client */
33#include "tilespec.h"
34
35/* gui-sdl3 */
36#include "themespec.h"
37
38#include "colors.h"
39
40/**********************************************************************/
47
48/**********************************************************************/
55
56/**********************************************************************/
60struct color *color_alloc_rgba(int r, int g, int b, int a)
61{
62 struct color *result = fc_malloc(sizeof(*result));
63 SDL_Color *pcolor = fc_malloc(sizeof(*pcolor));
64
65 pcolor->r = r;
66 pcolor->g = g;
67 pcolor->b = b;
68 pcolor->a = a;
69
70 result->color = pcolor;
71
72 return result;
73}
74
75/**********************************************************************/
78struct color *color_alloc(int r, int g, int b)
79{
80 struct color *result = fc_malloc(sizeof(*result));
81 SDL_Color *pcolor = fc_malloc(sizeof(*pcolor));
82
83 pcolor->r = r;
84 pcolor->g = g;
85 pcolor->b = b;
86 pcolor->a = 255;
87
88 result->color = pcolor;
89
90 return result;
91}
92
93/**********************************************************************/
96void color_free(struct color *pcolor)
97{
98 if (!pcolor) {
99 return;
100 }
101
102 if (pcolor->color) {
103 free(pcolor->color);
104 }
105
106 free(pcolor);
107}
108
109/**********************************************************************/
114{
115 struct rgbcolor *prgb = rgbcolor_new(pcolor->color->r,
116 pcolor->color->g,
117 pcolor->color->b);
118 int score = rgbcolor_brightness_score(prgb);
119
121 return score;
122}
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