Upped the version to 3.2.0
[gromacs.git] / src / ngmx / nleg.c
blobb7fe5a52b1b1f6c20d5f6aee0e6883c337df723f
1 /*
2 * $Id$
3 *
4 * This source code is part of
5 *
6 * G R O M A C S
7 *
8 * GROningen MAchine for Chemical Simulations
9 *
10 * VERSION 3.2.0
11 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
12 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
13 * Copyright (c) 2001-2004, The GROMACS development team,
14 * check out http://www.gromacs.org for more information.
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * If you want to redistribute modifications, please consider that
22 * scientific software is very special. Version control is crucial -
23 * bugs must be traceable. We will be happy to consider code for
24 * inclusion in the official distribution, but derived work must not
25 * be called official GROMACS. Details are found in the README & COPYING
26 * files - if they are missing, get the official version at www.gromacs.org.
28 * To help us fund GROMACS development, we humbly ask that you cite
29 * the papers on the package - you can find them in the top README file.
31 * For more info, check our website at http://www.gromacs.org
33 * And Hey:
34 * Gyas ROwers Mature At Cryogenic Speed
36 #include <ctype.h>
37 #include <string.h>
38 #include <smalloc.h>
39 #include <macros.h>
40 #include "buttons.h"
41 #include "nleg.h"
42 #include "writeps.h"
44 typedef struct {
45 char *tp;
46 unsigned long *col;
47 t_rgb rgb;
48 } t_atomcolor;
50 static t_atomcolor ac[] = {
51 { "O", &LIGHTRED, { 1, 0, 0 } },
52 { "N", &LIGHTCYAN, { 0, 0, 1 } },
53 { "NA", &LIGHTGREY, { 0.6,0.6,0.6 } },
54 { "S", &YELLOW, { 1, 1, 0 } },
55 { "C", &LIGHTGREEN, { 0, 1, 0 } },
56 { "CL", &VIOLET, { 1, 0, 1 } },
57 { "F", &LIGHTGREY, { 0.6,0.6,0.6 } },
58 { "Z", &LIGHTGREY, { 0.6,0.6,0.6 } },
59 { "P", &LIGHTBLUE, { 0.4,0.4,1.0 } },
60 { "H", &WHITE, { 0.8,0.8,0.8 } }
62 #define NAC asize(ac)
64 int search_ac(char *type)
66 int i,nb,mij,best,besti;
68 best=0;
69 besti=0;
70 if (type) {
71 for(i=0; (i<NAC); i++) {
72 mij=min((int)strlen(type),(int)strlen(ac[i].tp));
73 for(nb=0; (nb<mij); nb++)
74 if (type[nb] != ac[i].tp[nb])
75 break;
76 if (nb > best) {
77 best=nb;
78 besti=i;
82 return besti;
85 unsigned long Type2Color(char *type)
87 int i;
89 i=search_ac(type);
91 return *(ac[i].col);
94 t_rgb *Type2RGB(char *type)
96 int i;
98 i=search_ac(type);
100 return &(ac[i].rgb);
103 void DrawLegend(t_x11 *x11,t_windata *Win)
105 #define NLAB 6
106 #define COLS 3
107 static char *lab[NLAB] = { "C", "O", "H", "S", "N", "P" };
108 int i,i0,dh,dw,w,y,x1,x0;
109 unsigned long cind;
110 real h_2;
112 XClearWindow(x11->disp, Win->self);
113 w=Win->width;
114 h_2=Win->height/(2.0*NLAB/COLS);
115 dh=h_2-2;
116 dw=dh;
118 for (i=0; (i<NLAB); i++) {
119 i0=i % (NLAB/COLS);
120 x0=(i / (NLAB/COLS))*(Win->width/COLS)+AIR;
121 x1=x0+2*dw+AIR;
122 cind=Type2Color(lab[i]);
123 XSetForeground(x11->disp,x11->gc,cind);
124 y=((2*i0+1)*h_2);
125 XFillRectangle (x11->disp,Win->self,x11->gc,x0,y-dh,2*dw,2*dh);
126 XSetForeground(x11->disp,x11->gc,WHITE);
127 TextInRect(x11,Win->self,lab[i],x1,y-dh,w-x1,2*dh,
128 eXLeft,eYCenter);
130 XSetForeground(x11->disp,x11->gc,x11->fg);
133 static bool LegWCallBack(t_x11 *x11,XEvent *event, Window w, void *data)
135 t_legendwin *lw;
137 lw=(t_legendwin *)data;
138 switch(event->type) {
139 case Expose:
140 DrawLegend(x11,&lw->wd);
141 break;
142 default:
143 break;
145 return FALSE;
148 t_legendwin *init_legw(t_x11 *x11,Window Parent,
149 int x,int y,int width,int height,
150 unsigned long fg,unsigned long bg)
152 t_legendwin *lw;
154 snew(lw,1);
155 InitWin(&lw->wd,x,y,width,height,1,"Legend Window");
156 lw->wd.self=XCreateSimpleWindow(x11->disp,Parent,x,y,1,1,1,fg,bg);
157 x11->RegisterCallback(x11,lw->wd.self,Parent,LegWCallBack,lw);
158 x11->SetInputMask(x11,lw->wd.self,ExposureMask);
160 return lw;
163 void map_legw(t_x11 *x11,t_legendwin *lw)
165 XMapWindow(x11->disp,lw->wd.self);
169 void done_legw(t_x11 *x11,t_legendwin *lw)
171 x11->UnRegisterCallback(x11,lw->wd.self);
172 sfree(lw);