Rulesave saves trade.type and trade.bonus correctly.
[freeciv.git] / client / gui-gtk-3.22 / colors.c
blob619f93c66a51db77cdd447138218ac1ec279aa19
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.
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 ***********************************************************************/
14 #ifdef HAVE_CONFIG_H
15 #include <fc_config.h>
16 #endif
18 #include <stdio.h>
20 #include <gtk/gtk.h>
22 /* utility */
23 #include "log.h"
24 #include "mem.h"
26 /* common */
27 #include "rgbcolor.h"
29 /* client/gui-gtk-3.22 */
30 #include "gui_main.h"
32 #include "colors.h"
34 /*************************************************************
35 Get display color type of default visual
36 *************************************************************/
37 enum Display_color_type get_visual(void)
39 GdkVisual *visual;
40 GdkVisualType type;
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.");
48 return BW_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.");
59 return COLOR_DISPLAY;
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;
75 return color;
78 /****************************************************************************
79 Free a previously allocated color. See color_alloc.
80 ****************************************************************************/
81 void color_free(struct color *color)
83 free(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);
98 return score;