Computer Graphics Program source codes with full description.

Study of Various C Graphics Functions

Implementation and Using mouse in DOS

Implementation of DDA line algorithm with source code in C/C++.

Implementation of Bresenham Line algorithm with source code in C/C++.

Implementation of Midpoint Line algorithm with source code in C/C++.

Implementation of Bresenham Circle algorithm with source code in C/C++.

Implementation of Mid-point Circle algorithm with source code in C/C++.

Implementation of Mid-point Ellipse algorithm with source code in C/C++.

Implementation of Polygon Filling using Scan Fill with source code in C/C++.

Implementation of Polygon Filling using Flood Fill with source code in C/C++.

Implementation of Polygon Filling using Boundary Fill Algorithms.

Implementation of algorithm of 2D Transformation of an Object with source code in C/C++.

Implementation of Line Clipping using Cohen- Sutherland algorithm with source code in C/C++.

Implementation of Line Clipping using Liang-Barky algorithm with source code in C/C++.

Implementation of Polygon clipping using Sutherland-hodgeman algorithm with source code in C/C++.

Search

Saturday 30 April 2011

A C Program to lock the mouse pointer in definate area

#include
#include
#include
#include
#include

union REGS i,o;
int initmouse();
void showmouseptr();
void restrictmouseptr(int,int,int,int);
void getmousepos(int*,int*,int*);

void main()
{
//Request autodetection
 int gdriver = DETECT,gmode,errorcode;
 int xmax,ymax,x,y,button;
//Initialize graphics and local variables
 initgraph(&gdriver,&gmode,"C:\\TC\\BGI");
//Read result of initialization
 errorcode=graphresult();
 if(errorcode!=grOk) //Error occured
 {
  printf("Graphics error : %s\n",grapherrormsg(errorcode));
  printf("Press any key to halt.");
  getch();
  exit(1);
 }
 setcolor(getmaxx());
 xmax=getmaxx();
 ymax=getmaxy();
//Restrict the mouse pointer
 rectangle(0,56,xmax,ymax);
 setviewport(1,57,xmax-1,ymax-1,1);
 gotoxy(26,1);
 printf("Mouse demonstration program");
 if(initmouse()==0)
 {
  closegraph();
  restorecrtmode();
  printf("Mouse drivers not loaded.");
  exit(1);
 }
 restrictmouseptr(1,57,xmax-1,ymax-1);
 showmouseptr();
 gotoxy(1,2);
 printf("Left Button");
 gotoxy(15,2);
 printf("Right Button");
 gotoxy(55,3);
 printf("Press any key to exit");

 while(!kbhit()) //While keyboard is not hit.
 {
  getmousepos(&button,&x,&y);
  gotoxy(5,3);
  (button & 1)==1 ? printf("Down") : printf(" Up ");
  gotoxy(20,3);
  (button & 2)==2 ? printf("Down") : printf(" Up ");
  gotoxy(65,2);
  printf("x=%03d y=%03d",x-1,y-57);
 }
}
initmouse()
{
 i.x.ax=0;
 int86(0x33,&i,&o);
 return(o.x.ax);
}
void showmouseptr()
{
 i.x.ax=1;
 int86(0x33,&i,&o);
}
void restrictmouseptr(int x1,int y1,int x2,int y2)
{
 i.x.ax=7;
 i.x.cx=x1;
 i.x.dx=x2;
 int86(0x33,&i,&o);
 i.x.ax=8;
 i.x.cx=y1;
 i.x.dx=y2;
 int86(0x33,&i,&o);
}
void getmousepos(int *button,int *x,int *y)
{
 i.x.ax=3;
 int86(0x33,&i,&o);
 *button=o.x.bx;
 *x=o.x.cx;
 *y=o.x.dx;
}

No comments:

Post a Comment

Copyright Text

Copyright @ LDRP Student Community, webmaster Rahul Bhadauriya