4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
12 * Copyright (c) 1991-2001
13 * BIOSON Research Institute, Dept. of Biophysical Chemistry
14 * University of Groningen, The Netherlands
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 * Do check out http://www.gromacs.org , or mail us at gromacs@gromacs.org .
34 * Good gRace! Old Maple Actually Chews Slate
36 static char *SRCID_nener_c = "$Id$";
44 static void DrawEGraph(t_x11 *x11,t_enerwin *ew)
48 real epr,scale,MaxE,MinE;
54 XClearWindow(x11->disp,wd->self);
56 /* Calculate boundaries */
57 MaxE=MinE=ew->e[ew->etype][0];
58 for (i=1; (i<ew->nlast); i++) {
59 MaxE=max(ew->e[ew->etype][i],MaxE);
60 MinE=min(ew->e[ew->etype][i],MinE);
64 epr=max(fabs(MaxE),fabs(MinE));
65 sprintf(maxstr,"%.0f",epr);
66 EHeight=XTextHeight(x11->font)+AIR;
67 TextInRect(x11,wd->self,EType[ew->etype],AIR,0,
68 wd->width-2*AIR,EHeight,eXLeft,eYCenter);
69 TextInRect(x11,wd->self,maxstr,AIR,0,
70 wd->width-2*AIR,EHeight,eXRight,eYCenter);
71 XDrawLine(x11->disp, wd->self,x11->gc,0,EHeight,wd->width,EHeight);
76 if (fabs(MaxE-MinE) < 1e-5)
79 EZero=(wd->height-EHeight)/2;
80 scale=EZero/(real) epr;
82 XDrawLine(x11->disp,wd->self,x11->gc,0,EZero,wd->width,EZero);
84 for(i=0; (i<ew->nlast); i++) {
85 y=ew->e[ew->etype][i]*scale;
87 XDrawLine(x11->disp,wd->self,x11->gc,i,EZero,i,EZero-y);
91 static bool EWCallBack(t_x11 *x11,XEvent *event, Window w, void *data)
100 XSetForeground(x11->disp,x11->gc,WHITE);
102 XSetForeground(x11->disp,x11->gc,x11->fg);
104 case ConfigureNotify:
105 ew->wd.x=event->xconfigure.x;
106 ew->wd.y=event->xconfigure.y;
107 ew->wd.width=event->xconfigure.width;
108 ew->wd.height=event->xconfigure.height;
109 if (ew->wd.width > ew->nwidth) {
110 ew->nwidth=ew->wd.width;
111 for (i=0; (i<ew->nre); i++)
112 srenew(ew->e[i],ew->nwidth);
117 y=ew->wd.y+event->xbutton.y;
118 width=menu_width(ew->selener);
119 x=min(x+ew->wd.x,ew->wd.x+ew->wd.width-width);
120 printf("Showing at %d,%d, width %d\n",x,y,width);
121 show_menu(x11,ew->selener,x,y,TRUE);
124 ew->etype=event->xclient.data.l[0];
125 ExposeWin(x11->disp,ew->wd.self);
128 hide_menu(x11,ew->selener);
136 static void create_selener(t_x11 *x11,t_enerwin *ew,Window Parent)
142 for(i=0; (i<ew->nre); i++) {
143 se[i].send_to=ew->wd.self;
145 se[i].bChecked=FALSE;
148 ew->selener=init_menu(x11,Parent,x11->fg,x11->bg,ew->nre,se,1);
151 t_enerwin *init_ew(t_x11 *x11,Window Parent,
152 int x,int y,int width,int height,
153 unsigned long fg,unsigned long bg)
164 for(i=0; (i<ew->nre); i++)
165 snew(ew->e[i],width);
166 InitWin(&ew->wd,x,y,width,height,1,"Ener Window");
167 ew->wd.self=XCreateSimpleWindow(x11->disp,Parent,x,y,1,1,1,fg,bg);
168 x11->RegisterCallback(x11,ew->wd.self,Parent,EWCallBack,ew);
169 x11->SetInputMask(x11,ew->wd.self,ExposureMask | ButtonPressMask |
170 ButtonReleaseMask | StructureNotifyMask |
171 OwnerGrabButtonMask);
172 create_selener(x11,ew,Parent);
177 void map_ewin(t_x11 *x11,t_enerwin *ew)
179 XMapWindow(x11->disp,ew->wd.self);
182 void add_ener(t_x11 *x11,t_enerwin *ew,t_energy e[])
187 if (ew->nlast >= ew->nwidth) {
188 for(j=0; (j<ew->nre); j++)
190 ew->e[j][i]=ew->e[j][i+w];
194 for(j=0; (j<ew->nre); j++) {
195 ew->e[j][ew->nlast]=e[j].e;
198 ExposeWin(x11->disp,ew->wd.self);
201 void rewind_ener(t_x11 *x11,t_enerwin *ew)
204 ExposeWin(x11->disp,ew->wd.self);
207 void done_ew(t_x11 *x11,t_enerwin *ew)
209 done_menu(x11,ew->selener);
210 x11->UnRegisterCallback(x11,ew->wd.self);