Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!bloom-beacon!athena.mit.edu!jstravis From: jstravis@athena.mit.edu (John S. Travis) Newsgroups: comp.windows.x Subject: XDrawLine Message-ID: <1989Dec2.193728.2991@athena.mit.edu> Date: 2 Dec 89 19:37:28 GMT Sender: root@athena.mit.edu (Wizard A. Root) Reply-To: jstravis@athena.mit.edu (John S. Travis) Distribution: usa Organization: Massachusetts Institute of Technology Lines: 120 Can anyone help me with what must be an obvious(to others) error I am merely trying to read in some data ponts and draw lines connecting them. The window pops up, but nothing is drawn, not even the XDrawLines i threw in randomly throughout the program. What's the deal? Thanks for any help! john travis jstravis@athena.mit.edu --------------------------------------------------- #include #include #include #include #include #define MAXPOINTS 100 #define MAXLINES 100 void get_data(); void draw_data(); typedef struct { int line_num; int num_line_points; double points[MAXPOINTS]; } data_struct; int TOTAL_LINES; main(argc,argv) int argc; char *argv[]; { Widget toplevel,canvas; GC gc; XGCValues values; Arg wargs[2]; data_struct data[MAXLINES]; toplevel = XtInitialize(argv[0],"Stream",NULL,0,&argc,argv); canvas = XtCreateManagedWidget("canvas",XwworkSpaceWidgetClass,toplevel,NULL,0); XtRealizeWidget(toplevel); /* get the colors user has set for the widget */ XtSetArg(wargs[0],XtNforeground, &values.foreground); XtSetArg(wargs[1],XtNbackground, &values.background); XtGetValues(canvas,wargs,2); values.line_width =4; gc = XtGetGC(canvas,GCForeground | GCLineWidth | GCBackground, &values); XDrawLine(XtDisplay(canvas), XtWindow(canvas),gc, 24,89,30,133); get_data(data); draw_data(data,XtDisplay(canvas),XtWindow(canvas),gc); XtMainLoop(); } void get_data(data) data_struct data[]; /* 100 streamlines is the max! */ { FILE *fin; int i,j,num_line_points; fin = fopen("str.dat","r"); if (fin == NULL){ printf("Unable to open %s\n","str.dat"); exit(1); } i=0; printf("entering while\n"); while (fscanf(fin,"%d", &num_line_points) != EOF) { data[i].line_num = i; printf("line %d", data[i].line_num); data[i].num_line_points = num_line_points; printf(" has %d points\n",data[i].num_line_points); for (j=0; j < (2*num_line_points); j++){ fscanf(fin,"%lf",&data[i].points[j]); printf("%lf ",data[i].points[j]); } printf("\n"); i++; } TOTAL_LINES = i; printf("out of while\n"); } void draw_data(data,dpy,win,gc) data_struct data[]; Display *dpy; Window win; GC gc; { int j,i; printf("lines are %d\n",TOTAL_LINES); printf("first two point are %lf , %lf and %lf , %lf \n",data[0].points[0], data[0].points[1],data[0].points[2],data[0].points[3]); XDrawLine(dpy,win,gc,20,35,45,70); for (i=0; i<(TOTAL_LINES-1); i++) { XDrawLine(dpy,win,gc,data[i].points[0],data[i].points[1], data[i].points[2],data[i].points[3]); for(j=2; j < (data[i].num_line_points - 1); j++) XDrawLine(dpy,win,gc,data[i].points[j],data[i].points[j+1], data[i].points[j+2], data[i].points[j+3]); } }