FMxSceneEditor.pas 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. //
  2. // The graphics engine GLXEngine. The unit of GXScene for Delphi
  3. //
  4. unit FMxSceneEditor;
  5. (* Scene Editor, for adding + removing scene objects in Delphi IDE *)
  6. interface
  7. uses
  8. System.SysUtils,
  9. System.Types,
  10. System.UITypes,
  11. System.Classes,
  12. System.Variants,
  13. System.Actions,
  14. FMX.Types,
  15. FMX.Controls,
  16. FMX.Forms,
  17. FMX.Graphics,
  18. FMX.Dialogs,
  19. FMX.Menus,
  20. FMX.ActnList,
  21. FMX.StdCtrls,
  22. FMX.Layouts,
  23. FMX.TreeView,
  24. FMX.ListView.Types,
  25. FMX.ListView,
  26. FMX.Objects,
  27. FMX.ListView.Appearances,
  28. FMX.ListView.Adapters.Base,
  29. FMX.Controls.Presentation,
  30. FMxInfo,
  31. GXS.Scene,
  32. GXS.SceneViewer,
  33. GXS.SceneRegister,
  34. Stage.Strings,
  35. GXS.XCollection;
  36. type
  37. TSceneEditorForm = class(TForm)
  38. ToolBar: TToolBar;
  39. PATree: TPanel;
  40. PAGallery: TPanel;
  41. PAEffects: TPanel;
  42. ActionList: TActionList;
  43. PMToolBar: TPopupMenu;
  44. PopupMenu: TPopupMenu;
  45. SaveDialog: TSaveDialog;
  46. OpenDialog: TOpenDialog;
  47. Tree: TTreeView;
  48. PABehaviours: TPanel;
  49. PMBehavioursToolBar: TPopupMenu;
  50. PMEffectsToolBar: TPopupMenu;
  51. BehavioursPopupMenu: TPopupMenu;
  52. ToolBarBehaviours: TToolBar;
  53. ToolBarEffects: TToolBar;
  54. GalleryListView: TListView;
  55. BehavioursListView: TListView;
  56. EffectsListView: TListView;
  57. ACLoadScene: TAction;
  58. ACSaveScene: TAction;
  59. ACStayOnTop: TAction;
  60. ACAddObject: TAction;
  61. ACAddBehaviour: TAction;
  62. ACAddEffect: TAction;
  63. ACMoveUp: TAction;
  64. ACMoveDown: TAction;
  65. ACExpand: TAction;
  66. ACDeleteObject: TAction;
  67. ACDeleteBehaviour: TAction;
  68. ACCut: TAction;
  69. ACCopy: TAction;
  70. ACPaste: TAction;
  71. ACInfo: TAction;
  72. TBLoadScene: TSpeedButton;
  73. ImLoadScene: TImage;
  74. TBInfo: TSpeedButton;
  75. ImInfo: TImage;
  76. TBPaste: TSpeedButton;
  77. ImPaste: TImage;
  78. TBCopy: TSpeedButton;
  79. ImCopy: TImage;
  80. TBCut: TSpeedButton;
  81. ImCut: TImage;
  82. TBDeleteObject: TSpeedButton;
  83. ImDeleteObject: TImage;
  84. TBExpand: TSpeedButton;
  85. ImExpand: TImage;
  86. TBMoveDown: TSpeedButton;
  87. ImMoveDown: TImage;
  88. TBMoveUp: TSpeedButton;
  89. ImMoveUp: TImage;
  90. TBCharacterPanels: TSpeedButton;
  91. ImCharacterPanels: TImage;
  92. TBGalleryPanel: TSpeedButton;
  93. ImGalleryPanel: TImage;
  94. TBAddObjects: TSpeedButton;
  95. ImAddObjects: TImage;
  96. TBStayOnTop: TSpeedButton;
  97. ImStayOnTop: TImage;
  98. TBSaveScene: TSpeedButton;
  99. ImSaveScene: TImage;
  100. TBSeparator1: TSpeedButton;
  101. TBSeparator2: TSpeedButton;
  102. TBSeparator3: TSpeedButton;
  103. TBSeparator4: TSpeedButton;
  104. ACGallery: TAction;
  105. ImArrowDown: TImage;
  106. ImArrowDownBeh: TImage;
  107. ImArrowDownEff: TImage;
  108. TBAddBehaviours: TSpeedButton;
  109. TBAddEffects: TSpeedButton;
  110. MIAddObject: TMenuItem;
  111. MIAddBehaviour: TMenuItem;
  112. MIAddEffect: TMenuItem;
  113. MICut: TMenuItem;
  114. MICopy: TMenuItem;
  115. MIPaste: TMenuItem;
  116. MIDelObject: TMenuItem;
  117. MIMoveUp: TMenuItem;
  118. MIMoveDown: TMenuItem;
  119. StyleBook: TStyleBook;
  120. procedure FormCreate(Sender: TObject);
  121. procedure FormDestroy(Sender: TObject);
  122. procedure ACInfoExecute(Sender: TObject);
  123. end;
  124. function SceneEditorForm: TSceneEditorForm;
  125. procedure ReleaseSceneEditorForm;
  126. //==================================================================
  127. implementation
  128. //==================================================================
  129. {$R *.fmx}
  130. const
  131. cRegistryKey = 'Software\SceneEngine\SceneEditor';
  132. var
  133. vSceneEditorForm: TSceneEditorForm;
  134. function SceneEditorForm: TSceneEditorForm;
  135. begin
  136. if not Assigned(vSceneEditorForm) then
  137. vSceneEditorForm := TSceneEditorForm.Create(nil);
  138. Result := vSceneEditorForm;
  139. end;
  140. procedure ReleaseSceneEditorForm;
  141. begin
  142. if Assigned(vSceneEditorForm) then
  143. begin
  144. vSceneEditorForm.Free;
  145. vSceneEditorForm := nil;
  146. end;
  147. end;
  148. function ReadRegistryInteger(reg: TRegistry; const Name: string;
  149. defaultValue: Integer): Integer;
  150. begin
  151. if reg.ValueExists(name) then
  152. Result := reg.ReadInteger(name)
  153. else
  154. Result := defaultValue;
  155. end;
  156. procedure TSceneEditorForm.FormCreate(Sender: TObject);
  157. var
  158. CurrentNode: TTreeNode;
  159. reg: TRegistry;
  160. begin
  161. RegisterBaseSceneObjectNameChangeEvent(OnBaseSceneObjectNameChanged);
  162. Tree.Images := ObjectManager.ObjectIcons;
  163. Tree.Indent := ObjectManager.ObjectIcons.Width;
  164. with Tree.Items do
  165. begin
  166. // first add the scene root
  167. CurrentNode := Add(nil, strSceneRoot);
  168. with CurrentNode do
  169. begin
  170. ImageIndex := ObjectManager.SceneRootIndex;
  171. SelectedIndex := ImageIndex;
  172. end;
  173. // and the root for all objects
  174. FObjectNode := AddChild(CurrentNode, strObjectRoot);
  175. FSceneObjects := FObjectNode;
  176. with FObjectNode do
  177. begin
  178. ImageIndex := ObjectManager.ObjectRootIndex;
  179. SelectedIndex := ImageIndex;
  180. end;
  181. end;
  182. // Build SubMenus
  183. SetObjectsSubItems(MIAddObject);
  184. MIAddObject.SubMenuImages := ObjectManager.ObjectIcons;
  185. SetObjectsSubItems(PMToolBar.Items);
  186. PMToolBar.Images := ObjectManager.ObjectIcons;
  187. SetBehavioursSubItems(MIAddBehaviour, nil);
  188. SetBehavioursSubItems(PMBehavioursToolbar.Items, nil);
  189. SetEffectsSubItems(MIAddEffect, nil);
  190. SetEffectsSubItems(PMEffectsToolbar.Items, nil);
  191. reg := TRegistry.Create;
  192. try
  193. if reg.OpenKey(cRegistryKey, true) then
  194. begin
  195. if reg.ValueExists('CharacterPanels') then
  196. TBCharacterPanels.Down := reg.ReadBool('CharacterPanels');
  197. TBCharacterPanelsClick(Self);
  198. if reg.ValueExists('ExpandTree') then
  199. TBExpand.Down := reg.ReadBool('ExpandTree');
  200. ACExpandExecute(Self);
  201. Left := ReadRegistryInteger(reg, 'Left', Left);
  202. Top := ReadRegistryInteger(reg, 'Top', Top);
  203. Width := ReadRegistryInteger(reg, 'Width', 250);
  204. Height := ReadRegistryInteger(reg, 'Height', Height);
  205. end;
  206. finally
  207. reg.Free;
  208. end;
  209. // Trigger the event OnEdited manualy
  210. Tree.OnEdited := TreeEdited;
  211. end;
  212. procedure TSceneEditorForm.FormDestroy(Sender: TObject);
  213. var
  214. reg: TRegistry;
  215. begin
  216. DeRegisterBaseSceneObjectNameChangeEvent(OnBaseSceneObjectNameChanged);
  217. reg := TRegistry.Create;
  218. try
  219. if reg.OpenKey(cRegistryKey, true) then
  220. begin
  221. reg.WriteBool('CharacterPanels', TBCharacterPanels.Down);
  222. reg.WriteBool('ExpandTree', TBExpand.Down);
  223. reg.WriteInteger('Left', Left);
  224. reg.WriteInteger('Top', Top);
  225. reg.WriteInteger('Width', Width);
  226. reg.WriteInteger('Height', Height);
  227. end;
  228. finally
  229. reg.Free;
  230. end;
  231. end;
  232. procedure TSceneEditorForm.ACInfoExecute(Sender: TObject);
  233. var
  234. AScene: TgxSceneViewer;
  235. begin
  236. AScene := TgxSceneViewer.Create(Self);
  237. AScene.Name := 'SceneEditor';
  238. AScene.Width := 0;
  239. AScene.Height := 0;
  240. AScene.parent := Self;
  241. try
  242. AScene.Buffer.ShowInfo;
  243. finally
  244. AScene.Free;
  245. end;
  246. end;
  247. end.