Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.24 KB | None | 0 0
  1. type allThings = record
  2. line : array of TPoint;
  3. lineLength : integer;
  4. color : TColor;
  5. name : string;
  6. width : integer;
  7. end;
  8. var
  9. Form1: TForm1;
  10. i,j,penState, length: integer;
  11. drawing : boolean;
  12.  
  13. allLine : array of allThings;
  14.  
  15. implementation
  16.  
  17. {$R *.lfm}
  18. { TForm1 }
  19.  
  20. procedure TForm1.PaintBoxMouseUp(Sender: TObject; Button: TMouseButton;
  21. Shift: TShiftState; X, Y: Integer);
  22. begin
  23. if drawing = true then
  24. begin
  25. case penState of
  26. 1: begin
  27. allLine[length-1].name := 'brush';
  28. end;
  29. 2: begin
  30. allLine[length-1].line[1].x := x;
  31. allLine[length-1].line[1].y := y;
  32. PaintBox.Canvas.Line(allLine[length-1].line[0].x,allLine[length-1].line[0].y,allLine[length-1].line[1].x,allLine[length-1].line[1].y);
  33. allLine[length-1].name := 'line';
  34. end;
  35. 3: begin
  36. allLine[length-1].line[1].x := x;
  37. allLine[length-1].line[1].y := y;
  38. PaintBox.Canvas.Ellipse(allLine[length-1].line[0].x,allLine[length-1].line[0].y,allLine[length-1].line[1].x,allLine[length-1].line[1].y);
  39. allLine[length-1].name := 'Ellipse';
  40. end;
  41. 4: begin
  42. allLine[length-1].line[1].x := x;
  43. allLine[length-1].line[1].y := y;
  44. PaintBox.Canvas.Rectangle(allLine[length-1].line[0].x,allLine[length-1].line[0].y,allLine[length-1].line[1].x,allLine[length-1].line[1].y);
  45. allLine[length-1].name := 'Rectangle';
  46. end;
  47. end;
  48. drawing:= false;
  49.  
  50.  
  51. end;
  52. end;
  53.  
  54. procedure TForm1.PaintBoxMouseMove(Sender: TObject; Shift: TShiftState; X,
  55. Y: Integer);
  56. begin
  57. if drawing then
  58. begin
  59.  
  60. if (penState = 1) then
  61. begin
  62. allLine[length-1].lineLength := allLine[length-1].lineLength+1;
  63. setlength(allLine[length-1].line, allLine[length-1].lineLength);
  64. allLine[length-1].line[allLine[length-1].lineLength-1].x := x;
  65. allLine[length-1].line[allLine[length-1].lineLength-1].y := y;
  66.  
  67. PaintBox.Canvas.LineTo(x,y);
  68.  
  69. end;
  70. end;
  71. end;
  72.  
  73. procedure TForm1.PaintBoxMouseDown(Sender: TObject; Button: TMouseButton;
  74. Shift: TShiftState; X, Y: Integer);
  75. begin
  76. PaintBox.Canvas.MoveTo(x,y);
  77. if ssleft in shift then
  78. begin
  79. drawing := true;
  80.  
  81. length:=length+1;
  82. setlength(allLine,length);
  83. allLine[length-1].lineLength:=0;
  84.  
  85. allLine[length-1].color := PaintBox.Canvas.Pen.Color;
  86. allLine[length-1].width := PaintBox.Canvas.Pen.Width;
  87.  
  88. if (penState <> 1) then
  89. begin
  90. allLine[length-1].lineLength := 2;
  91. setlength(allLine[length-1].line, allLine[length-1].lineLength);
  92. allLine[length-1].line[0].x := x;
  93. allLine[length-1].line[0].y := y;
  94. end;
  95.  
  96. end;
  97. end;
  98.  
  99. procedure TForm1.FileSaveClick(Sender: TObject);
  100. var
  101. Bitmap: TBitmap;
  102. Source: TRect;
  103. Dest: TRect;
  104. begin
  105.  
  106. if SaveFile.Execute then
  107. begin
  108. Bitmap := TBitmap.Create;
  109. try
  110. Bitmap.Width := PaintBox.Width;
  111. Bitmap.Height:= PaintBox.Height;
  112. Dest := Rect(0, 0, Bitmap.Width, Bitmap.Height);
  113. Source := Rect(0, 0, PaintBox.Width, PaintBox.Height);
  114. Bitmap.Canvas.CopyRect(Dest, PaintBox.Canvas, Source);
  115. Bitmap.SaveToFile(SaveFile.FileName);
  116. finally
  117. Bitmap.Free;
  118. end;
  119.  
  120. end;
  121. end;
  122.  
  123. procedure TForm1.FormCreate(Sender: TObject);
  124. begin
  125. penState := 1;
  126. length := 0;
  127. end;
  128.  
  129. procedure TForm1.FileExitClick(Sender: TObject);
  130. begin
  131. Close;
  132. end;
  133.  
  134. procedure TForm1.MenuItem2Click(Sender: TObject);
  135. begin
  136. Application.MessageBox('Эта программа была сделана Самутиной Натальей студенткой первого курса Прикладной математики и Информатики', 'Справка');
  137. end;
  138.  
  139.  
  140. procedure TForm1.PaintBoxPaint(Sender: TObject);
  141. begin
  142. PaintBox.Canvas.FillRect(0,0,PaintBox.Canvas.width,PaintBox.Canvas.height);
  143.  
  144. if (length <> 0) then
  145. begin
  146.  
  147. For i := 0 to length-1 do
  148. begin
  149.  
  150. PaintBox.Canvas.Pen.Color := allLine[i].color;
  151. PaintBox.Canvas.Pen.Width := allLine[i].width;
  152.  
  153. if (allLine[i].name = 'line') then
  154. PaintBox.Canvas.Line(allLine[i].line[0].x,allLine[i].line[0].y,allLine[i].line[1].x,allLine[i].line[1].y);
  155.  
  156. if (allLine[i].name = 'Ellipse') then
  157. PaintBox.Canvas.Ellipse(allLine[i].line[0].x,allLine[i].line[0].y,allLine[i].line[1].x,allLine[i].line[1].y);
  158.  
  159. if (allLine[i].name = 'Rectangle') then
  160. PaintBox.Canvas.Rectangle(allLine[i].line[0].x,allLine[i].line[0].y,allLine[i].line[1].x,allLine[i].line[1].y);
  161.  
  162. if (allLine[i].name = 'brush') then
  163. PaintBox.Canvas.PolyLine(allLine[i].line[0..allLine[i].lineLength-1]);
  164.  
  165.  
  166.  
  167. end;
  168.  
  169. end;
  170. end;
  171.  
  172. procedure TForm1.bColorClick(Sender: TObject);
  173. begin
  174. if ColorDialog1.Execute then
  175. begin
  176. PaintBox.Canvas.Pen.Color:= ColorDialog1.Color ;
  177. end;
  178. end;
  179.  
  180. procedure TForm1.bBrushClick(Sender: TObject);
  181. begin
  182. penState := 1;
  183. end;
  184.  
  185. procedure TForm1.bLineClick(Sender: TObject);
  186. begin
  187. penState := 2;
  188. end;
  189.  
  190. procedure TForm1.bRectangleClick(Sender: TObject);
  191. begin
  192. penState := 4;
  193. end;
  194.  
  195. procedure TForm1.bEllipseClick(Sender: TObject);
  196. begin
  197. penState := 3;
  198. end;
  199.  
  200.  
  201. procedure TForm1.TrackBar1Change(Sender: TObject);
  202. begin
  203. PaintBox.Canvas.Pen.Width:= TrackBar1.Position;
  204. end;
  205.  
  206.  
  207. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement