Code:
# include <conio.h>
# include <string.h>
# include <fstream.h>
# include <stdio.h>
# include <dos.h>
# include <graphics.h>
//Mouse Class starting//
//------------------------------------------------------------------------------------------------------//
int graphicsdriver,gm,maxx,maxy,graphicsx,graphicsy,bu
tton;
static union REGS inregs, outregs;
static struct SREGS segregs;
typedef enum {ARROW, HAND, HOUR_GLASS, PEN} cursor_type;
union REGS graphicsi,graphicso;
static const int cursor_data[] = {
/* standard arrow cursor */
1, 0, /* x, graphicsy of hotpoint */
0x9FFF, 0x8FFF, 0x87FF, 0x83FF, /* SCREEN MASK (16 words) */
0x81FF, 0x80FF, 0x807F, 0x803F, /* Each word marks 16 pixels (lowest */
0x801F, 0x800F, 0x80FF, 0x887F, /* bit is rightmost pixel). The mask */
0x987F, 0xBC3F, 0xFC3F, 0xFE7F, /* is AND_ed with screen contents. */
0x0000, 0x2000, 0x3000, 0x3800, /* CURSOR MASK (16 words) */
0x3C00, 0x3E00, 0x3F00, 0x3F80, /* After the screen is AND_ed with the */
0x3FC0, 0x3E00, 0x3600, 0x2300, /* screen mask it is XOR_ed with this */
0x0300, 0x0180, 0x0180, 0x0000, /* cursor mask. */
/* pointing hand cursor */
2, 1,
0xCFFF, 0x87FF, 0x87FF, 0x87FF, 0x813F, 0x8007, 0x8003, 0x8003,
0x8003, 0x8003, 0x8003, 0x8003, 0x8007, 0xC007, 0xC007, 0xE03F,
0x0000, 0x3000, 0x3000, 0x3000, 0x3000, 0x36C0, 0x36D8, 0x36D8,
0x36D8, 0x36D8, 0x3FF8, 0x3FF8, 0x3FF0, 0x1FF0, 0x1FC0, 0x0000,
/* hourglass cursor */
7, 7,
0xC003, 0xC003, 0xC003, 0xC003, 0xE007, 0xF00F, 0xF81F, 0xFC3F,
0xFC3F, 0xF81F, 0xF00F, 0xE007, 0xC003, 0xC003, 0xC003, 0xC003,
0x0000, 0x1FF8, 0x0000, 0x1FF8, 0x0D50, 0x06A0, 0x0340, 0x0180,
0x0180, 0x03C0, 0x07E0, 0x0D50, 0x1AA8, 0x0000, 0x1FF8, 0x0000,
/* pen cursor */
0, 15,
0xFFF1, 0xFFE0, 0xFFC0, 0xFF80, 0xFF01, 0xFE03, 0xFC07, 0xF80F,
0xF01F, 0xE03F, 0xE07F, 0xC0FF, 0xC1FF, 0x87FF, 0x1FFF, 0x3FFF,
0x0000, 0x000E, 0x001C, 0x003A, 0x0074, 0x00E8, 0x01D0, 0x03A0,
0x0740, 0x0E80, 0x0D00, 0x1A00, 0x1800, 0x2000, 0x4000, 0x0000
};
static class mouse{
protected:
public:
mouse();
initmouse();
showmouseptr();
getpoint();
restrictmouseptr(int,int,int,int);
getmousepos(int*,int*,int*);
void setCursor(cursor_type cursor);
void disableMouse();
};
mouse::mouse()
{
setviewport(1,57,maxx-1,maxy-1,1);
restrictmouseptr(1,1,maxx-1,maxy-1);
}
mouse::getpoint()
{
int x,y,button;
getmousepos(&button,&x,&y);
if(x>30 && x<430 && y>70 && y<470)
{
int num=0;
x=x-30;
y=y-70;
x=x/50;
y=y/50;
num=y*8;
num=num+x;
return num;
}
return -1;
}
mouse::initmouse()
{
graphicsi.x.ax=0;
int86(0x33,&graphicsi,&graphicso);
return(graphicso.x.ax);
}
mouse::showmouseptr()
{
graphicsi.x.ax=1;
int86(0x33,&graphicsi,&graphicso);
return 0;
}
mouse::restrictmouseptr(int x1,int y1,int x2,int y2)
{
graphicsi.x.ax=7;
graphicsi.x.cx=x1;
graphicsi.x.dx=x2;
int86(0x33,&graphicsi,&graphicso);
graphicsi.x.ax=8;
graphicsi.x.cx=y1;
graphicsi.x.dx=y2;
int86(0x33,&graphicsi,&graphicso);
return 0;
}
mouse::getmousepos(int *button,int *x, int *graphicsy)
{
graphicsi.x.ax=3;
int86(0x33,&graphicsi,&graphicso);
*button=graphicso.x.bx;
*x=graphicso.x.cx;
*graphicsy=graphicso.x.dx;
return 0;
}
void mouse::setCursor(cursor_type cursor) { /* types defined in header */
inregs.x.ax = 9;
inregs.x.bx = *(cursor_data + 34 * cursor); /* x hotpoint */
inregs.x.cx = *(cursor_data + 34 * cursor + 1); /* graphicsy hotpoint */
inregs.x.dx = FP_OFF(cursor_data + 34 * cursor + 2); /* pointer to */
segregs.es = FP_SEG(cursor_data + 34 * cursor + 2); /* the masks */
int86x(0x33, &inregs, &outregs, &segregs);
}
void mouse::disableMouse()
{
inregs.x.ax = 2;
int86(0x33,&inregs,&outregs);
}
//------------------------------------------------------------------------------------------------------//
//Mouse Class End//