3 * This source code is part of
7 * GROningen MAchine for Chemical Simulations
10 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
11 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
12 * Copyright (c) 2001-2004, The GROMACS development team,
13 * check out http://www.gromacs.org for more information.
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * If you want to redistribute modifications, please consider that
21 * scientific software is very special. Version control is crucial -
22 * bugs must be traceable. We will be happy to consider code for
23 * inclusion in the official distribution, but derived work must not
24 * be called official GROMACS. Details are found in the README & COPYING
25 * files - if they are missing, get the official version at www.gromacs.org.
27 * To help us fund GROMACS development, we humbly ask that you cite
28 * the papers on the package - you can find them in the top README file.
30 * For more info, check our website at http://www.gromacs.org
33 * Gyas ROwers Mature At Cryogenic Speed
58 static bool ColCallBack(struct t_x11
*x11
,XEvent
*event
, Window w
, void *data
)
68 switch (event
->type
) {
73 printf("%6d%6d%6d\t\t%-20s\n",r
,g
,b
,wd
->text
);
79 static bool BCallBack(struct t_x11
*x11
,XEvent
*event
, Window w
, void *data
)
84 switch (event
->type
) {
86 XSetForeground(x11
->disp
,x11
->gc
,sc
->col
[sc
->ncol
-1].xc
.pixel
);
87 TextInWin(x11
,&sc
->but
,sc
->but
.text
,eXCenter
,eYCenter
);
90 sc
->but
.width
=event
->xconfigure
.width
;
91 sc
->but
.height
=event
->xconfigure
.height
;
94 LightBorder(x11
->disp
,sc
->but
.self
,sc
->col
[sc
->ncol
-1].xc
.pixel
);
97 LightBorder(x11
->disp
,sc
->but
.self
,sc
->col
[0].xc
.pixel
);
100 x11
->UnRegisterCallback(x11
,sc
->wd
.self
);
101 x11
->UnRegisterCallback(x11
,sc
->but
.self
);
107 static bool scCallBack(struct t_x11
*x11
,XEvent
*event
, Window w
, void *data
)
111 int nx
,ny
,X
,Y
,Dx
,Dy
,th
;
114 th
=XTextHeight(x11
->font
)+6;
116 switch (event
->type
) {
117 case ConfigureNotify
:
118 x
=sc
->wd
.width
=event
->xconfigure
.width
;
119 y
=sc
->wd
.height
=event
->xconfigure
.height
-th
;
120 if ((x
>= 100) && (y
>= 100)) {
122 printf("Disp: %x, But: %x, Font: %x x: %d, th: %d\n",
123 x11
->disp
,sc
->but
.self
,x11
->font
,(int)x
,th
);
125 XResizeWindow(x11
->disp
,sc
->but
.self
,(int)x
-4,th
-4);
128 while (nx
*ny
< sc
->ncol
)
132 for(i
=0; (i
<sc
->ncol
); i
++) {
137 XMoveWindow(x11
->disp
,sc
->col
[i
].wd
.self
,X
,th
+Y
);
138 XResizeWindow(x11
->disp
,sc
->col
[i
].wd
.self
,Dx
,Dy
);
146 static int col_comp(const void *c1
,const void *c2
)
152 x1
=&(((t_col
*)c1
)->xc
);
153 x2
=&(((t_col
*)c2
)->xc
);
155 /* sort on intensity */
156 diff
=(x1
->red
+x1
->green
+x1
->blue
)-(x2
->red
+x2
->green
+x2
->blue
);
159 if ((dr
=(x1
->red
-x2
->red
)) != 0)
161 if ((dg
=(x1
->green
-x2
->green
)) != 0)
163 return x1
->blue
-x2
->blue
;
169 static void read_col(t_x11
*x11
,t_sc
*sc
,char *rgb
)
172 char buf
[STRLEN
],name
[STRLEN
],*dummy
;
178 if ((fp
=fopen(rgb
,"r"))==NULL
) {
184 if (fscanf(fp
,"%d%d%d",&r
,&g
,&b
)==3) {
185 dummy
=fgets2(buf
,STRLEN
-1,fp
);
188 /* Filter out colours with names of two words */
189 sscanf(buf
,"%s",name
);
190 /* Filter out duplicate colours (grey and gray) */
191 if (strstr(name
,"gray")==0) {
192 if (XAllocNamedColor(x11
->disp
,x11
->cmap
,name
,&xc
,&exact
)) {
193 srenew(sc
->col
,++sc
->ncol
);
194 sc
->col
[sc
->ncol
-1].xc
=xc
;
196 printf("color %3d: %s\n",sc
->ncol
,buf
);
198 InitWin(&(sc
->col
[sc
->ncol
-1].wd
),0,0,1,1,0,name
);
206 qsort(sc
->col
,sc
->ncol
,sizeof(sc
->col
[0]),col_comp
);
207 /* Now filter out doubles */
209 for(i
=1,j
=0; (i
<sc
->ncol
); i
++) {
210 if ((cols
[i
].xc
.red
!= cols
[j
].xc
.red
) ||
211 (cols
[i
].xc
.green
!= cols
[j
].xc
.green
) ||
212 (cols
[i
].xc
.blue
!= cols
[j
].xc
.blue
)) {
220 static t_sc
*init_sc(t_x11
*x11
,Window Parent
,char *rgb
)
227 InitWin(&sc
->wd
,0,0,400,300,1,"Show Colours");
228 sc
->wd
.self
=XCreateSimpleWindow(x11
->disp
,Parent
,sc
->wd
.x
,sc
->wd
.y
,
229 sc
->wd
.width
,sc
->wd
.height
,
230 sc
->wd
.bwidth
,WHITE
,BLACK
);
231 x11
->RegisterCallback(x11
,sc
->wd
.self
,Parent
,scCallBack
,sc
);
232 x11
->SetInputMask(x11
,sc
->wd
.self
,ButtonPressMask
| ExposureMask
|
233 StructureNotifyMask
);
234 InitWin(&sc
->but
,0,0,sc
->wd
.width
-2,XTextHeight(x11
->font
)+2,1,"Quit");
235 sc
->but
.self
=XCreateSimpleWindow(x11
->disp
,sc
->wd
.self
,sc
->but
.x
,sc
->but
.y
,
236 sc
->but
.width
,sc
->but
.height
,
237 sc
->but
.bwidth
,BLACK
,BLACK
);
238 x11
->RegisterCallback(x11
,sc
->but
.self
,sc
->but
.self
,BCallBack
,sc
);
239 x11
->SetInputMask(x11
,sc
->but
.self
,ButtonPressMask
| ExposureMask
|
240 StructureNotifyMask
| EnterWindowMask
|
243 read_col(x11
,sc
,rgb
);
244 fprintf(stderr
,"%d colors found\n",sc
->ncol
);
245 fprintf(stderr
,"%6s%6s%6s\t\t%-20s\n","Red","Green","Blue","name");
246 for(i
=0; (i
<sc
->ncol
); i
++) {
247 sc
->col
[i
].wd
.self
=w
=XCreateSimpleWindow(x11
->disp
,sc
->wd
.self
,0,0,1,1,0,
248 BLACK
,sc
->col
[i
].xc
.pixel
);
249 x11
->RegisterCallback(x11
,w
,sc
->wd
.self
,ColCallBack
,&(sc
->col
[i
]));
250 x11
->SetInputMask(x11
,w
,ButtonPressMask
);
257 main(int argc
, char *argv
[])
263 x11
=GetX11(&argc
,argv
);
267 fn
="/usr/lib/X11/rgb.txt";
268 sc
=init_sc(x11
,x11
->root
,fn
);
269 XMapWindow(x11
->disp
,sc
->wd
.self
);
270 XMapSubwindows(x11
->disp
,sc
->wd
.self
);