Freeciv-3.3: /fast/freeciv/nightly/main/client/gui-sdl3/colors.c Source File

Freeciv-3.3

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/**********************************************************************/
43 SDL_Color *get_theme_color(enum theme_color themecolor)
44{
45 return theme_get_color(active_theme, themecolor)->color;
46}
47
48/**********************************************************************/
51 SDL_Color *get_game_color(enum color_std stdcolor)
52{
53 return get_color(tileset, stdcolor)->color;
54}
55
56/**********************************************************************/
60 struct 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/**********************************************************************/
78 struct 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/**********************************************************************/
96 void 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/**********************************************************************/
113 int color_brightness_score(struct color *pcolor)
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
120 rgbcolor_destroy(prgb);
121 return score;
122}
pcolor
struct canvas int int int int struct sprite *sprite struct canvas struct color * pcolor
Definition canvas_g.h:56
get_color
struct color * get_color(const struct tileset *t, enum color_std stdcolor)
Definition colors_common.c:100
incite_cost
char * incite_cost
Definition comments.c:74
color_alloc
struct color * color_alloc(int r, int g, int b)
Definition colors.c:38
color_free
void color_free(struct color *color)
Definition colors.c:53
color_brightness_score
int color_brightness_score(struct color *pcolor)
Definition colors.c:62
color_alloc_rgba
struct color * color_alloc_rgba(int r, int g, int b, int a)
Definition colors.c:64
get_theme_color
SDL_Color * get_theme_color(enum theme_color themecolor)
Definition colors.c:47
get_game_color
SDL_Color * get_game_color(enum color_std stdcolor)
Definition colors.c:55
theme_get_color
struct color * theme_get_color(const struct theme *t, enum theme_color color)
Definition themecolors.c:204
theme_color
theme_color
Definition themecolors.h:23
active_theme
struct theme * active_theme
Definition themespec.c:154
themespec.h
colors.h
fc_malloc
#define fc_malloc(sz)
Definition mem.h:34
rgbcolor_destroy
void rgbcolor_destroy(struct rgbcolor *prgbcolor)
Definition rgbcolor.c:74
rgbcolor_new
struct rgbcolor * rgbcolor_new(int r, int g, int b)
Definition rgbcolor.c:34
rgbcolor_brightness_score
int rgbcolor_brightness_score(struct rgbcolor *prgbcolor)
Definition rgbcolor.c:196
rgbcolor.h
color
Definition colors.h:21
color::g
int g
Definition colors.h:21
color::color
GdkRGBA color
Definition colors.h:22
color::r
int r
Definition colors.h:21
color::b
int b
Definition colors.h:21
rgbcolor
Definition rgbcolor.h:33
tileset
Definition tilespec.c:482
tilespec.h