4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
12 * Copyright (c) 1991-1999
13 * BIOSON Research Institute, Dept. of Biophysical Chemistry
14 * University of Groningen, The Netherlands
17 * GROMACS: A message-passing parallel molecular dynamics implementation
18 * H.J.C. Berendsen, D. van der Spoel and R. van Drunen
19 * Comp. Phys. Comm. 91, 43-56 (1995)
21 * Also check out our WWW page:
22 * http://md.chem.rug.nl/~gmx
27 * Great Red Oystrich Makes All Chemists Sane
29 static char *SRCID_nener_c
= "$Id$";
38 static void DrawEGraph(t_x11
*x11
,t_enerwin
*ew
)
42 real epr
,scale
,MaxE
,MinE
;
48 XClearWindow(x11
->disp
,wd
->self
);
50 /* Calculate boundaries */
51 MaxE
=MinE
=ew
->e
[ew
->etype
][0];
52 for (i
=1; (i
<ew
->nlast
); i
++) {
53 MaxE
=max(ew
->e
[ew
->etype
][i
],MaxE
);
54 MinE
=min(ew
->e
[ew
->etype
][i
],MinE
);
58 epr
=max(fabs(MaxE
),fabs(MinE
));
59 sprintf(maxstr
,"%.0f",epr
);
60 EHeight
=XTextHeight(x11
->font
)+AIR
;
61 TextInRect(x11
,wd
->self
,EType
[ew
->etype
],AIR
,0,
62 wd
->width
-2*AIR
,EHeight
,eXLeft
,eYCenter
);
63 TextInRect(x11
,wd
->self
,maxstr
,AIR
,0,
64 wd
->width
-2*AIR
,EHeight
,eXRight
,eYCenter
);
65 XDrawLine(x11
->disp
, wd
->self
,x11
->gc
,0,EHeight
,wd
->width
,EHeight
);
70 if (fabs(MaxE
-MinE
) < 1e-5)
73 EZero
=(wd
->height
-EHeight
)/2;
74 scale
=EZero
/(real
) epr
;
76 XDrawLine(x11
->disp
,wd
->self
,x11
->gc
,0,EZero
,wd
->width
,EZero
);
78 for(i
=0; (i
<ew
->nlast
); i
++) {
79 y
=ew
->e
[ew
->etype
][i
]*scale
;
81 XDrawLine(x11
->disp
,wd
->self
,x11
->gc
,i
,EZero
,i
,EZero
-y
);
85 static bool EWCallBack(t_x11
*x11
,XEvent
*event
, Window w
, void *data
)
94 XSetForeground(x11
->disp
,x11
->gc
,WHITE
);
96 XSetForeground(x11
->disp
,x11
->gc
,x11
->fg
);
99 ew
->wd
.x
=event
->xconfigure
.x
;
100 ew
->wd
.y
=event
->xconfigure
.y
;
101 ew
->wd
.width
=event
->xconfigure
.width
;
102 ew
->wd
.height
=event
->xconfigure
.height
;
103 if (ew
->wd
.width
> ew
->nwidth
) {
104 ew
->nwidth
=ew
->wd
.width
;
105 for (i
=0; (i
<ew
->nre
); i
++)
106 srenew(ew
->e
[i
],ew
->nwidth
);
111 y
=ew
->wd
.y
+event
->xbutton
.y
;
112 width
=menu_width(ew
->selener
);
113 x
=min(x
+ew
->wd
.x
,ew
->wd
.x
+ew
->wd
.width
-width
);
114 printf("Showing at %d,%d, width %d\n",x
,y
,width
);
115 show_menu(x11
,ew
->selener
,x
,y
,TRUE
);
118 ew
->etype
=event
->xclient
.data
.l
[0];
119 ExposeWin(x11
->disp
,ew
->wd
.self
);
122 hide_menu(x11
,ew
->selener
);
130 static void create_selener(t_x11
*x11
,t_enerwin
*ew
,Window Parent
)
136 for(i
=0; (i
<ew
->nre
); i
++) {
137 se
[i
].send_to
=ew
->wd
.self
;
139 se
[i
].bChecked
=FALSE
;
142 ew
->selener
=init_menu(x11
,Parent
,x11
->fg
,x11
->bg
,ew
->nre
,se
,1);
145 t_enerwin
*init_ew(t_x11
*x11
,Window Parent
,
146 int x
,int y
,int width
,int height
,
147 unsigned long fg
,unsigned long bg
)
158 for(i
=0; (i
<ew
->nre
); i
++)
159 snew(ew
->e
[i
],width
);
160 InitWin(&ew
->wd
,x
,y
,width
,height
,1,"Ener Window");
161 ew
->wd
.self
=XCreateSimpleWindow(x11
->disp
,Parent
,x
,y
,1,1,1,fg
,bg
);
162 x11
->RegisterCallback(x11
,ew
->wd
.self
,Parent
,EWCallBack
,ew
);
163 x11
->SetInputMask(x11
,ew
->wd
.self
,ExposureMask
| ButtonPressMask
|
164 ButtonReleaseMask
| StructureNotifyMask
|
165 OwnerGrabButtonMask
);
166 create_selener(x11
,ew
,Parent
);
171 void map_ewin(t_x11
*x11
,t_enerwin
*ew
)
173 XMapWindow(x11
->disp
,ew
->wd
.self
);
176 void add_ener(t_x11
*x11
,t_enerwin
*ew
,t_energy e
[])
181 if (ew
->nlast
>= ew
->nwidth
) {
182 for(j
=0; (j
<ew
->nre
); j
++)
184 ew
->e
[j
][i
]=ew
->e
[j
][i
+w
];
188 for(j
=0; (j
<ew
->nre
); j
++) {
189 ew
->e
[j
][ew
->nlast
]=e
[j
].e
;
192 ExposeWin(x11
->disp
,ew
->wd
.self
);
195 void rewind_ener(t_x11
*x11
,t_enerwin
*ew
)
198 ExposeWin(x11
->disp
,ew
->wd
.self
);
201 void done_ew(t_x11
*x11
,t_enerwin
*ew
)
203 done_menu(x11
,ew
->selener
);
204 x11
->UnRegisterCallback(x11
,ew
->wd
.self
);