MYTPU.PAS 4.0 KB

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