Take page as input and take advantage of s_visit_page.
[geda-gaf/berndj.git] / gschem / src / x_color.c
blob1013fafb1578764250cacefe838738ffd3204d00
1 /* gEDA - GPL Electronic Design Automation
2 * gschem - gEDA Schematic Capture
3 * Copyright (C) 1998-2007 Ales Hvezda
4 * Copyright (C) 1998-2007 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., 59 Temple Place, Suite 330, Boston, MA 02111 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"
29 #include <libgeda/s_color.h>
31 #ifdef HAVE_LIBDMALLOC
32 #include <dmalloc.h>
33 #endif
35 extern COLOR colors[MAX_COLORS];
37 static void x_color_allocate_all(void);
39 /*! \brief Initializes the color system for the application.
40 * \par Function Documentation
41 * This function initializes the default \b black and \b white color.
43 * It also allocates the colormap.
45 void
46 x_color_init (void)
48 gdk_color_parse ("black", &black);
49 if (!gdk_colormap_alloc_color (colormap,
50 &black,
51 FALSE,
52 TRUE)) {
53 fprintf (stderr, _("Could not allocate the color %s!\n"), _("black"));
54 exit (-1);
57 gdk_color_parse ("white", &white);
58 if (!gdk_colormap_alloc_color (colormap,
59 &white,
60 FALSE,
61 TRUE)) {
62 fprintf (stderr, _("Could not allocate the color %s!\n"), _("white"));
63 exit (-1);
66 x_color_allocate_all ();
70 /*! \todo Finish function documentation!!!
71 * \brief
72 * \par Function Documentation
75 static void x_color_allocate_all(void)
77 int error;
78 int i;
80 for (i = 0; i < MAX_COLORS; i++) {
81 if (colors[i].color_name) {
82 colors[i].gdk_color = (GdkColor *)
83 g_malloc(sizeof(GdkColor));
85 error = gdk_color_parse(colors[i].color_name,
86 colors[i].gdk_color);
88 if (error == FALSE) {
89 fprintf(stderr,
90 _("Could not find the color %s!\n"),
91 colors[i].color_name);
92 fprintf(stderr,
93 _("Defaulting color to white\n"));
95 error = gdk_color_parse("white",
96 colors[i].gdk_color);
98 if (error == FALSE) {
99 fprintf(stderr,
100 _("Ack! Cannot allocate white!\n"));
101 exit(-1);
107 error = gdk_color_alloc(colormap, colors[i].gdk_color);
109 if (error == FALSE) {
110 fprintf(stderr,
111 _("Could not allocate the color %s!\n"),
112 colors[i].color_name);
113 exit(-1);
118 if (colors[i].outline_color_name) {
119 colors[i].gdk_outline_color = (GdkColor *)
120 g_malloc(sizeof(GdkColor));
122 error = gdk_color_parse(colors[i].outline_color_name,
123 colors[i].gdk_outline_color);
125 if (error == FALSE) {
126 fprintf(stderr,
127 _("Could not find the color %s!\n"),
128 colors[i].outline_color_name);
129 fprintf(stderr,
130 _("Defaulting color to white\n"));
132 error = gdk_color_parse("white",
133 colors[i].gdk_outline_color);
135 if (error == FALSE) {
136 fprintf(stderr,
137 _("Ack! Cannot allocate white!\n"));
138 exit(-1);
143 /* Make sure the outline color is correct for non-black backgrounds */
144 if (i > 0) {
145 colors[i].gdk_outline_color->red =
146 colors[i].gdk_outline_color->red ^ colors[0].gdk_color->red;
147 colors[i].gdk_outline_color->green =
148 colors[i].gdk_outline_color->green ^
149 colors[0].gdk_color->green;
150 colors[i].gdk_outline_color->blue =
151 colors[i].gdk_outline_color->blue ^ colors[0].gdk_color->blue;
154 error = gdk_color_alloc(colormap,
155 colors[i].gdk_outline_color);
157 if (error == FALSE) {
158 fprintf(stderr,
159 _("Could not allocate the color %s!\n"),
160 colors[i].outline_color_name);
161 exit(-1);
168 /*! \todo Finish function documentation!!!
169 * \brief
170 * \par Function Documentation
173 GdkColor *x_get_color(int color)
175 if (colors[color].color_name) {
176 return(colors[color].gdk_color);
177 } else {
178 fprintf(stderr, _("Tried to get an invalid color: %d\n"), color);
179 return(&white);
183 /*! \todo Finish function documentation!!!
184 * \brief
185 * \par Function Documentation
187 * \todo this has to change... to the right code
189 GdkColor *x_get_darkcolor(int color)
191 if (colors[color].outline_color_name) {
192 return(colors[color].gdk_outline_color);
193 } else {
194 fprintf(stderr, _("Tried to get an invalid color: %d\n"), color);
195 return(&white);
200 /*! \todo Finish function documentation!!!
201 * \brief
202 * \par Function Documentation
205 gchar *x_color_get_name(int index)
207 if ((index >= MAX_COLORS) || (index < 0)) {
208 return(NULL);
211 /* only if these two variables are not null is the color settable */
212 if (colors[index].color_name && colors[index].outline_color_name) {
213 return (g_strdup(colors[index].color_name));
216 /* didn't find a color, but there still might be more */
217 return(NULL);