123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268 |
- //
- // The graphics engine GLXEngine. The unit of GXScene for Delphi
- //
- unit FMxSceneEditor;
- (* Scene Editor, for adding + removing scene objects in Delphi IDE *)
- interface
- uses
- System.SysUtils,
- System.Types,
- System.UITypes,
- System.Classes,
- System.Variants,
- System.Actions,
- FMX.Types,
- FMX.Controls,
- FMX.Forms,
- FMX.Graphics,
- FMX.Dialogs,
- FMX.Menus,
- FMX.ActnList,
- FMX.StdCtrls,
- FMX.Layouts,
- FMX.TreeView,
- FMX.ListView.Types,
- FMX.ListView,
- FMX.Objects,
- FMX.ListView.Appearances,
- FMX.ListView.Adapters.Base,
- FMX.Controls.Presentation,
- FMxInfo,
- GXS.Scene,
- GXS.SceneViewer,
- GXS.SceneRegister,
- Stage.Strings,
- GXS.XCollection;
- type
- TSceneEditorForm = class(TForm)
- ToolBar: TToolBar;
- PATree: TPanel;
- PAGallery: TPanel;
- PAEffects: TPanel;
- ActionList: TActionList;
- PMToolBar: TPopupMenu;
- PopupMenu: TPopupMenu;
- SaveDialog: TSaveDialog;
- OpenDialog: TOpenDialog;
- Tree: TTreeView;
- PABehaviours: TPanel;
- PMBehavioursToolBar: TPopupMenu;
- PMEffectsToolBar: TPopupMenu;
- BehavioursPopupMenu: TPopupMenu;
- ToolBarBehaviours: TToolBar;
- ToolBarEffects: TToolBar;
- GalleryListView: TListView;
- BehavioursListView: TListView;
- EffectsListView: TListView;
- ACLoadScene: TAction;
- ACSaveScene: TAction;
- ACStayOnTop: TAction;
- ACAddObject: TAction;
- ACAddBehaviour: TAction;
- ACAddEffect: TAction;
- ACMoveUp: TAction;
- ACMoveDown: TAction;
- ACExpand: TAction;
- ACDeleteObject: TAction;
- ACDeleteBehaviour: TAction;
- ACCut: TAction;
- ACCopy: TAction;
- ACPaste: TAction;
- ACInfo: TAction;
- TBLoadScene: TSpeedButton;
- ImLoadScene: TImage;
- TBInfo: TSpeedButton;
- ImInfo: TImage;
- TBPaste: TSpeedButton;
- ImPaste: TImage;
- TBCopy: TSpeedButton;
- ImCopy: TImage;
- TBCut: TSpeedButton;
- ImCut: TImage;
- TBDeleteObject: TSpeedButton;
- ImDeleteObject: TImage;
- TBExpand: TSpeedButton;
- ImExpand: TImage;
- TBMoveDown: TSpeedButton;
- ImMoveDown: TImage;
- TBMoveUp: TSpeedButton;
- ImMoveUp: TImage;
- TBCharacterPanels: TSpeedButton;
- ImCharacterPanels: TImage;
- TBGalleryPanel: TSpeedButton;
- ImGalleryPanel: TImage;
- TBAddObjects: TSpeedButton;
- ImAddObjects: TImage;
- TBStayOnTop: TSpeedButton;
- ImStayOnTop: TImage;
- TBSaveScene: TSpeedButton;
- ImSaveScene: TImage;
- TBSeparator1: TSpeedButton;
- TBSeparator2: TSpeedButton;
- TBSeparator3: TSpeedButton;
- TBSeparator4: TSpeedButton;
- ACGallery: TAction;
- ImArrowDown: TImage;
- ImArrowDownBeh: TImage;
- ImArrowDownEff: TImage;
- TBAddBehaviours: TSpeedButton;
- TBAddEffects: TSpeedButton;
- MIAddObject: TMenuItem;
- MIAddBehaviour: TMenuItem;
- MIAddEffect: TMenuItem;
- MICut: TMenuItem;
- MICopy: TMenuItem;
- MIPaste: TMenuItem;
- MIDelObject: TMenuItem;
- MIMoveUp: TMenuItem;
- MIMoveDown: TMenuItem;
- StyleBook: TStyleBook;
- procedure FormCreate(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- procedure ACInfoExecute(Sender: TObject);
- end;
- function SceneEditorForm: TSceneEditorForm;
- procedure ReleaseSceneEditorForm;
- //==================================================================
- implementation
- //==================================================================
- {$R *.fmx}
- const
- cRegistryKey = 'Software\SceneEngine\SceneEditor';
- var
- vSceneEditorForm: TSceneEditorForm;
- function SceneEditorForm: TSceneEditorForm;
- begin
- if not Assigned(vSceneEditorForm) then
- vSceneEditorForm := TSceneEditorForm.Create(nil);
- Result := vSceneEditorForm;
- end;
- procedure ReleaseSceneEditorForm;
- begin
- if Assigned(vSceneEditorForm) then
- begin
- vSceneEditorForm.Free;
- vSceneEditorForm := nil;
- end;
- end;
- function ReadRegistryInteger(reg: TRegistry; const Name: string;
- defaultValue: Integer): Integer;
- begin
- if reg.ValueExists(name) then
- Result := reg.ReadInteger(name)
- else
- Result := defaultValue;
- end;
- procedure TSceneEditorForm.FormCreate(Sender: TObject);
- var
- CurrentNode: TTreeNode;
- reg: TRegistry;
- begin
- RegisterBaseSceneObjectNameChangeEvent(OnBaseSceneObjectNameChanged);
- Tree.Images := ObjectManager.ObjectIcons;
- Tree.Indent := ObjectManager.ObjectIcons.Width;
- with Tree.Items do
- begin
- // first add the scene root
- CurrentNode := Add(nil, strSceneRoot);
- with CurrentNode do
- begin
- ImageIndex := ObjectManager.SceneRootIndex;
- SelectedIndex := ImageIndex;
- end;
- // and the root for all objects
- FObjectNode := AddChild(CurrentNode, strObjectRoot);
- FSceneObjects := FObjectNode;
- with FObjectNode do
- begin
- ImageIndex := ObjectManager.ObjectRootIndex;
- SelectedIndex := ImageIndex;
- end;
- end;
- // Build SubMenus
- SetObjectsSubItems(MIAddObject);
- MIAddObject.SubMenuImages := ObjectManager.ObjectIcons;
- SetObjectsSubItems(PMToolBar.Items);
- PMToolBar.Images := ObjectManager.ObjectIcons;
- SetBehavioursSubItems(MIAddBehaviour, nil);
- SetBehavioursSubItems(PMBehavioursToolbar.Items, nil);
- SetEffectsSubItems(MIAddEffect, nil);
- SetEffectsSubItems(PMEffectsToolbar.Items, nil);
- reg := TRegistry.Create;
- try
- if reg.OpenKey(cRegistryKey, true) then
- begin
- if reg.ValueExists('CharacterPanels') then
- TBCharacterPanels.Down := reg.ReadBool('CharacterPanels');
- TBCharacterPanelsClick(Self);
- if reg.ValueExists('ExpandTree') then
- TBExpand.Down := reg.ReadBool('ExpandTree');
- ACExpandExecute(Self);
- Left := ReadRegistryInteger(reg, 'Left', Left);
- Top := ReadRegistryInteger(reg, 'Top', Top);
- Width := ReadRegistryInteger(reg, 'Width', 250);
- Height := ReadRegistryInteger(reg, 'Height', Height);
- end;
- finally
- reg.Free;
- end;
- // Trigger the event OnEdited manualy
- Tree.OnEdited := TreeEdited;
- end;
- procedure TSceneEditorForm.FormDestroy(Sender: TObject);
- var
- reg: TRegistry;
- begin
- DeRegisterBaseSceneObjectNameChangeEvent(OnBaseSceneObjectNameChanged);
- reg := TRegistry.Create;
- try
- if reg.OpenKey(cRegistryKey, true) then
- begin
- reg.WriteBool('CharacterPanels', TBCharacterPanels.Down);
- reg.WriteBool('ExpandTree', TBExpand.Down);
- reg.WriteInteger('Left', Left);
- reg.WriteInteger('Top', Top);
- reg.WriteInteger('Width', Width);
- reg.WriteInteger('Height', Height);
- end;
- finally
- reg.Free;
- end;
- end;
- procedure TSceneEditorForm.ACInfoExecute(Sender: TObject);
- var
- AScene: TgxSceneViewer;
- begin
- AScene := TgxSceneViewer.Create(Self);
- AScene.Name := 'SceneEditor';
- AScene.Width := 0;
- AScene.Height := 0;
- AScene.parent := Self;
- try
- AScene.Buffer.ShowInfo;
- finally
- AScene.Free;
- end;
- end;
- end.
|