missing NULL terminator in set_config_x
[geda-gaf.git] / gschem / src / x_color.c
blobca5e18ecaa6a6cb843a1f89a70cedf27c5da9cb2
1 /* gEDA - GPL Electronic Design Automation
2 * gschem - gEDA Schematic Capture
3 * Copyright (C) 1998-2010 Ales Hvezda
4 * Copyright (C) 1998-2020 gEDA Contributors (see ChangeLog for details)
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #include <config.h>
22 #include <stdio.h>
23 #ifdef HAVE_STRING_H
24 #include <string.h>
25 #endif
26 #include <math.h>
28 #include "gschem.h"
30 COLOR display_colors[MAX_COLORS];
31 COLOR display_outline_colors[MAX_COLORS];
33 static GdkColor* gdk_colors[MAX_COLORS];
34 static GdkColor* gdk_outline_colors[MAX_COLORS];
36 static GdkColormap *colormap = NULL;
38 /*! \brief Initializes the color system for the application.
39 * \par Function Documentation
41 * Initialises the color maps to defaults.
43 void
44 x_color_init (void)
46 colormap = gdk_colormap_get_system ();
48 /* Initialise default color maps */
49 s_color_map_defaults (display_colors);
50 s_color_map_defaults (display_outline_colors);
53 /*! \brief Frees memory used by the color system.
54 * \par Function Documentation
55 * This function frees the colors from colormap along with
56 * \b black and \b white.
58 void
59 x_color_free (void)
61 int i;
63 gdk_colormap_free_colors (colormap, &black, 1);
64 gdk_colormap_free_colors (colormap, &white, 1);
66 for (i = 0; i < MAX_COLORS; i++) {
67 if (display_colors[i].enabled)
68 gdk_colormap_free_colors (colormap, gdk_colors[i], 1);
69 if (display_outline_colors[i].enabled)
70 gdk_colormap_free_colors (colormap, gdk_outline_colors[i], 1);
74 /*! \todo Finish function documentation!!!
75 * \brief
76 * \par Function Documentation
79 void x_color_allocate (void)
81 int error;
82 int i;
83 COLOR c;
85 gdk_color_parse ("black", &black);
86 if (!gdk_colormap_alloc_color (colormap,
87 &black,
88 FALSE,
89 TRUE)) {
90 fprintf (stderr, _("Could not allocate the color %s!\n"), _("black"));
91 exit (-1);
94 gdk_color_parse ("white", &white);
95 if (!gdk_colormap_alloc_color (colormap,
96 &white,
97 FALSE,
98 TRUE)) {
99 fprintf (stderr, _("Could not allocate the color %s!\n"), _("white"));
100 exit (-1);
103 for (i = 0; i < MAX_COLORS; i++) {
105 if (display_colors[i].enabled) {
106 gdk_colors[i] = (GdkColor *)
107 g_malloc(sizeof(GdkColor));
109 c = display_colors[i];
111 /* Interpolate 8-bpp colours into 16-bpp GDK color
112 * space. N.b. ignore transparency because GDK doesn't
113 * understand it. */
114 gdk_colors[i]->red = c.r + (c.r<<8);
115 gdk_colors[i]->green = c.g + (c.g<<8);
116 gdk_colors[i]->blue = c.b + (c.b<<8);
118 error = gdk_color_alloc(colormap, gdk_colors[i]);
120 if (error == FALSE) {
121 g_error (_("Could not allocate display color %i!\n"), i);
123 } else {
124 gdk_colors[i] = NULL;
127 if (display_outline_colors[i].enabled) {
128 gdk_outline_colors[i] = (GdkColor *)
129 g_malloc(sizeof(GdkColor));
131 c = display_outline_colors[i];
133 /* Interpolate 8-bpp colours into 16-bpp GDK color
134 * space. N.b. ignore transparency because GDK doesn't
135 * understand it. */
136 gdk_outline_colors[i]->red = c.r + (c.r<<8);
137 gdk_outline_colors[i]->green = c.g + (c.g<<8);
138 gdk_outline_colors[i]->blue = c.b + (c.b<<8);
140 error = gdk_color_alloc(colormap, gdk_outline_colors[i]);
142 if (error == FALSE) {
143 g_error (_("Could not allocate outline color %i!\n"), i);
145 } else {
146 gdk_outline_colors[i] = NULL;
150 x_colorcb_update_store ();
153 /*! \todo Finish function documentation!!!
154 * \brief
155 * \par Function Documentation
158 GdkColor *x_get_color(int color)
160 if ((color < 0) || (color >= MAX_COLORS)
161 || (gdk_colors[color] == NULL)) {
162 g_warning (_("Tried to get an invalid color: %d\n"), color);
163 return(&white);
164 } else {
165 return(gdk_colors[color]);
169 /*! \todo Finish function documentation!!!
170 * \brief
171 * \par Function Documentation
174 COLOR *x_color_lookup (int color)
176 if (color < 0 || color >= MAX_COLORS ||
177 !display_colors[color].enabled) {
178 fprintf(stderr, _("Tried to get an invalid color: %d\n"), color);
179 return &display_colors[DEFAULT_COLOR];
180 } else {
181 return &display_colors[color];
185 gboolean
186 x_color_display_enabled (int index)
188 return (gdk_colors[index] != NULL);