diff options
| author | Ian C <ianc@noddybox.co.uk> | 2005-05-12 23:40:12 +0000 | 
|---|---|---|
| committer | Ian C <ianc@noddybox.co.uk> | 2005-05-12 23:40:12 +0000 | 
| commit | fb7306526f0d6e2fe58c12ec7daad098f97b709f (patch) | |
| tree | 19e9ebe656001218a003c2ee0b560531b01f2db1 | |
| parent | 46e4cd640c247ace1ab16c63b157c0608161806e (diff) | |
Fixed ledit
| -rw-r--r-- | ledit.c | 155 | 
1 files changed, 66 insertions, 89 deletions
| @@ -42,26 +42,28 @@ static char rcs_id[]="$Id$";  #define RND(x) (rand()%(x))  XSizeHints  	size_hints; -int         	black,white; +ulong         	black,white;  Display     	*disp;  Window      	window;  Colormap    	cm;  XFontStruct 	*font; -XFuncControl	Key(); -XFuncControl 	Mouse(); -XFuncControl 	Motion(); -XFuncControl 	Process(); +XFuncControl	Key(Window w, XPressRelease mode, XEvent *e); +XFuncControl 	Mouse(Window w, XPressRelease mode, int b, int x, int y); +XFuncControl 	Motion(Window w, int x, int y); +XFuncControl 	Process(void); +void 		ReadFile(void); +void 		WriteFile(void); -XCallBack	key[2]={{0,Key},{0,NULL}}; -XCallBack	mouse[2]={{0,Mouse},{0,NULL}}; -XCallBack	motion[2]={{0,Motion},{0,NULL}}; +XWindowKeyCallback	key[2]={{0,Key},{0,NULL}}; +XWindowButtonCallback	mouse[2]={{0,Mouse},{0,NULL}}; +XWindowMoveCallBack	motion[2]={{0,Motion},{0,NULL}};  #define NOCOL	7 -char		*colnames[NOCOL]= +const char	*colnames[NOCOL]=  			{"black","white","red","yellow","blue","green","cyan"}; -int		pix[NOCOL]; +ulong		pix[NOCOL];  #define	BLACK	pix[0]  #define	WHITE	pix[1] @@ -113,10 +115,7 @@ int		mx,my;  int		gx=0,gy=0; -int main(argc,argv) -int argc; -char *argv[]; - +int main(int argc, char *argv[])  {      unsigned long evmask; @@ -141,15 +140,15 @@ char *argv[];  		   &size_hints,&black,&white);      if (argc>1) -	{ +    {  	fname=argv[1];  	ReadFile(); -	} +    }      else -	{ +    {  	fprintf(stderr,"Must supply a level file\n");  	exit(1); -	} +    }      if (argc>2)  	CONST=atoi(argv[2]); @@ -164,19 +163,15 @@ char *argv[];  } -XFuncControl Key(w,m,e) -Window w; -int m; -XEvent *e; - +XFuncControl Key(Window w,XPressRelease m, XEvent *e)  {      KeySym k;      if (m==XPRESS)  	return; -    switch(k=XLookupKeysym(e,ShiftMapIndex)) -	{ +    switch(k=XLookupKeysym((XKeyEvent*)e,ShiftMapIndex)) +    {  	case XK_G:					/* Set centre */  	case XK_g:  	    gx=STOMX(e->xkey.x); @@ -192,20 +187,20 @@ XEvent *e;  	case XK_C:					/* Create poly */  	case XK_c:  	    if (no<MAXOBJ-1) -		{ +	    {  		obj[no].o.x=STOMX(e->xkey.x);  		obj[no].o.y=STOMY(e->xkey.y);  		cur=no++; -		} +	    }  	    break;  	case XK_O:					/* Set origin */  	case XK_o:  	    if (no) -		{ +	    {  		obj[cur].o.x=STOMX(e->xkey.x);  		obj[cur].o.y=STOMY(e->xkey.y); -		} +	    }  	    break;  	case XK_D:					/* Delete poly */ @@ -257,17 +252,13 @@ XEvent *e;  	default:  	    break; -	} +    } -    return(XFUNCCONT); +    return XFUNCCONT;  } -XFuncControl Mouse(w,m,b,x,y) -Window w; -int m; -int b,x,y; - +XFuncControl Mouse(Window w, XPressRelease m, int b, int x, int y)  {      int mapx,mapy; @@ -275,10 +266,10 @@ int b,x,y;  	return (XFUNCCONT);      switch(b) -	{ +    {  	case 1:					/* Add point */  	    if (obj[cur].no<MAXLINE) -		{ +	    {  		/* Convert to map co-ords  		*/  		mapx=STOMX(x); @@ -292,7 +283,7 @@ int b,x,y;  		obj[cur].p[obj[cur].no].x=mapx;  		obj[cur].p[obj[cur].no].y=mapy;  		obj[cur].no++; -		} +	    }  	    break;  	case 2:					/* Remove point */ @@ -302,35 +293,27 @@ int b,x,y;  	default:  	    break; -	} +    } -    return(XFUNCCONT); +    return XFUNCCONT;  } -XFuncControl Motion(w,x,y) -Window w; -int x,y; - +XFuncControl Motion(Window w, int x, int y)  {      mx=x;      my=y; -    return(XFUNCCONT); +    return XFUNCCONT;  } -MapLine(x1,y1,x2,y2,c) -int x1,y1,x2,y2,c; - +void MapLine(int x1,int y1,int x2,int y2,ulong c)  {      XLine(MTOSX(x1),MTOSY(y1),MTOSX(x2),MTOSY(y2),c);  } -DrawLines(p,n,c) -Pt p[]; -int n,c; - +void DrawLines(Pt *p,int n,ulong c)  {      int f; @@ -340,7 +323,7 @@ int n,c;  } -RedrawObj() +void RedrawObj(void)  {      Pt p[MAXLINE]; @@ -361,25 +344,24 @@ RedrawObj()      /* Draw all objects      */      for(f=0;f<no;f++) -	{ +    {  	if (f==cur)  	    c=pix[RND(NOCOL)];  	else  	    c=pix[obj[f].ty];  	for(r=0;r<obj[f].no;r++) -	    { +	{  	    p[r].x=obj[f].o.x+obj[f].p[r].x;  	    p[r].y=obj[f].o.y+obj[f].p[r].y; -	    } +	}  	DrawLines(p,obj[f].no,c); -	} +    }  } -RedrawText() - +void RedrawText(void)  {      Xprintf(0,WINH-2,WHITE,      "Pos : %5d,%5d  Centre : %5d,%5d  Scale : %3d  Title : %s  File : %s", @@ -400,8 +382,7 @@ RedrawText()  } -XFuncControl Process() - +XFuncControl Process(void)  {      XCls(BLACK); @@ -410,13 +391,11 @@ XFuncControl Process()      Redraw(0,0); -    return (XFUNCCONT); +    return XFUNCCONT;  } -char *GetLine(fp) -FILE *fp; - +char *GetLine(FILE *fp)  {      static char s[1204]; @@ -429,16 +408,13 @@ FILE *fp;  } -GetNum(fp,x,y) -FILE *fp; -int *x,*y; - +void GetNum(FILE *fp,int *x,int *y)  {      sscanf(GetLine(fp),"%d,%d",x,y);  } -ReadFile() +void ReadFile(void)  {      FILE *fp;      int f,x,y; @@ -449,16 +425,16 @@ ReadFile()      cur=-1;      for(f=0;f<MAXOBJ;f++) -	{ +    {  	obj[f].no=0;  	obj[f].ty=MNT; -	} +    }      if (!(fp=fopen(fname,"r"))) -	{ +    {  	fprintf(stderr,"Couldn't open lunar level file '%s'\n",fname);  	return; -	} +    }      title=strdup(GetLine(fp)); @@ -467,9 +443,9 @@ ReadFile()      p=GetLine(fp);      while (!feof(fp)) -	{ +    {  	switch(*p) -	    { +	{  	    case 'M':  		obj[poly_no].ty=MNT;  		break; @@ -485,7 +461,7 @@ ReadFile()  	    case 'O':  		obj[poly_no].ty=MINE;  		break; -	    } +	}  	GetNum(fp,&x,&y); @@ -497,18 +473,18 @@ ReadFile()  	pt_no=0;  	while((x!=-666)||(y!=-666)) -	    { +	{  	    obj[poly_no].p[pt_no].x=x;  	    obj[poly_no].p[pt_no].y=y;  	    pt_no++;  	    GetNum(fp,&x,&y); -	    } +	}  	obj[poly_no].no=pt_no;  	poly_no++;  	p=GetLine(fp); -	} +    }      no=poly_no; @@ -519,21 +495,21 @@ ReadFile()  } -WriteFile() +void WriteFile(void)  { -     FILE *fp; -     int f,r; +    FILE *fp; +    int f,r; -     if (!(fp=fopen(fname,"w"))) -	{ +    if (!(fp=fopen(fname,"w"))) +    {  	fprintf(stderr,"Couldn't write lunar level file '%s'\n",fname);  	exit(0); -	} +    }      fprintf(fp,"%s\n",title);      for(f=0;f<no;f++) -	{ +    {  	fprintf(fp,"%c        Object #%d\n",ty_code[obj[f].ty],f);  	fprintf(fp,"%d,%d\n",obj[f].o.x,obj[f].o.y); @@ -542,6 +518,7 @@ WriteFile()  	    fprintf(fp,"%d,%d\n",obj[f].p[r].x,obj[f].p[r].y);  	fprintf(fp,"-666,-666\n"); -	} +    } +      fclose(fp);  } | 
