/**************************************************************************/ /* GTCLIB- graphics interface to Turbo C */ /**************************************************************************/ #include #include #include #include #include #include #define CURLEN 3 void *curbuf; static int gmode; static int gdriver; static int gerror; static int xmaxsc; static int ymaxsc; static int palsize; static int xasp; static int yasp; static int debug=0; static int mback=1; static int pback=1; static int sback=3; static int tback=6; static int pleft,pright,pbottom,ptop; /*prompt viewport */ static int tleft,tright,tbottom,ttop; /* title viewport */ static int sleft,sright,sbottom,stop; /* status viewport */ static int mleft,mright,mbottom,mtop; /* map viewport */ /**************************************************************************/ /* GINIT initializes graphics mode */ ginit() { if(debug) printf("GINIT \n"); detectgraph(&gdriver,&gmode); if(gdriver<0) { printf("No graphics hardware detected\n"); gmode=-1; return; } /* testing graphics modes */ /* printf("gdriver:%d gmode:%d Enter new?\n",gdriver,gmode); scanf("%d %d",&gdriver,&gmode); */ if(debug) { printf("Detected graphics driver: %d, mode: %d\n",gdriver,gmode); printf("Any key!\n"); getch(); } initgraph(&gdriver,&gmode,""); gerror=graphresult(); if(gerror<0) { printf("Error setting TC graphic mode!\n"); printf("INITGRAPH return value: %d\n",gmode); printf("graphdriver: %d\n",gdriver); printf("graphmode : %d\n",gmode); return; } else { xmaxsc=getmaxx(); ymaxsc=getmaxy(); if(debug) printf("xmaxsc: %d ymaxsc %d\n",xmaxsc,ymaxsc); palsize=getpalettesize(); if(debug) printf("palsize: %d\n",palsize); getaspectratio(&xasp,&yasp); if(debug) printf("xasp: %d yasp %d\n",xasp,yasp); pleft=0; pright=xmaxsc; pbottom=ymaxsc-15; ptop=ymaxsc-30; tleft=0; tright=xmaxsc; tbottom=15; ttop=0; sleft=0; sright=xmaxsc; sbottom=ymaxsc; stop=ymaxsc-15; mleft=0; mright=xmaxsc; mbottom=ymaxsc-30; mtop=15; setviewport(mleft,mtop,mright,mbottom,1); clearport(mleft,mtop,mright,mbottom,mback); /* allocate a little memory for cursor */ curbuf=malloc(imagesize(0,0,0,2*CURLEN+1)); } } /**************************************************************************/ /* GTERM terminates the graphics mode */ gterm() { if(debug) printf("GTERM \n"); if(gmode) closegraph(); } /**************************************************************************/ /* GGETLM inquires for the graphics limits and pixel aspect ratio */ ggetlm(float *xmin, float *xmax, float *ymin, float *ymax, float *pixasp) { int fudge=2; *xmin=mleft+fudge; *xmax=mright-fudge; *ymax=mbottom-fudge; *ymin=mtop+fudge; *pixasp=(float) yasp / (float) xasp; return; } /**************************************************************************/ /* GCLEAR clears the map viewport */ gclear() { if(debug) printf("GCLEAR \n"); clearport(mleft,mtop,mright,mbottom,mback); } /**************************************************************************/ /* GMOVE- moves to new position x,y */ gmove(int x, int y) { if(debug) printf("GMOVE x: %d y: %d\n",x,y); moveto(x,y); } /**************************************************************************/ /* GDRAW- draws to new position x,y */ gdraw(int x, int y) { if(debug) printf("GDRAW x: %d y: %d\n",x,y); lineto(x,y); } /**************************************************************************/ /* GPIX- sets pixel at x,y to current color */ gpix(int x, int y, int color) { if(debug) printf("GPIX x: %d y: %d color: %d\n",x,y,color); putpixel(x,y,color); } /**************************************************************************/ /* GSETCO- sets color for line drawing */ gsetco(int color) { if(debug) printf("GSETCO color: %d\n",color); setcolor(color); } /**************************************************************************/ /* GTIC inverts the image in shape of a tic */ void gtic(int tx,int ty) { int op=4; if( tx>CURLEN && txCURLEN && ty