Guest User

Untitled

a guest
Jan 23rd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.59 KB | None | 0 0
  1. uses Containers, GraphABC, Events;
  2.  
  3. const H = 1;
  4.  
  5. var
  6. a : StringArray;
  7. f : Text;
  8. s : string;
  9. i, x, y, xc, yc, cnt, xl, yl, nums, num, fst, last : integer;
  10. was, button, move, shift : boolean;
  11.  
  12. function min(a, b : integer) : integer;
  13. begin
  14. if (a > b) then
  15. result := b
  16. else
  17. result := a;
  18. end;
  19.  
  20. function max(a, b : integer) : integer;
  21. begin
  22. if (a > b) then
  23. result := a
  24. else
  25. result := b;
  26. end;
  27.  
  28. procedure Clear;
  29. begin
  30. SetBrushColor(clWhite);
  31. FillRect(0, 0, WindowWidth, WindowHeight);
  32. end;
  33.  
  34. procedure TOut(s : string; w, id : integer);
  35. begin
  36. SetBrushColor(clWhite);
  37. SetFontColor(clBlack);
  38. TextOut(w, (TextHeight(s) + H) * (id - fst), s);
  39. end;
  40.  
  41. procedure Blue;
  42. var
  43. sbeg, send, idbeg, idend : integer;
  44. s1, s2 : string;
  45. begin
  46. sbeg := xl;
  47. idbeg := yl;
  48. send := nums;
  49. idend := num;
  50. if (sbeg > send) then
  51. begin
  52. sbeg := nums;
  53. send := xl;
  54. idbeg := num;
  55. idend := yl;
  56. end;
  57. if ((sbeg = send) and (idbeg > idend)) then
  58. begin
  59. idbeg := num;
  60. idend := yl;
  61. end;
  62.  
  63. SetBrushColor(clBlue);
  64. SetFontColor(clWhite);
  65. for i := sbeg to send do
  66. begin
  67. if (Length(a[i]) = 0) then
  68. TextOut(0, (textHeight(a[1]) + H) * (i - fst), ' ')
  69. else
  70. TextOut(0, (textHeight(a[1]) + H) * (i - fst), a[i]);
  71. end;
  72. s1 := ''; s2 := '';
  73. for i := 1 to idbeg - 1 do
  74. s1 := s1 + a[sbeg][i];
  75. for i := num + 1 to length(a[send]) do
  76. s2 := s2 + a[send][i];
  77. TOut(s1, 0, sbeg);
  78. Tout(s2, TextWidth(a[send]) - TextWidth(s2), send);
  79.  
  80. end;
  81.  
  82. procedure Cursor(s : string; w, id : integer);
  83. begin
  84. SetFontColor(clWhite);
  85. SetBrushColor(clBlack);
  86. TextOut(w, (TextHeight(s) + H) * (id - fst), s);
  87. end;
  88.  
  89. procedure CD;
  90. var
  91. t, t1 : string;
  92. begin
  93. if (nums < a.count) then
  94. begin
  95. TOut(' ', 0, nums);
  96. TOut(a[nums], 0, nums);
  97.  
  98. inc(nums);
  99. if (shift) then
  100. Blue;
  101. if (length(a[nums]) < 1) then
  102. begin
  103. Cursor(' ', 0, nums);
  104. num := 1;
  105. end
  106. else
  107. begin
  108. if (num > length(a[nums])) then
  109. num := length(a[nums]);
  110.  
  111. t1 := '';
  112. t1 := t1 + a[nums][num];
  113.  
  114. t := '';
  115. for i := 1 to num - 1 do
  116. t := t + a[nums][i];
  117. Cursor(t1, TextWidth(t), nums);
  118. end;
  119. end;
  120. end;
  121.  
  122. procedure CU;
  123. var
  124. t, t1 : string;
  125. begin
  126. if (nums > 1) then
  127. begin
  128. TOut(' ', 0, nums);
  129. TOut(a[nums], 0, nums);
  130. dec(nums);
  131.  
  132. if (shift) then
  133. Blue;
  134. if (length(a[nums]) < 1) then
  135. begin
  136. Cursor(' ', 0, nums);
  137. num := 1;
  138. end
  139. else
  140. begin
  141. if (num > length(a[nums])) then
  142. num := length(a[nums]);
  143.  
  144. t := ''; t1 := '';
  145. t1 := t1 + a[nums][num];
  146. for i := 1 to num - 1 do
  147. t := t + a[nums][i];
  148. Cursor(t1, TextWidth(t), nums);
  149. end;
  150. end;
  151. end;
  152.  
  153. procedure CR;
  154. var
  155. t, t1 : string;
  156. begin
  157. if (length(a[nums]) - 1 >= num) then
  158. begin
  159. TOut(' ', 0, nums);
  160. TOut(a[nums], 0, nums);
  161. t := '';
  162. t1 := '';
  163. for i := 1 to num do
  164. t := t + a[nums][i];
  165. t1 := t1 + a[nums][num + 1];
  166. inc(num);
  167. if (shift) then
  168. Blue;
  169.  
  170. Cursor(t1, TextWidth(t), nums);
  171. end
  172. else
  173. if (nums < a.count) then
  174. begin
  175. TOut(' ', 0, nums);
  176. TOut(a[nums], 0, nums);
  177. num := 1;
  178. CD;
  179. end;
  180. end;
  181.  
  182. procedure CL;
  183. var
  184. t, t1 : string;
  185. begin
  186. if (num - 1 > 0) then
  187. begin
  188. TOut(' ', 0, nums);
  189. TOut(a[nums], 0, nums);
  190. t := '';
  191. t1 := '';
  192. for i := 1 to num - 1 do
  193. t := t + a[nums][i];
  194. t1 := t1 + a[nums][num - 1];
  195.  
  196. dec(num);
  197. if (shift) then
  198. Blue;
  199. Cursor(t1, TextWidth(t) - TextWidth(t1), nums);
  200. end
  201. else
  202. if (nums > 1) then
  203. begin
  204. TOut(' ', 0, nums);
  205. TOut(a[nums], 0, nums);
  206. num := length(a[nums - 1]);
  207. CU;
  208. end;
  209. end;
  210.  
  211. procedure KU(key :integer);
  212. begin
  213. if (key = vk_Shift) then
  214. shift := false;
  215. end;
  216.  
  217. procedure KD(key : integer);
  218. begin
  219. if (not(shift)) then
  220. begin
  221. xl := nums;
  222. yl := num;
  223. end;
  224.  
  225. if (key = vk_shift) then
  226. shift := true;
  227.  
  228. if ((key = vk_Down) and (nums >= last ) and (nums < a.count)) then
  229. begin
  230. Clear;
  231. inc(fst); inc(last);
  232. for i := fst to a.count do
  233. TOut(a[i], 0, i);
  234. end;
  235. if ((key = vk_Up) and (nums > 1) and (nums <= fst)) then
  236. begin
  237. Clear;
  238. dec(fst); dec(last);
  239. for i := fst to a.count do
  240. TOut(a[i], 0, i);
  241. end;
  242. if ((key = vk_Right) and (num >= length(a[nums])) and (nums >= last) and (nums < a.count)) then
  243. begin
  244. Clear;
  245. inc(fst); inc(last);
  246. for i := fst to a.count do
  247. TOut(a[i], 0, i);
  248. end;
  249. if ((key = vk_Left) and (num <= 1) and (nums <= fst) and (nums > 1)) then
  250. begin
  251. Clear;
  252. dec(fst); dec(last);
  253. for i := fst to a.count do
  254. TOut(a[i], 0, i);
  255. end;
  256.  
  257. if (key = vk_Right) then
  258. CR;
  259. if (key = vk_Left) then
  260. CL;
  261. if (key = vk_Down) then
  262. CD;
  263. if (key = vk_Up) then
  264. CU;
  265.  
  266.  
  267. end;
  268.  
  269. begin
  270. cls;
  271. OnKeyDown := KD;
  272. OnKeyUp := KU;
  273. Assign(f, 'sample.txt');
  274. Reset(f);
  275. SetFontName('Tahoma');
  276. SetFontSize(14);
  277. nums := 1;
  278. fst := 1;
  279.  
  280. a := StringArray.create;
  281. while (not eof(f)) do
  282. begin
  283. readln(f, s);
  284. a.add(s);
  285. end;
  286. for i := 1 to a.count do
  287. TOut(a[i], 0, i);
  288.  
  289. y := 0;
  290. cnt := 0;
  291. while ((y < WindowHeight) and (cnt < a.count)) do
  292. begin
  293. y := y + TextHeight(a[1]) + 5;
  294. inc(last);
  295. inc(cnt);
  296. end;
  297. //dec(last);
  298.  
  299. nums := 1;
  300. num := 1;
  301. s := '';
  302. s := s + a[1][1];
  303. Cursor(s, 0, 1);
  304.  
  305. Close(f);
  306. end.
Add Comment
Please, Sign In to add comment