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
29 #include <libgeda/s_color.h>
31 #ifdef HAVE_LIBDMALLOC
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.
48 gdk_color_parse ("black", &black
);
49 if (!gdk_colormap_alloc_color (colormap
,
53 fprintf (stderr
, _("Could not allocate the color %s!\n"), _("black"));
57 gdk_color_parse ("white", &white
);
58 if (!gdk_colormap_alloc_color (colormap
,
62 fprintf (stderr
, _("Could not allocate the color %s!\n"), _("white"));
66 x_color_allocate_all ();
70 /*! \todo Finish function documentation!!!
72 * \par Function Documentation
75 static void x_color_allocate_all(void)
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
,
90 _("Could not find the color %s!\n"),
91 colors
[i
].color_name
);
93 _("Defaulting color to white\n"));
95 error
= gdk_color_parse("white",
100 _("Ack! Cannot allocate white!\n"));
107 error
= gdk_color_alloc(colormap
, colors
[i
].gdk_color
);
109 if (error
== FALSE
) {
111 _("Could not allocate the color %s!\n"),
112 colors
[i
].color_name
);
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
) {
127 _("Could not find the color %s!\n"),
128 colors
[i
].outline_color_name
);
130 _("Defaulting color to white\n"));
132 error
= gdk_color_parse("white",
133 colors
[i
].gdk_outline_color
);
135 if (error
== FALSE
) {
137 _("Ack! Cannot allocate white!\n"));
143 /* Make sure the outline color is correct for non-black backgrounds */
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
) {
159 _("Could not allocate the color %s!\n"),
160 colors
[i
].outline_color_name
);
168 /*! \todo Finish function documentation!!!
170 * \par Function Documentation
173 GdkColor
*x_get_color(int color
)
175 if (colors
[color
].color_name
) {
176 return(colors
[color
].gdk_color
);
178 fprintf(stderr
, _("Tried to get an invalid color: %d\n"), color
);
183 /*! \todo Finish function documentation!!!
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
);
194 fprintf(stderr
, _("Tried to get an invalid color: %d\n"), color
);
200 /*! \todo Finish function documentation!!!
202 * \par Function Documentation
205 gchar
*x_color_get_name(int index
)
207 if ((index
>= MAX_COLORS
) || (index
< 0)) {
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 */