minor fixes in ditribution files
[gromacs/qmmm-gamess-us.git] / src / ngmx / nener.c
blob366947dbf9bd8f970160d48e700fe7148b6f4428
1 /*
2 *
3 * This source code is part of
4 *
5 * G R O M A C S
6 *
7 * GROningen MAchine for Chemical Simulations
8 *
9 * VERSION 3.2.0
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
32 * And Hey:
33 * Gyas ROwers Mature At Cryogenic Speed
35 #ifdef HAVE_CONFIG_H
36 #include <config.h>
37 #endif
39 #include <math.h>
40 #include <smalloc.h>
41 #include <macros.h>
42 #include <names.h>
43 #include "nener.h"
44 #include "buttons.h"
46 static void DrawEGraph(t_x11 *x11,t_enerwin *ew)
48 t_windata *wd;
49 int i,EHeight,EZero;
50 real epr,scale,MaxE,MinE;
51 char maxstr[80];
52 int y;
54 wd=&(ew->wd);
55 /* Clear */
56 XClearWindow(x11->disp,wd->self);
58 /* Calculate boundaries */
59 MaxE=MinE=ew->e[ew->etype][0];
60 for (i=1; (i<ew->nlast); i++) {
61 MaxE=max(ew->e[ew->etype][i],MaxE);
62 MinE=min(ew->e[ew->etype][i],MinE);
65 /* Print title */
66 epr=max(fabs(MaxE),fabs(MinE));
67 sprintf(maxstr,"%.0f",epr);
68 EHeight=XTextHeight(x11->font)+AIR;
69 TextInRect(x11,wd->self,EType[ew->etype],AIR,0,
70 wd->width-2*AIR,EHeight,eXLeft,eYCenter);
71 TextInRect(x11,wd->self,maxstr,AIR,0,
72 wd->width-2*AIR,EHeight,eXRight,eYCenter);
73 XDrawLine(x11->disp, wd->self,x11->gc,0,EHeight,wd->width,EHeight);
75 if (ew->nlast==0)
76 return;
78 if (fabs(MaxE-MinE) < 1e-5)
79 return;
81 EZero=(wd->height-EHeight)/2;
82 scale=EZero/(real) epr;
83 EZero+=EHeight;
84 XDrawLine(x11->disp,wd->self,x11->gc,0,EZero,wd->width,EZero);
86 for(i=0; (i<ew->nlast); i++) {
87 y=ew->e[ew->etype][i]*scale;
88 if (y)
89 XDrawLine(x11->disp,wd->self,x11->gc,i,EZero,i,EZero-y);
93 static bool EWCallBack(t_x11 *x11,XEvent *event, Window w, void *data)
95 t_enerwin *ew;
96 int i,x,y,width;
98 return FALSE;
99 ew=(t_enerwin *)data;
100 switch(event->type) {
101 case Expose:
102 XSetForeground(x11->disp,x11->gc,WHITE);
103 DrawEGraph(x11,ew);
104 XSetForeground(x11->disp,x11->gc,x11->fg);
105 break;
106 case ConfigureNotify:
107 ew->wd.x=event->xconfigure.x;
108 ew->wd.y=event->xconfigure.y;
109 ew->wd.width=event->xconfigure.width;
110 ew->wd.height=event->xconfigure.height;
111 if (ew->wd.width > ew->nwidth) {
112 ew->nwidth=ew->wd.width;
113 for (i=0; (i<ew->nre); i++)
114 srenew(ew->e[i],ew->nwidth);
116 break;
117 case ButtonPress:
118 x=event->xbutton.x;
119 y=ew->wd.y+event->xbutton.y;
120 width=menu_width(ew->selener);
121 x=min(x+ew->wd.x,ew->wd.x+ew->wd.width-width);
122 printf("Showing at %d,%d, width %d\n",x,y,width);
123 show_menu(x11,ew->selener,x,y,TRUE);
124 break;
125 case ClientMessage:
126 ew->etype=event->xclient.data.l[0];
127 ExposeWin(x11->disp,ew->wd.self);
128 /* Fall thru... */
129 case ButtonRelease:
130 hide_menu(x11,ew->selener);
131 break;
132 default:
133 break;
135 return FALSE;
138 static void create_selener(t_x11 *x11,t_enerwin *ew,Window Parent)
140 static t_mentry *se;
141 int i;
143 snew(se,ew->nre);
144 for(i=0; (i<ew->nre); i++) {
145 se[i].send_to=ew->wd.self;
146 se[i].nreturn=i;
147 se[i].bChecked=FALSE;
148 se[i].str=EType[i];
150 ew->selener=init_menu(x11,Parent,x11->fg,x11->bg,ew->nre,se,1);
153 t_enerwin *init_ew(t_x11 *x11,Window Parent,
154 int x,int y,int width,int height,
155 unsigned long fg,unsigned long bg)
157 t_enerwin *ew;
158 int i;
160 snew(ew,1);
161 ew->etype=0;
162 ew->nlast=0;
163 ew->nwidth=width;
164 ew->nre=F_NRE;
165 snew(ew->e,ew->nre);
166 for(i=0; (i<ew->nre); i++)
167 snew(ew->e[i],width);
168 InitWin(&ew->wd,x,y,width,height,1,"Ener Window");
169 ew->wd.self=XCreateSimpleWindow(x11->disp,Parent,x,y,1,1,1,fg,bg);
170 x11->RegisterCallback(x11,ew->wd.self,Parent,EWCallBack,ew);
171 x11->SetInputMask(x11,ew->wd.self,ExposureMask | ButtonPressMask |
172 ButtonReleaseMask | StructureNotifyMask |
173 OwnerGrabButtonMask);
174 create_selener(x11,ew,Parent);
176 return ew;
179 void map_ewin(t_x11 *x11,t_enerwin *ew)
181 XMapWindow(x11->disp,ew->wd.self);
184 void add_ener(t_x11 *x11,t_enerwin *ew,t_energy e[])
186 int i,j,w;
188 w=ew->nwidth/2;
189 if (ew->nlast >= ew->nwidth) {
190 for(j=0; (j<ew->nre); j++)
191 for(i=0; (i<w); i++)
192 ew->e[j][i]=ew->e[j][i+w];
193 ew->nlast=w;
196 for(j=0; (j<ew->nre); j++) {
197 ew->e[j][ew->nlast]=e[j].e;
199 ew->nlast++;
200 ExposeWin(x11->disp,ew->wd.self);
203 void rewind_ener(t_x11 *x11,t_enerwin *ew)
205 ew->nlast=0;
206 ExposeWin(x11->disp,ew->wd.self);
209 void done_ew(t_x11 *x11,t_enerwin *ew)
211 done_menu(x11,ew->selener);
212 x11->UnRegisterCallback(x11,ew->wd.self);
213 sfree(ew);