From 7fbd8d53b1932e40676a120cfd84868f3758465b Mon Sep 17 00:00:00 2001 From: Ian C Date: Thu, 12 May 2005 00:59:39 +0000 Subject: This commit was generated by cvs2svn to compensate for changes in r2, which included commits to RCS files with non-trunk default branches. --- ledit.c | 547 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 547 insertions(+) create mode 100644 ledit.c (limited to 'ledit.c') diff --git a/ledit.c b/ledit.c new file mode 100644 index 0000000..1a5c26c --- /dev/null +++ b/ledit.c @@ -0,0 +1,547 @@ +/* + + lunar - Simple X11 Lunar Lander + + Copyright (C) 2005 Ian Cowburn (ianc@noddybox.demon.co.uk) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + ------------------------------------------------------------------------- + +*/ +static char rcs_id[]="$Id$"; + +#include +#include +#include +#include +#include + +#include +#include + +#include "Xbit.h" + +#define WINX 100 +#define WINY 100 +#define WINW 640 +#define WINH 640 + +#define RND(x) (rand()%(x)) + +XSizeHints size_hints; +int black,white; +Display *disp; +Window window; +Colormap cm; +XFontStruct *font; + +XFuncControl Key(); +XFuncControl Mouse(); +XFuncControl Motion(); +XFuncControl Process(); + +XCallBack key[2]={{0,Key},{0,NULL}}; +XCallBack mouse[2]={{0,Mouse},{0,NULL}}; +XCallBack motion[2]={{0,Motion},{0,NULL}}; + + +#define NOCOL 7 +char *colnames[NOCOL]= + {"black","white","red","yellow","blue","green","cyan"}; +int pix[NOCOL]; + +#define BLACK pix[0] +#define WHITE pix[1] +#define RED pix[2] +#define YELLOW pix[3] +#define BLUE pix[4] +#define GREEN pix[5] +#define CYAN pix[6] + +typedef struct + { + int x,y; + } Pt; + +#define MNT 1 +#define MINE 2 +#define ASTCW 3 +#define ASTACW 4 +#define PAD 5 + +char *ty_type[]={"BUG?!","MNT","MINE","ASTCW","ASTACW","PAD"}; +char ty_code[]={'?','M','O','X','Y','P'}; + +int CONST =3; +#define STOMX(x) (((x)-WINW/2)*CONST+gx) +#define STOMY(y) (((y)-WINH/2)*CONST+gy) + +#define MTOSX(x) (((x-gx)/CONST)+(WINW/2)) +#define MTOSY(y) (((y-gy)/CONST)+(WINH/2)) + +#define MAXLINE 32 +typedef struct + { + int ty; + Pt o; + int no; + Pt p[MAXLINE]; + } Obj; + + +#define MAXOBJ 64 + +Obj obj[MAXOBJ]; +int no; +int cur; +char *fname; +char *title="LEVEL TITLE"; +int mx,my; +int gx=0,gy=0; + + +int main(argc,argv) +int argc; +char *argv[]; + +{ + unsigned long evmask; + + srand(getpid()); + + size_hints.flags=PPosition|PSize|PMinSize|PMaxSize; + size_hints.x=WINX; + size_hints.y=WINY; + size_hints.width=size_hints.min_width=WINW; + size_hints.height=size_hints.min_height=WINH; + size_hints.max_width=WINW; + size_hints.max_height=WINH; + + evmask=ButtonPressMask|ButtonReleaseMask| + KeyPressMask|KeyReleaseMask|PointerMotionMask; + + motion[0].w=mouse[0].w=key[0].w=window= + OpenWin(argc,argv,argv[0], + WINX,WINY,WINW,WINH, + WINW,WINH, + evmask, + &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]); + + DisableDoubleBuffer(); + + disp=GetDisplay(); + + AllocColors(NOCOL,pix,colnames); + + XDoWindows(mouse,motion,key,Process); +} + + +XFuncControl Key(w,m,e) +Window w; +int m; +XEvent *e; + +{ + KeySym k; + + if (m==XPRESS) + return; + + switch(k=XLookupKeysym(e,ShiftMapIndex)) + { + case XK_G: /* Set centre */ + case XK_g: + gx=STOMX(e->xkey.x); + gy=STOMY(e->xkey.y); + break; + + case XK_H: /* Clear centre */ + case XK_h: + gx=0; + gy=0; + break; + + case XK_C: /* Create poly */ + case XK_c: + if (noxkey.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 */ + case XK_d: + if (no) + if (cur==(--no)) + cur--; + break; + + case XK_Left: /* Prev poly */ + if (no) + if (cur) + cur--; + break; + + case XK_Right: /* Prev poly */ + if (no) + if (cur<(no-1)) + cur++; + break; + + case XK_Up: /* Scale up */ + if (CONST>1) + CONST--; + break; + + case XK_Down: /* Scale down */ + CONST++; + break; + + case XK_S: /* Save */ + case XK_s: + WriteFile(); + break; + + case XK_Q: /* Quit */ + case XK_q: + return (XFUNCSTOP); + break; + + case XK_1: + case XK_2: + case XK_3: + case XK_4: + case XK_5: + if (no) + obj[cur].ty=k-XK_0; + break; + + default: + break; + } + + return(XFUNCCONT); +} + + +XFuncControl Mouse(w,m,b,x,y) +Window w; +int m; +int b,x,y; + +{ + int mapx,mapy; + + if ((m==XPRESS)||(cur==-1)) + return (XFUNCCONT); + + switch(b) + { + case 1: /* Add point */ + if (obj[cur].no