1
/* colors.c -- Colour handling
2
$Id: colors.c,v 1.22 2001/04/23 06:20:49 jsh Exp $
4
Copyright (C) 1999 John Harper <john@dcs.warwick.ac.uk>
6
This file is part of sawmill.
8
sawmill is free software; you can redistribute it and/or modify it
9
under the terms of the GNU General Public License as published by
10
the Free Software Foundation; either version 2, or (at your option)
13
sawmill is distributed in the hope that it will be useful, but
14
WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU General Public License for more details.
18
You should have received a copy of the GNU General Public License
19
along with sawmill; see the file COPYING. If not, write to
20
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
24
static Lisp_Color *color_list;
27
DEFSYM(default_foreground, "default-foreground");
29
DEFUN("get-color-rgb", Fget_color_rgb, Sget_color_rgb,
30
(repv red, repv green, repv blue), rep_Subr3) /*
31
::doc:sawfish.wm.colors#get-color-rgb::
32
get-color-rgb RED GREEN BLUE
36
rep_DECLARE1(red, rep_INTP);
37
rep_DECLARE2(green, rep_INTP);
38
rep_DECLARE3(blue, rep_INTP);
46
if (f->red == rep_INT(red)
47
&& f->green == rep_INT(green)
48
&& f->blue == rep_INT(blue))
56
int pixel = best_color_match (rep_INT(red) / 256,
60
f = rep_ALLOC_CELL(sizeof(Lisp_Color));
61
rep_data_after_gc += sizeof (Lisp_Color);
66
f->red = rep_INT(red);
67
f->green = rep_INT(green);
68
f->blue = rep_INT(blue);
74
DEFUN("get-color", Fget_color, Sget_color, (repv name), rep_Subr1) /*
75
::doc:sawfish.wm.colors#get-color::
78
Return the color object representing the color named NAME, a standard
83
rep_DECLARE1(name, rep_STRINGP);
88
if (XParseColor (dpy, image_cmap, rep_STR(name), &exact_col) != 0)
90
return Fget_color_rgb (rep_MAKE_INT(exact_col.red),
91
rep_MAKE_INT(exact_col.green),
92
rep_MAKE_INT(exact_col.blue));
96
return Fsignal (Qerror,
97
rep_list_2 (rep_string_dup("no such color"),
102
DEFUN("color-name", Fcolor_name, Scolor_name, (repv color), rep_Subr1) /*
103
::doc:sawfish.wm.colors#color-name::
106
Return the name of the color represented by the color object COLOR.
110
rep_DECLARE1(color, COLORP);
111
sprintf (buf, "#%04x%04x%04x",
112
VCOLOR(color)->red, VCOLOR(color)->green, VCOLOR(color)->blue);
113
return rep_string_dup (buf);
116
DEFUN("color-rgb", Fcolor_rgb, Scolor_rgb, (repv color), rep_Subr1) /*
117
::doc:sawfish.wm.colors#color-rgb::
120
Returns a list of integers (RED GREEN BLUE) representing the actual
121
color values of the color represented by object COLOR. The individual
122
values range from zero to 65535.
125
rep_DECLARE1(color, COLORP);
126
return rep_list_3 (rep_MAKE_INT(VCOLOR(color)->red),
127
rep_MAKE_INT(VCOLOR(color)->green),
128
rep_MAKE_INT(VCOLOR(color)->blue));
131
DEFUN("color-rgb-8", Fcolor_rgb_8, Scolor_rgb_8, (repv color), rep_Subr1) /*
132
::doc:sawfish.wm.colors#color-rgb::
135
Returns a list of integers (RED GREEN BLUE) representing the actual
136
color values of the color represented by object COLOR. The individual
137
values range from zero to 255.
140
rep_DECLARE1(color, COLORP);
141
return rep_list_3 (rep_MAKE_INT(VCOLOR(color)->red / 256),
142
rep_MAKE_INT(VCOLOR(color)->green / 256),
143
rep_MAKE_INT(VCOLOR(color)->blue / 256));
146
DEFUN("colorp", Fcolorp, Scolorp, (repv win), rep_Subr1) /*
147
::doc:sawfish.wm.colors#colorp::
150
Returns t if ARG is a color object.
153
return COLORP(win) ? Qt : Qnil;
160
color_cmp (repv w1, repv w2)
166
color_prin (repv stream, repv obj)
169
sprintf (buf, "#<color #%04x%04x%04x>",
170
VCOLOR(obj)->red, VCOLOR(obj)->green, VCOLOR(obj)->blue);
171
rep_stream_puts (stream, buf, -1, FALSE);
177
Lisp_Color *w = color_list;
181
Lisp_Color *next = w->next;
182
if (!rep_GC_CELL_MARKEDP(rep_VAL(w)))
186
rep_GC_CLR_CELL(rep_VAL(w));
187
w->next = color_list;
200
repv tem = rep_push_structure ("sawfish.wm.colors");
201
color_type = rep_register_new_type ("color", color_cmp, color_prin,
202
color_prin, color_sweep, 0,
203
0, 0, 0, 0, 0, 0, 0);
204
rep_ADD_SUBR(Sget_color_rgb);
205
rep_ADD_SUBR(Sget_color);
206
rep_ADD_SUBR(Scolor_name);
207
rep_ADD_SUBR(Scolor_rgb);
208
rep_ADD_SUBR(Scolor_rgb_8);
209
rep_ADD_SUBR(Scolorp);
210
rep_INTERN_SPECIAL(default_foreground);
211
if (!batch_mode_p ())
213
repv black = Fget_color (rep_string_dup("#000000"));
214
if (black == rep_NULL)
216
Fset (Qdefault_foreground, black);
218
rep_pop_structure (tem);