Committing another fix!
[gromacs/rigid-bodies.git] / src / ngmx / nload.c
blobec1b21df7dcebe86355950598036ab449485fdac
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 <typedefs.h>
41 #include <macros.h>
42 #include <smalloc.h>
43 #include <string.h>
44 #include "nload.h"
45 #include "buttons.h"
47 void DrawLoad(t_x11 *x11,t_windata *Win,int nloads,int *loadinfo)
49 static char *Strings[] = { "Unbalance","Single Node","Your Ad Here ?"};
50 int i,y0,bwidth,boff,bar,bmax,bmin,ym,yh;
51 int *lb;
52 real bav,bscale;
53 char maxstr[6];
55 return;
57 XClearWindow(x11->disp, Win->self);
58 y0=XTextHeight(x11->font)+AIR;
59 yh=(Win->height-y0)/2;
60 ym=y0+yh;
61 XSetForeground(x11->disp,x11->gc,WHITE);
62 XDrawLine(x11->disp,Win->self,x11->gc,0,y0,Win->width,y0);
64 if (nloads >= 2) {
65 TextInRect(x11,Win->self,Strings[0],AIR,0,Win->width-2*AIR,y0,
66 eXLeft,eYCenter);
67 if (loadinfo[0] == 0) {
68 nloads--;
69 lb=&loadinfo[1];
71 else {
72 lb=loadinfo;
73 if (loadinfo[nloads-1] == 0)
74 nloads--;
76 bwidth = (Win->width) / nloads;
77 boff = (Win->width % nloads)/2;
78 bav = 0.0;
80 bmax=bmin=lb[0];
82 for (i=1; (i<nloads); i++) {
83 bmax = max (bmax,lb[i]);
84 bmin = min (bmin,lb[i]);
85 bav += lb[i];
87 bav/=nloads;
88 bscale = (yh-2)/max(fabs(bmax-bav),fabs(bav-bmin));
89 sprintf(maxstr,"(%d%%)",(int)(100.0*(bmax-bav)/bav));
90 TextInRect(x11,Win->self,maxstr,AIR,0,Win->width-2*AIR,y0,
91 eXRight,eYCenter);
93 XDrawLine(x11->disp,Win->self,x11->gc,0,ym,Win->width,ym);
94 if (bmax-bmin) {
95 for(i=0; i<nloads; i++) {
96 bar=(lb[i]-bav)*bscale;
97 if (bar != 0) {
98 if (bar > 0)
99 XFillRectangle(x11->disp,Win->self,x11->gc,
100 (i*bwidth)+boff+1,ym-bar+1,bwidth-2,bar);
101 else
102 XFillRectangle(x11->disp,Win->self,x11->gc,
103 (i*bwidth)+boff+1,ym,bwidth-2,-bar);
109 else {
110 TextInRect(x11,Win->self,Strings[1],AIR,0,Win->width,y0,eXLeft,eYCenter);
111 TextInRect(x11,Win->self,Strings[2],AIR,y0,Win->width,
112 Win->height-y0,eXLeft,eYCenter);
114 XSetForeground(x11->disp,x11->gc,x11->fg);
117 static bool LWCallBack(t_x11 *x11,XEvent *event, Window w, void *data)
119 t_loadwin *lw;
121 lw=(t_loadwin *)data;
122 switch(event->type) {
123 case Expose:
124 DrawLoad(x11,&lw->wd,lw->nnodes,lw->load);
125 break;
126 default:
127 break;
129 return FALSE;
132 t_loadwin *init_lw(t_x11 *x11,Window Parent,
133 int x,int y,int width,int height,
134 unsigned long fg,unsigned long bg)
136 t_loadwin *lw;
138 snew(lw,1);
139 snew(lw->load,MAXNODES);
140 lw->nnodes=1;
141 InitWin(&lw->wd,x,y,width,height,1,"Load Window");
142 lw->wd.self=XCreateSimpleWindow(x11->disp,Parent,x,y,1,1,1,fg,bg);
143 x11->RegisterCallback(x11,lw->wd.self,Parent,LWCallBack,lw);
144 x11->SetInputMask(x11,lw->wd.self,ExposureMask);
146 return lw;
149 void map_lw(t_x11 *x11,t_loadwin *lw)
151 XMapWindow(x11->disp,lw->wd.self);
154 void set_load(t_x11 *x11,t_loadwin *lw,int nnodes,int load[])
156 int i;
157 bool bChange=FALSE;
159 lw->nnodes=nnodes;
160 for(i=0; (i<nnodes); i++)
161 if (lw->load[i] != load[i]) {
162 bChange=TRUE;
163 lw->load[i]=load[i];
165 if (bChange)
166 ExposeWin(x11->disp,lw->wd.self);
169 void done_lw(t_x11 *x11,t_loadwin *lw)
171 x11->UnRegisterCallback(x11,lw->wd.self);
172 sfree(lw);