Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
13
Добавлен:
17.04.2013
Размер:
8.33 Кб
Скачать
#include <conio.h>
#include <graphics.h>
#include "btn.h"
#include "ob.h"

int clr=1;
char c;
Buttons btn1,btn2,btn3,btn4,btn5,btn6,btn7,btn8;
void  few();


void change_color()
{
  if(clr==15) clr=0;
	setcolor(clr++);
				   }

void Clrscr()
{
int box1[10]=
			 { 101,11,
			   101,459,
			   629,459,
			   629,11,
			   101,11
					  };
setcolor(0);
setfillstyle(SOLID_FILL,0);
fillpoly(5,box1);
}

void ekran()
{
//а Ў®в  б нЄа ­®¬
int box[10]=
			 { 100,10,
			   100,460,
			   630,460,
			   630,10,
			   100,10
					  };
setcolor(GREEN);
drawpoly(5,box);
btn1.Btn_Up(20,50,"POINT");
btn2.Btn_Up(20,100,"LINE");
btn3.Btn_Up(20,150,"RECT.");
btn4.Btn_Up(20,200,"CIRCLE");
btn5.Btn_Up(20,250,"CLEAR");
btn6.Btn_Up(20,300,"COLOR");
btn7.Btn_Up(20,350,"REDACT");
btn8.Btn_Up(20,400,"FILL");
setcolor(13);
outtextxy(100,1,"梥⮢ п Ї «Ёва :");
int i;
for(i=1;i<16;i++)
{
  setfillstyle(SOLID_FILL,i);
  bar(230+i*10,1,240+i*10,8);
				 }
}

void restore()
{
 Clrscr();
  int i;
  for(i=0;i<nom;i++)
 {
  if (ptr[i].name==1)  {Pixel a; a.drawpix2(ptr[i].x11,ptr[i].y11,ptr[i].col);}
  if (ptr[i].name==2)  {Line  b; b.drawline2(ptr[i].x11,ptr[i].y11,ptr[i].x22,ptr[i].y22,ptr[i].col);}
  if (ptr[i].name==3)  {Rect  c; c.drawrect2(ptr[i].x11,ptr[i].y11,ptr[i].x22,ptr[i].y22,ptr[i].col,ptr[i].f_col);}
  if (ptr[i].name==4)  {Circle d; d.drawcirc2(ptr[i].x11,ptr[i].y11,ptr[i].rad,ptr[i].col,ptr[i].f_col);}
			  }
				 }

void restore2()
{
 Clrscr();
  hidemouse();
  int i;
  for(i=0;i<=nom;i++)
 {
  if (ptr[i].name==1)  {Pixel a; a.drawpix2(ptr[i].x11,ptr[i].y11,ptr[i].col);}
  if (ptr[i].name==2)  {Line  b; b.drawline2(ptr[i].x11,ptr[i].y11,ptr[i].x22,ptr[i].y22,ptr[i].col);}
  if (ptr[i].name==3)  {Rect  c; c.drawrect2(ptr[i].x11,ptr[i].y11,ptr[i].x22,ptr[i].y22,ptr[i].col,ptr[i].f_col);}
  if (ptr[i].name==4)  {Circle d; d.drawcirc2(ptr[i].x11,ptr[i].y11,ptr[i].rad,ptr[i].col,ptr[i].f_col);}
			  }
  showmouse();
				 }

void filr(int lx,int ly,int rx,int ry)
{
 hidemouse();
 restore();
 setfillstyle(SOLID_FILL,clr);
 bar(lx,ly,rx,ry);
 in_mas(3,lx,ly,rx,ry,0,clr,1);
 showmouse();
}

void filc(int lx,int ly,int rd)
{
 hidemouse();
 restore();
 setfillstyle(SOLID_FILL,clr);
 setcolor(clr);
 fillellipse(lx,ly,rd,rd);
 in_mas(4,lx,ly,0,0,rd,clr,1);
 showmouse();
}

int slx1,sly1,slx2,sly2;

void drawselect(int cl)
{
mouselimit(101,11,629,459);
  if(mousepressed()!=0)
	  {
		slx1=mousegetx();
		sly1=mousegety();
	while(mousepressed()!=0)
		{
		slx2=mousegetx();
		sly2=mousegety();
		setwritemode(XOR_PUT);
		setcolor(cl);
		hidemouse();
		rectangle(slx1,sly1,slx2,sly2);
		showmouse();
		delay(30);
		hidemouse();
		rectangle(slx1,sly1,slx2,sly2);
		showmouse();
		}                }
	   int z;
	   if (slx1>slx2) {z=slx1; slx1=slx2; slx2=z;}
	   if (sly1>sly2) {z=slx1; slx1=slx2; slx2=z;}
				  }
