您现在的位置: IT技术文档中心 >> 文档资源 >> 编程语言及开发环境 >> C/C++ >> 文档正文
C语言图形模式编程,个性鼠标
作者:未知 文章来源:互联网 点击数: 更新时间:2007-7-22 2:59:29
/* -----  C语言图形模式编程,个性鼠标。 -----*/

int Msinit()
{   /* 初始化鼠标*/
    int recored;

    regs.x.ax=0;
    int86(0x33,&regs,&regs);
    recored=regs.x.ax;
    if(recored==0)
    {   printf("Mouse not found !\n");
        getch();return 0;
    }
    regs.x.ax = 1;  /* 显示鼠标*/
    int86(0x33,&regs,&regs);
    return recored;
}

void MskindMath()    /*计算鼠标的样子*/
{   /*Point hotspot[]={{0,11},{0,0},{4,0},{4,0}};热点*/
    int    i,j,jj,k;
    int    full,kind;
    long   UpNum[2][16] = {/*  hand */
        0xf3ff,0xe1ff,0xe1ff,0xe1ff,
        0xe001,0xe000,0xe000,0xe000,
        0x8000,0x0000,0x0000,0x0000,
        0x0000,0x0000,0x8001,0xc003,

        0x3fff,0x1fff,0x0fff,0x07ff,/*  arrow箭头 */
        0x03ff,0x01ff,0x00ff,0x007f,
        0x003f,0x00ff,0x01ff,0x10ff,
        0x30ff,0xf87f,0xf87f,0xfc3f,
    };
    long   DownNum[2][16]={/*  hand */
        0x0c00,0x1200,0x1200,0x1200,
        0x13fe,0x1249,0x1249,0x1249,
        0x7249,0x9001,0x9001,0x9001,
        0x8001,0x8001,0x4002,0x3ffc,

        0x0000,0x4000,0x6000,0x7000,/*  arrow箭头 */
        0x7800,0x7c00,0x7e00,0x7f00,
        0x7f80,0x7e00,0x7c00,0x4600,
        0x0600,0x0300,0x0300,0x0180,
    };
    kind = (Mskind>>1)%2;  /* 手形还是箭头*/
    full = Mskind%2;       /* 是否空心*/

    for(i=0;i<16;i++)
    {
         j=jj=15;
         while(UpNum[kind][i]!=0)
         {
             up[i][j]=UpNum[kind][i]%2;
             j--;
             UpNum[kind][i]/=2;
         }
         while(DownNum[kind][i]!=0)
         {
             down[i][jj--]=DownNum[kind][i]%2;
             DownNum[kind][i]/=2;
         }
         for(k=j ;k>=0;k--)  up  [i][k]=0;
         for(k=jj;k>=0;k--)  down[i][k]=0;
         for(k=0;k<16;k++)
         {   /*四种组合方式*/
             if(up[i][k]==0&&down[i][k]==0)
             {   /* 是否为空心*/
                 if(full) mouse_draw[i][k]=1;
                 else     mouse_draw[i][k]=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 */
}

[1] [2] [3] 下一页

网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
| 设为首页 | 加入收藏 | 联系站长 | 版权申明 | 雁过留声 | 会员中心 |