?? amain.cpp
字號:
bar(210,430,260,445);
PutCC16(270,430,0,14,pstr);
setfillstyle(1,VCOLOR);
bar(410,430,460,445);
PutCC16(470,430,0,14,vstr);
setcolor(oldcolor);
setwritemode(COPY_PUT);
}
//----------------------------------------------------//
//函數名:SHOWGRAPH()
//功能: 在作圖區顯示曲線
//入口參數:
// yratio: 作圖比例
// 1----2:1
// 2----1:1
//出口參數:
//----------------------------------------------------//
void ShowGraph(int yratio)
{
int x,y;
register int i,j;
x=130;
y=410;
for(i=x0;(i-x0)<=50;i++) //在當前作圖范圍顯示兩條曲線
{
if (((head[i].y-y0)<=80/yratio) && (head[i].y>=y0))
ShowElement(x+(head[i].x-x0)*10,y-(head[i].y-y0)*5*yratio,
0,360,2,head[i].color);
}
for(i=x0+100;(i-x0-100)<=50;i++)
{
if (((head[i].y-y0)<=80/yratio) && (head[i].y>=y0))
ShowElement(x+(head[i].x-x0)*10,y-(head[i].y-y0)*5*yratio,
0,360,2,head[i].color);
}
}
//----------------------------------------------------//
//函數名:SHOWELEMENT()
//功能: 以餅圖方式顯示曲線上的點
//入口參數:
// x,y: 屏幕上點的座標
// stangle: 餅圖起始角
// endangle: 餅圖結束角
// radius: 餅圖半徑
// color: 餅圖顏色
//出口參數:
//----------------------------------------------------//
void ShowElement(int x,int y,int stangle,int endangle,int radius,int color)
{
int oldcolor;
oldcolor=getcolor();
setcolor(color);
pieslice(x,y,stangle,endangle,radius);
setcolor(oldcolor);
}
//----------------------------------------------//
//函數名:FULLGRAPH()
//功能: 全圖顯示
//入口參數:
//出口參數:
//----------------------------------------------//
void FullGraph()
{
int oldcolor,btn=0;
int i,oldx0,oldy0,x,y;
char *help="右鍵結束";
oldcolor=getcolor();
oldx0=x0; //保存當前作圖信息:坐標參考點
oldy0=y0;
x=130;
y=410;
x0=0;
y0=0;
setfillstyle(1,0);
bar(100,6,128,414);
bar(106,412,638,428);
bar(128,8,638,412);
ClearState();
PutCC16(81,461,0,14,help);
setcolor(14);
setlinestyle(0,0,1);
line(130+i*10,10,130+i*10,410); //重畫坐標軸
line(130,410+i*10,631,410+i*10);
line(131+i*10,10,131+i*10,410);
line(130,409+i*10,630,409+i*10);
for (i=0;i<200;i++) //水平方向縮小一倍,垂直方向縮小十倍,顯示曲線
ShowElement(x+(head[i].x-x0)*5,y-(head[i].y-y0)*1.5,0,360,1,head[i].color);
while(btn!=RIGHT) ReadMouse(&btn,&x,&y);
while(RightPrsd()); //按鼠標右鍵結束,返回主界面
x0=oldx0;
y0=oldy0;
HideMouse();
ShowBkGrnd(1);
ShowCoord(10,20);
if (graphexist==TRUE) ShowGraph(1); //主界面有曲線,顯示之
ShowMouse();
ClearState();
ShowCurState();
setcolor(oldcolor);
}
//----------------------------------------------//
//函數名:PAGEUP()
//功能: 頁面上移
//入口參數:
//出口參數:
//----------------------------------------------//
void PageUp()
{
if (y0>=175) return; //縱坐標上限為215+40
y0+=step; //更新坐標參考點
ShowBkGrnd(1); //更新畫圖區
ShowCoord(10,20);
ShowGraph(1);
}
//----------------------------------------------//
//函數名:PAGEDOWN()
//功能: 頁面下移
//入口參數:
//出口參數:
//----------------------------------------------//
void PageDown()
{
if (y0<=0) return; //縱坐標上限為215+40
y0-=step; //更新坐標參考點
ShowBkGrnd(1); //更新畫圖區
ShowCoord(10,20);
ShowGraph(1);
}
//----------------------------------------------//
//函數名:PAGELEFT()
//功能: 頁面左移
//入口參數:
//出口參數:
//----------------------------------------------//
void PageLeft()
{
if (x0<=0) return; //橫坐標下限為0
x0-=step; //更新坐標參考點
ShowBkGrnd(1); //更新畫圖區
ShowCoord(10,20);
ShowGraph(1);
}
//----------------------------------------------//
//函數名:PAGERIGHT()
//功能: 頁面右移
//入口參數:
//出口參數:
//----------------------------------------------//
void PageRight()
{
if (x0>=50) return; //橫坐標上限為50+50
x0+=step; //更新坐標參考點
ShowBkGrnd(1); //更新畫圖區
ShowCoord(10,20);
ShowGraph(1);
}
//--------------------------------------------------------//
//函數名:SETSYSPARA()
//功能: 設置系統參數
//入口參數:
//出口參數:
//--------------------------------------------------------//
void SetSysPara()
{
int x1,y1,len,high,i;
int x,y,btn,choice;
void *buf;
char *help="左鍵選擇,右鍵返回";
char *item[]={ "機臺編號",
"氣門型號",
"桿 長",
"桿 徑"};
char oldcolor;
HideMouse();
oldcolor=getcolor();
setfillstyle(1,7);
setlinestyle(0,0,1);
setcolor(15);
x1=83;
y1=26+35*7;
len=80;
high=30;
buf=malloc(imagesize(x1-2,y1-2,x1+len+2,y1+high*4+2));
getimage(x1-2,y1-2,x1+len+2,y1+high*4+2,buf);
bar(x1-2,y1-2,x1+len+2,y1+high*4+2);
rectangle(x1-2,y1-2,x1+len+2,y1+high*4+2);
for(i=0;i<4;i++) //顯示子菜單
{
PutCC16(x1+12,y1+high*i+6,0,1,item[i]);
setcolor(15);
rectangle(x1,y1+high*i,x1+len,y1+high*(i+1));
}
ShowMouse();
for (;;)
{
choice=0;
btn=0;
ClearState();
PutCC16(81,461,0,14,help);
while(btn!=LEFT && btn!=RIGHT) ReadMouse(&btn,&x,&y);
while(LeftPrsd() || RightPrsd());
if (btn==RIGHT) break;
for(i=0;i<4;i++) //判斷所選的子菜單功能
{
if (MsInBox(x1,y1+high*i,x1+len,y1+high*(i+1),x,y))
{
choice=i+1;
break;
}
}
switch(choice)
{
case 1:
GetPara(MNUMBER,mnumber);
break;
case 2:
GetPara(MTYPE,mtype);
break;
case 3:
GetPara(MLEN,mlen);
break;
case 4:
GetPara(MRADIUS,mradius);
break;
}
}
HideMouse();
putimage(x1-2,y1-2,buf,COPY_PUT);
free(buf);
ClearState();
ShowCurState();
setcolor(oldcolor);
ShowMouse();
}
//----------------------------------------------------//
//函數名:GETPARA()
//功能: 獲取有效參數
//入口參數:
// flag:調用方式
// MNUMBER:機臺編號
// MTYPE: 氣門型號
// MLEN: 桿長
// MRADIUS:桿徑
//出口參數:
// 0:無效
// 1:有效
// para:參數指針
//----------------------------------------------------//
int GetPara(char flag,char *para)
{
int x1,y1,len,high,i,j;
FILE *fp;
char *buf;
char oldcolor;
char *msg;
char *help="按ESC鍵取消";
ClearState();
PutCC16(81,461,0,14,help);
HideMouse();
oldcolor=getcolor();
setfillstyle(1,7);
setlinestyle(0,0,1);
setcolor(15);
x1=170;
y1=28+35*9;
if (flag==MNUMBER) msg="N0:";
if (flag==MTYPE) msg="TYPE:";
if (flag==MLEN) msg="LEN:";
if (flag==MRADIUS) msg="RADIUS";
len=230;
high=50;
buf=(char*)malloc(imagesize(x1,y1,x1+len,y1+high));
getimage(x1,y1,x1+len,y1+high,buf);
bar(x1,y1,x1+len,y1+high);
rectangle(x1,y1,x1+len,y1+high);
rectangle(x1+2,y1+2,x1+len-2,y1+high-2);
setfillstyle(1,7);
bar(x1+4,y1+4,x1+len-4,y1+high-4);
PutCC16(x1+18,y1+17,0,14,msg);
if ((flag==MLEN)||(flag==MRADIUS))
GetData(NUMBER,x1+18,y1+17,msg,para,4);
if (flag==MNUMBER)
GetData(NUMBER,x1+18,y1+17,msg,para,2);
if (flag==MTYPE)
GetData(TEXT,x1+18,y1+17,msg,para,12);
putimage(x1,y1,buf,COPY_PUT);
ClearState();
ShowCurState();
free(buf);
ShowMouse();
setcolor(oldcolor);
if (strchr(para,' ')||!strcmp(para,"")) return(0);
return 1;
}
//--------------------------------------------------------//
//函數名:PRINTGRAPH()
//功能: 當前作圖區圖形打印
//入口參數:
//出口參數:
//--------------------------------------------------------//
void PrintGraph()
{
int x1,y1,len,high,i;
int x,y,btn,choice;
void *buf;
char *item[]={ "確 定",
"取 消"};
char oldcolor;
oldcolor=getcolor();
HideMouse();
setfillstyle(1,7);
setlinestyle(0,0,1);
setcolor(15);
x1=83;
y1=341;
len=80;
high=30;
buf=malloc(imagesize(x1-2,y1-2,x1+len+2,y1+high*2+2));
getimage(x1-2,y1-2,x1+len+2,y1+high*3+2,buf);
bar(x1-2,y1-2,x1+len+2,y1+high*2+2);
rectangle(x1-2,y1-2,x1+len+2,y1+high*2+2);
for(i=0;i<2;i++) //顯示子菜單
{
PutCC16(x1+12,y1+high*i+6,0,1,item[i]);
setcolor(15);
rectangle(x1,y1+high*i,x1+len,y1+high*(i+1));
}
ShowMouse();
btn=0;
while(btn!=LEFT) ReadMouse(&btn,&x,&y);
while(LeftPrsd());
for(i=0;i<2;i++) //判斷所選的子菜單功能
{
if (MsInBox(x1,y1+high*i,x1+len,y1+high*(i+1),x,y))
{
choice=i+1;
break;
}
}
HideMouse();
putimage(x1-2,y1-2,buf,COPY_PUT);
free(buf);
setcolor(oldcolor);
switch(choice)
{
case 1:
if (graphexist==TRUE) PrintScr(80,6,640,479,0,39);
break;
case 2:
break;
}
ShowMouse();
}
//--------------------------------------------------------//
//函數名:PRINTSCR
//功能: 屏幕圖形打印----點陣方式
//入口參數:
// x1,y1:屏幕左上角座標
// x2,y2:屏幕右上角座標
// rev: 標志,0:正向打印;1:反向打印
// m: 打印模式號(39---三倍密度,180,24針)
//出口參數:
//--------------------------------------------------------//
void PrintScr(int x1,int y1,int x2,int y2,int rev,int m)
{
int i,j,k,p,t;
int n,n1,n2;
int pinum,linum,mode;
unsigned char pt;
static unsigned char ch;
fprintf(stdprn,"%c%c\n",27,'@'); //打印機初始化
fprintf(stdprn,"%c%c%c\n",27,'3',24); //打印機行距設為24/280
n=2*(x2-x1+1); //計算打印列
n2=n/256;
n1=n-n2*256;
mode=m; //打印方式
linum=(y2-y1+12)/12; //計算打印行
pinum=24; //24針打印
for(i=0;i<linum;i++) //打印行數
{
fputc(27,stdprn); //ESC
fputc('*',stdprn); //設定圖形打印命令
fputc(mode,stdprn); //打印方式:圖象密度
fputc(n1,stdprn);
fputc(n2,stdprn); //打印列數(n1+n2*256)=n
for(j=0;j<n;j++)
{
k=y1+i*pinum/2; //對指定區域
for(p=0;p<pinum/8;p++) //連續獲得垂直方向12個象素
{
for(ch=0,t=0;t<4;t++,k++)
if(k<=y2) //右邊界檢查
{
pt=getpixel(x1+j/2,k); //獲得屏幕像素值
if(j/2==(float)j/2)
{
if(pt&8) ch|=1<<(7-2*t); //第四位為1
if(pt&4) ch|=1<<(7-2*t-1); //第三位為1
}
else
{
if(pt&2) ch|=1<<(7-2*t); //第二位為1
if(pt&1) ch|=1<<(7-2*t-1); //第一位為1
}
}
if(rev) ch=~ch; //反相打印
fprintf(stdprn,"%c",ch); //打印出該字節
}
}
fprintf(stdprn,"\n"); //換行
}
fprintf(stdprn,"\n"); //換行
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -