
{                                                                            }
{                              ALPAINT verze 2.0                             }
{                               Graficky editor                              }
{          Naprogramoval v jazyce Turbo - Pascal 7.0 : Pavel Kopecky         }
{                                                                            }
{                                                                            }

program alpaint2;
uses crt,graph,dos,myska;
var a,b,c,d,e,vel,vel2,font,r,vrchu,splvrchu,styl,rezim,color,bkcolor:integer;
    aa,bb,cc,sx,sy,x,y,zx,zy,zzx,zzy,but,sbut:word;
    velf,velf2:array [1..10,1..10] of integer;
    p:pointer;
    f,soub:text;
    inf1,inf2:file of integer;
    zn:char;
    but1,but2,but3,sbut1,sbut2,sbut3,muze,poprve,uplne_poprve,konc:boolean;
    st1,st2,txt,sou:string;
procedure kruznice (zx,zy,pol:integer);
var bodu,xf,yf,xs,ys,xd:integer;
          begin
          bodu:=25;
          xf:=zx+pol;
          yf:=zy;
          for xd:=1 to 38 do begin
                             xs:=round (zx+pol*cos(xd / 6));
                             ys:=round (zy+pol*sin(xd / 6));
                             line (xf,yf,xs,ys);
                             line (xf,yf,xf,yf);
                             xf:=xs;
                             yf:=ys;
                             end;
          end;
procedure elipsa (zx,zy,pol,pol2:integer);
var bodu,xf,yf,xs,ys,xd:integer;
          begin
          bodu:=25;
          xf:=zx+pol;
          yf:=zy;
          for xd:=1 to 38 do begin
                             xs:=round (zx+pol*cos(xd / 6));
                             ys:=round (zy+pol2*sin(xd / 6));
                             line (xf,yf,xs,ys);
                             line (xf,yf,xf,yf);
                             xf:=xs;
                             yf:=ys;
                             end;
          end;
procedure onoff;
begin
setwritemode (1);
if (x=sx) and (y=sy) then begin
line (x,y,x+5,y);
line (x,y,x+4,y+7);
end;
setwritemode (1);
end;
procedure v1;
begin
setcolor (0);
line (37-23,3,31-23,3);
line (31-23,3,31-23,13);
line (37-23,3,37-23,13);
line (31-23,13,34-23,18);
line (34-23,18,37-23,13);
line (31-23,12,37-23,12);
line (27-23,19,42-23,17);
line (34-23,3,34-23,13);
end;

procedure v2;
begin
setcolor (0);
rectangle (51-23-23,325-276-23,63-23-23,340-276-23);
settextstyle (0,0,0);
outtextxy (54-23-23,328-276-23,'s');
end;

procedure v3;
begin
setcolor (0);
line (28-23,48,40-23,64);
end;

procedure v4;
begin
line (4,73,11,73);
line (11,73,8,82);
line (8,82,4,73);
rectangle (13,79,18,87);
end;

procedure v5;
begin
setcolor (0);
line (53-46,188+92-184,56-46,190+92-184);
line (56-46,190+92-184,59-46,192+92-184);
line (59-46,192+92-184,62-46,197+92-184);
line (62-46,197+92-184,63-46,201+92-184);
line (63-46,201+92-184,61-46,203+92-184);
line (61-46,203+92-184,57-46,203+92-184);
line (57-46,203+92-184,54-46,200+92-184);
line (54-46,200+92-184,52-46,194+92-184);
line (52-46,194+92-184,53-46,188+92-184);
end;

procedure v6;
begin
setcolor (8);
setfillstyle (1,3);
bar (29-23,72+46,39-23,87+46);
rectangle (29-23,72+46,39-23,87+46);
end;

procedure v7;
begin
setcolor (0);
circle (35-23,103+46,6);
end;

procedure v8;
begin
setcolor (0);
ellipse (57-46,126+46,0,360,8,5);
end;

procedure v9;
begin
ellipse (13,197,56,209,8,8);
end;

procedure v10;
begin
setcolor (0);
rectangle (27-23,165+46,41-23,179+46);
end;

procedure v11;
begin
setcolor (8);
setfillstyle (1,3);
bar (27-23,165+69,41-23,179+69);
rectangle (27-23,165+69,41-23,179+69);
end;

procedure v12;
begin
setcolor (0);
settextstyle (2,0,8);
outtextxy (29-23,226+23,'A');
end;

procedure v13;
begin
settextstyle (2,0,6);
setcolor (0);
outtextxy (49-23-23,140+69+69,'Ab');
end;

procedure v14;
begin
line (26-23,394-92,40-23,404-92);
line (27-23,403-92,41-23,396-92);
line (30-23,394-92,30-23,409-92);
line (33-23,394-92,37-23,406-92);
line (26-23,403-92,38-23,408-92);
end;

procedure v15;
begin
setcolor (0);
rectangle (30-23,121+184+23,36-23,134+184+23);
rectangle (31-23,117+184+23,35-23,121+184+23);
line (36-23,120+184+23,40-23,121+184+23);
line (36-23,118+184+23,40-23,117+184+23);
end;

procedure v16;
begin
setcolor (0);
line (28-23,289-46+115,42-23,282-46+115);
line (28-23,282-46+115,42-23,289-46+115);
circle (40-23,281-46+115,2);
circle (40-23,290-46+115,2);
end;

procedure v17;
begin
setcolor (0);
line (34-23,256+115,34-23,271+115);
line (32-23,259+115,34-23,256+115);
line (36-23,259+115,34-23,256+115);
line (32-23,268+115,34-23,271+115);
line (36-23,268+115,34-23,271+115);
end;

procedure v18;
begin
circle (30-23,305+92,3);
circle (38-23,305+92,3);
circle (30-23,313+92,3);
circle (38-23,313+92,3);
end;

procedure v19;
begin
setcolor (0);
circle (54-23-23,350+69,3);
circle (58-23-23,355+69,3);
circle (62-23-23,360+69,3);
end;

procedure v20;
begin
setcolor (0);
rectangle (32-23,421+23,37-23,431+23);
line (34-23,421+23,36-23,417+23);
end;

procedure v21;
begin
setfillstyle (1,7);
setcolor (0);
bar3d (29,29-23,37,42-23,4,true);
end;

procedure v22;
begin
setfillstyle (1,7);
setcolor (0);
bar3d (28,305-253-23,38,318-253-23,4,true);
settextstyle (0,0,0);
outtextxy (30,307-253-23,'s');
end;

procedure v23;
begin
line (27,73-23,29,84-23);
line (29,84-23,33,75-23);
line (33,75-23,36,86-23);
line (36,86-23,39,76-23);
line (39,76-23,41,83-23);
end;

procedure v24;
begin
setcolor (0);
line (32,257+23-207,28,270+23-207);
line (28,270+23-207,41,270+23-207);
line (41,270+23-207,41,260+23-207);
line (41,260+23-207,32,257+23-207);
end;

procedure v25;
begin
setcolor (0);
rectangle (29,72+23,39,87+23);
end;

procedure v26;
begin
setcolor (0);
setfillstyle (1,3);
bar (29,72+46,39,87+46);
rectangle (29,72+46,39,87+46);
end;

procedure v27;
begin
setfillstyle (1,3);
setcolor (0);
fillellipse (35,103+23+23,6,6);
end;

procedure v28;
begin
setcolor (0);
setfillstyle (1,3);
fillellipse (57-23,356-207+23,8,5);
end;

procedure v29;
begin
setcolor (0);
ellipse (36,195,56,269,9,6);
end;

procedure v30;
begin
setcolor (0);
setfillstyle (1,3);
bar (27,165+46,41,179+46);
rectangle (27,165+46,41,179+46);
end;

