Freeciv-3.1
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/* client */
34#include "tilespec.h"
35
36/* gui-sdl2 */
37#include "themespec.h"
38
39#include "colors.h"
40
41/**********************************************************************/
44SDL_Color *get_theme_color(enum theme_color themecolor)
45{
46 return theme_get_color(active_theme, themecolor)->color;
47}
48
49/**********************************************************************/
52SDL_Color *get_game_color(enum color_std stdcolor)
53{
54 return get_color(tileset, stdcolor)->color;
55}
56
57/**********************************************************************/
61struct color *color_alloc_rgba(int r, int g, int b, int a)
62{
63 struct color *result = fc_malloc(sizeof(*result));
64 SDL_Color *pcolor = fc_malloc(sizeof(*pcolor));
65
66 pcolor->r = r;
67 pcolor->g = g;
68 pcolor->b = b;
69 pcolor->a = a;
70
71 result->color = pcolor;
72
73 return result;
74}
75
76/**********************************************************************/
79struct color *color_alloc(int r, int g, int b)
80{
81 struct color *result = fc_malloc(sizeof(*result));
82 SDL_Color *pcolor = fc_malloc(sizeof(*pcolor));
83
84 pcolor->r = r;
85 pcolor->g = g;
86 pcolor->b = b;
87 pcolor->a = 255;
88
89 result->color = pcolor;
90
91 return result;
92}
93
94/**********************************************************************/
97void color_free(struct color *pcolor)
98{
99 if (!pcolor) {
100 return;
101 }
102
103 if (pcolor->color) {
104 free(pcolor->color);
105 }
106
107 free(pcolor);
108}
109
110/**********************************************************************/
115{
116 struct rgbcolor *prgb = rgbcolor_new(pcolor->color->r,
117 pcolor->color->g,
118 pcolor->color->b);
119 int score = rgbcolor_brightness_score(prgb);
120
121 rgbcolor_destroy(prgb);
122 return score;
123}
struct canvas int int struct sprite bool int int fog_y struct canvas struct sprite struct color * pcolor
Definition canvas_g.h:57
struct color * get_color(const struct tileset *t, enum color_std stdcolor)
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:61
SDL_Color * get_theme_color(enum theme_color themecolor)
Definition colors.c:44
SDL_Color * get_game_color(enum color_std stdcolor)
Definition colors.c:52
#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:20
int g
Definition colors.h:21
GdkRGBA color
Definition colors.h:21
int r
Definition colors.h:21
int b
Definition colors.h:21
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