#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "wllib.h" #define SAFE_BORDER (4) #define SIZE_MIN (16) extern void drawgfx(void); long xcur,ycur,xmin,xmax,ymin,ymax; int winx,winy,iniline,minimax=1; float coefx,coefy; int xofs,yofs,xbor,ybor; struct RastPort *rport; struct Window *win; char *pname; struct NewWindow nwin={0,0,0,0,UCHAR_MAX,UCHAR_MAX, IDCMP_NEWSIZE|IDCMP_CLOSEWINDOW|IDCMP_MOUSEBUTTONS|IDCMP_VANILLAKEY, WFLG_SIZEGADGET|WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SIZEBRIGHT |WFLG_SMART_REFRESH|WFLG_ACTIVATE|WFLG_RMBTRAP|WFLG_NOCAREREFRESH, NULL,NULL,NULL,NULL,NULL,0,0,0,0,CUSTOMSCREEN}; #define pubscr (nwin.Screen) #define gfxfail() { fprintf(stderr,"%s: Gfx subsys failed!\n",pname); \ exit(EXIT_FAILURE); } while (0) void wl_line(long x,long y) { if (iniline) { iniline=0; if (minimax) { xmin=xmax=x; ymin=ymax=y; } else Move(rport,(long)(coefx*(x-xmin)+xofs), (long)(yofs-coefy*(y-ymin))); } else if (minimax) { if (xxmax) xmax=x; if (yymax) ymax=y; } else Draw(rport,(long)(coefx*(x-xmin)+xofs), (long)(yofs-coefy*(y-ymin))); } static void wl_safeclose(void) { struct IntuiMessage *msg; Forbid(); while (msg=(struct IntuiMessage *)GetMsg(win->UserPort)) ReplyMsg((struct Message *)msg); ModifyIDCMP(win,0); Permit(); CloseWindow(win); win=NULL; } void wl_done(void) { struct IntuiMessage *msg; ULONG cls; iniline=1; drawgfx(); minimax=0; if (xmax==xmin) xmax++; if (ymax==ymin) ymax++; if (IntuitionBase->LibNode.lib_Version>=39) SetWindowPointer(win,TAG_DONE); for (;;) { if (!iniline) { coefx=(float)(winx-xbor-1)/(xmax-xmin); coefy=(float)(winy-ybor-1)/(ymax-ymin); yofs=winy-SAFE_BORDER-win->BorderBottom; SetAPen(rport,0); RectFill(rport,(long)win->BorderLeft,(long)win->BorderTop, (long)(winx-win->BorderRight-1),(long)(winy-win->BorderBottom-1)); SetAPen(rport,1); iniline=1; drawgfx(); } while (!(msg=(struct IntuiMessage *)GetMsg(win->UserPort))) WaitPort(win->UserPort); cls=msg->Class; ReplyMsg((struct Message *)msg); if (cls!=IDCMP_NEWSIZE) { wl_safeclose(); return; } winx=win->Width; winy=win->Height; } } static void wl_cleanup(void) { while (win) wl_safeclose(); if (pubscr) { UnlockPubScreen(NULL,pubscr); pubscr=NULL; } } void wl_init(int *argcp,char **argv,const char *class) { if ((pname=rindex(*argv,'/'))) pname++; else pname=*argv; atexit(wl_cleanup); if (!(pubscr=LockPubScreen(NULL))) gfxfail(); nwin.Title=(char *)class; nwin.LeftEdge=(winx=nwin.Width=pubscr->Width/2)/2; nwin.TopEdge=(winy=nwin.Height=pubscr->Height/2)/2; if (!(win=OpenWindow(&nwin))) gfxfail(); if (IntuitionBase->LibNode.lib_Version>=39) SetWindowPointer(win,WA_BusyPointer,TRUE,WA_PointerDelay,TRUE,TAG_DONE); WindowLimits(win, (long)(xbor=(xofs=win->BorderLeft+SAFE_BORDER) +SAFE_BORDER+win->BorderRight )+SIZE_MIN, (long)(ybor=win->BorderTop +SAFE_BORDER +SAFE_BORDER+win->BorderBottom)+SIZE_MIN,~0,~0); SetDrMd(rport=win->RPort,JAM1); }