void clrstr()
{
 setcolor(0);
 outtextxy(100,465,"1-г¤ «Ёвм  2-Ё§¬Ґ­Ёвм жўҐв  3-ЇҐаҐ¬ҐбвЁвм  4-§ «ЁўЄ   5-®в¬Ґ­ ");
	 }
void select(int sx,int sy,int ex,int ey)
{
  int i;
  for(i=0;i<=nom;i++)
 {
   if (((sx<=ptr[i].x11) && (sy<=ptr[i].y11) && (ex>=ptr[i].x11) && (ey>=ptr[i].y11))|| //
	  ((sx<=ptr[i].x22) && (sy<=ptr[i].y22) && (ex>=ptr[i].x22) && (ey>=ptr[i].y22)))
	  {
		cons=i;
		setwritemode(XOR_PUT);
		setcolor(0);
		outtextxy(100,465,"ўл¤Ґ«ЁвҐ дЁЈгаг");
		setcolor(13);
 outtextxy(100,465,"1-г¤ «Ёвм  2-Ё§¬Ґ­Ёвм жўҐв  3-ЇҐаҐ¬ҐбвЁвм  4-§ «ЁўЄ   5-®в¬Ґ­ ");
		hidemouse();
	   switch (ptr[i].name)
		{    case 0: showmouse(); break;
			 case 1: while (1)
					{putpixel(ptr[i].x11,ptr[i].y11,15);
					 putpixel(ptr[i].x11,ptr[i].y11,4);
				   if (kbhit()) { c=getch();
				   if ((c=='1') || (c=='2') || (c=='3') || (c=='4') || (c=='5')) break;}}
				   few();
				   break;
			 case 2: while (1)
				   { setcolor(15);
				   line(ptr[i].x11,ptr[i].y11,ptr[i].x22,ptr[i].y22);
				   setcolor(3);
				   line(ptr[i].x11,ptr[i].y11,ptr[i].x22,ptr[i].y22);
				   if (kbhit()) { c=getch();
				   if ((c=='1') || (c=='2') || (c=='3') || (c=='4') || (c=='5')) break;}}
				   few();
				   break;
			case 3: while (1)
					{setcolor(15);
					 rectangle(ptr[i].x11,ptr[i].y11,ptr[i].x22,ptr[i].y22);
					 setcolor(4); delay(100);
					 rectangle(ptr[i].x11,ptr[i].y11,ptr[i].x22,ptr[i].y22);
					 if (kbhit()) { c=getch();
					 if ((c=='1') || (c=='2') || (c=='3') || (c=='4') || (c=='5')) break;}}
					 few(); break;
			case 4: while (1)
					{setcolor(15);
					 ellipse(ptr[i].x11,ptr[i].y11,0,360,ptr[i].rad,ptr[i].rad);
					 setcolor(7);
					 ellipse(ptr[i].x11,ptr[i].y11,0,360,ptr[i].rad,ptr[i].rad);
					 if (kbhit()) { c=getch();
					 if ((c=='1') || (c=='2') || (c=='3') || (c=='4') || (c=='5')) break;}}
					 few(); break;
					 }
					 }}
					 showmouse();
					 }

void otmena()
{
 setwritemode(COPY_PUT);
 hidemouse();
 if(ptr[cons].name==1) putpixel(ptr[cons].x11,ptr[cons].y11,ptr[cons].col);
 if(ptr[cons].name==2) {setcolor(ptr[cons].col);line(ptr[cons].x11,ptr[cons].y11,ptr[cons].x22,ptr[cons].y22);     }
 if(ptr[cons].name==3) {setcolor(ptr[cons].col);rectangle(ptr[cons].x11,ptr[cons].y11,ptr[cons].x22,ptr[cons].y22);}
 if(ptr[cons].name==4) {setcolor(ptr[cons].col);ellipse(ptr[cons].x11,ptr[cons].y11,0,360,ptr[cons].rad,ptr[cons].rad);}
 showmouse();
  }

