Graphics editor in c++
I am trying to develop a simple graphics editor in C++. I'm relatively new to graphics and mouse programming. My problem is that i can't flood fill the shape that's drawn with the selected color.I'd really appreciate some help.

   
      #include<iostream.h> 
      #include<conio.h>
      #include<graphics.h>  
      #include<math.h>  
      #include<dos.h>
     union REGS in,out;

    int callmouse()
    {
     in.x.ax=1;
     int86(51,&in,&out);
     return 1;
    }

    int mouse_position(int *xpos,int *ypos,int *click)
     {
      in.x.ax=3;
      int86(51,&in,&out);
      *click=out.x.bx;
      *xpos=out.x.cx;
      *ypos=out.x.dx;
       return 1;
      }

     int mouse_hide()
    {
       in.x.ax=2;
     int86(51,&in,&out);
     return 1;
     }

    void set_position(int &xpos,int &ypos)
     {
      in.x.ax=4;
      in.x.cx=xpos;
      in.x.dx=ypos;
      int86(51,&in,&out);
     }

    void restrictmouseptr(int x1,int y1,int x2,int y2)
     {
      in.x.ax=7;
      in.x.cx=x1;
      in.x.dx=x2;
      int86(51,&in,&out);
      in.x.ax=8;
      in.x.cx=y1;
      in.x.dx=y2;
      int86(51,&in,&out);
     }
     void draw_options()
    {
      setcolor(WHITE);
     rectangle(0,0,120,80);
     rectangle(0,80,120,160);
     rectangle(0,160,120,240);
     rectangle(0,240,120,320);
      setcolor(GREEN);
     settextstyle(TRIPLEX_FONT,0,3);
     outtextxy(10,10,"RECTANGLE");
     outtextxy(10,100,"LINE");
     outtextxy(10,180,"CIRCLE");
     outtextxy(10,260,"ELLIPSE");
      setcolor(WHITE);
    }

    void colour_pallete()
     { int x,y,c;
       int maxcolor=getmaxcolor();
        for(x=10,c=1,y=400;c<=maxcolor;x+=40,c++)
         {
           setfillstyle(SOLID_FILL,c);
           bar(x,y+20,x+20,y);
         }
     }

     int choose_shape(int x,int y)
       {
        if(0<x&&x<120&&0<y&&y<80)
         return 1;
        if(0<x&&x<120&&80<y&&y<160)
         return 2;
        if(0<x&&x<120&&160<y&&y<240)
         return 3;
        if(0<x&&x<120&&240<y&&y<320)
         return 4;
       }

    int pick_color(int x,int y)
     { 
       int clr;
       for(int temp=10,i=1;temp<=580,i<=15;temp+=40,i++)
        {
          if(temp<=x&&x<temp+20&&400<y&&y<420)
          setcolor(i);
          clr=getcolor();
          return clr;
        }
      }
     void main()
     {
       int x,y,cl,a,b,xl,yl,xr,yr,t1,t2,shape,cl1,clc;
       clrscr();

     int get_driver=DETECT,get_mode;
     initgraph(&get_driver,&get_mode,"C:\BGI");

     restrictmouseptr(0,0,640,480); //for being able to use entire screen

     setcolor(BLUE);
     rectangle(0,0,639,479);
     setcolor(0);

     draw_options();
     colour_pallete();

     a=100,b=400;                  // setting initial position
     set_position(a,b);

     callmouse();

    while(1)

    {
     if(kbhit())
      break;
     mouse_position(&x,&y,&cl);

     if(cl==1)
      {
	if(0<x&&x<120&&0<y&&y<320)
	 shape=choose_shape(x,y);
	//if(10<x<210&&400<y&&y<420);
	 //clr=pick_color(x,y)
	  if(shape==1)
	   {
	  mouse_position(&x,&y,&cl);
	  t1=x;
	  t2=y;

	  while(cl==1)
	   {mouse_position(&x,&y,&cl);}
	    rectangle(t1,t2,x,y);

	    mouse_position(&x,&y,&cl1);  //picking a color
	    //cout<<x<<" "<<y;
	     if(cl1==1)
	      {
	       if(10<x&&x<590&&400<y&&y<420)
		{ int color_to_fill=pick_color(x,y);


		  mouse_position(&x,&y,&clc);   //for seed point
		   if(clc==1)
		  {floodfill(x,y,color_to_fill);}
		 }
	       }
	      // }
	      }
	 else if(shape==2)
	  {
	    mouse_position(&x,&y,&cl);
	    t1=x;
	    t2=y;

	    while(cl==1)
	     {mouse_position(&x,&y,&cl);}
	     line(t1,t2,x,y);
	  }
	else if(shape==3)
	  {
	   mouse_position(&x,&y,&cl);
	    t1=x;
	    t2=y;

	    while(cl==1)
	     {mouse_position(&x,&y,&cl);}
	      circle(t1,t2,abs(x-t1));
	  }
	else if(shape==4)
	  {
	    mouse_position(&x,&y,&cl);
	     t1=x;
	     t2=y;

	    while(cl==1)
	     {mouse_position(&x,&y,&cl);}
	      ellipse(t1,t2,0,360,abs(x-t1),abs(y-t2));
	   }
      }

    }
      getch();
      mouse_hide();
      cout<<"\nPress any key to exit ";
      getch();
    }

