MYTPU.PAS 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. Unit MyTPU;
  2. INTERFACE
  3. {----------------------------------------}
  4. Procedure InitVGA;
  5. Procedure CloseVGA;
  6. Procedure Mouse;
  7. Function GetValue(text:string;x1,y1,MinValue,MaxValue:integer):integer;
  8. {----------------------------------------------}
  9. IMPLEMENTATION
  10. {----------------------------------------------}
  11. Uses CRT,Graph,F_Mouse;
  12. {--------------------------------------}
  13. Procedure VGADRV;external;
  14. {$L vgadrv.obj}
  15. {---------------------------------------}
  16. Procedure InitVGA;
  17. Var
  18. Gd,Gm:Integer;
  19. Begin
  20. if RegisterBGIDriver(@VGADRV) < 1 then Halt(1);
  21. Gd := VGA;Gm:=VGAhi;
  22. InitGraph(Gd, Gm,'');
  23. if GraphResult <> grOk then begin
  24. Write(GraphErrorMsg(GraphResult));
  25. Halt(1);
  26. end;
  27. end{InitVGA};
  28. {--------------------------------------}
  29. Procedure CloseVGA;
  30. begin
  31. CloseGraph
  32. end;{CloseVGA}
  33. {--------------------------------------------}
  34. Procedure MOUSE;
  35. begin
  36. if not InitMouse then begin
  37. WriteLn('Unable to Init mouse');
  38. Halt(1);
  39. end
  40. else
  41. ShowMouse;
  42. end;{MOUSE}
  43. {------------------------------------------}
  44. Function GetValue(text:string;x1,y1,MinValue,MaxValue:integer):integer;
  45. Var
  46. p1 : pointer;
  47. s1 : word;
  48. x,y,StartX,StartY,xk : integer;
  49. k : real;
  50. length : integer;
  51. ch : char;
  52. st : string;
  53. value : byte;
  54. code : integer;
  55. {--------------------------------------}
  56. Procedure EnterVal;
  57. Begin
  58. SetFillStyle(CloseDotFill,LightBlue);
  59. Bar(Startx,starty,Startx+length,Starty+60);
  60. SetColor(White);
  61. Rectangle(Startx,starty,Startx+length,Starty+60);
  62. SetColor(LightGray);
  63. SetTextJustify(CenterText,TopText);
  64. OutTextXY(startx + length div 2, Starty+15,Text);
  65. SetColor(Yellow);
  66. SetTextJustify(LeftText,TopText);
  67. x := Startx+20;
  68. y := Starty+35;
  69. st := '';
  70. Repeat
  71. ch := readkey;
  72. if ch <> #13 then
  73. begin
  74. st := st + ch;
  75. OutTextXY(x,y,ch);
  76. if x < startx+length-40 then x := x + TextWidth(ch);
  77. end;
  78. Until ch = #13;
  79. End;{EnterVal}
  80. {-----------------------------------}
  81. Procedure WriteBox(x,y:Integer);
  82. Begin
  83. SetColor(White);
  84. SetFillStyle(CloseDotFill,LightBlue);
  85. Bar(StartX+length div 2 - x,StartY+30-y,StartX+length div 2+x,StartY+30+y);
  86. Rectangle(StartX+length div 2 - x,StartY+30-y,StartX+length div 2+x,StartY+30+y);
  87. Delay(5);
  88. End;{WriteBox}
  89. {-------------------------------------}
  90. Begin
  91. If MinValue > MaxValue then begin
  92. GetValue := 0;
  93. Exit;
  94. end;
  95. length := TextWidth(text) + 50;
  96. StartX := x1 - length div 2;
  97. StartY := y1 - 30;
  98. if length div 2 > x1 then startX := 2;
  99. if y1 - 30 < 2 then Starty := 1;
  100. if length div + x1 > 639 then Startx := 639 - length;
  101. if y1 + 30 > 479 then StartY := 419;
  102. s1 := ImageSize(Startx,Starty,startx+length,Starty+60);
  103. GetMem(p1,s1);
  104. GetImage(Startx,Starty,startx+length,Starty+60,p1^);
  105. value :=0 ;
  106. xk := 1;
  107. k :=60/length;
  108. for xk := 1 to length div 2 do WriteBox(xk,round(xk*k));
  109. Repeat
  110. EnterVal;
  111. val(st,value,code);
  112. Until (code = 0) and (value in [MinValue..MaxValue]);
  113. PutImage(Startx,Starty,p1^,NormalPut);
  114. GetValue := Value;
  115. End;{GetValue}
  116. {----------------------------------------------}
  117. end.