Code Search for Developers
 
 
  

Unit1.pas from Sector-37 at Krugle


Show Unit1.pas syntax highlighted

unit Unit1;

interface

{$I GLscene.inc}

uses
  //VCL
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, Grids,

  //GLScene
  GLTexture, StdCtrls, GLCadencer, GLScene, GLObjects, GLSimpleNavigation,
  GLWin32Viewer, GLMisc, GLBehaviours, GLFireFX, GLMovement, GLPhongShader,
  GLCustomShader, GLAsmShader,

  //GLScene DesignTime
  FMaterialEditorForm, GLTextureImageEditors, FLibMaterialPicker,

  //GLScene ported editors
  StrangeXCollectionEditor, StrangeBorlandCollectionEditor,
  StrangeGLSceneEdit, StrangeGLSceneRegister,

  //File Formats
  JPEG,

  //StrangeComponents
  {$IFDEF STRANGE_INIFILE_SUPPORT}StrangeIniObjects,{$ENDIF}

  //Third party components
  ELPropInsp;

type
  //a container for TGLLibMaterial, because we need an initial TComponent
  TTempMaterialSaver = class(TComponent)
  private
    FLibMaterial: TGLLibMaterial;
  published
    property LibMaterial: TGLLibMaterial read FLibMaterial write FLibMaterial;
  end;

  TForm1 = class(TForm)
    GLSceneViewer1: TGLSceneViewer;
    ELPropertyInspector1: TELPropertyInspector;
    GroupBox1: TGroupBox;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    GLMaterialLibrary1: TGLMaterialLibrary;
    SaveDialog1: TSaveDialog;
    OpenDialog1: TOpenDialog;
    Button4: TButton;
    GLScene1: TGLScene;
    CameraTargetDummy: TGLDummyCube;
    Cube: TGLCube;
    GLLightSource1: TGLLightSource;
    GLCamera1: TGLCamera;
    Button5: TButton;
    GLCadencer1: TGLCadencer;
    Button6: TButton;
    GLPhongShader1: TGLPhongShader;
    Button7: TButton;
    GLSimpleNavigation1: TGLSimpleNavigation;
    procedure Button1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure ELPropertyInspector1GetComponent(Sender: TObject;
      const AComponentName: string; var AComponent: TComponent);
    procedure ELPropertyInspector1GetComponentNames(Sender: TObject;
      AClass: TComponentClass; AResult: TStrings);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

//Utility function (actually from StrangeSDKMisc), but I dropped that dependancy
procedure GetComponentNames(AOwner: Tcomponent; AClass: TComponentClass; AResult: TStrings);
var
  I: Integer;
begin
  if AOwner.ComponentCount <> 0 then
    for I := 0 to AOwner.ComponentCount - 1 do
      if AOwner.Components[I] is AClass then
        AResult.Add(AOwner.Components[I].Name);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  Saver:      TTempMaterialSaver;
  FileStream: TFileStream;
begin
  if not SaveDialog1.Execute then
    Exit;

  Saver := TTempMaterialSaver.Create(nil);
  FileStream := TFileStream.Create(SaveDialog1.FileName, fmCreate or fmOpenWrite or fmShareExclusive);

  try
    Saver.LibMaterial := GLMaterialLibrary1.Materials.GetLibMaterialByName(Cube.Material.LibMaterialName);
    FileStream.WriteComponent(saver);
  finally
    Saver.Free;
    FileStream.Free;
  end;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  MaterialEditorForm.Execute(GLMaterialLibrary1.LibMaterialByName(Cube.Material.LibMaterialName).Material);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  Saver: TTempMaterialSaver;
  FileStream:     TFileStream;
begin
  if not OpenDialog1.Execute then
    Exit;

  FileStream := TFileStream.Create(OpenDialog1.FileName, fmOpenRead or fmShareExclusive);
  Saver := TTempMaterialSaver.Create(nil);
  Saver.LibMaterial := GLMaterialLibrary1.LibMaterialByName(Cube.Material.LibMaterialName);

  try
    FileStream.ReadComponent(saver);
  finally
    FileStream.Free;
    Saver.Free;
  end;
end;

procedure TForm1.Button4Click(Sender: TObject);
var
  NewName: string;
begin
  NewName := Cube.Material.LibMaterialName;
  LibMaterialPicker.Execute(NewName, GLMaterialLibrary1);
  Cube.Material.LibMaterialName := NewName;
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
  GetStrangeXCollectionEditor.SetXCollection(Cube.Behaviours, ELPropertyInspector1);
  GetStrangeXCollectionEditor.Show;
end;

procedure TForm1.Button6Click(Sender: TObject);
begin
  GetBorlandCollectionEditor.SetCollection(GLMaterialLibrary1.Materials, ELPropertyInspector1);
  GetBorlandCollectionEditor.Show;
end;

procedure TForm1.Button7Click(Sender: TObject);
begin
  GetStrangeGLSceneEditorForm.SetScene(GLScene1, ELPropertyInspector1);
  GetStrangeGLSceneEditorForm.Show;
end;

procedure TForm1.ELPropertyInspector1GetComponent(Sender: TObject;
  const AComponentName: string; var AComponent: TComponent);
begin
  AComponent := FindComponent(AComponentName);
end;

procedure TForm1.ELPropertyInspector1GetComponentNames(Sender: TObject;
  AClass: TComponentClass; AResult: TStrings);
begin
  GetComponentNames(Self, AClass, AResult);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  ELPropertyInspector1.Designer := ELPropertyInspector1;
  RegisterGLScenePropertyEditors(ELPropertyInspector1);
  RegisterBorlandCollectionPropertyEditor(ELPropertyInspector1);
  RegisterStrangeXCollectionPropertyEditor(ELPropertyInspector1);
end;

initialization
  RegisterClass(TTempMaterialSaver);

finalization

end.





See more files for this project here

Sector-37

Sector-37 (real time 3D cosmic strategy)

Project homepage: http://sourceforge.net/projects/sector37
Programming language(s): Pascal
License: lgpl21

  Readme.txt
  StrangeGLSceneEditorDemo.dpr
  StrangeGLSceneEditorDemo.res
  Unit1.dfm
  Unit1.pas
  _Cleanup.bat