Graphics editor in c++
===

I am trying to develop a simple graphics editor in C++. I'm relatively new to graphics and mouse programming. My problem is that i can't flood fill the shape that's drawn with the selected color.I'd really appreciate some help.

   
      #include<iostream.h> 
      #include<conio.h>
      #include<graphics.h>  
      #include<math.h>  
      #include<dos.h>
     union REGS in,out;

    int callmouse()
    {
     in.x.ax=1;
     int86(51,&in,&out);
     return 1;
    }

    int mouse_position(int *xpos,int *ypos,int *click)
     {
      in.x.ax=3;
      int86(51,&in,&out);
      *click=out.x.bx;
      *xpos=out.x.cx;
      *ypos=out.x.dx;
       return 1;
      }

     int mouse_hide()
    {
       in.x.ax=2;
     int86(51,&in,&out);
     return 1;
     }

    void set_position(int &xpos,int &ypos)
     {
      in.x.ax=4;
      in.x.cx=xpos;
      in.x.dx=ypos;
      int86(51,&in,&out);
     }

    void restrictmouseptr(int x1,int y1,int x2,int y2)
     {
      in.x.ax=7;
      in.x.cx=x1;
      in.x.dx=x2;
      int86(51,&in,&out);
      in.x.ax=8;
      in.x.cx=y1;
      in.x.dx=y2;
      int86(51,&in,&out);
     }
     void draw_options()
    {
      setcolor(WHITE);
     rectangle(0,0,120,80);
     rectangle(0,80,120,160);
     rectangle(0,160,120,240);
     rectangle(0,240,120,320);
      setcolor(GREEN);
     settextstyle(TRIPLEX_FONT,0,3);
     outtextxy(10,10,"RECTANGLE");
     outtextxy(10,100,"LINE");
     outtextxy(10,180,"CIRCLE");
     outtextxy(10,260,"ELLIPSE");
      setcolor(WHITE);
    }

    void colour_pallete()
     { int x,y,c;
       int maxcolor=getmaxcolor();
        for(x=10,c=1,y=400;c<=maxcolor;x+=40,c++)
         {
           setfillstyle(SOLID_FILL,c);
           bar(x,y+20,x+20,y);
         }
     }

     int choose_shape(int x,int y)
       {
        if(0<x&&x<120&&0<y&&y<80)
         return 1;
        if(0<x&&x<120&&80<y&&y<160)
         return 2;
        if(0<x&&x<120&&160<y&&y<240)
         return 3;
        if(0<x&&x<120&&240<y&&y<320)
         return 4;
       }

    int pick_color(int x,int y)
     { 
       int clr;
       for(int temp=10,i=1;temp<=580,i<=15;temp+=40,i++)
        {
          if(temp<=x&&x<temp+20&&400<y&&y<420)
          setcolor(i);
          clr=getcolor();
          return clr;
        }
      }
     void main()
     {
       int x,y,cl,a,b,xl,yl,xr,yr,t1,t2,shape,cl1,clc;
       clrscr();

     int get_driver=DETECT,get_mode;
     initgraph(&get_driver,&get_mode,"C:\BGI");

     restrictmouseptr(0,0,640,480); //for being able to use entire screen

     setcolor(BLUE);
     rectangle(0,0,639,479);
     setcolor(0);

     draw_options();
     colour_pallete();

     a=100,b=400;                  // setting initial position
     set_position(a,b);

     callmouse();

    while(1)

    {
     if(kbhit())
      break;
     mouse_position(&x,&y,&cl);

     if(cl==1)
      {
	if(0<x&&x<120&&0<y&&y<320)
	 shape=choose_shape(x,y);
	//if(10<x<210&&400<y&&y<420);
	 //clr=pick_color(x,y)
	  if(shape==1)
	   {
	  mouse_position(&x,&y,&cl);
	  t1=x;
	  t2=y;

	  while(cl==1)
	   {mouse_position(&x,&y,&cl);}
	    rectangle(t1,t2,x,y);

	    mouse_position(&x,&y,&cl1);  //picking a color
	    //cout<<x<<" "<<y;
	     if(cl1==1)
	      {
	       if(10<x&&x<590&&400<y&&y<420)
		{ int color_to_fill=pick_color(x,y);


		  mouse_position(&x,&y,&clc);   //for seed point
		   if(clc==1)
		  {floodfill(x,y,color_to_fill);}
		 }
	       }
	      // }
	      }
	 else if(shape==2)
	  {
	    mouse_position(&x,&y,&cl);
	    t1=x;
	    t2=y;

	    while(cl==1)
	     {mouse_position(&x,&y,&cl);}
	     line(t1,t2,x,y);
	  }
	else if(shape==3)
	  {
	   mouse_position(&x,&y,&cl);
	    t1=x;
	    t2=y;

	    while(cl==1)
	     {mouse_position(&x,&y,&cl);}
	      circle(t1,t2,abs(x-t1));
	  }
	else if(shape==4)
	  {
	    mouse_position(&x,&y,&cl);
	     t1=x;
	     t2=y;

	    while(cl==1)
	     {mouse_position(&x,&y,&cl);}
	      ellipse(t1,t2,0,360,abs(x-t1),abs(y-t2));
	   }
      }

    }
      getch();
      mouse_hide();
      cout<<"\nPress any key to exit ";
      getch();
    }
