橡皮筋画线法

王朝other·作者佚名  2008-06-01
窄屏简体版  字體: |||超大  

在这里我用STRUCT和指向函数的指针定义结合实现了模拟鼠标类,并用它来写了橡皮筋画线法

#include <stdio.h>

#include <graphics.h>

#include <dos.h>

typedef struct

{

void (*Inits)();/*初始化鼠标驱动*/

int (*MButton)();/*按键位置与按键状态*/

void (*MouseIco)();/*画鼠标光标*/

int x;/*横向坐标*/

int y;/*竖向坐标*/

int ox;

int oy;

int button;/*按键标志*/

}MOUSE;/*鼠标类*/

void mInits();

int mMButton();

void mMouseIco();

union REGS rg;

int main()

{

MOUSE *pM,mouse;

int graphdrive=0,graphmode=0;

int tracking=0,x1,y1,ox1,oy1;

pM=&mouse;

pM->Inits=mInits;

pM->MButton=mMButton;

pM->MouseIco=mMouseIco;

initgraph(&graphdrive,&graphmode,"");

setbkcolor(1);

setwritemode(1);/*画线模式*/

pM->Inits(&pM->x,&pM->y);

pM->ox=pM->x;

pM->oy=pM->y;

do

{

pM->button=pM->MButton(&pM->x,&pM->y);

pM->MouseIco(&pM->x,&pM->y,&pM->ox,&pM->oy);

if(pM->button==1)

{

if(!tracking)/*捕捉开关*/

{

ox1=x1=pM->x;

oy1=y1=pM->y;

tracking=1;

}

if(pM->x!=ox1pM->y!=oy1)

{

line(x1,y1,ox1,oy1);

ox1=pM->x;

oy1=pM->y;

line(x1,y1,pM->x,pM->y);

}

}

else tracking=0;

}while(pM->button!=3);

}

void mInits(int *mx,int *my)

{

rg.x.ax=0;

int86(0x33,&rg,&rg);

if(rg.x.ax==0)

exit(1);

rg.x.ax=7;

rg.x.cx=2;

rg.x.dx=640;

int86(0x33,&rg,&rg);

rg.x.ax=8;

rg.x.cx=2;

rg.x.dx=480;

int86(0x33,&rg,&rg);

rg.x.ax=4;

*mx=rg.x.cx=640/2;

*my=rg.x.dx=480/2;

int86(0x33,&rg,&rg);

rectangle(rg.x.cx-2,rg.x.dx-2,rg.x.cx+2,rg.x.dx+2);

}

int mMButton(int *lx,int *ly)

{

rg.x.ax=3;

int86(0x33,&rg,&rg);

*lx=rg.x.cx;

*ly=rg.x.dx;

return rg.x.bx;

}

void mMouseIco(int *x,int *y,int *oldx,int *oldy)

{

if(*x!=*oldx*y!=*oldy)

{

rectangle(*oldx-2,*oldy-2,*oldx+2,*oldy+2);

*oldx=*x;

*oldy=*y;

rectangle(*x-2,*y-2,*x+2,*y+2);

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航