NBPrg40. NBPRG40U.PAS. MiniOS. OpenSource.

NBPrg40. NBPRG40U.PAS. MiniOS. OpenSource.
***************************************

{ Nikita Beloshenko (GNU) 2013  }

{ NBPRG23 -> ... -> NBPRG40 }

{ Nikita Beloshenko (GNU) 2012 }

Unit NBPRG40U;

(***************************************************
 *                                                 *
 *   NBPRG40U.PAS                                  *
 *                                                 *
 *   NBPRG40U.                                     *
 *                                                 *
 ***************************************************)

Interface

Procedure NBPRG40U_run;

Implementation

Uses Graph,Crt,N40t1,N40t2,N40t3,N40t4,Inst,Simple,Calc,Edit,Files,NBPRG_I;

Const
  MaxNTask = 20;
  MenuColor = 4;
Var
  TFile : Text;
  TaskList : Array[1..MaxNTask] Of String;
  PNameList : Array[1..MaxNTask] Of String;
  Ntask : Byte;
  gd,gm,i : Integer;
  s : String;
  ch : Char;

Procedure DrawSmallPicture16x16(Var X0,Y0 : Integer; Path : String);
Var
  X,Y : Integer;
  i1,j1 : Byte;
  TFile : Text;
  Color : Byte;
Begin
  assign(TFile, Path);
  reset(TFile);
  For i1 := 1 To 16 Do
  Begin
    For j1 := 1 To 16 Do
    Begin
      X := X0 + j1;
      Y := Y0 + i1;
      Read(TFile, Color);
      PutPixel(X,Y,Color);
    End;
    ReadLn(TFile);
  End;
  close(TFile);
End;

Procedure DrawRectangle(Var x1,y1,x2,y2:Integer);
Begin
  Line(x1,y1,x2,y1);
  Line(x2,y1,x2,y2);
  Line(x2,y2,x1,y2);
  Line(x1,y2,x1,y1);
End;

Procedure DrawNtaskRectangle;
Var
  x1,y1,x2,y2:Integer;
  j:Byte;
  Path : String;
Begin
  SetColor(MenuColor);
  For j:=1 To Ntask Do
  Begin
    x1 := 20; y1 := 20 + (j-1)*40;
    x2 := 40; y2 := 40 + (j-1)*40;
    DrawRectangle(x1,y1,x2,y2);
    SetTextStyle(2, HorizDir, 5);
    OutTextXY(x2 + 20, y1, TaskList[j]);

    Path := PNameList[j];
    DrawSmallPicture16x16(x1,y1,Path);
  End;

  x1 := 20 - 5;
  x2 := 20 + 20 + 5;
  y1 := 20 - 5;
  y2 := 40 + (Ntask - 1)*40 + 5;

  DrawRectangle(x1,y1,x2,y2);
End;

Procedure DrawMRectangle;
Var
  x1,y1,x2,y2:Integer;
Begin
  SetColor(4);
  x1:=20 - 1;y1:=20 + (i-1)*40 - 1;x2:=40 + 1;y2:=40 + (i-1)*40 + 1;
  DrawRectangle(x1,y1,x2,y2);
End;

Procedure ErraseMRectangle;
Var
  x1,y1,x2,y2:Integer;
Begin
  SetColor(0);
  x1:=20 - 1;y1:=20 + (i-1)*40 - 1;x2:=40 + 1;y2:=40 + (i-1)*40 + 1;
  DrawRectangle(x1,y1,x2,y2);
End;

Procedure ExecuteTask(Var Command:String);
Begin
  If Command ='task1' Then DoTask1;
  If Command ='task2(histogram)' Then DoTask2; {task2->histogram}
  If Command ='task3' Then DoTask3;
  If Command ='task4' Then DoTask4;

  {...TODO : ADD HERE REACTIONS...}

  If Command = 'calc' Then DoCalc;
  If Command = 'edit' Then DoEdit;
  If Command = 'files' Then DoFiles;

  If Command ='install/del customer task (help)' Then DoInstHelp;
  If Command ='Reset SIMPLE.PAS (test user task)' Then DoInst;
  If Command ='Simple (test user task)' Then DoSimple;

End;

Procedure NBPRG40U_run;
Label NEXT,PREV,START,EXIT;
Var
  x1,y1,x2,y2 : Integer;
Begin
  gd := Detect;
  InitGraph(gd,gm,'');

  Ntask := 0;

  assign(TFile,'list.tck');
  reset(TFile);
  While Not eof(TFile) Do
  Begin
    Inc(NTask);
    ReadLn(TFile,TaskList[Ntask]);
    ReadLn(TFile,PNameList[Ntask]);
  End;
  close(TFile);

  If NTask > MaxNTask Then NTask := MaxNTask;

  i:=1;

  { ADDITION GRAPHICAL INTERFACE RELOADING ... }
  NBPRG_I_reload_interf;

START:

  DrawNtaskRectangle;

  SetTextStyle(2, HorizDir, 5);
  OutTextXY(350,300,'Enter - Select task');

  x1 := 350 - 10;
  x2 := 500 + 10;
  y1 := 300 - 10;
  y2 := 300 + 20 + 10;
  DrawRectangle(x1,y1,x2,y2);

  OutTextXY(350,50,'Nikita Beloshenko (GNU) 2012, 2013');

  DrawMRectangle;
  ch := ReadKey;
  ErraseMRectangle;
  If Ord(ch) = 80 Then Goto NEXT;
  If Ord(ch) = 72 Then Goto PREV;
  If Ord(ch) = 27 Then Goto EXIT;

  { 13 = "ENTER". }
  If Ord(ch) = 13 Then
  Begin
    ExecuteTask(TaskList[i]);

    { ADDITION GRAPHICAL INTERFACE RELOADING ... }
    NBPRG_I_reload_interf;
  End;
  Goto START;

NEXT:
  Inc(i);
  If i>Ntask Then Dec(i);
  Goto START;

PREV:
  Dec(i);
  If i<1 Then Inc(i);
  Goto START;

EXIT:
  ReadLn(s);
  CloseGraph;
End;

End.