 {~ Rectangle of any size and orientation, movable by cursor keys ~}

Unit MBox; {plots a rectangle of a given size and orientation and enables to
            shift it slowly by cursor keys and quickly by ...,
            as well as rotate it by + and -.}
(*  Copyright (C) 1999 David Motl, Rudolf Novak and Jan Hollan;
  by "program" this unit is further meant.

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*)

INTERFACE
uses crt,dos,graph;

Procedure Box(var x_centre,y_centre:integer; x_pm, y_pm:byte);
 {shows a rectangle sized 2 * x_pm, 2 * y_pm which can be then moved
  by cursor keys}

Procedure Kursor(var x_centre,y_centre:integer);
  {same, just size is fixed to 10*10}

Implementation

var x,y:word;
ch:char;
p:pointer;
Size_of_box:word;
Stop_moving: boolean;

Procedure Box(var x_centre,y_centre:integer; x_pm, y_pm:byte);


procedure borders;        {of the box}
 begin
{  line(x-x_pm,y-y_pm,x+x_pm,y-y_pm);
  line(x-x_pm,y-y_pm,x-x_pm,y+y_pm);
  line(x+x_pm,y-y_pm,x+x_pm,y+y_pm);
  line(x-x_pm,y+y_pm,x+x_pm,y+y_pm);
} rectangle(x-x_pm,y-y_pm,x+x_pm,y+y_pm);
 end;

begin
Stop_moving:=false;
x:=x_centre; y:=y_centre;
setlinestyle(solidln,0,normwidth);
Size_of_box:=imagesize(0,0,1+2*x_pm,1+2*y_pm);
getmem(p,Size_of_box);
getimage(x-x_pm,y-y_pm,x+x_pm,y+y_pm,p^);
borders;
repeat
   ch:=readkey;
   putimage(x-x_pm,y-y_pm,p^,0);
   if ch=#0 then 
    begin 
     ch:=readkey; 
     Case ch of
      #77: inc(x);
      #75: dec(x);
      #72: dec(y);
      #80: inc(y);
      #116:inc(x,20);
      #115:dec(x,20);
      #73: dec(y,20);
      #81: inc(y,20);
      else stop_moving:=true;
     end;
     getimage(x-x_pm,y-y_pm,x+x_pm,y+y_pm,p^);
     setcolor(white);
     borders;
    end
   else stop_moving:=true;
until stop_moving;
freemem(p,Size_of_box);
x_centre:=x; y_centre:=y;
end;

Procedure Kursor(var x_centre,y_centre:integer);
begin
 Box(x_centre,y_centre, 10, 10);
end;

end.
