1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
|
#include "torus.h"
#include <stdlib.h>
#include <string.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <stdio.h>
#include <math.h>
#include "xpplim.h"
#include "ggets.h"
#include "pop_list.h"
#include "many_pops.h"
#include "info.bitmap"
#include "browse.h"
extern int DisplayHeight,DisplayWidth;
#define EV_MASK (ButtonPressMask |\
KeyPressMask |\
ExposureMask |\
StructureNotifyMask)
#define BUT_MASK (ButtonPressMask |\
KeyPressMask |\
ExposureMask |\
StructureNotifyMask |\
EnterWindowMask |\
LeaveWindowMask)
extern Display *display;
extern int screen;
extern GC gc, small_gc;
extern int DCURX,DCURXs,DCURY,DCURYs,CURY_OFFs,CURY_OFF;
extern int NUPAR,NODE,NEQ;
extern char upar_names[MAXPAR][11],uvar_names[MAXODE][12];
extern Window main_win,info_pop;
extern int TORUS;
extern double TOR_PERIOD;
extern int itor[MAXODE];
struct {
Window base,done,cancel;
Window w[MAXODE];
} torbox;
void do_torus_com(int c)
{
int i;
TORUS=0;
if(c==0||c==2){
new_float("Period :",&TOR_PERIOD);
if(TOR_PERIOD<=0.0){
err_msg("Choose positive period");
return;
}
if(c==0){
for(i=0;i<MAXODE;i++)itor[i]=1;
TORUS=1;
return;
}
/* Choose them */
choose_torus();
return;
}
for(i=0;i<MAXODE;i++)itor[i]=0;
TORUS=0;
}
void draw_tor_var(i)
int i;
{
char strng[15];
XClearWindow(display,torbox.w[i]);
if(itor[i]==1)sprintf(strng,"X %s",uvar_names[i]);
else sprintf(strng," %s",uvar_names[i]);
XDrawString(display,torbox.w[i],small_gc,0,CURY_OFFs,strng,strlen(strng));
}
void draw_torus_box(win)
Window win;
{
int i;
if(win==torbox.cancel){
XDrawString(display,win,small_gc,5,CURY_OFFs,"Cancel",6);
return;
}
if(win==torbox.done){
XDrawString(display,win,small_gc,5,CURY_OFFs,"Done",4);
return;
}
for(i=0;i<NEQ;i++){
if(win==torbox.w[i])
draw_tor_var(i);
}
}
void choose_torus()
{
int i;
make_tor_box("Fold which");
do_torus_events();
for(i=0;i<NEQ;i++)if(itor[i]==1)TORUS=1;
}
void make_tor_box(title)
char *title;
{
int ndn,nac,width,height;
int nv;
/*int nh; Not used anywhere*/
int i,i1,j1,xpos,ypos;
int xstart=DCURXs;
int ystart=DCURYs;
Window base;
XTextProperty winname;
XSizeHints size_hints;
nv=4*DisplayHeight/(5*(DCURYs+8));
/*nh=DisplayWidth/(18*DCURXs);*/
if(NEQ<nv)ndn=NEQ;
else ndn=nv;
nac=NEQ/ndn;
if(nac*ndn<NEQ)nac++;
width=24*DCURXs*nac+10;
height=3*DCURYs+ndn*(DCURYs+8);
base=make_plain_window(RootWindow(display,screen),0,0,width,height,4);
torbox.base=base;
XStringListToTextProperty(&title,1,&winname);
size_hints.flags=PPosition|PSize|PMinSize|PMaxSize;
size_hints.x=0;
size_hints.y=0;
size_hints.width=width;
size_hints.height=height;
size_hints.min_width=width;
size_hints.min_height=height;
size_hints.max_width=width;
size_hints.max_height=height;
XClassHint class_hints;
class_hints.res_name="";
class_hints.res_class="";
make_icon((char*)info_bits,info_width,info_height,base);
XSetWMProperties(display,base,&winname,NULL,NULL,0,&size_hints,NULL,&class_hints);
for(i=0;i<NEQ;i++){
i1=i/nv;
j1=i%nv;
xpos=xstart+18*DCURXs*i1;
ypos=ystart+j1*(DCURYs+8);
torbox.w[i]=make_window(base,xpos,ypos,15*DCURXs,DCURYs,1);
}
xpos=(width-16*DCURXs-10)/2;
ypos=height-3*DCURYs/2;
torbox.cancel=make_window(base,xpos,ypos,8*DCURXs,DCURYs,1);
torbox.done=make_window(base,xpos+8*DCURXs+10,ypos,8*DCURXs,DCURYs,1);
XSelectInput(display,torbox.cancel,BUT_MASK);
XSelectInput(display,torbox.done,BUT_MASK);
XRaiseWindow(display,torbox.base);
}
void do_torus_events()
{
XEvent ev;
int status=-1;
int done=0;
Window wt;
int i;
int oldit[MAXODE];
for(i=0;i<NEQ;i++)oldit[i]=itor[i];
while(!done){
XNextEvent(display,&ev);
switch(ev.type){
case Expose:
do_expose(ev); /* menus and graphs etc */
draw_torus_box(ev.xany.window);
break;
case ButtonPress:
if(ev.xbutton.window==torbox.done){status=1;done=1;break;}
if(ev.xbutton.window==torbox.cancel){status=-1;done=1;break;}
for(i=0;i<NEQ;i++)
{
if(ev.xbutton.window==torbox.w[i]){
itor[i]=1-itor[i];
draw_tor_var(i);
break;
}
}
break;
case EnterNotify:
wt=ev.xcrossing.window;
if(wt==torbox.done||wt==torbox.cancel)
XSetWindowBorderWidth(display,wt,2);
break;
case LeaveNotify:
wt=ev.xcrossing.window;
if(wt==torbox.done||wt==torbox.cancel)
XSetWindowBorderWidth(display,wt,1);
break;
}
}
if(status==-1){
for(i=0;i<NEQ;i++)itor[i]=oldit[i];
TORUS=0;
}
XSelectInput(display,torbox.cancel,EV_MASK);
XSelectInput(display,torbox.done,EV_MASK);
waitasec(ClickTime);
XDestroySubwindows(display,torbox.base);
XDestroyWindow(display,torbox.base);
}
|