procedure v31;
begin
setcolor (0);
rectangle (50-23,394-161,58-23,402-161);
rectangle (56-23,402-161,64-23,410-161);
setfillstyle (1,3);
bar (57-23,403-161,63-23,409-161);
end;

procedure v32;
begin
settextstyle (2,0,8);
setcolor (8);
outtextxy (31,205+46,'A');
setcolor (0);
outtextxy (29,203+46,'A');
end;

procedure v33;
begin
settextstyle (2,0,6);
setcolor (8);
outtextxy (50-23,164+46+69,'Ab');
setcolor (0);
outtextxy (48-23,162+46+69,'Ab');
end;

procedure v34;
begin
setcolor (0);
rectangle (50-23,187+138-23,58-23,195+138-23);
rectangle (56-23,195+138-23,64-23,203+138-23);
setfillstyle (1,3);
bar (57-23,196+138-23,63-23,202+138-23);
settextstyle (2,0,3);
outtextxy (53-23,187+138-23,'X');
setcolor (11);
outtextxy (59-23,195+138-23,'X');
end;

procedure v35;
begin
setcolor (0);
line (42,149+184,38,142+184);
line (42,149+184,30,142+184);
line (42,149+184,35,141+184);
line (42,149+184,30,154+184);
line (42,149+184,37,158+184);
line (42,149+184,34,158+184);
line (42,149+184,40,157+184);
line (30,148+184,40,150+184);
end;

procedure v36;
begin
end;

procedure v37;
begin
line (28,286-23+115,41,286-23+115);
line (31,284-23+115,28,286-23+115);
line (31,288-23+115,28,286-23+115);
line (38,284-23+115,41,286-23+115);
line (38,288-23+115,41,286-23+115);
end;

procedure v38;
begin
circle (30,305+92,3);
circle (37,308+92,3);
circle (30,312+92,3);
circle (39,313+92,3);
end;

procedure v39;
begin
setcolor (0);
rectangle (51-23,372-23+69,56-23,377-23+69);
rectangle (55-23,376-23+69,60-23,381-23+69);
rectangle (59-23,380-23+69,64-23,386-23+69);
end;

procedure v40;
begin
setfillstyle (1,3);
bar (24,415+23,24+20,415+20+23);
setcolor (0);
rectangle (32,421+23,37,431+23);
line (34,421+23,36,417+23);
end;

procedure iko (x,y:integer);
begin
{  setfillstyle (1,7);
  bar (x,y,x+22,y+22);}
  setcolor (15);
  rectangle (x,y,x+22,y+22);
  setcolor (0);
  line (x+22,y,x+22,y+22);
  line (x,y+22,x+22,y+22);
end;

procedure stlaciko (x,y:integer);
begin
{  setfillstyle (1,7);
  bar (x,y,x+22,y+22);}
  setcolor (0);
  rectangle (x,y,x+22,y+22);
  setcolor (15);
  line (x+22,y,x+22,y+22);
  line (x,y+22,x+22,y+22);
end;

procedure obn (a,b:integer);
begin
schovej_mysku;
if a>19 then iko (23,(a-20)*23) else iko (0,a*23);
if b>19 then stlaciko (23,(b-20)*23) else stlaciko (0,b*23);
ukaz_mysku;
end;

procedure uloz (x,y,x1,y1:integer);
var a,b:integer;
begin
   rewrite (f);
   for a:=x to x1 do
      for b:=y to y1 do begin
         c:=getpixel (a,b);
         write (f,chr(c));
         end;
end;

procedure uloz2;
var a,b:integer;
begin
   schovej_mysku;
   setcolor (15);
   rewrite (soub);
   for a:=48 to 639 do begin
      for b:=0 to 410 do begin
         c:=getpixel (a,b);
         write (soub,chr(c));
         end;
   setfillstyle (1,8);
   bar (19,468,80,476);
   str (round((a-48)/5.91),st1);
   outtextxy (19,468,st1+' %.');
   end;
   ukaz_mysku;
end;

procedure nacti (x,y,x1,y1:integer);
var a,b:integer;
begin
   reset (f);
   for a:=x to x1 do
      for b:=y to y1 do begin
         read (f,zn);
         putpixel (a,b,ord (zn));
         end;
end;

procedure nacti2;
var a,b:integer;
begin
   schovej_mysku;
   reset (soub);
   for a:=48 to 639 do
      for b:=0 to 410 do begin
         read (soub,zn);
         putpixel (a,b,ord (zn));
         end;
   ukaz_mysku;
end;

procedure nactiv (x,y,x1,y1:integer);
var a,b:integer;
begin
   reset (f);
   for a:=x to x1 do
      for b:=y1 downto y do begin
         read (f,zn);
         putpixel (a,b,ord (zn));
         end;
end;

procedure nactis (x,y,x1,y1:integer);
var a,b:integer;
begin
   reset (f);
   for a:=x1 downto x do
      for b:=y to y1 do begin
         read (f,zn);
         putpixel (a,b,ord (zn));
         end;
end;

procedure srovnej (var x1,y1,x2,y2:word);
var a:integer;
begin
if x2<x1 then begin
   a:=x2;
   x2:=x1;
   x1:=a;
   end;
if y2<y1 then begin
   a:=y2;
   y2:=y1;
   y1:=a;
   end;
end;

{            T V O R B A   G R A F I C K E H O   P R O S T R E D I              }

procedure ikony;
begin
setfillstyle (1,8);
bar (0,0,47,479);
bar (0,412,639,479);
setfillstyle (1,7);
setlinestyle (0,0,0);
setwritemode (0);
for b:=0 to 1 do begin
  for a:=0 to 19 do begin
  setfillstyle (1,7);
  bar (b*23,a*23,b*23+22,a*23+22);
  iko (b*23,a*23);
  end;
end;
stlaciko (0,0);
for a:=0 to 15 do begin
    setfillstyle (1,a);
    bar ((a*37)+46,414,(a*37+36)+46,436);
    setcolor (15);
    rectangle (a*37+46,414,a*37+36+46,436);
    setcolor (0);
    line (a*37+36+46,414,a*37+36+46,436);
    line (a*37+46,436,a*37+36+46,436);
    end;
setcolor (15);
line (47,0,47,411);
line (47,411,639,411);
line (0,461,95,461);
line (0,461,0,479);
line (46,437,95,437);
line (46,437,46,459);
setfillstyle (1,bkcolor);
bar (47,438,94,459);
setfillstyle (1,color);
bar (55,444,86,453);
setcolor (0);
line (95,437,95,460);
line (95,461,95,479);
setfillstyle (1,7);
bar (110,447,180,468);
bar (273,444,303,471);
bar (423,444,453,471);
bar (523,444,553,471);
setcolor (0);
rectangle (110,447,180,468);
setcolor (15);
rectangle (109,446,181,469);
rectangle (273,444,303,471);
rectangle (423,444,453,471);
rectangle (523,444,553,471);
setcolor (0);
line (303,444,303,471);
line (273,471,303,471);
line (453,444,453,471);
line (423,471,453,471);
line (553,444,553,471);
line (523,471,553,471);
setfillstyle (1,0);
bar (323,438,403,478);
setfillstyle (styl,3);
bar (475,440,501,476);
setcolor (0);
rectangle (474,439,502,477);
setcolor (7);
rectangle (323,438,403,478);
          setviewport (324,439,402,477,true);
          setcolor (15);
          if vel<11 then settextstyle (font,0,vel) else settextstyle (font,0,10);
          outtextxy (1,1-(velf2[font,vel]-velf[font,vel]),'abcd ABCD');
          setviewport (0,0,639,479,false);
