MathgeomGLS
231 строка · 5.5 Кб
1unit fVor2dPick;
2
3interface
4
5uses
6Winapi.Windows,
7Winapi.Messages,
8System.SysUtils,
9System.Variants,
10System.Classes,
11Vcl.Graphics,
12Vcl.Controls,
13Vcl.Forms,
14Vcl.Dialogs,
15Vcl.ExtCtrls,
16Vcl.StdCtrls,
17Vor.GraphObjects,
18GLS.Material,
19GLS.Cadencer,
20GLS.SceneViewer,
21
22GLS.BaseClasses,
23GLS.Scene,
24GLS.Canvas,
25GLS.RenderContextInfo,
26Vor.Shamos,
27GLS.Coordinates;
28
29type
30TFormVor2dPick = class(TForm)
31GroupBox1: TGroupBox;
32CheckBox1: TCheckBox;
33CheckBox2: TCheckBox;
34CheckBox3: TCheckBox;
35Button1: TButton;
36Label1: TLabel;
37GLScene1: TGLScene;
38GLCadencer1: TGLCadencer;
39GLMaterialLibrary1: TGLMaterialLibrary;
40GLDirectOpenGL: TGLDirectOpenGL;
41GLCamera: TGLCamera;
42GLLightSource: TGLLightSource;
43PanelPB: TPanel;
44PaintBox: TPaintBox;
45GLSceneViewer: TGLSceneViewer;
46procedure PaintBoxPaint(Sender: TObject);
47procedure PaintBoxMouseMove(Sender: TObject; Shift: TShiftState;
48X, Y: Integer);
49procedure FormCreate(Sender: TObject);
50procedure Button1Click(Sender: TObject);
51procedure CheckBox1Click(Sender: TObject);
52procedure PaintBoxMouseDown(Sender: TObject; Button: TMouseButton;
53Shift: TShiftState; X, Y: Integer);
54procedure PaintBoxMouseUp(Sender: TObject; Button: TMouseButton;
55Shift: TShiftState; X, Y: Integer);
56procedure GLDirectOpenGLRender(Sender: TObject;
57var rci: TGLRenderContextInfo);
58private
59end;
60
61var
62FormVor2dPick: TFormVor2dPick;
63
64implementation
65
66{$R *.dfm}
67
68var
69List: TList;
70Vor: TVoronoi;
71mx, my, i: Integer;
72Down: Boolean;
73
74procedure TFormVor2dPick.PaintBoxPaint(Sender: TObject);
75var
76z: Integer;
77begin
78// for Paintbox.Color
79PaintBox.Canvas.FillRect(Rect(0, 0, PanelPB.Width , PanelPB.Height));
80// PaintBox.Canvas.FloodFill(0, 0, Paintbox.Color, fsSurface);
81if List = nil then
82Exit;
83PaintBox.Canvas.Font.Color := clWhite;
84for z := 0 to List.Count - 1 do
85begin
86TGraphObject(List.items[z]).draw;
87if (TObject(List.items[z]) is TGPoint) and CheckBox3.Checked then
88PaintBox.Canvas.TextOut(
89Round(TGPoint(List.items[z]).GetX + 1),
90Round(TGPoint(List.items[z]).GetY + 1), IntToStr(z));
91end;
92end;
93
94procedure TFormVor2dPick.PaintBoxMouseMove(Sender: TObject; Shift: TShiftState;
95X, Y: Integer);
96begin
97mx := X;
98my := Y;
99FormVor2dPick.Caption := IntToStr(mx) + ' ' + IntToStr(my);
100if down then
101begin
102TGPoint(List.items[i]).MoveTo(X, Y);
103CheckBox1Click(FormVor2dPick);
104end;
105end;
106
107procedure TFormVor2dPick.FormCreate(Sender: TObject);
108begin
109List := TList.Create;
110down := false;
111end;
112
113procedure TFormVor2dPick.GLDirectOpenGLRender(Sender: TObject;
114var rci: TGLRenderContextInfo);
115var
116i, x, y: Integer;
117GLCanvas: TGLCanvas;
118r: TRect;
119Color: TColor;
120begin
121GLCanvas := TGLCanvas.Create(256, 256);
122(*
123GLCanvas.PenWidth := vPenWidth;
124case vWhat of
125wLines:
126begin
127for i := 1 to cNbLines do
128begin
129GLCanvas.PenColor := Random(256 * 256 * 256);
130GLCanvas.MoveTo(Random(256), Random(256)); // first point
131GLCanvas.LineTo(Random(256), Random(256)); // second point
132end;
133end;
134wEllipses:
135for i := 1 to cNbEllipses do
136begin
137GLCanvas.PenColor := Random(256 * 256 * 256);
138GLCanvas.EllipseBB(Random(256), Random(256), Random(256), Random(256));
139end;
140wRects:
141for i := 1 to cNbRects do
142begin
143GLCanvas.PenColor := Random(256 * 256 * 256);
144r := Rect(Random(256), Random(256), Random(256), Random(256));
145GLCanvas.FillRect(r.Left, r.Top, r.Right, r.Bottom);
146end;
147wPoints:
148begin
149for i := 1 to cNbPoints do
150begin
151GLCanvas.PenColor := Random(256 * 256 * 256);
152GLCanvas.PlotPixel(Random(256), Random(256));
153end;
154end;
155wTextOut:
156begin
157for i := 1 to cNbTextOuts do
158begin
159Color := Random(256 * 256 * 256);
160x := Random(256);
161y := Random(256);
162WindowsBitmapFont.TextOut(rci, x, y, 'Hello', Color);
163end;
164end;
165wArcs:
166begin
167for i := 1 to cNbEllipses do
168begin
169GLCanvas.PenColor := Random(256 * 256 * 256);
170GLCanvas.Arc(Random(256), Random(256), Random(256), Random(256),
171Random(256), Random(256), Random(256), Random(256))
172end;
173end;
174end;
175*)
176GLCanvas.Free;
177end;
178
179procedure TFormVor2dPick.Button1Click(Sender: TObject);
180begin
181List.Clear;
182PaintBox.OnPaint(FormVor2dPick);
183end;
184
185procedure TFormVor2dPick.CheckBox1Click(Sender: TObject);
186begin
187Vor := TVoronoi.Create(PaintBox.Canvas, List);
188Vor.ClearLines;
189Vor.CalcVoronoi(CheckBox1.Checked, CheckBox2.Checked);
190Vor.Free;
191PaintBox.OnPaint(FormVor2dPick);
192
193end;
194
195procedure TFormVor2dPick.PaintBoxMouseDown(Sender: TObject; Button: TMouseButton;
196Shift: TShiftState; X, Y: Integer);
197var
198p: TGPoint;
199z: Integer;
200begin
201p := TGPoint.Create(X, Y, nil, nil);
202p.closeDist := 5;
203for z := 0 to List.Count - 1 do
204begin
205if TObject(List.items[z]) is TGPoint then
206if p.Match(TGPoint(List.Items[z])) then
207begin
208if (Button = TMouseButton.mbRight) then
209TGPoint(List.Items[z]).Delete(true)
210else
211begin
212down := True;
213i := z;
214end;
215CheckBox1Click(FormVor2dPick);
216exit;
217end;
218end;
219p.Free;
220
221TGPoint.Create(X, Y, List, PaintBox.Canvas);
222CheckBox1Click(FormVor2dPick);
223end;
224
225procedure TFormVor2dPick.PaintBoxMouseUp(Sender: TObject; Button: TMouseButton;
226Shift: TShiftState; X, Y: Integer);
227begin
228down := false;
229end;
230
231end.
232