1 unit Unit1;
2
3 interface
4
5 uses
6 Windows, Messages, SysUtils, Variants, Cl
7 Dialogs, StdCtrls, ExtCtrls, Buttons, Gri
8
9 type
10 TForm1 = class(TForm)
11 Panel1: TPanel;
12 Panel2: TPanel;
13 Image1: TImage;
14 GroupBox1: TGroupBox;
15 GroupBox3: TGroupBox;
16 GroupBox2: TGroupBox;
17 LabelPosisi: TLabel;
18 ButtonClose: TButton;
19 LabelVertex: TLabel;
20 GroupBox4: TGroupBox;
21 StringGrid1: TStringGrid;
22 ButtonDelete: TButton;
23 ButtonDraw: TButton;
24 ButtonEdit: TButton;
25 ButtonInsert: TButton;
26 ButtonClear: TButton;
27 ButtonSave: TButton;
28 ButtonOpen: TButton;
29 Label1: TLabel;
30 procedure ButtonDrawClick(Sender: TObje
85 begin
86 if polygon[i].X = ‐1 then
87 break;
88 StringGrid1.Cells[0,i+1] := inttostr(i+
89 StringGrid1.Cells[1,i+1] := inttostr(po
90 StringGrid1.Cells[2,i+1] := inttostr(po
91
92 if i = 0 then
93 begin
94 image1.Canvas.rectangle(0,0,image1.wi
95 image1.Canvas.MoveTo(polygon[0].X, ti
96 end
97 else
98 begin
99 if (modeOperasi = modeInsert) and (ed
100 begin
101 Image1.Canvas.Pen.Color := clRed;
102 end
103 else
104 begin
105 Image1.Canvas.Pen.Color := clBlack;
106 end;
107 image1.Canvas.LineTo(polygon[i].X, ti
108 end;
109
110 i := i + 1;
111 if i = 20 then
112 break;
113
114 end;
115
116 if modeOperasi = modeEdit then
117 begin
118 image1.Canvas.Rectangle(polygon[editInd
119 polygon[editIndex].X+5, tinggiCanvas
120 end;
121
122 end;
123
124 procedure TForm1.FormCreate(Sender: TObject
125 begin
126 StringGrid1.Cells[0,0] := 'No';
127 StringGrid1.Cells[1,0] := 'X';
128 StringGrid1.Cells[2,0] := 'Y';
129 end;
130
131
132 procedure TForm1.FormResize(Sender: TObject
133 begin
134 tinggiCanvas := Image1.Height;
135
136 end;
137
138 procedure TForm1.ButtonDrawClick(Sender: TO
139 begin
140 buttonDraw.Font.Style := [fsBold];
141 ButtonEdit.Font.Style := [];
142 ButtonInsert.Font.Style := [];
143
144 modeOperasi := modeDraw;
145 startPolygon := true;
146 polygonCount := 0;
147 polygon[polygonCount].X := ‐1;
148
149 refreshCanvas();
150 end;
151
152 procedure TForm1.ButtonCloseClick(Sender: T
153 begin
154
155 if (modeOperasi = modeDraw) and (polygonC
156 begin
157 polygon[polygonCount] := polygon[0];
158 polygonCount := polygonCount + 1;
159
160 polygon[polygonCount].X := ‐1;
161
162 LabelVertex.Caption := 'Vertex ' + intt
163
164 refreshCanvas();
165
166 buttonDraw.Font.Style := [];
167 ButtonEdit.Font.Style := [];
168 ButtonInsert.Font.Style := [];
169 modeOperasi := modeIdle;
170 end;
171
172 end;
173
174 procedure TForm1.ButtonEditClick(Sender: TO
175 begin
176 buttonDraw.Font.Style := [];
177 ButtonEdit.Font.Style := [fsBold];
178 ButtonInsert.Font.Style := [];
179 modeOperasi := modeEdit;
180 editIndex := 1;
181 refreshCanvas();
182 end;
183
184 procedure TForm1.ButtonInsertClick(Sender:
185 begin
186 buttonDraw.Font.Style := [];
187 ButtonEdit.Font.Style := [];
188 ButtonInsert.Font.Style := [fsBold];
189 modeOperasi := modeInsert;
190 editIndex := 1;
191 refreshCanvas();
192 end;
193
194
195 procedure TForm1.ButtonClearClick(Sender: T
196 begin
197 polygonCount := 0;
198 polygon[polygonCount].X := ‐1;
199
200 refreshCanvas();
201 end;
202
203 procedure TForm1.ButtonDeleteClick(Sender:
204 var
205 i : integer;
206 begin
207 if editIndex <> 0 then
208 begin
209 for i := editIndex to polygonCount do
210 begin
211 polygon[i].X := polygon[i+1].X;
212 polygon[i].Y := polygon[i+1].Y;
213 end;
214 polygonCount := polygonCount ‐ 1;
215 refreshCanvas();
216 end;
217 end;
218
219
220 procedure TForm1.Image1MouseMove(Sender: TO
221 Y: Integer);
222 begin
223 posisi.X := X;
224 posisi.Y := tinggiCanvas ‐ Y;
225 LabelPosisi.Caption := 'Posisi ' + inttos
226 end;
227
228 procedure TForm1.Image1Click(Sender: TObjec
229 var
230 i : integer;
231 begin
232 if (modeOperasi = modeDraw) and (polygonC
233 begin
234 polygon[polygonCount].X := posisi.X;
235 polygon[polygonCount].Y := posisi.Y;
236 polygonCount := polygonCount + 1;
237 polygon[polygonCount].X := ‐1;
238 LabelVertex.Caption := 'Vertex ' + intt
239
240 refreshCanvas();
241 end
242 else if (modeOperasi = modeEdit) and (edi
243 begin
244 if (editIndex = 1) or (editIndex = poly
245 begin
246 polygon[1].X := posisi.X;
←
→