鼠标绘图 c语言,C语言图形模式编程,个性鼠标(2)

else if(up[i][k]==0&&down[i][k]==1)

{

if(full) mouse_draw[i][k]=2;

else     mouse_draw[i][k]=1;

}

else if(up[i][k]==1&&down[i][k]==0) mouse_draw[i][k]=3;

else                                mouse_draw[i][k]=4;

}

}

if(kind==1) mouse_draw[1][2]=0;/*特殊点*/

else        mouse_draw[1][2]=0;

}

void MsOn(int x,int y)

{   /* 鼠标光标显示*/

int  i,j;

int  color[2];

color[0]=Mskind>>2;

color[1]=Mskind>>6;

for(i=0;i<16;i++)

{

for(j=0;j<16;j++)

{

pixel_save[i][j]=getpixel(x+j,y+i);/* 保存原来的颜色*/

if(mouse_draw[i][j]==1)

putpixel(x+j,y+i,color[0]);

else if(mouse_draw[i][j]==2)       /* 画鼠标*/

putpixel(x+j,y+i,color[1]);

}

}

}

void MsOff(int x,int y)

{   /* 隐藏鼠标*/

int  i,j,color;

for(i=0;i<16;i++)

for(j=0;j<16;j++)

{

if(mouse_draw[i][j]==3||mouse_draw[i][j]==4)  continue;

color=getpixel(x+j,y+i);

putpixel(x+j,y+i,color^color);     /* 原位置异或消去*/

putpixel(x+j,y+i,pixel_save[i][j]);/* 还原原背景*/

}

}

int Msread(int *px,int *py,int *buttons)

{  /* 读取鼠标及键盘状态*/

int    but_old=*buttons;

int    x_old=*px,y_old=*py;

struct time t;

struct date d;/* 当前时间信息*/

do{

if(kbhit()) return bioskey(0);

regs.x.ax=3;

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

*px=regs.x.cx;

*py=regs.x.dx;

*buttons=regs.x.bx;

}while(*px==x_old&&*py==y_old&&*buttons==but_old);

MsOff(x_old,y_old);

but_old=*buttons;

x_old=*px;

y_old=*py;

MsOn(x_old,y_old);

return -1;

}

int Msinbox(int x1,int y1,int x2,int y2,int x,int y)

{

return((x>=x1&&x<=x2&&y>=y1&&y<=y2)?1:0);  /* 若在预定区域就返回 1 */

}

/***********************************************************************

简易绘图板

楼主写的引擎很不错哦!但是我现在也没找到合适的Mskind值描述鼠标,我感

觉是你的程序问题?!楼主光写个鼠标引擎不写实例这样会让很多人看不懂,我用

你的引擎写了个简易绘画版。

修改人:cdmalcl

***********************************************************************/

/* -----  图形模式编程,个性鼠标。 -----*/

#include #include

#define WL -3   /* 鼠标绘制的横向宽度 */

#define HL 3    /* 鼠标绘制的纵向高度 */

#define LEFT_C 15       /* 鼠标左键绘制图形的颜色 */

#define RIGHT_C 0       /* 鼠标右键绘制图形的颜色 */

#define EXIT_X 450      /* 退出菜单的横坐标位置 */

#define EXIT_Y 350      /* 退出菜单的纵坐标位置 */

#define E_WL 60         /* 退出菜单的横向长度 */

#define E_HL 15         /* 退出菜单的纵向高度 */

int Init();     /*程序初始化*/

int Run();      /*程序主要过程*/

int DrawRectangle(int OutType ,int x ,int y);       /*绘制一个矩形或线或点*/

int Msinit();

void MskindMath();

void MsOn(int x,int y);

void MsOff(int x,int y);

int Msread(int *px,int *py,int *buttons);

int Msinbox(int x1,int y1,int x2,int y2,int x,int y);

int End();      /*结束程序*/

int Mskind = 0xb;

long up[2][16]={0} ,down[2][16]={0};

long mouse_draw[16][16]={0} ,pixel_save[16][16]={0};

union REGS regs;

int main()

{

Init();

Run();

End();

}

int Init()

{

int gd = DETECT ,gm = 0;

initgraph(&gd ,&gm ,"");

rectangle(EXIT_X ,EXIT_Y ,EXIT_X+E_WL ,EXIT_Y + E_HL);

settextstyle(1 ,0 ,4);

outtextxy(EXIT_X+E_WL/4 ,EXIT_Y+E_HL/3 ,"EXIT");

Msinit();

MskindMath();

}

int Run()

{

int x ,y ,buttons = 0;

x = getmaxx()/2;

y = getmaxy()/2;

MsOn(x,y);

while(Msread(&x ,&y ,&buttons)!=283)    /* 退出键退出程序 */

{

if(Msinbox(EXIT_X ,EXIT_Y ,EXIT_X+E_WL ,EXIT_Y + E_HL ,x ,y))  /* 点击退出选项退出程序 */

{

if(buttons == 1)

{

End();

}

}

else

{

if(buttons == 1)

{

DrawRectangle(0 ,x ,y);

}

if(buttons == 2)

{

DrawRectangle(1 ,x ,y);

}

}

}

return 1;

}

#if WL < 0

#define WL 0

#endif

#if HL < 0

#define HL 0

#endif

int DrawRectangle(int OutType ,int x ,int y)

{

MsOff(x ,y);

if(OutType)

{

#if HL > 1

setcolor(RIGHT_C);

rectangle(x ,y ,x+WL ,y+HL);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值