void chang_color()
{
 setwritemode(COPY_PUT);
 hidemouse();
 setcolor(clr);
 setfillstyle(SOLID_FILL,clr);
 if(ptr[cons].name==1) {ptr[cons].col=clr;putpixel(ptr[cons].x11,ptr[cons].y11,clr);}
 if(ptr[cons].name==2) {ptr[cons].col=clr;line(ptr[cons].x11,ptr[cons].y11,ptr[cons].x22,ptr[cons].y22);     }
 if((ptr[cons].name==3)&&(ptr[cons].f_col==0)) {ptr[cons].col=clr;rectangle(ptr[cons].x11,ptr[cons].y11,ptr[cons].x22,ptr[cons].y22);}
 if((ptr[cons].name==3)&&(ptr[cons].f_col==1)) {ptr[cons].col=clr;bar(ptr[cons].x11,ptr[cons].y11,ptr[cons].x22,ptr[cons].y22);}
 if((ptr[cons].name==4)&&(ptr[cons].f_col==0)) {ptr[cons].col=clr;ellipse(ptr[cons].x11,ptr[cons].y11,0,360,ptr[cons].rad,ptr[cons].rad);}
 if((ptr[cons].name==4)&&(ptr[cons].f_col==1)) {ptr[cons].col=clr;fillellipse(ptr[cons].x11,ptr[cons].y11,ptr[cons].rad,ptr[cons].rad);}
 showmouse();
  clrstr();  }

void del()
{
 setwritemode(COPY_PUT);
 hidemouse();
 setfillstyle(SOLID_FILL,0);
 if(ptr[cons].name==1) {out_mas(cons);putpixel(ptr[cons].x11,ptr[cons].y11,0);}
 if(ptr[cons].name==2) {out_mas(cons);line(ptr[cons].x11,ptr[cons].y11,ptr[cons].x22,ptr[cons].y22);     }
 if((ptr[cons].name==3)&&(ptr[cons].f_col==0)) {out_mas(cons);rectangle(ptr[cons].x11,ptr[cons].y11,ptr[cons].x22,ptr[cons].y22);}
 if((ptr[cons].name==3)&&(ptr[cons].f_col==1)) {out_mas(cons);bar(ptr[cons].x11,ptr[cons].y11,ptr[cons].x22,ptr[cons].y22);}
 if((ptr[cons].name==4)&&(ptr[cons].f_col==0)) {out_mas(cons);ellipse(ptr[cons].x11,ptr[cons].y11,0,360,ptr[cons].rad,ptr[cons].rad);}
 if((ptr[cons].name==4)&&(ptr[cons].f_col==1)) {out_mas(cons);fillellipse(ptr[cons].x11,ptr[cons].y11,ptr[cons].rad,ptr[cons].rad);}
 showmouse();
 restore2();
			 }

void move()
{
 all t=ptr[cons];
  clrstr();
  del();
  hidemouse();
  if (t.name==2)  {Line  b;  b.Mdrawline(t.x11,t.y11,t.x22,t.y22,t.col);}
  if (t.name==3)  {Rect  c; c.Mdrawrect(t.x11,t.y11,t.x22,t.y22,t.col,t.f_col);}
  if (t.name==4)  {Circle  d; d.Mdrawcirc(t.x11,t.y11,t.rad,t.col,t.f_col);}
	  restore2();
		delay(200);
		}

void zakr()
{
clrstr();
if (ptr[cons].name==3) {
ptr[cons].f_col=1; ptr[cons].col=clr;}
if (ptr[cons].name==4) {
ptr[cons].f_col=1; ptr[cons].col=clr;}
 restore2();
}


void redact()
{
 c='0';
 setcolor(13);
 outtextxy(100,465,"ўл¤Ґ«ЁвҐ дЁЈгаг");
 while (1)
{
	mouselimit(0,11,629,459);
	while(mousepressed()!=0)
	{drawselect(15);
	 hidemouse();
	 select(slx1,sly1,slx2,sly2);
	 showmouse();
	 break; }
   if ((c=='1') || (c=='2') || (c=='3') || (c=='4') || (c=='5')) break;
	  }
  clrstr();
  //	restore2();
	}

void few()
{
			 switch (c)
			 {
			  case '1': del();          break;
			  case '2': chang_color();  break;
			  case '3': move();         break;
			  case '4': zakr();         break;
			  case '5': otmena();       break;
				  }
  clrstr();
  showmouse();
 }
Соседние файлы в папке GRAPH_RD