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
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.
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.
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!!!
76 * \par Function Documentation
79 void x_color_allocate (void)
85 gdk_color_parse ("black", &black
);
86 if (!gdk_colormap_alloc_color (colormap
,
90 fprintf (stderr
, _("Could not allocate the color %s!\n"), _("black"));
94 gdk_color_parse ("white", &white
);
95 if (!gdk_colormap_alloc_color (colormap
,
99 fprintf (stderr
, _("Could not allocate the color %s!\n"), _("white"));
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
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
);
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
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
);
146 gdk_outline_colors
[i
] = NULL
;
150 x_colorcb_update_store ();
153 /*! \todo Finish function documentation!!!
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
);
165 return(gdk_colors
[color
]);
169 /*! \todo Finish function documentation!!!
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
];
181 return &display_colors
[color
];
186 x_color_display_enabled (int index
)
188 return (gdk_colors
[index
] != NULL
);