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