unit mx;

 interface  {zagolovki, strukturi}
  uses graph;


  const MaxList = 20;
        SelectedColor = WHITE;
        NotSelectedColor = DARKGRAY;

   VK_ESC   = #27;
   VK_UP    = #72;
   VK_DOWN  = #80;
   VK_ENTER = #13;


  {STRUCTURI}

  { - Vspomogatelnie structuri - }

   type mxRect = record
    x,y, x2, y2 : Longint;
   end;



  { - Osnovnie structuri i funkcii - }



  {Parametri input box}
   type mxInpTextBox = record
    position : mxRect;
    text : Longint;
   end;

  {Procedura inicilizacii input box}
   procedure mx_Init_InpTextBox(var obj:mxInpTextBox);

  {Procedura otrisovki input box}
   procedure mx_Draw_InpTextBox(var obj:mxInpTextBox; Caption : string);

  {Procedura Vipolnenia Zadania 4isla + otrisovka}
   procedure mx_Execute_InpTextBox(var obj:mxInpTextBox; Caption : string);




  {Parametri input box}
   type mxListBox = record
     position : mxRect;
     text : array[1..MaxList] of string [50];
     selected : Longint;
     UsedList : Longint;
   end;

  {Procedura inicilizacii input box}
   procedure mx_Init_ListBox(var obj:mxListBox);

  {Procedura otrisovki input box}
   procedure mx_Draw_ListBox(var obj:mxListBox; Caption : string);

  {Procedura Vipolnenia Zadania 4isla + otrisovka}
   procedure mx_Execute_ListBox(var obj:mxListBox; Caption : string);

  {Parametri label}
  type mxRealLabel = record
    position : mxRect;
    data     : Real;
  end;
  {Procedura inicializacii input box}
   procedure mx_Init_RealLabel( var obj: mxRealLabel );
  {Procedure otrisovki input box}
   procedure mx_Draw_RealLabel( var obj: mxRealLabel; Caption : string );
  {Procedura vipolnenia}
   procedure mx_Execute_RealLabel( var obj: mxRealLabel; Caption : string );


   function inttostr(x:Longint) : string;

 implementation {opisania}
  uses crt;


 {--- Perevod iz Longint v string ---}
 function inttostr(x:Longint) : string;
 var s:string;
 begin
  str(x, s);
  inttostr:=s;
 end;




  {Procedura otrisovki input box}
   procedure mx_Draw_InpTextBox;
   var size_letter , center_x: Longint;
    begin
     setcolor(LIGHTGRAY);
    with obj.position do
     begin
       setcolor(DARKGRAY);
      rectangle (x,y, x2+1, y2+1);
       setcolor(LIGHTGRAY);
      rectangle (x,y, x2, y2);
       setcolor(DARKGRAY);
      rectangle (x+30 , y+40, x2-30, y2-100);
       setcolor(WHITE);
      outtextxy(x+120, y2-20, 'Enter ~ Ok' );
       setcolor(LIGHTGRAY);
       size_letter := 8;
       center_x := x+40+((x2-40)-(x+40)) div 2;
      outtextxy(center_x - size_letter * (Length(caption) div 2),
                 y + (y2-y) div 2, Caption);
      outtextxy(center_x - size_letter * (Length('Old input: '+inttostr(obj.text)) div 2),
                 y + (y2-y) div 2 + 16, 'Old input: '+inttostr(obj.text));
     end;
    end;

  {Procedura inicilizacii input box}
   procedure mx_Init_InpTextBox;
    begin

     with obj.position do begin
     x := getmaxx div 2 - getmaxx div 4;  { levo x }
     y := getmaxy div 2 - getmaxy div 8 +22;  { verh y }
     x2 := getmaxx div 2 + getmaxx div 4; { pravo x }
     y2 := getmaxy div 2 + getmaxy div 8 +22; { niz y }
                          end;
     obj.text := 0;
    end;

  {Procedura Vipolnenia Zadania 4isla + otrisovka}
   procedure mx_Execute_InpTextBox;
    var xt, yt : Longint;
    begin
    cleardevice;
     mx_Draw_InpTextBox(obj, Caption);
       xt:= round(79*((obj.position.x+48) / getmaxx));
       yt:= round(24*((obj.position.y+90) / getmaxy));
      gotoxy(xt, yt);
     readln(obj.text);
    end;



  {Procedura otrisovki LIST  box}
   procedure mx_Draw_ListBox;
   var size_letter , center_x: Longint;
        i : Longint;

    begin
     setcolor(LIGHTGRAY);
    with obj.position do
     begin
       setcolor(DARKGRAY);
      rectangle (x,y, x2+1, y2+1);
       setcolor(LIGHTGRAY);
      rectangle (x,y, x2, y2);
      rectangle (x,y+1, x2, y+16);
      rectangle (x, y2 - 16, x2, y2);
       setcolor(WHITE);
      outtextxy(x+120, y2-12, 'Enter ~ Ok' );
       setcolor(LIGHTGRAY);
       size_letter := 8;
       center_x := x+40+((x2-40)-(x+40)) div 2;
      outtextxy(center_x - size_letter * (Length(caption) div 2),
                 y+6 , Caption);
     end;

      for i:= 1 to MaxList do
       if obj.text[i] <> '' then
        begin
          if obj.selected = i then
           setcolor(SelectedColor) else
            setcolor(NotSelectedColor);

         outtextxy(center_x - size_letter * (Length(obj.text[i]) div 2),
                    obj.position.y+40 + 11*i,
                     obj.text[i]);
        end;


    end;

  {Procedura inicilizacii LIST box}
   procedure mx_Init_ListBox;
   var i:Longint;
    begin

     with obj.position do begin
     x := getmaxx div 2 - getmaxx div 4;  { levo x }
     y :=             getmaxy div 9;  { verh y }
     x2 := getmaxx div 2 + getmaxx div 4; { pravo x }
     y2 := getmaxy - getmaxy div 9; { niz y }
                          end;
     obj.selected := 1;
     for i:=1 to MaxList do obj.text[i] := '';
    end;

  {Procedura Vipolnenia LIST box}
   procedure mx_Execute_ListBox;
    var xt, yt : Longint;
        c : char;
    begin
    cleardevice;
     mx_Draw_ListBox(obj, Caption);

     repeat
        c := readkey;
        case c of
            VK_DOWN : obj.selected := obj.selected + ord(obj.selected<obj.UsedList);
            VK_UP : obj.selected := obj.selected - ord(obj.selected>1);
            VK_ESC : obj.selected :=  obj.UsedList;
        end;
         mx_Draw_ListBox(obj, Caption);
     until c=VK_ENTER;
      end;



  {Procedura otrisovki input box}
   procedure mx_Draw_RealLabel;
   var size_letter , center_x: Longint;
    begin
     setcolor(LIGHTGRAY);
    with obj.position do
     begin
       setcolor(DARKGRAY);
      rectangle (x,y, x2+1, y2+1);
       setcolor(LIGHTGRAY);
      rectangle (x,y, x2, y2);
       setcolor(DARKGRAY);
      rectangle (x+30 , y+40, x2-30, y2-100);
       setcolor(WHITE);
      outtextxy(x+120, y2-20, 'Enter ~ Ok' );
       setcolor(LIGHTGRAY);
       size_letter := 8;
       center_x := x+40+((x2-40)-(x+40)) div 2;
      outtextxy(center_x - size_letter * (Length(caption) div 2),
                 y + (y2-y) div 2, Caption);
       end;
    end;

  {Procedura inicilizacii input box}
   procedure mx_Init_RealLabel;
    begin

     with obj.position do begin
     x := getmaxx div 2 - getmaxx div 4;  { levo x }
     y := getmaxy div 2 - getmaxy div 8 +22;  { verh y }
     x2 := getmaxx div 2 + getmaxx div 4; { pravo x }
     y2 := getmaxy div 2 + getmaxy div 8 +22; { niz y }
                          end;
     obj.data := 0;
    end;

  {Procedura Vipolnenia Zadania 4isla + otrisovka}
   procedure mx_Execute_RealLabel;
    var xt, yt : Longint;
        c : char;
        s : string;
    begin
    cleardevice;
     mx_Draw_RealLabel(obj, Caption);
     Str( obj.data: 8 : 6, s);
      xt := obj.position.x + (obj.position.x2-obj.position.x) div 2 - Length(s)*5;
      yt := obj.position.y + 25;
      gotoxy(xt, yt);

      outtextxy( xt, yt, s );

     repeat
        c := readkey;
        {mx_Draw_RealLabel(obj, Caption);}
     until c=VK_ENTER;
    end;


end.

