1 #include <Quickdraw.h>
2 #include <Windows.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 
7 #define BASE_RES_ID 401
8 #define NIL_POINTER 0L
9 #define MOVE_TO_FRONT (WindowPtr)-1L
10 #define REMOVE_ALL_EVENTS 0
11 #define MENU_HEIGHT 30
12 
13 int colorArray[]={blackColor,whiteColor,redColor,greenColor,blueColor,
14 					cyanColor,magentaColor,yellowColor};
15 
16 int ncolors=8;
17 int icolor=0;
18 
19 #define PEN_WIDTH 2
20 #define PEN_HEIGHT 2
21 static int curHt=PEN_HEIGHT;
22 static int curWd=PEN_WIDTH;
23 ConstPatternParam curPat=&qd.black;
24 
25 WindowPtr	gDrawWindow;
26 long		gFillColor=blackColor;
27 
28 int max_x, max_y;
29 
30 float fxscal, fyscal, fxoff, fyoff,aratio;
31 
32 int ErrorCode, palette, MaxColors, MaxX, MaxY;
33 int xasp, yasp;
34 
35 PicHandle		aPic;
36 
WindowInit()37 WindowInit()
38 {
39 
40 	gDrawWindow=GetNewWindow(BASE_RES_ID,NIL_POINTER,(WindowPtr)MOVE_TO_FRONT);
41 	SizeWindow(gDrawWindow,qd.screenBits.bounds.right-qd.screenBits.bounds.left-10,
42 		qd.screenBits.bounds.bottom-qd.screenBits.bounds.top-20-MENU_HEIGHT,TRUE);
43 	SelectWindow(gDrawWindow);
44 	ShowWindow(gDrawWindow);
45 
46 	SetPort(gDrawWindow);
47 	TextFont(monaco);
48 	TextSize(9);
49 	PenPat(&qd.black);
50 	PenSize(PEN_WIDTH,PEN_HEIGHT);
51 	PenMode(patOr);
52 
53 
54 	max_x = gDrawWindow->portRect.right-gDrawWindow->portRect.left;
55 	max_y = gDrawWindow->portRect.bottom-gDrawWindow->portRect.top-MENU_HEIGHT;
56 
57 	ClipRect(&(gDrawWindow->portRect));
58 	aPic = OpenPicture(&gDrawWindow->portRect);
59 	ShowPen();
60 	}
61 
openpl()62 openpl()
63 {
64 
65 	WindowInit();
66 	linetype(0);
67 	}
68 
linetype(type)69 linetype(type)
70 	int type;
71 {
72 	switch (type) {
73 		case -1: curHt=curWd=2; ForeColor(blackColor); break;
74 		case 0: curHt=curWd=1; ForeColor(blackColor); break;
75 		case 1: curHt=curWd=1; ForeColor(blueColor); break;
76 		case 2: curHt=curWd=1; ForeColor(greenColor); break;
77 		case 3: curHt=curWd=1; ForeColor(yellowColor); break;
78 		}
79 
80 	}
81 
82 SFReply			reply;
83 OSErr			err;
84 long			refCon;
85 short PicFile;
86 
closepl()87 closepl()
88 {
89 	short vRefNum,err;
90 	char buffer[512];
91 	long hsize;
92 
93 	SetWTitle(gDrawWindow,"\pClick close-box to continue");
94 
95 	ClosePicture();
96 
97 	SelectWindow(gDrawWindow);
98 	SetPort(gDrawWindow);
99 
100 	HidePen();
101 /*	DrawPicture(aPic,&(gDrawWindow->portRect)); */
102 	GetVol((unsigned char *)buffer,&vRefNum);
103 	memset((void *)buffer,0,(size_t)512);
104 	Create("\pplot.PICT",0,'MDRW','PICT');
105 	if ((err=FSOpen("\pplot.PICT",0,&PicFile))!=noErr)
106 		fprintf(stderr," cannot open Pic File %d\n",err);
107 	else {
108 		hsize= 512L;
109 		FSWrite(PicFile,&hsize,buffer);
110 		hsize=GetHandleSize((Handle)aPic);
111 		FSWrite(PicFile,&hsize,*aPic);
112 		FSClose(PicFile);
113 		}
114 	while (Waitkey((int)'\n')==0);
115 	KillPicture(aPic);
116 	}
117 
space(x0,y0,x1,y1)118 space(x0,y0,x1,y1)
119 	int x0, x1, y0, y1;
120 {
121 	fxoff = (float)x0;
122 	fyoff = (float)y0;
123 	fxscal = (float)(max_x)/(float)(x1-x0);
124 	fyscal = (float)(max_y)/(float)(y1-y0);
125 	}
126 
move(x,y)127 move(x,y)
128 	int x, y;
129 {
130 	int xx, yy;
131 
132 	xx = (int)(((float)(x)-fxoff)*fxscal);
133 	yy = (int)(((float)(y)-fyoff)*fyscal);
134 
135 	MoveTo(xx,max_y-yy);
136 	}
137 
cont(x,y)138 cont(x,y)
139 	int x, y;
140 {
141 	int xx, yy;
142 
143 	xx = (int)(((float)(x)-fxoff)*fxscal);
144 	yy = (int)(((float)(y)-fyoff)*fyscal);
145 
146 	PenPat(curPat);
147 	PenSize(curHt,curWd);
148 	LineTo(xx,max_y-yy);
149 	}
150 
drawstr(str)151 drawstr(str)
152 	unsigned char *str;
153 {
154 	CtoPstr((char *)str);
155 	DrawString(str);
156 	PtoCstr(str);
157 	}
158 
psizex()159 psizex()
160 {
161 	return 8;
162 	}
163 
psizey()164 psizey()
165 {
166 	return 8;
167 }
168