setcolor (0);
settextstyle (0,0,0);
st1:='Soubor';
outtextxy (145-(length(st1)*4),453,st1);
outtextxy (277,448,'vel');
str (vel,st1);
if vel<10 then st1:='0'+st1;
outtextxy (280,460,st1);
outtextxy (427,448,'fnt');
str (font,st1);
if font<10 then outtextxy (435,460,st1) else outtextxy (431,460,st1);
outtextxy (527,448,'stl');
str (styl,st1);
if styl<10 then st1:='0'+st1;
outtextxy (535,460,st1);
setcolor (0);
sou:=txt;
delete (sou,length(sou)-3,4);
setfillstyle (1,8);
bar (189,450,269,460);
outtextxy (189,450,sou);
setcolor (15);
outtextxy (191,451,sou);
v1;
v2;
v3;
v4;
v5;
v6;
v7;
v8;
v9;
v10;
v11;
v12;
v13;
v14;
v15;
v16;
v17;
v18;
v19;
v20;
v21;
v22;
v23;
v24;
v25;
v26;
v27;
v28;
v29;
v30;
v31;
v32;
v33;
v34;
v35;
v36;
v37;
v38;
v39;
v40;
end;
procedure wokno (x,y,x1,y1:integer);
var a:word;
begin
      schovej_mysku;
      a:=imagesize (x,y,x1,y1);
      r:=a;
      getmem (p,a);
      getimage (x,y,x1,y1,p^);
      setwritemode (0);
      setfillstyle (1,7);
      bar (x,y,x1,y1);
      rectangle (x,y,x1,y1);
      setcolor (0);
      line (x1,y,x1,y1);
      line (x1,y1,x,y1);
      ukaz_mysku;
end;
procedure zaWokno (x,y:integer);
begin
  schovej_mysku;
  putimage (x,y,p^,normalput);
  freemem (p,r);
  ukaz_mysku;
end;

procedure menus (p1,p2,p3,p4,p5,p6,p7:string);
begin
{190,80,340,300}
setcolor (1);
outtextxy (265-(6*4),90,'Soubor');
setcolor (15);
line (191,105,339,105);
setcolor (0);
line (191,106,339,106);
outtextxy (200,120,p1);
outtextxy (200,135,p2);
outtextxy (200,150,p3);
outtextxy (200,165,p4);
outtextxy (200,180,p5);
outtextxy (200,195,p6);
outtextxy (200,210,p7);
end;

procedure mozaika (x1,y1,x2,y2:word);
var a,b,c,d,nanic:word;
begin
uloz (x1,y1,x2,y2);
a:=x2-x1;
b:=y2-y1;
c:=0;
d:=0;
setviewport (48,0,639,410,true);
repeat
c:=0;
  repeat
  pozice_mysky (nanic,nanic,but1,but2,but3);
  nacti (c,d,c+a,d+b);
  c:=c+a+1;
  until (c>639-48) or (but2=true);
d:=d+b+1;
until (d>410) or (but2=true);
setviewport (0,0,639,479,false);
end;

procedure nmozaika (x1,y1,x2,y2:word);
var a,b,c,d,nanic:word;
begin
uloz (x1,y1,x2,y2);
a:=x2-x1;
b:=y2-y1;
setviewport (48,0,639,410,true);
  repeat
  c:=random (639-48);
  d:=random (410);
  pozice_mysky (nanic,nanic,but1,but2,but3);
  nacti (c,d,c+a,d+b);
  until but2=true;
setviewport (0,0,639,479,false);
end;

function inkey:integer;
var s:char;
    a:integer;
begin
a:=0;
if keypressed then begin
   s:=readkey;
   if ord(s)=0 then begin
      s:=readkey;
      a:=ord(s)+256;
      end else a:=ord(s);
   end;
