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)
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 ***********************************************************************/
15 #include <fc_config.h>
29 /* client/gui-gtk-3.22 */
34 /*************************************************************
35 Get display color type of default visual
36 *************************************************************/
37 enum Display_color_type
get_visual(void)
42 visual
= gdk_screen_get_system_visual(gdk_screen_get_default());
43 type
= gdk_visual_get_visual_type(visual
);
45 if (type
== GDK_VISUAL_STATIC_GRAY
) {
46 /* StaticGray, use black and white */
47 log_verbose("found B/W display.");
51 if(type
< GDK_VISUAL_STATIC_COLOR
) {
52 /* No color visual available at default depth */
53 log_verbose("found grayscale(?) display.");
54 return GRAYSCALE_DISPLAY
;
57 log_verbose("color system booted ok.");
62 /****************************************************************************
63 Allocate a color (well, sort of)
64 and return a pointer to it.
65 ****************************************************************************/
66 struct color
*color_alloc(int r
, int g
, int b
)
68 struct color
*color
= fc_malloc(sizeof(*color
));
70 color
->color
.red
= (double)r
/255;
71 color
->color
.green
= (double)g
/255;
72 color
->color
.blue
= (double)b
/255;
73 color
->color
.alpha
= 1.0;
78 /****************************************************************************
79 Free a previously allocated color. See color_alloc.
80 ****************************************************************************/
81 void color_free(struct color
*color
)
86 /****************************************************************************
87 Return a number indicating the perceptual brightness of this color
88 relative to others (larger is brighter).
89 ****************************************************************************/
90 int color_brightness_score(struct color
*pcolor
)
92 struct rgbcolor
*prgb
= rgbcolor_new(pcolor
->color
.red
* 255,
93 pcolor
->color
.green
* 255,
94 pcolor
->color
.blue
* 255);
95 int score
= rgbcolor_brightness_score(prgb
);
97 rgbcolor_destroy(prgb
);