예제 #1
0
void main()
{
	int gd=DETECT, gm, maxx, maxy, x, y, button;

	initgraph(&gd, &gm, "c:/tc/bgi");
	maxx=getmaxx();
	maxy=getmaxy();

	rectangle(0,56,maxx,maxy);
	setviewport(1,57,maxx-1,maxy-1,1);

	gotoxy(26,1);
	printf("DEMONSTRATION : MOUSE IN C");
	gotoxy(28,2);
	printf("BY: OSHO PRAKASH GIRI");

	if(initmouse()==0)
	{
		closegraph();
		restorecrtmode();
		printf("\nMOUSE DRIVER NOT LOADED");
		exit();
	}

	restrictmouseptr(1,57,maxx-1,maxy-1);
	showmouseptr();

	getch();
}
예제 #2
0
void user_save()
{
	int a,b,w,px,i=-1;
	char filename[60],ch;
	restrictmouseptr(0,0,xmax,20);
	hidemouseptr();
	a=textwidth("Enter File Name");
	setfillstyle(1,BLUE);
	bar(0,0,xmax,20);
	setcolor(BLACK);
	outtextxy(10,5,"Enter File Name:");
	setfillstyle(1,WHITE);
	bar((a+10),2,(a+410),18);
	setfillstyle(1,CYAN);
	a=textwidth("No");
	bar((xmax-10-a),2,(xmax-10),18);
	b=a+10+textwidth("Save");
	bar((xmax-10-b),2,(xmax-20-a),18);
	setcolor(BLACK);
	outtextxy((xmax-9-b),3,"Save");
	outtextxy((xmax-9-a),3,"No");
	px=textwidth("Enter File Name")+10;
	while(1)
	{
	ch=get_filename(px,4);
	if(ch==13||ch==27)
	break;
	w=textwidth("A");
	px+=w;
	filename[++i]=ch;
	}
	filename[++i]='\0';
	showmouseptr();
	for(;;)
	{
		getmousepos(&button,&mousex,&mousey);
		if(mousex>(xmax-10-a)&&mousex<(xmax-10)&&button==1)       //deny loading/saving
		{
			button_hover((xmax-10-a),2,(xmax-10),18);
			hidemouseptr();
			initmouse();
			top_panel_default();
			top_panel_buttons(tool_but_num,0,1);
			showmouseptr();
			break;
		}
	else if(mousex>(xmax-10-b)&&mousex<(xmax-20-a)&&button==1)        //confirm loading/saving
		{
			button_hover((xmax-10-b),2,(xmax-20-a),18);
			save_bitmap(filename);
			hidemouseptr();
			initmouse();
			top_panel_default();
			top_panel_buttons(tool_but_num,0,1);
			showmouseptr();
			break;
		}
	}
}
예제 #3
0
void main()
{int gd=DETECT,gm;
initgraph(&gd,&gm,"G:\\install\\tc\\bgi");
restrictmouseptr(0,0,710,710);
showmouseptr();
shakil sa;

sa.first();

closegraph();

}
예제 #4
0
void main()
{
	int gd=DETECT,gm,maxx,maxy,x,y,button;

	initgraph(&gd,&gm,"C:\\TC");
	maxx=getmaxx();
	maxy=getmaxy();

	rectangle(0,56,maxx,maxy);
	setviewport(1,57,maxx-1,maxy-1,1);

	gotoxy(26,1);
	printf("MOUSE DEMONSTRATION PROGRAM");

	if(initmouse()==0)
	{
		closegraph();
		restorecrtmode();
		printf("\nMouseDriver not loaded");
		exit(0);
	}

	restrictmouseptr(1,57,maxx-1,maxy-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())
	{
		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,y);
	}
}
예제 #5
0
void main()
{
int gd=DETECT,gm,maxx,maxy,x,y,button,prevx,prevy;

initgraph(&gd,&gm,"d:\\tc\\bgi");

printf("Freehand drawing  with the mouse");

maxx=getmaxx();
maxy=getmaxy();
rectangle(0,0,maxx,maxy);
setviewport(1,1,maxx-1,maxy-1,1);

if(initmouse()==0)
	{
	closegraph();
	restorecrtmode();
	printf("Mouse driver not loaded");
	exit(1);
	}

restrictmouseptr(1,1,maxx-1,maxy-1);
showmouseptr();

while(!kbhit())
	{
	getmousepos(&button,&x,&y);
	if((button & 1)==1)
		{
		hidemouseptr();
		prevx=x;
		prevy=y;

		while((button & 1)==1)
			{
			line(prevx,prevy,x,y);
			prevx=x;
			prevy=y;
			getmousepos(&button,&x,&y);
			}

		showmouseptr();
		}
	}
}
예제 #6
0
void main()
{
	int gd=DETECT,gm,maxx,maxy,x,y,button;

	initgraph(&gd,&gm,"c:\\tc\\bgi");
	maxx=getmaxx();
	maxy=getmaxy();

	rectangle(0,56,maxx,maxy);
	setviewport(1,57,maxx-1,maxy-1,1);
	gotoxy(26,1);
	printf("Mouse Demonstration Program!");

	if(initmouse()==0)
	{
		closegraph();
		restorecrtmode();
		printf("Mouse driver not loaded");
		exit(1);
	}
	restrictmouseptr(1,57,maxx-1,maxy-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())
	{
		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,y);

	}
}
예제 #7
0
int user_new()
{
	int a,b;
	restrictmouseptr(0,0,xmax,20);
	hidemouseptr();
	a=textwidth("This Action will erase current drawing, Continue?")+10;
	setfillstyle(1,BLUE);
	bar(0,0,xmax,20);
	settextstyle(0,0,1);
	setcolor(BLACK);
	outtextxy(10,5,"This Action will erase current drawing, Continue?");
	setfillstyle(1,CYAN);
	bar((a+18),1,(a+18+textwidth("Ya")+2),18);
	outtextxy((a+20),5,"Ya");
	b=a+textwidth("Ya")+10;
	bar((b+18),1,(b+18+textwidth("Na")+2),18);
	outtextxy((b+20),5,"Na");
	showmouseptr();
	for(;;)
	{	
		getmousepos(&button,&mousex,&mousey);
		if(mousex>(a+20)&&mousex<b+10&&button==1)      //new confirm
		{
			hidemouseptr();
			initmouse();
			draw_canvas_default();
			top_panel_default();
			top_panel_buttons(tool_but_num,0,1);
			showmouseptr();
			arrcnt=-1;
			return 1;
		}
	else if(mousex>b+20&&mousex<(b+36)&&button==1)        //deny new
		{
			hidemouseptr();
			initmouse();
			top_panel_default();
			top_panel_buttons(tool_but_num,0,1);
			showmouseptr();
			return 0;
		}
	}
}
예제 #8
0
void top_message(char *message)
{
	top_panel_default();
	restrictmouseptr(0,0,xmax,20);
	hidemouseptr();
	setcolor(BLACK);
	outtextxy(10,3,message);
	showmouseptr();
	for(;;)
	{	
		getmousepos(&button,&mousex,&mousey);
		if(mousex>619&&button==1)      
		{
			hidemouseptr();
			button_hover((xmax-13),4,(xmax-4),11);
			initmouse();
			showmouseptr();
			return;
		}
	}
}
예제 #9
0
void main()
{int gd=DETECT,gm;
initgraph(&gd,&gm,"e:\\tc\\bgi");
int button,x,y;
restrictmouseptr(55,445,585,445);  //55,445,585,455

xx: int yy;
shakil ob;
ob.life();
ob.get();
ob.bo1();
ob.pic();
while(1)
{
 getmousepos(&button,&x,&y);
 ob.calcu(x,y);
 ob.show();
 int a=ob.oo+ob.mn;
 if(a>=25)
  a=25;
 delay(40-a);
 if((button & 2)==2)
 {goto xy;
  }
 if((button & 1)==1)
 ob.free();
 if(ob.li==0)
 {outtextxy(30,300,"IF YOU WANT TO PLAY AGAIN PRESS 1 OR OTHED");
  scanf("%d",&yy);
  if(yy==1)
  goto xx;
  else
  goto xy;
 }
}
xy:

closegraph();
}
예제 #10
0
void shownumbers(int x1,int y1,int x2,int y2)
{
int k;
restrictmouseptr(0,400,getmaxx(),getmaxy());
setcolor(12);
settextstyle(0,0,0);
outtextxy(20,410,"Enter the number or click any of the following");
setcolor(RED);
	for(k=0;k<=9;k++)
	{
	settextstyle(0,0,1);
	setfillstyle(SOLID_FILL,CYAN);
	bar(x1,y1,x2,y2);
	rectangle(x1,y1,x2,y2);
	if(k==0)
	{
	outtextxy(x1+20,y1+20,"0");
	}
	if(k==1)
	{
	outtextxy(x1+20,y1+20,"1");
	}
	if(k==2)
	{
	outtextxy(x1+20,y1+20,"2");
	}
	if(k==3)
	{
	outtextxy(x1+20,y1+20,"3");
	}
	if(k==4)
	{
	outtextxy(x1+20,y1+20,"4");
	}
	if(k==5)
	{
	outtextxy(x1+20,y1+20,"5");
	}
	if(k==6)
	{
	outtextxy(x1+20,y1+20,"6");
	}
	if(k==7)
	{
	outtextxy(x1+20,y1+20,"7");
	}
	if(k==8)
	{
	outtextxy(x1+20,y1+20,"8");
	}
	if(k==9)
	{
	outtextxy(x1+20,y1+20,"9");
	}
	x1=x2;
	x2=x2+40;
	}
	setfillstyle(SOLID_FILL,8);
	setcolor(BLUE);
	bar(x1+100,y1+15,getmaxx()-10,y2);
	rectangle(x1+100,y1+15,getmaxx()-10,y2);
	rectangle(x1+102,y1+17,getmaxx()-12,y2-2);
	setcolor(BLUE);
	outtextxy(x1+130,y1+25,"C");
	setcolor(LIGHTCYAN);
	outtextxy(x1+138,y1+25,"ancel");
}
예제 #11
0
void main()
{

// VARIABLE DECLARATIONS

int i=0,j=0,a,front=-1,rear=-1;
char ch,ch1;
int item;

// FUNCTION PROTOTYPE DECLARATIONS

void show();
void slidebar(int *rear,int *front);
void showqueuesize();
void slidebar();
void cpoiters();
void drawq();
void moveptrs(int *rear,int *front);
void insertq(int *rear,char c);
void deleteq(int *front);
void qdelete(int q[],int rear,int front);
void hidequeueinfo();
void shownumbers(int x1,int y1,int x2,int y2);
int initmouse();
void getmousepos(int *button,int *x,int *y);
void showmouseptr();
void restrictmouseptr(int a,int b,int c,int d);
void exitbutton(int x1,int y1,int x2,int y2,int e_x,int e_y,int xit_x,int xit_y);
void zoomin();

// CHECKING THE GRAPHICS DRIVER

int gd=DETECT,gm,maxx,maxy,x,y,button;
initgraph(&gd,&gm,"c:\\TC");

// GET THE MAXIMUM X AND Y CO ORDINATES

	maxx=getmaxx();
	maxy=getmaxy();

// DRAW THE BORDER FOR THE WINDOW

	rectangle(0,0,maxx,maxy);

// SET THE AREA WITHIN THE SCREEN WHERE GRAPHICAL O/P DISPLAYED

	setviewport(1,1,maxx-1,maxy-1,1);

// WRITE THE HEADDING

	gotoxy(150,1);
	settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
	setcolor(WHITE);
	setbkcolor(216);
	settextjustify(0,2);
	outtextxy(220,2," LINEAR QUEUE ");
	setcolor(RED);
	settextstyle(8,HORIZ_DIR,3);
	outtextxy(40,35,"DEVELOPED IN 'C'  : IT'S A KVSM PRODUCT");
	settextstyle(0,HORIZ_DIR,0);

// INITIALIZE MOUSE,IF IT DOESN'T GET INITIALIZED CLOSE GRAPHICS MODE

	if (initmouse()==0)
	{
		closegraph();
		restorecrtmode();
		printf("\nMouse Driver not installed");
		exit(1);
	}

// IF MOUSE DRIVER INITIALISED THEN
// RESTRICT THE MOUSE POINTER WITHIN THE COORDINATES GIVEN GIVEN BELOW

	restrictmouseptr(1,57,maxx-1,maxy-1);

// SHOW THE MOUSE POINTER

	showmouseptr();

// SET THE TEXT COLOR TO WHITE

	setcolor(WHITE);
	line(0,70,getmaxx(),70);
	line(0,400,getmaxx(),400);

	setcolor(14);
	outtextxy(65,115,"QUEUE OPERATIONS                      QUEUE STATUS");
	outtextxy(140,440,"Press the Key that is Highlighted or use Mouse.");
	setcolor(CYAN);
	line(65,125,190,125);
	line(368,125,464,125);

// CALL THE SHOW FUNCTION TO DRAW THE VARIOUS BUTTONS

	show();

// DRAW THE QUEUE

	drawq();

// DRAW THE POINTERS THAT IS FRONT AND REAR

	moveptrs(&rear,&front);

// SET THE LABEL M THAT WILL BE USED LATER FOR UNCONDITIONAL JUMP

	m:

// GO ON CHECKING WHETHER A KEY IS PRESSED OR NOT

	while (i==0)
	       {
	       if (kbhit())
	       {
	       ch=getche();

	       // CHECK IF THE KEY PRESSED IS E OR e
	       switch(ch)
	       {
	       case 'e':
	       case 'E':

	       {
	       // CALL THE FUNCTION THAT WILL BE FOR EXIT
	       zoomin();
	       }
	       reset:
	       case 'R':
	       case 'r':
	       {
	       // CALL THE RESET QUEUE FUNCTION
	       hidequeueinfo();
	       // CALL THE PROGRESSBAR
	       slidebar(&rear,&front);
	       // AGAIN DRAW THE QUEUE
	       drawq();
	       restrictmouseptr(1,57,maxx-1,maxy-1);
	       goto m;
	       }
	       queueinfo:
	       case 'A' :
	       case 'a':
	       {
	       // CALL THE FUNCTION TO GIVE INFORMATION ABOUT QUEUE
	       hidequeueinfo();
	       showqueuesize();
	       goto m;
	       }
	       delet:
	       case 'D':
	       case 'd':
	       {
	       //  CALL THE DELETE QUEUE OPERATIONS
	       hidequeueinfo();
	       deleteq(&front);
	       // CHECK IF QUEUE IS EMPTY, IF SO PRINT THE MESSAGE
		       if(rear==-1 || front==5 ||rear<front)
			{
			// CLEAR THE INFO, THERE IN INFORMATION PART
			hidequeueinfo();
			// DISPLAY THE TEXT IN THE INFORMATION PART
			outtextxy(200,430,"Queue is empty, you can't delete");
			}
			else
			{
			front=front+1;
			moveptrs(&rear,&front);
			}
		goto m;
	       }
	       ins:
	       case 'I':
	       case 'i':
	       {
	       // HERE IS THE OPERATIONS FOR INSERTING AN ELEMENT
	       hidequeueinfo();
	       if(rear==4)
			{
			hidequeueinfo();
			outtextxy(200,430,"Queue is full, you can't insert");
			goto m;
			}

	       // SHOWS THE NUMBERS AND CANCEL BUTTON
	       shownumbers(20,430,60,470);
	       // CHECK FOR WHAT KEY PRESSED

	       n:

	       while(j==0)
	       {
		 if (kbhit())
		  {
		   ch1=getche();

			       if(front==-1)
			       {
			       front=front+1;
			       }
		   switch(ch1)
		   {
		   cancel:
		   case 'C':
		   case 'c':
		       {
		       hidequeueinfo();
		       restrictmouseptr(1,57,maxx-1,maxy-1);
		       goto m;
		       }
		   zero:
		   case '0':
		       {
			       insertq(&rear,'0');
			       rear=rear+1;
			       moveptrs(&rear,&front);
			       hidequeueinfo();
			       restrictmouseptr(1,57,maxx-1,maxy-1);
			       goto m;
		       }
		   one:
		   case '1':
		       {
			       insertq(&rear,'1');
			       rear=rear+1;
			       moveptrs(&rear,&front);
			       hidequeueinfo();
			       restrictmouseptr(1,57,maxx-1,maxy-1);
			       goto m;
		       }
		   two:
		   case '2':
		       {
			       insertq(&rear,'2');
			       rear=rear+1;
			       moveptrs(&rear,&front);
			       hidequeueinfo();
			       restrictmouseptr(1,57,maxx-1,maxy-1);
			       goto m;
		       }
		   three:
		  case '3':
		       {
			       insertq(&rear,'3');
			       rear=rear+1;
			       moveptrs(&rear,&front);
			       hidequeueinfo();
			       restrictmouseptr(1,57,maxx-1,maxy-1);
			       goto m;
		       }
		  four:
		   case '4':
		       {
			       insertq(&rear,'4');
			       rear=rear+1;
			       moveptrs(&rear,&front);
			       hidequeueinfo();
			       restrictmouseptr(1,57,maxx-1,maxy-1);
			       goto m;
		       }
		   five:
		   case '5':
		       {
			       insertq(&rear,'5');
			       rear=rear+1;
			       moveptrs(&rear,&front);
			       hidequeueinfo();
			       restrictmouseptr(1,57,maxx-1,maxy-1);
			       goto m;
		       }
		   six:
		   case '6':
		       {
			       insertq(&rear,'6');
			       rear=rear+1;
			       moveptrs(&rear,&front);
			       hidequeueinfo();
			       restrictmouseptr(1,57,maxx-1,maxy-1);
			       goto m;
		       }
		   seven:
		   case '7':
		       {
			       insertq(&rear,'7');
			       rear=rear+1;
			       moveptrs(&rear,&front);
			       hidequeueinfo();
			       restrictmouseptr(1,57,maxx-1,maxy-1);
			       goto m;
		       }
		  eight:
		   case '8':
		       {
			       insertq(&rear,'8');
			       rear=rear+1;
			       moveptrs(&rear,&front);
			       hidequeueinfo();
			       restrictmouseptr(1,57,maxx-1,maxy-1);
			       goto m;
		       }
		   nine:
		   case '9':
		       {
			       insertq(&rear,'9');
			       rear=rear+1;
			       moveptrs(&rear,&front);
			       hidequeueinfo();
			       restrictmouseptr(1,57,maxx-1,maxy-1);
			       goto m;
		       }
		   default :
				hidequeueinfo();
				outtextxy(200,430,"Invalid Key Pressed ! Press a valid key");
				delay(550);
				hidequeueinfo();
				shownumbers(20,430,60,470);
				goto n;
		   }
		}
		else
		{
		//write code here to press the 0-----9 and cancel
		       getmousepos(&button,&x,&y);
		       if((button & 1)==1)
		       {
			       if(front==-1)
			       {
			       front=front+1;
			       }
		       }
		       if( (x>500 && x<getmaxx()-10 && y>445 && y<470) && (button & 1)==1)
			{
			goto cancel;
			}
		       if( (x>20 && x<60 && y>430 && y<470) && (button & 1)==1)
			{
			goto zero;
			}
		       if( (x>60 && x<100 && y>430 && y<470) && (button & 1)==1)
			{
			goto one;
			}
		       if( (x>100 && x<140 && y>430 && y<470) && (button & 1)==1)
			{
			goto two;
			}
		       if( (x>140 && x<180 && y>430 && y<470) && (button & 1)==1)
			{
			goto three;
			}
		       if( (x>180 && x<220 && y>430 && y<470) && (button & 1)==1)
			{
			goto four;
			}
		       if( (x>220 && x<260 && y>430 && y<470) && (button & 1)==1)
			{
			goto five;
			}
		       if( (x>260 && x<300 && y>430 && y<470) && (button & 1)==1)
			{
			goto six;
			}
		       if( (x>300 && x<340 && y>430 && y<470) && (button & 1)==1)
			{
			goto seven;
			}
		       if( (x>340 && x<380 && y>430 && y<470) && (button & 1)==1)
			{
			goto eight;
			}
		       if( (x>380 && x<420 && y>430 && y<470) && (button & 1)==1)
			{
			goto nine;
			}
		}
	}
	}
	 default :
			hidequeueinfo();
			outtextxy(220,420,"Please Press a Valid Key");
			goto m;
	 }
	 }
	 // ELSE CONDITION FOR THE IF AFTER THE FIRST WHILE
	 else
	       {

		  getmousepos(&button,&x,&y);
		  if( (x>50 && x<200 && y<370 && y>350) && (button & 1)==1)
			{
			//exit button click
			zoomin();
			}
		  if( (x>50 && x<200 && y>150 && y<170) && (button & 1)==1)
			{
			//clicked the queueinfo button
			goto queueinfo;
			}
		  if( (x>50 && x<200 && y>200 && y<220) && (button & 1)==1)
			{
			//clicked the insert button
			goto ins;
			}

		  if( (x>50 && x<200 && y>250 && y<270) && (button & 1)==1)
			{
			//clicked the delete button
			delay(500);
			goto delet;
			}
		  if( (x>50 && x<200 && y>300 && y<320) && (button & 1)==1)
			{
			//clicked the reset button
			goto reset;
			}

		}


	}

getche();
}
예제 #12
0
void canvas()
{	
	int button,mousex,mousey;	//local mouse variables
	if(cur_panel==0&&canvas_flag!=1)
	{
	top_panel_buttons(tool_but_num,0,5);
	hover_text(cur_tool);
	button_click((2+cur_tool*20),2,(18+cur_tool*20),18);
	canvas_flag=1;
	}
	else if(cur_panel==1&&canvas_flag!=2)
	{
	hover_text(cur_tool);
	top_panel_buttons(buttons_data[cur_tool-1],0,5);
	button_click((2+cur_style*20),2,(18+cur_style*20),18);
	canvas_flag=2;
	}
	hover_text(cur_tool);
	getmousepos(&button,&mousex,&mousey);
	for(;mousey>20;getmousepos(&button,&mousex,&mousey))
	{
		if(button==1)
		{
			restrictmouseptr(0,27,xmax,ymax);
			switch(cur_tool)
			{
				case 4: user_text(mousex,mousey);
						break;
				case 5: pencil();
						break;
				case 6: brush(2);
						break;
				case 7: bfill(mousex,mousey);
						break;
				case 8: brush(1);
						break;
				case 9: user_pickcolor();
						break;
				case 10: user_line();
						break;
				case 11: drawRectangle();
						break;
				case 12: drawEllipse();
						break;
				case 13: drawSpray();
						break;
				case 14: drawSpiral();
						break;
				case 15:user_clip();
						break;
				case 16:user_poly();
						break;
				case 17:drawCircle(cur_style);
						break;

			}

		}
		else
		{
			restrictmouseptr(0,0,xmax,ymax);
			
		}
	}
}
main()
{
   int gd = DETECT,gm;

   int maxx,maxy,x,y,button,prevx,prevy,temp1,temp2,key,color;
   char ch = 'f' ;            // default free-hand drawing

   initgraph(&gd,&gm,"C:\\TC\\BGI");

   maxx = getmaxx();
   maxy = getmaxy();

   setcolor(BLUE);
   rectangle(0,0,maxx,maxy);

   setcolor(WHITE);
   settextstyle(SANS_SERIF_FONT,HORIZ_DIR,2);
   outtextxy(maxx/2-180,maxy-28,"<a href="http://www.programmingsimplified.com"">www.programmingsimplified.com"</a>);

   draw_color_panel();
   draw_shape_panel();

   setviewport(1,1,maxx-1,maxy-1,1);

   restrictmouseptr(1,1,maxx-1,maxy-1);
   showmouseptr();
   rectangle(2,2,518,427);
   setviewport(1,1,519,428,1);

   while(1)
   {
      if(kbhit())
      {
         key = get_key();

         if( key == 1 )
         {
            closegraph();
            exit(0);
         }
      }

      getmousepos(&button,&x,&y);

      if( button == 1 )
      {
         if( x > 4 && x < 635 && y > 431 && y < 457 )
            change_color( x, y );
         else if ( x > 529 && x < 625 && y > 40 && y < 250 )
             ch = change_shape( x, y );

         temp1 = x ;
         temp2 = y ;

         if ( ch == 'f' )
         {
            hidemouseptr();
            while( button == 1 )
            {
               line(temp1,temp2,x,y);
               temp1 = x;
               temp2 = y;
               getmousepos(&button,&x,&y);
            }
            showmouseptr();
         }

         while( button == 1)
            getmousepos(&button,&x,&y);

         /* to avoid interference of mouse while drawing */
         hidemouseptr();

         if( ch == 'p')
            putpixel(x,y,getcolor());

         else if ( ch == 'b' )
         {
            setfillstyle(SOLID_FILL,getcolor());
            bar(temp1,temp2,x,y);
         }
         else if ( ch == 'l')
            line(temp1,temp2,x,y);
         else if ( ch == 'e')
            ellipse(temp1,temp2,0,360,abs(x-temp1),abs(y-temp2));
         else if ( ch == 'r' )
            rectangle(temp1,temp2,x,y);
         else if ( ch == 'c' )
         {
            ch = 'f';          // setting to freehand drawing
            clearviewport();
            color = getcolor();
            setcolor(WHITE);
            rectangle(2,2,518,427);
            setcolor(color);
         }

         showmouseptr();
      }
   }
}
예제 #14
0
main()
{
int gd=DETECT,gm,maxx,maxy,x,y,xp,yp,button,ch=0,i=1,flag=0;
initgraph(&gd,&gm,"");
maxx=getmaxx();
maxy=getmaxy();
setbkcolor(BLACK);
setlinestyle(SOLID_LINE,1,3);
rectangle(0,56,maxx,maxy);
setviewport(1,1,maxx-1,maxy-1,1);
/*gotoxy(10,1);
printf("1=CIRCLE");
gotoxy(20,1);
printf("2=LINE");*/
setcolor(LIGHTCYAN);
settextstyle(5,0,3);
outtextxy(200,0,"CATCH ME IF YOU CAN");

if(initmouse()==0)
{
 closegraph();
 restorecrtmode();
 printf("mouse driver not loaded");
 getch();
 exit(1);
}
restrictmouseptr(1,57,maxx-1,maxy-1);
getmousepos(&button,&x,&y);
xp=x;
yp=y;
showmouseptr();
while(!kbhit())
{
setcolor(i);
setlinestyle(SOLID_LINE,0,2);
xp=x;
yp=y;
getmousepos(&button,&x,&y);
while((button & 1)==1)
{
setcolor(RED);
circle(xp,yp,x-xp);
delay(20);
setcolor(BLACK);
circle(xp,yp,x-xp);
getmousepos(&button,&x,&y);
flag=1;
}
if(flag==1)
{
setcolor(RED);
circle(xp,yp,x-xp);
flag=0;
}
if(xp!=x && yp!=y)
{
setcolor(i);
settextstyle(5,0,1);
outtextxy(380,440,"designed by:Soumen Mukherjee");
i++;
if(i==15)
i=1;
}
}
ch=getch();
if(ch==13)
{
closegraph();
restorecrtmode();
exit(1);
}
if(ch==1)
cleardevice();
main();
}
void mouse()
{
    initmouse();
    restrictmouseptr();
    showmouseptr();
}