inkey:=a;
end;
{procedure okno0 (x,y,a,b:integer);
begin
{rectangle (x-1,y-1,a+3,b+3);
rectangle (x-1,y-1,a+4,b+4);}


{setcolor (0);
line (x+5,y,a-5,y);
line (x+3,y+1,a-3,y+1);
line (x+2,y+2,a-2,y+2);
line (x+1,y+3,a-1,y+3);
line (x+1,y+4,a-1,y+4);
line (x,y+5,a,y+5);
line (x+5,b,a-5,b);
line (x+3,b-1,a-3,b-1);
line (x+2,b-2,a-2,b-2);
line (x+1,b-3,a-1,b-3);
line (x+1,b-4,a-1,b-4);
line (x,b-5,a,b-5);
line (x,y+5,x,b-6);
line (x+1,y+4,x+1,b-6);
line (x+2,y+5,x+2,b-6);
line (x+3,y+5,x+3,b-6);
line (x+4,y+5,x+4,b-6);
line (x+5,y+5,x+5,b-6);
line (a,y+6,a,b-5);
line (a-1,y+6,a-1,b-4);
line (a-2,y+6,a-2,b-4);
line (a-3,y+6,a-3,b-4);
line (a-4,y+6,a-4,b-4);
line (a-5,y+6,a-5,b-4);
end;}

procedure okno (x,y,a,b:integer;str:string);
begin
{rectangle (x-1,y-1,a+3,b+3);
rectangle (x-1,y-1,a+4,b+4);}

{okno0 (x-1,y-1,a+1,b+1);}
{setcolor (15);
line (x+5,y,a-5,y);
line (x+3,y+1,a-3,y+1);
setcolor (7);
line (x+2,y+2,a-2,y+2);
line (x+1,y+3,a-1,y+3);
setcolor (8);
line (x+1,y+4,a-1,y+4);
line (x,y+5,a,y+5);

setcolor (8);
line (x+5,b,a-5,b);
line (x+3,b-1,a-3,b-1);
setcolor (7);
line (x+2,b-2,a-2,b-2);
line (x+1,b-3,a-1,b-3);
setcolor (15);
line (x+1,b-4,a-1,b-4);
line (x,b-5,a,b-5);

setcolor (15);
line (x,y+5,x,b-6);
line (x+1,y+4,x+1,b-6);
setcolor (7);
line (x+2,y+5,x+2,b-6);
line (x+3,y+5,x+3,b-6);
setcolor (8);
line (x+4,y+5,x+4,b-6);
line (x+5,y+5,x+5,b-6);

setcolor (8);
line (a,y+6,a,b-5);
line (a-1,y+6,a-1,b-4);
setcolor (7);
line (a-2,y+6,a-2,b-4);
line (a-3,y+6,a-3,b-4);
setcolor (15);
line (a-4,y+6,a-4,b-4);
line (a-5,y+6,a-5,b-4);}
{setcolor (8);
line (x-1,y-1,x-1,b+1);
line (x-1,y-1,a+1,y-1);}
setcolor (7);
line (x,y,x,b);
line (x,y,a,y);
setcolor (15);
line (x+1,y+1,x+1,b-1);
line (x+1,y+1,a-1,y+1);
setcolor (8);
line (x+1,b-1,a-1,b-1);
line (a-1,b-1,a-1,y+1);
setcolor (0);
line (x,b,a,b);
line (a,b,a,y);

setfillstyle (1,7);
bar (x+2,y+2,a-2,b-2);
setfillstyle (1,4);
bar (x+2,y+2,a-2,y+19);
setcolor (12);
outtextxy (x+10,y+7,str);
setcolor (0);
line (x+2,y+20,a-2,y+20);
outtextxy (x+12,y+9,str);
setcolor (15);
outtextxy (x+11,y+8,str);

{setcolor (15);
line (x+2,y+25,a-6,y+25);
line (x+2,y+26,a-6,y+26);
setcolor (7);
line (x+4,y+27,a-6,y+27);
line (x+4,y+28,a-6,y+28);
setcolor (8);
line (x+6,y+29,a-6,y+29);
line (x+6,y+30,a-6,y+30);}




{setcolor (15);
line (x,y,a,y);
line (x,y+1,a-1,y+1);
line (x,y,x,b);
line (x+1,y,x+1,b-1);

setcolor (0);
line (a,y,a,b);
line (a-1,y+1,a-1,b);
line (a-2,b,x,b);
line (a-2,b-1,x+1,b-1);
setfillstyle (1,8);
bar (x+2,y+2,a-2,b-2);

setcolor (15);
rectangle (x+5,y+5,a-5,b-5);
setcolor (0);
line (x+5,y+5,a-5,y+5);
line (x+5,y+5,x+5,b-5);
setfillstyle (1,4);
bar (x+6,y+6,a-6,y+23);
setcolor (15);
line (x+6,y+23,a-6,y+23);
setcolor (0);
line (x+6,y+25,a-6,y+25);
setcolor (0);
settextstyle (0,0,1);
setcolor (11);
outtextxy (x+15,y+9,str);}
end;










































procedure novys;
begin
schovej_mysku;
uloz (199,199,401,301);
okno (200,200,400,300,'Jmeno souboru');
settextstyle (0,0,0);
setcolor (0);
outtextxy (220,235,'Zadej jmeno souboru :');
setfillstyle (1,8);
bar (240,260,360,280);
setcolor (0);
rectangle (240,260,360,280);
setcolor (15);
line (360,260,360,280);
line (360,280,240,280);

      setfillstyle (1,8);
      bar (113+135,193+70,260+95,204+70);
      setcolor (15);
      OutTextXY (130+120,196+68,'_        .gra');
      txt:='';
      repeat
      zn:=readkey;
      if zn=#8 then begin
                    sou:=txt;
                    txt:='';
                    for a:=1 to (length(sou)-1) do txt:=txt+sou[a];
                    end
         else if (zn<#127) and (zn>#32) then begin
                 if length(txt)=8 then begin
                    sou:=txt;
                    txt:='';
                    for a:=2 to length(sou) do txt:=txt+sou[a];
                 end;
                 txt:=txt+zn;
             end;

      bar (113+135,193+70,260+95,204+70);
      setcolor (15);
      OutTextXY (130+120,196+68,'         .gra');
      OutTextXY (130+120,196+68,txt+'_');
      until zn=#13;
nacti(199,199,401,301);
txt:=txt+'.gra';
setfillstyle (1,8);
bar (189,450,269,460);
setcolor (0);
sou:=txt;
delete (sou,length(sou)-3,4);
outtextxy (189,450,sou);
setcolor (15);
outtextxy (191,451,sou);
ukaz_mysku;
end;
















begin
rezim:=0;
color:=15;
vel:=5;
vel2:=5;
font:=1;
styl:=1;
bkcolor:=0;
assign (inf1,'fonty.inf');
assign (inf2,'fonty1.inf');
reset (inf1);
reset (inf2);
for a:=1 to 10 do for c:=1 to 10 do read (inf1,velf[a,c]);
for a:=1 to 10 do for c:=1 to 10 do read (inf2,velf2[a,c]);
a:=vga;
b:=vgahi;
close (inf1);
close (inf2);
initgraph (a,b,'system');
txt:='noname.gra';
ikony;
ukaz_mysku;
assign (soub,'noname.gra');
assign (f,'VYMAZME.XXX');
repeat
setwritemode (0);
setlinestyle (0,0,1);
sx:=x;
sy:=y;
sbut1:=but1;
sbut2:=but2;
sbut3:=but3;
if inkey = 316 then begin
   uloz2;
   end;

if inkey = 318 then begin
   nacti2;
   end;

pozice_mysky (x,y,but1,but2,but3);
if (x>47) and (y<411) and ((sx<48) or (sy>410)) then nastav_kriz;
if ((x<48) or (y>410)) and ((sx>47) and (sy<411)) then nastav_sipku;
setwritemode (1);
{if (x<>sx) or (y<>sy) then begin
line (sx,sy,sx+4,sy);
line (sx,sy,sx,sy+5);
line (sx,sy,sx+5,sy+7);
setwritemode (0);
end;}
if (sx<>x) or (sy<>y) then begin
   settextstyle (0,0,0);
   setfillstyle (1,8);
   bar (19,468,80,476);
   str (x,st1);
   str (y,st2);
   setcolor (15);
   outtextxy (19,468,st1+','+st2);
   end;



{  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!   }


{  Jestli je kurzor mimo obrazek a je stisknute tlacitko mysi, delej tohle :   }


{  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!   }


if ((but1) or (but2)) and ((x<48) or (y>410)) then begin
{   rectangle (109,446,181,469);}
   for b:=0 to 1 do begin
      for a:=0 to 19 do begin
      if (but1) and (sbut1=false) and (x>b*23) and (x<b*23+22) and (y>a*23) and (y<a*23+22) then begin
         c:=rezim;
         uplne_poprve:=true;
         if x>22 then rezim:=a+20 else rezim:=a;
         setwritemode (0);
         obn (c,rezim);
         if rezim=3 then begin
            schovej_mysku;
            uloz (200-1,200-1,350+1,260+1);
            okno (200,200,350,260,'X-uhelnik');
            settextstyle (0,0,0);
            setcolor (0);
            outtextxy (206,235,'Pocet vrcholu : _');
            while keypressed do readkey;
            repeat
            zn:=readkey;
            setfillstyle (1,7);
            bar (205,235,345,245);
            outtextxy (206,235,'Pocet vrcholu : '+zn);
            until (zn='3') or(zn='4') or(zn='5') or(zn='6') or(zn='7') or(zn='8') or(zn='9');
            case zn of
              '3':vrchu:=3;
              '4':vrchu:=4;
              '5':vrchu:=5;
              '6':vrchu:=6;
              '7':vrchu:=7;
              '8':vrchu:=8;
              '9':vrchu:=9;
            end;
            nacti (200-1,200-1,350+1,260+1);
            ukaz_mysku;
            hranice_mysky (48,0,639,410);
           end;
         end;
      end;
   end;

{   D Y N A M I T                                                               }

   if rezim=19 then begin
      setfillstyle (0,0);
      bar (48,0,639,410);
      rezim:=c;
      c:=19;
      obn (c,rezim);
      end;

{   B A R E V N Y   D Y N A M I T                                             }

   if rezim=39 then begin
      setfillstyle (styl,color);
      bar (48,0,639,410);
      rezim:=c;
      c:=39;
      obn (c,rezim);
      end;

{                    O K N O   U K A Z U J I C I   F O N T                      }

   if (x>323) and (x<403) and (y>438) and (y<478) and (but1) and (not sbut1) then begin
      setwritemode (1);
      for a:=438 downto 100 do begin
          line (323,a,403,a);
          delay (1);
          if a<>330 then line (323,a,403,a);
          end;
      delay (20);
      line (323,330,403,330);
      line (250,330,420,330);
      line (250,100,420,100);
      delay (20);
      line (250,330,420,330);
      line (250,100,420,100);
      line (200,330,470,330);
      line (200,100,470,100);
      delay (60);
      line (200,100,470,100);
      line (200,330,470,330);
      setwritemode (0);
      wokno (200,100,470,330);
      setcolor (15);
      rectangle (220,120,450,280);
      settextstyle (0,0,0);
      setcolor (0);
      rectangle (219,119,449,279);
      outtextxy (226,296,'Informace o aktualnim fontu.');
      outtextxy (230,308,'Stiskni libovolnou klavesu.');
      setcolor (15);
      outtextxy (225,295,'Informace o aktualnim fontu.');
      outtextxy (229,307,'Stiskni libovolnou klavesu.');
      setfillstyle (0,0);
      bar (221,121,448,278);
      setcolor (8);
      rectangle (221,121,448,278);
      settextstyle (font,0,vel);
      setviewport (222,122,447,277,true);
      setcolor (15);
      outtextxy (1,1-(velf2[font,vel2]-velf[font,vel2]),'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz');
     outtextxy (1,velf[font,vel2]+4-(velf2[font,vel2]-velf[font,vel2]),'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ');
      setviewport (0,0,639,479,true);
      while keypressed do readkey;
      zn:=readkey;
      if zn=#0 then zn:=readkey;
      zaWokno (200,100);
      end;







{rectangle (273,444,303,471);
rectangle (423,444,453,471);
rectangle (523,444,553,471);}
{str (vel,st1);
outtextxy (285,460,st1);
outtextxy (427,448,'fnt');
str (font,st1);
outtextxy (435,460,st1);
outtextxy (527,448,'stl');
str (styl,st1);
outtextxy (535,460,st1);
bar (273,444,303,471);
bar (423,444,453,471);
bar (523,444,553,471);  }
   setwritemode (0);
   IF (BUT1) and (but2=false) AND (SBUT1=false) and (x>523) and (x<553) and (y>444) and (y<471) and (styl<11) then begin
      styl:=styl+1;
      setfillstyle (1,7);
      setcolor (0);
      schovej_mysku;
      bar (524,445,552,470);
      str (styl,st1);
      if styl<10 then st1:='0'+st1;
      settextstyle (0,0,0);
      outtextxy (527,448,'stl');
      outtextxy (531,460,st1);
      setfillstyle (styl,3);
      bar (475,440,501,476);
      ukaz_mysku;
      end;

   IF (BUT2) and (but1=false) AND (SBUT2=false) and (x>523) and (x<553) and (y>444) and (y<471) and (styl>1) then begin
      styl:=styl-1;
      setfillstyle (1,7);
      setcolor (0);
      schovej_mysku;
      bar (524,445,552,470);
      str (styl,st1);
      if styl<10 then st1:='0'+st1;
      settextstyle (0,0,0);
      outtextxy (527,448,'stl');
      outtextxy (531,460,st1);
      setfillstyle (styl,3);
      bar (475,440,501,476);
      ukaz_mysku;
      end;


   IF (BUT1) and (but2=false) AND (SBUT1=false) and (x>423) and (x<453) and (y>444) and (y<471) and (font<10) then begin
      font:=font+1;
      setfillstyle (1,7);
      setcolor (0);
      schovej_mysku;
      bar (424,445,452,470);
      settextstyle (0,0,0);
      outtextxy (427,448,'fnt');
      str (font,st1);
      if font<10 then outtextxy (435,460,st1) else outtextxy (431,460,st1);
          setfillstyle (0,0);
          bar (324,439,402,477);
          setviewport (324,439,402,477,true);
          setcolor (15);
          settextstyle (font,0,vel2);
          outtextxy (1,1-(velf2[font,vel2]-velf[font,vel2]),'abcd ABCD');
          setviewport (0,0,639,479,false);
      ukaz_mysku;
      end;

   IF (BUT2) and (but1=false) AND (SBUT2=false) and (x>423) and (x<453) and (y>444) and (y<471) and (font>1) then begin
      font:=font-1;
      setfillstyle (1,7);
      setcolor (0);
      schovej_mysku;
      bar (424,445,452,470);
      settextstyle (0,0,0);
      outtextxy (427,448,'fnt');
      str (font,st1);
      if font<10 then outtextxy (435,460,st1) else outtextxy (431,460,st1);
          setfillstyle (0,0);
          bar (324,439,402,477);
          setviewport (324,439,402,477,true);
          setcolor (15);
          settextstyle (font,0,vel2);
          outtextxy (1,1-(velf2[font,vel2]-velf[font,vel2]),'abcd ABCD');
          setviewport (0,0,639,479,false);
      ukaz_mysku;
      end;

   IF (BUT1) and (but2=false) AND (SBUT1=false) and (x>273) and (x<303) and (y>444) and (y<471) and (vel<15) then begin
      vel:=vel+1;
      if vel<11 then vel2:=vel else vel2:=10;
      setfillstyle (1,7);
      setcolor (0);
      schovej_mysku;
      bar (274,445,302,470);
      str (vel,st1);
      if vel<10 then st1:='0'+st1;
      settextstyle (0,0,0);
      outtextxy (277,448,'vel');
      outtextxy (280,460,st1);
          setfillstyle (0,0);
          bar (324,439,402,477);
          setviewport (324,439,402,477,true);
          setcolor (15);
          settextstyle (font,0,vel2);
          outtextxy (1,1-(velf2[font,vel2]-velf[font,vel2]),'abcd ABCD');
          setviewport (0,0,639,479,false);
      ukaz_mysku;
      end;

   IF (BUT2) and (but1=false) AND (SBUT2=false) and (x>273) and (x<303) and (y>444) and (y<471) and (vel>1) then begin
      vel:=vel-1;
      if vel<11 then vel2:=vel else vel2:=10;
      setfillstyle (1,7);
      setcolor (0);
      schovej_mysku;
      bar (274,445,302,470);
      str (vel,st1);
      if vel<10 then st1:='0'+st1;
      settextstyle (0,0,0);
      outtextxy (277,448,'vel');
      outtextxy (280,460,st1);
          setfillstyle (0,0);
          bar (324,439,402,477);
          setviewport (324,439,402,477,true);
          setcolor (15);
          settextstyle (font,0,vel2);
          outtextxy (1,1-(velf2[font,vel2]-velf[font,vel2]),'abcd ABCD');
          setviewport (0,0,639,479,false);
      ukaz_mysku;
      end;





{-----------------------------------------------------------------------------
                           Polozka  S O U B O R
 -----------------------------------------------------------------------------}





   if (x>109) and (y>446) and (x<181) and (y<469) then begin
      setcolor (15);
      setwritemode (1);
      schovej_mysku;
      for a:=446 downto 80 do begin
          line (109,a,181,a);
          delay (1);
          line (109,a,181,a);
          end;
      for a:=1 to 80 do begin
          line (109+a,80,181+a,80);
          delay (1);
          line (109+a,80,181+a,80);
          end;
      wokno (190,80,340,240);
      menus ('Novy','Otevri','Uloz','Uloz pod jmenem','Nacti','Napoveda','Konec');
      ukaz_mysku;
      hranice_mysky (190,80,340,240);
konc:=false;
repeat
sx:=x;
sy:=y;
sbut1:=but1;
sbut2:=but2;
sbut3:=but3;
if inkey = 316 then begin
   uloz2;
   end;
if inkey = 318 then begin
   nacti2;
   end;
pozice_mysky (x,y,but1,but2,but3);

      if (but1=true) and (sbut1=false) and (x>192) and (y>115) and (x<338) and (y<130) then begin
         setcolor (color);
         schovej_mysku;
         setfillstyle (1,2);
         bar (192,115,338,130);
         menus ('-> Novy','Otevri','Uloz','Uloz pod jmenem','Nacti','Napoveda','Konec');
         delay (100);
         ukaz_mysku;
         novys;
         schovej_mysku;
         zawokno (190,80);
         setfillstyle (0,0);
         bar (48,0,639,410);
         konc:=true;
         ukaz_mysku;
         hranice_mysky (0,0,639,479);
         end;

      if (but1=true) and (sbut1=false) and (x>192) and (y>115+15) and (x<338) and (y<130+15) then begin
         setcolor (color);
         schovej_mysku;
         setfillstyle (1,2);
         bar (192,130,338,145);
         menus ('Novy','-> Otevri','Uloz','Uloz pod jmenem','Nacti','Napoveda','Konec');
         delay (100);
         ukaz_mysku;
         novys;
         schovej_mysku;
         zawokno (190,80);
         assign (soub,txt);
         nacti2;
         konc:=true;
         ukaz_mysku;
         hranice_mysky (0,0,639,479);
         end;

      if (but1=true) and (sbut1=false) and (x>192) and (y>115+30) and (x<338) and (y<130+30) then begin
         setcolor (color);
         schovej_mysku;
         setfillstyle (1,2);
         bar (192,145,338,160);
         menus ('Novy','Otevri','-> Uloz','Uloz pod jmenem','Nacti','Napoveda','Konec');
         delay (100);
         zawokno (190,80);
         uloz2;
         konc:=true;
         ukaz_mysku;
         hranice_mysky (0,0,639,479);
         end;
      if (but1=true) and (sbut1=false) and (x>192) and (y>115+45) and (x<338) and (y<130+45) then begin
         setcolor (color);
         schovej_mysku;
         setfillstyle (1,2);
         bar (192,160,338,175);
         menus ('Novy','Otevri','Uloz','-> Pod jmenem','Nacti','Napoveda','Konec');
         delay (100);
         ukaz_mysku;
         novys;
         schovej_mysku;
         zawokno (190,80);
         assign (soub,txt);
         uloz2;
         konc:=true;
         ukaz_mysku;
         hranice_mysky (0,0,639,479);
         end;
      if (but1=true) and (sbut1=false) and (x>192) and (y>115+60) and (x<338) and (y<130+60) then begin
         setcolor (color);
         schovej_mysku;
         setfillstyle (1,2);
         bar (192,175,338,190);
         menus ('Novy','Otevri','Uloz','Uloz pod jmenem','-> Nacti','Napoveda','Konec');
         delay (100);
         zawokno (190,80);
         nacti2;
         konc:=true;
         ukaz_mysku;
         hranice_mysky (0,0,639,479);
         end;
      if (but1=true) and (sbut1=false) and (x>192) and (y>115+75) and (x<338) and (y<130+75) then begin
         setcolor (color);
         schovej_mysku;
         setfillstyle (1,2);
         bar (192,190,338,205);
         menus ('Novy','Otevri','Uloz','Uloz pod jmenem','Nacti','-> Napoveda','Konec');
         delay (100);
         zawokno(190,80);
         konc:=true;
         ukaz_mysku;
         hranice_mysky (0,0,639,479);
         end;
      if (but1=true) and (sbut1=false) and (x>192) and (y>115+90) and (x<338) and (y<130+90) then begin
         setcolor (color);
         schovej_mysku;
         setfillstyle (1,2);
         bar (192,205,338,220);
         menus ('Novy','Otevri','Uloz','Uloz pod jmenem','Nacti','Napoveda','-> Konec');
         delay (100);
         closegraph;
         halt;
         end;

until konc=true;
but1:=false;
but2:=false;
but3:=false;
sbut1:=false;
sbut2:=false;
sbut3:=false;
konc:=false;
       end;

   for a:=0 to 15 do begin
       if (but1) and (sbut1=false) and (x>(a*37)+46) and (x<(a*37+36)+46) and (y>414) and (y<436) then begin
          color:=a;
          setfillstyle (1,bkcolor);
          schovej_mysku;
          bar (47,438,94,459);
          setfillstyle (1,color);
          bar (55,444,86,453);
          ukaz_mysku;
          end;
       end;
   for a:=0 to 15 do begin
       if (but2) and (sbut2=false) and (x>(a*37)+46) and (x<(a*37+36)+46) and (y>414) and (y<436) then begin
          bkcolor:=a;
          setfillstyle (1,bkcolor);
          schovej_mysku;
          bar (47,438,94,459);
          setfillstyle (1,color);
          bar (55,444,86,453);
          ukaz_mysku;
          end;
       end;
   end;

{  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!   }


{                   Jestli je kurzor v obrazku, delej tohle :                    }


{  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!   }


if ((x>47) and (y<411) and (sx>47) and (sy<411)) then begin
   setcolor (color);
   setwritemode (0);

{    V A L E C                                                                          }

  if (rezim=30) and (but1) and (sbut1=false) then begin
     schovej_mysku;
     setcolor (bkcolor);
     line (47,0,47,410);
     line (47,410,639,410);
     setfillstyle (styl,color);
     floodfill (x,y,bkcolor);
     setcolor (15);
     line (47,0,47,410);
     line (47,410,639,410);
     ukaz_mysku;
     end;

{    T U Z K A ,
     U Z A V R E N Y   O B R A Z E C                                          }

   if ((rezim = 0) or (rezim = 4)) and (but1) and (sbut1=false) then begin
      hranice_mysky (48,0,639,410);
      zx:=x;
      zy:=y;
      sx:=x;
      sy:=y;
      sbut1:=but1;
      sbut2:=but2;
      sbut3:=but3;
      pozice_mysky (x,y,but1,but2,but3);
      poprve:=true;
      muze:=true;
      end;
   if ((rezim = 0) or (rezim = 4)) and (but1=false) and (sbut1) then begin
      if rezim=4 then begin
         schovej_mysku;
         line (sx,sy,zx,zy);
         ukaz_mysku;
         end;
      hranice_mysky (0,0,639,479);
      poprve:=false;
      muze:=false;
      end;
   if (rezim = 0) or (rezim = 4) then begin
      if (but1) and (muze) and (((x<>sx) or (y<>sy)) or (poprve)) then begin
         schovej_mysku;
         poprve:=false;
         line (sx,sy,x,y);
         ukaz_mysku;
         end;
      end;

{   C A R A,
    M U L T I C A R A                                                               }

   if ((rezim = 2) or (rezim = 34)) and (but1) and (sbut1=false) then begin
      hranice_mysky (48,0,639,410);
      sx:=x;
      sy:=y;
      sbut1:=but1;
      sbut2:=but2;
      sbut3:=but3;
      pozice_mysky (x,y,but1,but2,but3);
      zx:=sx;
      zy:=sy;
      muze:=true;
      end;
   if ((rezim = 2) or (rezim = 34)) and (muze) and (but1=false) and (sbut1) then begin
      schovej_mysku;
      setwritemode (1);
      if rezim=2 then line (zx,zy,sx,sy);
      setwritemode (0);
      line (zx,zy,x,y);
      ukaz_mysku;
      hranice_mysky (0,0,639,479);
      muze:=false;
      end;
   if (rezim = 2) or (rezim = 34) then begin
      if (but1) and (muze) and ((x<>sx) or (y<>sy)) then begin
         schovej_mysku;
         if rezim=2 then begin
            setwritemode (1);
            line (zx,zy,sx,sy);
            end;
         line (zx,zy,x,y);
         setwritemode (0);
         ukaz_mysku;
         end;
      end;

{   K R U Z N I C E ,
    K R U H ,
    E L I P S A ,
    V Y B A R V E N A   E L I P S A                                                       }

   if ((rezim = 6) or (rezim = 7) or (rezim = 26) or (rezim = 27)) and (but1) and (sbut1=false) then begin
      if (rezim=6) or (rezim=26) then begin
        a:=x-48;
        if x+a>639 then c:=639 else c:=x+a;
        if y+a>410 then c:=x+(410-y);
        d:=48;
        if y+a>410 then d:=x-(410-y);
        hranice_mysky (d,0,c,410);
      end else begin
          a:=x-48;
          if x+a>639 then c:=639 else c:=x+a;
          d:=48;
          if 410-y<y then b:=y-(410-y);
          hranice_mysky (d,b,c,410);
          end;

      sx:=x;
      sy:=y;
      sbut1:=but1;
      sbut2:=but2;
      sbut3:=but3;
      pozice_mysky (x,y,but1,but2,but3);
      zx:=sx;
      zy:=sy;
      muze:=true;
      end;
   if ((rezim = 6) or (rezim = 7) or (rezim = 26) or (rezim = 27)) and (muze) and (but1=false) and (sbut1) then begin
      schovej_mysku;
      setwritemode (1);
      if (rezim=6) or (rezim=26) then kruznice (zx,zy,sx-zx) else elipsa (zx,zy,sx-zx,sy-zy);
      setwritemode (0);
      setcolor (color);
      if zx>x then a:=zx-x else a:=x-zx;
      if zy>y then b:=zy-y else b:=y-zy;
      if rezim=6 then circle (zx,zy,a);
      if rezim=7 then ellipse (zx,zy,0,360,a,b);
      setfillstyle (styl,bkcolor);
      if rezim=26 then fillellipse (zx,zy,a,a);
      if rezim=27 then fillellipse (zx,zy,a,b);
      ukaz_mysku;
      hranice_mysky (0,0,639,479);
      muze:=false;
      end;
   if (rezim = 6) or (rezim = 7) or (rezim = 26) or (rezim = 27) then begin
      if (but1) and (muze) and ((x<>sx) or (y<>sy)) then begin
         schovej_mysku;
         setwritemode (1);
         if (rezim=6) or (rezim=26) then begin
            kruznice (zx,zy,sx-zx);
            kruznice (zx,zy,x-zx);
            end else begin
                elipsa (zx,zy,sx-zx,sy-zy);
                elipsa (zx,zy,x-zx,y-zy);
                end;
         setwritemode (0);
         ukaz_mysku;
         end;
      end;

{   N A V A Z N A   C A R A                                                                }

   if (rezim = 22) and (but1) and (sbut1=false) then begin
      hranice_mysky (48,0,639,410);
      sx:=x;
      sy:=y;
      sbut1:=but1;
      sbut2:=but2;
      sbut3:=but3;
      pozice_mysky (x,y,but1,but2,but3);
      if uplne_poprve then begin
         zx:=sx;
         zy:=sy;
         uplne_poprve:=false;
         end;
      if rezim=22 then begin
         schovej_mysku;
         setwritemode (1);
         line (zx,zy,x,y);
         ukaz_mysku;
         end;
      muze:=true;
      end;
   if (rezim = 22) and (muze) and (but1=false) and (sbut1) then begin
      schovej_mysku;
      setwritemode (1);
      line (zx,zy,sx,sy);
      setwritemode (0);
      line (zx,zy,x,y);
      zx:=x;
      zy:=y;
      ukaz_mysku;
      hranice_mysky (0,0,639,479);
      muze:=false;
      end;
   if rezim = 22 then begin
      if (but1) and (muze) and ((x<>sx) or (y<>sy)) then begin
         schovej_mysku;
         setwritemode (1);
         line (zx,zy,sx,sy);
         line (zx,zy,x,y);
         setwritemode (0);
         ukaz_mysku;
         end;
      end;

{   M N O H O U H E L N I K ,
    X  -  U H E L N I K                                                               }

   if ((rezim = 23) or (rezim=3)) and (but1) and (sbut1=false) and (muze=false) then begin
   splvrchu:=0;
   zx:=x;
   zy:=y;
   zzx:=x;
   zzy:=y;
   hranice_mysky (48,0,639,410);
   sx:=x;
   sy:=y;
   sbut1:=but1;
   sbut2:=but2;
   sbut3:=but3;
   pozice_mysky (x,y,but1,but2,but3);
   muze:=true;
   end;
   if ((rezim = 23) or (rezim=3)) and (but1) and (sbut1=false) and (muze) then begin
      {if rezim=23 then begin}
         schovej_mysku;
         setwritemode (1);
         line (zx,zy,sx,sy);
         splvrchu:=splvrchu+1;
         if (rezim=3) and (splvrchu = vrchu-2) then line (zzx,zzy,sx,sy);
         ukaz_mysku;
{         end;                 }
      end;

   if ((rezim = 23) or (rezim=3)) and (muze) and (but2) and (but1=false) then begin
      schovej_mysku;
{      setwritemode (1);
      line (zx,zy,sx,sy);}
      setwritemode (0);
      line (zx,zy,zzx,zzy);
      hranice_mysky (0,0,639,479);
      muze:=false;
      ukaz_mysku;
   end;

   if (rezim=3) and (splvrchu=vrchu-2) and (muze) and (but1=false) and (sbut1) then begin
      schovej_mysku;
      setwritemode (1);
      line (zx,zy,sx,sy);
      line (zzx,zzy,sx,sy);
      setwritemode (0);
      line (x,y,zx,zy);
      line (x,y,zzx,zzy);
      hranice_mysky (0,0,639,479);
      muze:=false;
      ukaz_mysku;
   end;

   if ((rezim = 23) or ((rezim=3) and (splvrchu<vrchu-2))) and (muze) and (but1=false) and (sbut1) then begin
      schovej_mysku;
      setwritemode (1);
      line (zx,zy,sx,sy);
      setwritemode (0);
      line (zx,zy,x,y);
      zx:=x;
      zy:=y;
      ukaz_mysku;
{      muze:=false;}
      end;
   if (rezim = 23) or (rezim=3) then begin
      if (but1) and (muze) and ((x<>sx) or (y<>sy)) then begin
         schovej_mysku;
         setwritemode (1);
         line (zx,zy,sx,sy);
         if (rezim=3) and (splvrchu = vrchu-2) then line (zzx,zzy,sx,sy);
         line (zx,zy,x,y);
         if (rezim=3) and (splvrchu = vrchu-2) then line (zzx,zzy,x,y);
         setwritemode (0);
         ukaz_mysku;
         end;
      end;

{   G U M A ,
    S E L E K T I V N I   G U M A ,
    S P R E J ,
    N A H O D N E   C A R Y ,
    K R U H Y   Z A   S E B O U ,
    C T V E R C E   Z A   S E B O U                                                  }

   if ((rezim = 20) or (rezim = 14) or (rezim = 21) or (rezim = 13) or (rezim = 18) or (rezim = 38))
                    and (but1) and (sbut1=false) then begin
      hranice_mysky (48+((vel+1)*3),0,639,410-((vel+1)*3));
      sx:=x;
      sy:=y;
      sbut1:=but1;
      sbut2:=but2;
      sbut3:=but3;
      pozice_mysky (x,y,but1,but2,but3);
      muze:=true;
      poprve:=true;
      if (rezim=14) or (rezim = 13) then schovej_mysku;
      end;
   if ((rezim = 20) or (rezim = 14) or (rezim = 21) or (rezim = 13) or (rezim = 18) or (rezim = 38))
                    and (but1=false) and (sbut1) then begin
      hranice_mysky (0,0,639,479);
      muze:=false;
      poprve:=false;
      if (rezim=14) or (rezim = 13) then ukaz_mysku;
      end;
   if (rezim = 20) or (rezim = 18) or (rezim = 21) or (rezim = 38) then begin
      if (but1) and (muze) and (((x<>sx) or (y<>sy)) or (poprve)) then begin
         poprve:=false;
         schovej_mysku;
         setfillstyle (styl,bkcolor);
         setcolor (color);
         if rezim=20 then bar (x-((vel+1)*3),y-((vel+1)*3),x+((vel+1)*3),y+((vel+1)*3));
         if rezim=21 then
            for a:=x-((vel+1)*3) to x+((vel+1)*3) do
                for b:=y-((vel+1)*3) to y+((vel+1)*3) do
                    if getpixel (a,b)=color then putpixel (a,b,bkcolor);
         if rezim=18 then circle (x,y,(vel+1)*3);
         if rezim=38 then rectangle (x-((vel+1)*3),y-((vel+1)*3),x+((vel+1)*3),y+((vel+1)*3));
         ukaz_mysku;
         end;
      end;
   if (rezim = 14) or (rezim = 13) then begin
      if (but1) and (muze) then begin
         poprve:=false;
         setfillstyle (styl,bkcolor);
         if rezim=14 then if random(4) = 2 then putpixel (x-((vel+1)*3)+random((vel+1)*6),
                                                y-((vel+1)*3)+random((vel+1)*6),color);
         if rezim=13 then if random(50) = 2 then line (x-((vel+1)*3)+random((vel+1)*6),y-((vel+1)*3)+random((vel+1)*6),
                                                 x-((vel+1)*3)+random((vel+1)*6),y-((vel+1)*3)+random((vel+1)*6));
         end;
      end;



{   O B D E L N I K ,
    V Y B A R V E N Y   O B D E L N I K ,
    P L O C H A                                                                 }

   if ((rezim = 24) or (rezim = 25) or (rezim = 5)) and (but1) and (sbut1=false) then begin
      hranice_mysky (48,0,639,410);
      zx:=sx;
      zy:=sy;
      muze:=true;
      end;
   if ((rezim = 24) or (rezim = 25) or (rezim = 5)) and (muze) and (but1=false) and (sbut1) then begin
      schovej_mysku;
      setwritemode (1);
      rectangle (zx,zy,sx,sy);
      setwritemode (0);
      setfillstyle (styl,bkcolor);
      if rezim<>24 then bar (zx,zy,x,y);
      if rezim<>5 then rectangle (zx,zy,x,y);
      ukaz_mysku;
      hranice_mysky (0,0,639,479);
      muze:=false;
      end;
   if (rezim = 24) or (rezim = 25) or (rezim = 5) then begin
      if (but1) and (muze) and ((x<>sx) or (y<>sy)) then begin
         schovej_mysku;
         setwritemode (1);
         rectangle (zx,zy,sx,sy);
         rectangle (zx,zy,x,y);
         setwritemode (0);
         ukaz_mysku;
         end;
      end;

{   C T V E R E C ,
    V Y B A R V E N Y   C T V E R E C ,
    C T V E R C O V A  P L O C H A                                                      }


   if ((rezim = 9) or (rezim = 29) or (rezim = 10)) and (but1) and (sbut1=false) then begin
      a:=sy;
      b:=0;
      while a<410 do begin
         b:=b+1;
         a:=a+1;
         end;
      hranice_mysky (48,0,sx+b,410);
      zx:=sx;
      zy:=sy;
      muze:=true;
      end;
   if ((rezim = 9) or (rezim = 29) or (rezim = 10)) and (muze) and (but1=false) and (sbut1) then begin
      schovej_mysku;
      setwritemode (1);
      rectangle (zx,zy,sx,zy+(sx-zx));
      setwritemode (0);
      setfillstyle (styl,bkcolor);
      if rezim<>9 then bar (zx,zy,x,zy+(x-zx));
      if rezim<>10 then rectangle (zx,zy,x,zy+(x-zx));
      ukaz_mysku;
      hranice_mysky (0,0,639,479);
      muze:=false;
      end;
   if (rezim = 9) or (rezim = 29) or (rezim = 10) then begin
      if (but1) and (muze) and ((x<>sx) or (y<>sy)) then begin
         schovej_mysku;
         setwritemode (1);
         rectangle (zx,zy,sx,zy+(sx-zx));
         rectangle (zx,zy,x,zy+(x-zx));
         setwritemode (0);
         ukaz_mysku;
         end;
      end;

{    S E L E K T I V N I   O B D E L N I K ,
     N U Z K Y ,
     N E G A T I V N I   O B D E L N I K ,
     O T O C E N I   P O D L E   V O D O R O V N E   O S Y ,
     O T O C E N I   P O D L E   S V I S L E   O S Y ,
     M O Z A I K A ,
     N A H O D N A   M O Z A I K A                                              }

   if ((rezim = 1) or (rezim = 17) or (rezim = 37) or (rezim = 15) or (rezim = 16) or (rezim = 36) or (rezim = 33))
              and (but1) and (sbut1=false) then begin
      hranice_mysky (48,0,639,410);
      zx:=sx;
      zy:=sy;
      muze:=true;
      end;
   if ((rezim = 1) or (rezim = 17) or (rezim = 37) or (rezim = 15) or (rezim = 16) or (rezim = 36) or (rezim = 33))
                   and (muze) and (but1=false) and (sbut1) then begin
      schovej_mysku;
      setcolor (15);
      setwritemode (1);
      rectangle (zx,zy,sx,sy);
      setwritemode (0);
      srovnej (zx,zy,sx,sy);
      if (rezim=17) then begin
         mozaika (zx,zy,sx,sy);
         end;
      if (rezim=37) then begin
         nmozaika (zx,zy,sx,sy);
         end;
      if rezim=33 then begin
         setwritemode (1);
         for a:=zx to sx do line (a,zy,a,sy);
         setwritemode (0);
         end;
      if rezim=1 then
          for a:=zx to sx do
             for b:=zy to sy do
                if getpixel (a,b) = color then putpixel (a,b,bkcolor);
      if (rezim=15) or (rezim = 16) or (rezim = 36) then begin
         uloz (zx,zy,sx,sy);
         hranice_mysky (48,0,639,410-(sy-zy));
         ukaz_mysku;
         a:=sx-zx;
         b:=sy-zy;
         setlinestyle (3,0,1);
         setwritemode (1);
         sx:=x;
         sy:=y;
         sbut1:=but1;
         sbut2:=but2;
         sbut3:=but3;
         pozice_mysky (x,y,but1,but2,but3);
         schovej_mysku;
         rectangle (x,y,x+a,y+b);
         repeat
           sx:=x;
           sy:=y;
           sbut1:=but1;
           sbut2:=but2;
           sbut3:=but3;
           pozice_mysky (x,y,but1,but2,but3);
           if (x<>sx) or (y<>sy) then begin
              rectangle (sx,sy,sx+a,sy+b);
              end;
           if (x<>sx) or (y<>sy) then begin
              rectangle (x,y,x+a,y+b);
              end;
           if (but1) and (sbut1=false) then begin
              rectangle (x,y,x+a,y+b);
              setwritemode (0);
              case rezim of 15:nacti (sx,sy,sx+a,sy+b);
                            16:nactiv (sx,sy,sx+a,sy+b);
                            36:nactis (sx,sy,sx+a,sy+b);
                            end;
              setwritemode (1);
              rectangle (x,y,x+a,y+b);
              end;
         until but2;
         rectangle (x,y,x+a,y+b);
         setwritemode (0);
         case rezim of 15:nacti (sx,sy,sx+a,sy+b);
               16:nactiv (sx,sy,sx+a,sy+b);
               36:nactis (sx,sy,sx+a,sy+b);
               end;
         end;
      ukaz_mysku;
      hranice_mysky (0,0,639,479);
      muze:=false;
      end;
   if ((rezim = 1) or (rezim = 15) or (rezim = 17) or (rezim = 37) or (rezim = 16) or (rezim = 36) or (rezim = 33)) then begin
      if (but1) and (muze) and ((x<>sx) or (y<>sy)) then begin
         schovej_mysku;
         setwritemode (1);
         setcolor (15);
         rectangle (zx,zy,sx,sy);
         rectangle (zx,zy,x,y);
         setwritemode (0);
         ukaz_mysku;
         end;
      end;
   end;

setwritemode (1);
{if (x<>sx) or (y<>sy) then begin
line (x,y,x+4,y);
line (x,y,x,y+5);
line (x,y,x+5,y+7);
end;}
setwritemode (0);
until inkey=27;
end.