THIS IS A DEMONSTRATION OF THE CLASS I CREATED FOR MOUSE OPERATIONS
THIS IS PERFORMED IN VGA 320X200 WITH 256 COLOR DEPTH
AS I AM A BEGINNER THERE MAY BE SOMETHING WRONG WITH THE STANDARDS I USE
I WELCOME COMMENTS AND SUGGESSIONS FROM YOU
PLEASE FEEL FREE TO DOWNLOAD THIS PROGRAM IF YOU WISH TO
THIS SHOULD WORK WITH ALMOST ALL CONVENSIONAL COMPILERS
I WORKED IT OUT USING TURBO C COMPILER
SET COMPILER MEMORY SETTINGS TO LARGE OR HUGE BEFORE COMPILATION
MY EMAIL ID IS : dibu_george@yahoo.co.in
I AM DIBU GEORGE JOSEPH
THANK YOU FOR VIEWING THIS
******************************************************************************************
*****************************************************************************************/
/* I DIIDN'T USE TWO FUNCTIONS IN DEMONSTRATION pressed(),released() U CAN MAKE USE OF
THEM TOO*/
#include(dos.h)
#include(conio.h)
#include(iostream.h)
/*CLASS FOR MOUSE OPERATIONS*/
class mouse
{
union REGS i;
int x_pos,y_pos;
int but_state;
public:
void update();/* updates the x_pos,y_pos and but_status*/
void show();/*shows the hidden mouse pointer*/
void restrict(int,int,int,int);/*restricts the mouse pointer with limits x1,x2,y1,y2*/
void wait();/*waits foe retrace for preventing flickering*/
void hide();/*hide the mouse pointer*/
int check(int,int,int,int,int);/*check whether mouse
entered the given pixels*/
int pressed()/*checks whether left mouse button is pressed*/
{
i.x.ax=5;
int86(0x33,&i,&i);
return i.x.bx;
}
int released()/*check whether the left mouse button is released*/
{
i.x.ax=0x06;
int86(0x33,&i,&i);
return i.x.bx;
}
void get(int &a,int &b,int &c)/*function to give out the values of mouse pointer
variables*/
{
update();
a=x_pos;
b=y_pos;
c=but_state;
}
void reset()/*reset the mouse,this could be used to get the details of mouse
installed such as no of mouse,no of buttons etc.*/
{
i.x.ax=0;
int86(0x33,&i,&i);
}
mouse(int rx0,int rx1,int ry0,int ry1)/*constructor for the class.use the
parameters to restrict mouse ptr*/
{
reset();
show();
restrict(rx0,rx1,ry0,ry1);
}
~mouse(){}/*destructor for the class*/
};
void mouse::update()
{
i.x.ax=0x03;
int86(0x33,&i,&i);
x_pos=(i.x.cx>>1);
y_pos=i.x.dx;
but_state=i.x.bx;
}
void mouse::show()
{
i.x.ax=1;
wait();
int86(0x33,&i,&i);
}
void mouse::wait()
{
/* wait until done with vertical retrace */
while ((inp(0x03da) & 0x08));
/* wait until done refreshing */
while (!(inp(0x03da) &0x08));
}
void mouse::restrict(int a,int b,int c,int d)
{
i.x.ax=7;
i.x.cx=a;
i.x.dx=b;
int86(0x33,&i,&i);
i.x.ax=8;
i.x.cx=c;
i.x.dx=d;
int86(0x33,&i,&i);
}
void mouse::hide()
{
i.x.ax=2;
int86(0x33,&i,&i);
}
int mouse::check(int a,int b,int c=0,int d=0,int e=0)
{
update();
if(c==0&&d==0)
{
c=a;
d=a;
}
if(a<=x_pos&&b<=y_pos&&c>=x_pos&&d>=y_pos)
if(e==0||e==but_state)
return 1;
return 0;
}
/* FUNCTION FOR DISPLAYING GRAPHICS CONTENT*/
typedef unsigned char byte;
byte *vga=(byte *)0xA0000000L;
void disp()
{
for(int j=0;j<256;j++)
for(int k=0;k<80;k++)
{
vga[j+(k<<8)+(k<<6)]=j;
}
}
/*MAIN FUNCTION*/
void main()
{
int x=0,y,b;
union REGS i;
i.h.ah=0;
i.h.al=0x13;
int86(0x10,&i,&i);//initiallize 320*200 256 color mode
disp();
mouse m(0,639,0,199);
while(!kbhit())
{
m.hide();
disp();
m.show();
gotoxy(10,11);
m.get(x,y,b);
cout<
cout<<"x "<
cout<<"y "<
cout<<"but "< gotoxy(20,14);
if(m.check(10,10,100,100))
cout<<"passed";
else
cout<<" ";
m.show();
}
m.reset();
}