fGizmoEx.pas 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  1. unit fGizmoEx;
  2. interface
  3. uses
  4. Winapi.Windows,
  5. Winapi.OpenGL,
  6. System.SysUtils,
  7. System.Classes,
  8. System.Math,
  9. Vcl.Controls,
  10. Vcl.Forms,
  11. Vcl.StdCtrls,
  12. Vcl.ExtCtrls,
  13. Vcl.Buttons,
  14. Vcl.ComCtrls,
  15. GLS.Scene,
  16. GLS.PersistentClasses,
  17. GLS.Cadencer,
  18. GLS.Objects,
  19. GLS.VectorTypes,
  20. GLS.SceneViewer,
  21. GLS.Keyboard,
  22. GLS.Utils,
  23. GLS.GizmoEx,
  24. GLS.Coordinates,
  25. GLS.BaseClasses,
  26. GLS.VectorGeometry,
  27. GLS.GeomObjects,
  28. GLS.BitmapFont,
  29. GLS.WindowsFont,
  30. GLS.HUDObjects,
  31. GLS.Graph,
  32. GLS.VectorFileObjects;
  33. type
  34. TFormGizmoEx = class(TForm)
  35. GLScene1: TGLScene;
  36. GLRootObjects: TGLDummyCube;
  37. GLCadencer1: TGLCadencer;
  38. GLLightSource1: TGLLightSource;
  39. GLLightSource2: TGLLightSource;
  40. RootGizmo: TGLDummyCube;
  41. GLDodecahedron3: TGLDodecahedron;
  42. GLArrowLine3: TGLArrowLine;
  43. GLArrowLine4: TGLArrowLine;
  44. Label9: TLabel;
  45. GLSphere1: TGLSphere;
  46. GLCube1: TGLCube;
  47. WindowsBitmapFont: TGLWindowsBitmapFont;
  48. GLFrustrum1: TGLFrustrum;
  49. GLDisk1: TGLDisk;
  50. GLCube2: TGLCube;
  51. Panel2: TPanel;
  52. SpeedButton1: TSpeedButton;
  53. SpeedButton2: TSpeedButton;
  54. SpeedButton3: TSpeedButton;
  55. SpeedButton4: TSpeedButton;
  56. SpeedButton5: TSpeedButton;
  57. Label12: TLabel;
  58. Viewer: TGLSceneViewer;
  59. SpeedButton6: TSpeedButton;
  60. Panel4: TPanel;
  61. SpeedButton7: TSpeedButton;
  62. SpeedButton8: TSpeedButton;
  63. SpeedButton9: TSpeedButton;
  64. SpeedButton10: TSpeedButton;
  65. RootTempObjects: TGLDummyCube;
  66. SpeedButton11: TSpeedButton;
  67. Label15: TLabel;
  68. SpeedButton12: TSpeedButton;
  69. SpeedButton13: TSpeedButton;
  70. PageControl1: TPageControl;
  71. TabSheet1: TTabSheet;
  72. TabSheet2: TTabSheet;
  73. CheckBox1: TCheckBox;
  74. CheckBox10: TCheckBox;
  75. CheckBox11: TCheckBox;
  76. CheckBox12: TCheckBox;
  77. CheckBox2: TCheckBox;
  78. CheckBox4: TCheckBox;
  79. CheckBox5: TCheckBox;
  80. CheckBox6: TCheckBox;
  81. CheckBox7: TCheckBox;
  82. CheckBox8: TCheckBox;
  83. CheckBox9: TCheckBox;
  84. edAutoZoomFactor: TEdit;
  85. edtGizmoThickness: TEdit;
  86. edtScaleCoef: TEdit;
  87. edzoomfactor: TEdit;
  88. Label10: TLabel;
  89. Label11: TLabel;
  90. Label4: TLabel;
  91. Label5: TLabel;
  92. OptPickMode: TRadioGroup;
  93. ColorBox1: TColorBox;
  94. ColorBox2: TColorBox;
  95. ColorBox3: TColorBox;
  96. ColorBox4: TColorBox;
  97. Label1: TLabel;
  98. Label14: TLabel;
  99. Label2: TLabel;
  100. Label3: TLabel;
  101. Label16: TLabel;
  102. ComboBox3: TComboBox;
  103. CheckBox13: TCheckBox;
  104. CheckBox14: TCheckBox;
  105. CheckBox15: TCheckBox;
  106. Panel1: TPanel;
  107. SpeedButton14: TSpeedButton;
  108. SpeedButton15: TSpeedButton;
  109. ComboBox4: TComboBox;
  110. CheckBox3: TCheckBox;
  111. edMoveCoef: TEdit;
  112. Label6: TLabel;
  113. edRotateCoef: TEdit;
  114. Label7: TLabel;
  115. CheckBox16: TCheckBox;
  116. TabSheet3: TTabSheet;
  117. Label8: TLabel;
  118. Edit1: TEdit;
  119. Label13: TLabel;
  120. Panel3: TPanel;
  121. TreeView1: TTreeView;
  122. GLRootUserInterface: TGLDummyCube;
  123. GLXYZGrid1: TGLXYZGrid;
  124. GLTargetCamera: TGLDummyCube;
  125. Camera: TGLCamera;
  126. SpeedButton17: TSpeedButton;
  127. SpeedButton18: TSpeedButton;
  128. Panel5: TPanel;
  129. GroupBox1: TGroupBox;
  130. SpeedButton16: TSpeedButton;
  131. SpeedButton19: TSpeedButton;
  132. SpeedButton20: TSpeedButton;
  133. Label17: TLabel;
  134. Timer1: TTimer;
  135. procedure GLCadencer1Progress(Sender: TObject; const DeltaTime, newTime: Double);
  136. procedure ViewerMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  137. procedure ViewerMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
  138. procedure ViewerMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  139. procedure FormShow(Sender: TObject);
  140. procedure edAutoZoomFactorKeyPress(Sender: TObject; var Key: Char);
  141. procedure CheckBox12Click(Sender: TObject);
  142. procedure ColorBox1Change(Sender: TObject);
  143. procedure edtGizmoThicknessChange(Sender: TObject);
  144. procedure OptPickModeClick(Sender: TObject);
  145. procedure FormCreate(Sender: TObject);
  146. procedure FormDestroy(Sender: TObject);
  147. procedure ViewerMouseWheel(Sender: TObject; Shift: TShiftState;
  148. WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
  149. procedure FormMouseWheel(Sender: TObject; Shift: TShiftState;
  150. WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
  151. procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  152. procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
  153. procedure SpeedButton1Click(Sender: TObject);
  154. procedure ComboBox3Change(Sender: TObject);
  155. function MouseWorldPos(const X, Y: Integer; isy: boolean = false): TGLVector;
  156. procedure ComboBox4Change(Sender: TObject);
  157. procedure SpeedButton6MouseDown(Sender: TObject; Button: TMouseButton;
  158. Shift: TShiftState; X, Y: Integer);
  159. procedure SpeedButton7MouseUp(Sender: TObject; Button: TMouseButton;
  160. Shift: TShiftState; X, Y: Integer);
  161. procedure SpeedButton17Click(Sender: TObject);
  162. procedure SpeedButton14Click(Sender: TObject);
  163. procedure SpeedButton16Click(Sender: TObject);
  164. function ObjectName(value: string): string;
  165. procedure Timer1Timer(Sender: TObject);
  166. private
  167. public
  168. mx, my: Integer;
  169. MousePos,LostMousePos: TGLVector;
  170. MouseMoving: boolean;
  171. pos: TGLVector;
  172. FObj: TGLBaseSceneObject;
  173. procedure UpdateTreeView;
  174. end;
  175. var
  176. FormGizmoEx: TFormGizmoEx;
  177. Gizmo: TGLGizmoEx;
  178. FVectorLength: Single;
  179. FCreationScenarious: integer;
  180. implementation
  181. {$R *.dfm}
  182. procedure SettingsObj(Obj: TGLBaseSceneObject; Step: Integer; Length: TGLVector);
  183. begin
  184. if (Obj is TGLCube) then
  185. with (Obj as TGLCube) do
  186. case Step of
  187. 0:
  188. begin
  189. CubeWidth := Length.X*2;
  190. CubeDepth := Length.Z*2;
  191. end;
  192. 1: CubeHeight := FVectorLength;
  193. 2: FCreationScenarious := -1;
  194. end;
  195. if (Obj is TGLSphere) then
  196. with (Obj as TGLSphere) do
  197. case Step of
  198. 0: Radius := FVectorLength;
  199. 1: FCreationScenarious := -1;
  200. end;
  201. if (Obj is TGLPlane) then
  202. with (Obj as TGLPlane) do
  203. case Step of
  204. 0:
  205. begin
  206. Width := Length.X*2;
  207. Height := Length.Z*2;
  208. end;
  209. 1: FCreationScenarious := -1;
  210. end;
  211. end;
  212. function TFormGizmoEx.ObjectName(value: string): string;
  213. var
  214. i: integer;
  215. begin
  216. Result := value;
  217. i := 1;
  218. while glScene1.FindSceneObject(Result) <> nil do
  219. begin
  220. Result := value + IntToStr(i);
  221. Inc(i);
  222. end;
  223. end;
  224. function TFormGizmoEx.MouseWorldPos(const X, Y: Integer; isy: boolean = false): TGLVector;
  225. var
  226. v: TGLVector;
  227. InvertedY: Integer;
  228. begin
  229. InvertedY := Viewer.Height - Y;
  230. SetVector(v, X, InvertedY, 0);
  231. if not isy then
  232. Viewer.Buffer.ScreenVectorIntersectWithPlaneXZ
  233. (v, GLTargetCamera.AbsolutePosition.Y, Result)
  234. else
  235. Viewer.Buffer.ScreenVectorIntersectWithPlaneXY
  236. (v, GLTargetCamera.AbsolutePosition.Z, Result)
  237. end;
  238. procedure TFormGizmoEx.UpdateTreeView;
  239. var
  240. I: Integer;
  241. ObjectNode: TTreeNode;
  242. CurrentNode: TTreeNode;
  243. function AddNodes(ANode: TTreeNode; AObject: TGLBaseSceneObject): TTreeNode;
  244. var
  245. I: Integer;
  246. begin
  247. if IsSubComponent(AObject) then
  248. begin
  249. Result := TreeView1.Selected;
  250. exit;
  251. end else
  252. begin
  253. Result := TreeView1.Items.AddChildObject(ANode, AObject.Name, AObject);
  254. CurrentNode := Result;
  255. for I := 0 to AObject.Count -1 do
  256. Result := AddNodes(CurrentNode, AObject[I]);
  257. end;
  258. end;
  259. begin
  260. TreeView1.Items.Clear;
  261. // -- add two root nodes --
  262. ObjectNode := TreeView1.Items.AddFirst(nil, 'RootTempObjects');
  263. // -- get the object's tree --
  264. TreeView1.Items.BeginUpdate();
  265. with RootTempObjects do
  266. begin
  267. // -- objects (with children too) --
  268. if Assigned(RootTempObjects) then
  269. begin
  270. ObjectNode.Data := RootTempObjects;
  271. with RootTempObjects do
  272. for I := 0 to Count -1 do
  273. AddNodes(ObjectNode, Children[I]);
  274. ObjectNode.Expand(True);
  275. end;
  276. end;
  277. TreeView1.Items.EndUpdate();
  278. // -- add two root nodes --
  279. ObjectNode := TreeView1.Items.AddFirst(nil, 'World');
  280. // -- get the object's tree --
  281. TreeView1.Items.BeginUpdate();
  282. with GLRootObjects do
  283. begin
  284. // -- objects (with children too) --
  285. if Assigned(GLRootObjects) then
  286. begin
  287. ObjectNode.Data := GLRootObjects;
  288. with GLRootObjects do
  289. for I := 0 to Count -1 do
  290. AddNodes(ObjectNode, Children[I]);
  291. ObjectNode.Expand(True);
  292. end;
  293. end;
  294. TreeView1.Items.EndUpdate();
  295. end;
  296. procedure TFormGizmoEx.GLCadencer1Progress(Sender: TObject; const DeltaTime, newTime: Double);
  297. begin
  298. Viewer.Invalidate;
  299. end;
  300. procedure TFormGizmoEx.OptPickModeClick(Sender: TObject);
  301. begin
  302. Gizmo.PickMode := TGLGizmoExPickMode(OptPickMode.ItemIndex);
  303. end;
  304. procedure TFormGizmoEx.SpeedButton14Click(Sender: TObject);
  305. begin
  306. gizmo.Enabled := not ((SpeedButton18.Down or SpeedButton15.Down) or SpeedButton14.Down);
  307. CheckBox12.Checked := Gizmo.Enabled;
  308. end;
  309. procedure TFormGizmoEx.SpeedButton16Click(Sender: TObject);
  310. begin
  311. Gizmo.Enabled := not (Sender as TSpeedButton).Down;
  312. end;
  313. procedure TFormGizmoEx.SpeedButton17Click(Sender: TObject);
  314. begin
  315. GLTargetCamera.Position.SetPoint(0, 0, 0);
  316. GLTargetCamera.Direction.SetVector(0, 0, 1);
  317. GLTargetCamera.Up.SetVector(0, 1, 0);
  318. end;
  319. procedure TFormGizmoEx.SpeedButton1Click(Sender: TObject);
  320. begin
  321. (Sender as TSpeedButton).Down:=false;
  322. case (Sender as TSpeedButton).Tag of
  323. 0: Gizmo.OperationMode:=gomSelect;
  324. 1: Gizmo.OperationMode:=gomMove;
  325. 2: Gizmo.OperationMode:=gomRotate;
  326. 3: Gizmo.OperationMode:=gomScale;
  327. 4: Gizmo.OperationMode:=gomNone;
  328. 5: Gizmo.Undo;
  329. 6: Gizmo.Redo;
  330. 7: Gizmo.RemoveSelectedObjects;
  331. end;
  332. UpdateTreeView;
  333. // Disable buttons Camera Translate
  334. SpeedButton18.Down := false;
  335. SpeedButton15.Down := false;
  336. SpeedButton14.Down := false;
  337. SpeedButton17.Down := false;
  338. end;
  339. procedure TFormGizmoEx.SpeedButton6MouseDown(Sender: TObject; Button: TMouseButton;
  340. Shift: TShiftState; X, Y: Integer);
  341. begin
  342. Panel4.Visible:= not Panel4.Visible;
  343. Panel4.Left:=SpeedButton6.Left;
  344. Panel4.Top:= SpeedButton6.Top+SpeedButton6.Height;
  345. end;
  346. procedure TFormGizmoEx.SpeedButton7MouseUp(Sender: TObject; Button: TMouseButton;
  347. Shift: TShiftState; X, Y: Integer);
  348. begin
  349. case (Sender as TSpeedButton).Tag of
  350. 20:
  351. begin
  352. Gizmo.SelectionRegion:= gsrRectangular;
  353. SpeedButton6.Glyph.Assign(SpeedButton7.Glyph);
  354. end;
  355. 21:
  356. begin
  357. Gizmo.SelectionRegion:= gsrCircular;
  358. SpeedButton6.Glyph.Assign(SpeedButton8.Glyph);
  359. end;
  360. 22:
  361. begin
  362. Gizmo.SelectionRegion:= gsrFence;
  363. SpeedButton6.Glyph.Assign(SpeedButton9.Glyph);
  364. end;
  365. 23:
  366. begin
  367. Gizmo.SelectionRegion:= gsrLasso;
  368. SpeedButton6.Glyph.Assign(SpeedButton10.Glyph);
  369. end;
  370. end;
  371. Panel4.Visible:=false;
  372. SpeedButton6.Down:=false;
  373. end;
  374. procedure TFormGizmoEx.ViewerMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  375. begin
  376. mx := X;
  377. my := Y;
  378. Gizmo.viewerMouseDown(X, Y);
  379. if SpeedButton15.Down or SpeedButton18.Down then
  380. begin
  381. if SpeedButton15.Down then
  382. LostMousePos := MouseWorldPos(x, y)
  383. else
  384. LostMousePos := MouseWorldPos(x, y, true);
  385. pos:=GLTargetCamera.Position.AsVector;
  386. MouseMoving:=true;
  387. end;
  388. //Create Cube With Mouse
  389. if SpeedButton16.Down then
  390. begin
  391. LostMousePos := MouseWorldPos(x, y);
  392. MouseMoving := true;
  393. if FCreationScenarious = -1 then
  394. begin
  395. FObj := TGLCube.CreateAsChild(GLRootObjects);
  396. (FObj as tglcube).CubeDepth := 0;
  397. (FObj as tglcube).CubeHeight := 0;
  398. (FObj as tglcube).CubeWidth := 0.1;
  399. FObj.Position.AsVector := LostMousePos;
  400. FObj.Name:= ObjectName('GLCube');
  401. UpdateTreeView;
  402. FCreationScenarious := 0;
  403. end;
  404. end;
  405. //Create Sphere With Mouse
  406. if SpeedButton19.Down then
  407. begin
  408. LostMousePos := MouseWorldPos(x, y);
  409. MouseMoving := true;
  410. if FCreationScenarious = -1 then
  411. begin
  412. FObj := TGLSphere.CreateAsChild(GLRootObjects);
  413. (FObj as tglSphere).Radius := 0;
  414. FObj.Position.AsVector := LostMousePos;
  415. FObj.Name:= ObjectName('GLSphere');
  416. UpdateTreeView;
  417. FCreationScenarious := 0;
  418. end;
  419. end;
  420. //Create Sphere With Mouse
  421. if SpeedButton20.Down then
  422. begin
  423. LostMousePos := MouseWorldPos(x, y);
  424. MouseMoving := true;
  425. if FCreationScenarious = -1 then
  426. begin
  427. FObj := TGLPlane.CreateAsChild(GLRootObjects);
  428. (FObj as TGLPlane).Height := 0;
  429. (FObj as TGLPlane).Width := 0;
  430. FObj.Position.AsVector := LostMousePos;
  431. FObj.PitchAngle := 90 ;
  432. FObj.Name:= ObjectName('GLPlane');
  433. UpdateTreeView;
  434. FCreationScenarious := 0;
  435. end;
  436. end;
  437. end;
  438. procedure TFormGizmoEx.ViewerMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
  439. begin
  440. if SpeedButton14.Down then
  441. begin
  442. if (shift = [ssLeft]) then
  443. GLTargetCamera.turn(mx - X)
  444. else if (shift = [ssRight]) then
  445. begin
  446. if my > Y then
  447. Camera.AdjustDistanceToTarget(1.05)
  448. else
  449. Camera.AdjustDistanceToTarget(0.95);
  450. gizmo.MoveCoef := Camera.DistanceToTarget / 1000;
  451. end;
  452. end
  453. else
  454. gizmo.viewerMouseMove(X, Y);
  455. if MouseMoving then
  456. begin
  457. if SpeedButton15.Down or SpeedButton18.Down then
  458. begin
  459. if SpeedButton15.Down then
  460. MousePos := MouseWorldPos(x, y)
  461. else
  462. MousePos := MouseWorldPos(x, y, true);
  463. MousePos := VectorSubtract(LostMousePos,MousePos);
  464. MousePos.X:= -MousePos.X*0.4 ;
  465. MousePos.Z:= -MousePos.Z*0.4 ;
  466. GLTargetCamera.Position.AsVector := Vectoradd(pos, MousePos);
  467. end;
  468. if SpeedButton16.Down or SpeedButton19.Down or SpeedButton20.Down then
  469. begin
  470. MousePos := MouseWorldPos(x, y);
  471. FVectorLength := VectorLength(VectorSubtract(LostMousePos,MousePos));
  472. pos := VectorSubtract(LostMousePos,MousePos);
  473. SettingsObj(Fobj, FCreationScenarious, pos)
  474. end;
  475. end;
  476. mx := X;
  477. my := Y;
  478. end;
  479. procedure TFormGizmoEx.ViewerMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  480. begin
  481. //
  482. MouseMoving:=false;
  483. gizmo.viewerMouseUp(X, Y);
  484. if TMouseButton(Button)=mbRight then
  485. begin
  486. if gizmo.CursorSelectingRegion then
  487. begin
  488. gizmo.LooseCursorSelection;
  489. end;
  490. if SpeedButton15.Down or SpeedButton14.Down or SpeedButton18.Down
  491. then
  492. begin
  493. SpeedButton15.Down := false;
  494. SpeedButton14.Down := false;
  495. SpeedButton18.Down := false;
  496. Gizmo.Enabled := true;
  497. CheckBox12.Checked := true;
  498. end;
  499. if SpeedButton16.Down or SpeedButton19.Down or
  500. SpeedButton20.Down then
  501. begin
  502. if FCreationScenarious>=0 then
  503. FreeAndNil(Fobj);
  504. Gizmo.Enabled := true;
  505. FCreationScenarious :=-1;
  506. SpeedButton16.Down := false;
  507. SpeedButton19.Down := false;
  508. SpeedButton20.Down := false;
  509. UpdateTreeView;
  510. end;
  511. end;
  512. if SpeedButton16.Down or SpeedButton19.Down or
  513. SpeedButton20.Down then
  514. begin
  515. If (FCreationScenarious = 0) and (VectorLength(VectorSubtract(LostMousePos,MousePos))<0.1) then
  516. begin
  517. FreeAndNil(Fobj);
  518. SpeedButton16.Down := false;
  519. FCreationScenarious :=-1;
  520. end;
  521. LostMousePos := MouseWorldPos(x, y);
  522. FCreationScenarious := FCreationScenarious + 1;
  523. MouseMoving := true;
  524. end;
  525. end;
  526. procedure TFormGizmoEx.ViewerMouseWheel(Sender: TObject; Shift: TShiftState;
  527. WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
  528. begin
  529. Camera.AdjustDistanceToTarget(Power(1.1, WheelDelta / 120));
  530. Gizmo.UpdateGizmo;
  531. end;
  532. procedure TFormGizmoEx.FormShow(Sender: TObject);
  533. begin
  534. Viewer.SetFocus;
  535. Gizmo.RootGizmo := rootGizmo;
  536. Gizmo.RootObjects:= GLRootObjects;
  537. Gizmo.GizmoTmpRoot := RootTempObjects;
  538. Gizmo.ExcludeObjects := true;
  539. Gizmo.ExcludeObjectsList.Add('GLXYZGrid1');
  540. Gizmo.ExcludeObjectsList.Add('GLHUDText1');
  541. Camera.TurnAngle:=45;
  542. Camera.PitchAngle:=-45;
  543. UpdateTreeView;
  544. end;
  545. procedure TFormGizmoEx.edAutoZoomFactorKeyPress(Sender: TObject; var Key: Char);
  546. begin
  547. if not CharInSet(Key,['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', ',']) then
  548. Key := #0;
  549. end;
  550. procedure TFormGizmoEx.CheckBox12Click(Sender: TObject);
  551. var
  552. check: Boolean;
  553. begin
  554. check := (Sender as TCheckBox).Checked;
  555. case (Sender as TCheckBox).Tag of
  556. 0: Gizmo.Enabled := Check;
  557. 1: Gizmo.ExcludeObjects := Check;
  558. 2: Gizmo.ExcludeClassname:= Check;
  559. 3: Gizmo.EnableLoopCursorMoving := Check;
  560. 4: Gizmo.EnableMultiSelection:= Check;
  561. 5: Gizmo.EnableActionHistory:= Check;
  562. 6: Gizmo.ShowBoundingBox := Check;
  563. 7: Gizmo.ShowAxisLabel := Check;
  564. 8:
  565. begin
  566. Gizmo.ShowObjectInfos := not Gizmo.ShowObjectInfos;
  567. CheckBox7.Enabled := Check;
  568. CheckBox8.Enabled := Check;
  569. CheckBox9.Enabled := Check;
  570. end;
  571. 9: if Check then
  572. Gizmo.VisibleInfoLabels := Gizmo.VisibleInfoLabels + [vliName]
  573. else
  574. Gizmo.VisibleInfoLabels := Gizmo.VisibleInfoLabels - [vliName];
  575. 10: if Check then
  576. Gizmo.VisibleInfoLabels := Gizmo.VisibleInfoLabels + [vliOperation]
  577. else
  578. Gizmo.VisibleInfoLabels := Gizmo.VisibleInfoLabels - [vliOperation];
  579. 11: if Check then
  580. Gizmo.VisibleInfoLabels := Gizmo.VisibleInfoLabels + [vliCoords]
  581. else
  582. Gizmo.VisibleInfoLabels := Gizmo.VisibleInfoLabels - [vliCoords];
  583. 12: Gizmo.NoZWrite := Check;
  584. 13: Gizmo.AntiAliasedLines := Check;
  585. 14: Gizmo.CanChangeWithChildren := Check;
  586. 15:
  587. begin
  588. Gizmo.AutoZoom := Check;
  589. if Check then
  590. begin
  591. edAutoZoomFactor.Enabled := True;
  592. edZoomFactor.Enabled := False;
  593. end
  594. else
  595. begin
  596. edAutoZoomFactor.Enabled := False;
  597. edZoomFactor.Enabled := True;
  598. end;
  599. end;
  600. end;
  601. end;
  602. procedure TFormGizmoEx.edtGizmoThicknessChange(Sender: TObject);
  603. var
  604. value: Extended;
  605. begin
  606. TryStrToFloat((Sender as TEdit).Text, value);
  607. if value > 0 then
  608. case (Sender as TEdit).Tag of
  609. 1: Gizmo.GizmoThickness := value;
  610. 2: Gizmo.ScaleCoef := value;
  611. 3: Gizmo.MoveCoef := value;
  612. 4: Gizmo.RotationCoef := value;
  613. 5: Gizmo.HistoryStepsCount:=Round(value);
  614. 6: Gizmo.AutoZoomFactor := value;
  615. 7: Gizmo.ZoomFactor := value;
  616. end;
  617. end;
  618. procedure TFormGizmoEx.ColorBox1Change(Sender: TObject);
  619. begin
  620. case (Sender as TColorBox).Tag of
  621. 0: Gizmo.BoundingBoxColor.AsWinColor := ColorBox1.Selected;
  622. 1: Gizmo.VisibleInfoLabelsColor.AsWinColor := ColorBox2.Selected;
  623. 2: Gizmo.SelectedColor.AsWinColor := ColorBox3.Selected;
  624. 3: Gizmo.SelectionRegionColor.AsWinColor := ColorBox4.Selected;
  625. end;
  626. end;
  627. procedure TFormGizmoEx.ComboBox3Change(Sender: TObject);
  628. begin
  629. case ComboBox3.ItemIndex of
  630. 0: Gizmo.InfoLabelCoordType := ilcChanging;
  631. 1: Gizmo.InfoLabelCoordType := ilcChangeRate;
  632. end;
  633. end;
  634. procedure TFormGizmoEx.ComboBox4Change(Sender: TObject);
  635. begin
  636. Gizmo.ReferenceCoordSystem:=TGLGizmoExReferenceCoordinateSystem(ComboBox4.ItemIndex);
  637. end;
  638. procedure TFormGizmoEx.FormCreate(Sender: TObject);
  639. begin
  640. Gizmo := TGLGizmoEx.Create(Self);
  641. Gizmo.LabelFont := WindowsBitmapFont;
  642. Gizmo.Viewer := Viewer;
  643. Gizmo.ExcludeClassnameList.Add('TGLSphere');
  644. FCreationScenarious := -1;
  645. end;
  646. procedure TFormGizmoEx.FormDestroy(Sender: TObject);
  647. begin
  648. Gizmo.Free;
  649. end;
  650. procedure TFormGizmoEx.FormKeyDown(Sender: TObject; var Key: Word;
  651. Shift: TShiftState);
  652. begin
  653. Gizmo.CanAddObjToSelectionList:=(key=VK_Control);
  654. Gizmo. CanRemoveObjFromSelectionList:=(Key=VK_MENU);
  655. end;
  656. procedure TFormGizmoEx.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
  657. begin
  658. Gizmo.CanAddObjToSelectionList:=false;
  659. Gizmo. CanRemoveObjFromSelectionList:=false;
  660. end;
  661. procedure TFormGizmoEx.FormMouseWheel(Sender: TObject; Shift: TShiftState;
  662. WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
  663. begin
  664. Camera.AdjustDistanceToTarget(Power(1.1, WheelDelta / 120));
  665. gizmo.UpdateGizmo;
  666. end;
  667. procedure TFormGizmoEx.Timer1Timer(Sender: TObject);
  668. begin
  669. Panel1.Caption := Viewer.FramesPerSecondText();
  670. Viewer.ResetPerformanceMonitor;
  671. if GLScene1.IsUpdating then UpdateTreeView;
  672. end;
  673. end.