| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- //
- // This unit is part of the GLScene Engine, http://glscene.org
- //
- unit FLibMaterialPicker;
- (* Allows choosing a material in a material library *)
- interface
- {$I GLScene.inc}
- uses
- System.Classes,
- VCL.Forms,
- VCL.StdCtrls,
- VCL.Buttons,
- VCL.Controls,
- GLSceneViewer,
- GLMaterial,
- FRMaterialPreview;
- type
- TGLLibMaterialPickerForm = class(TForm)
- LBMaterials: TListBox;
- Label1: TLabel;
- Label2: TLabel;
- BBOk: TBitBtn;
- BBCancel: TBitBtn;
- MPPreview: TRMaterialPreview;
- procedure LBMaterialsClick(Sender: TObject);
- procedure LBMaterialsKeyPress(Sender: TObject; var Key: Char);
- procedure LBMaterialsDblClick(Sender: TObject);
- private
- public
- function Execute(var materialName: TGLLibMaterialName;
- materialLibrary: TGLAbstractMaterialLibrary): Boolean;
- end;
- function GLLibMaterialPickerForm: TGLLibMaterialPickerForm;
- procedure ReleaseLibMaterialPickerForm;
- //-------------------------------------------------
- implementation
- //-------------------------------------------------
- {$R *.dfm}
- var
- vGLLibMaterialPickerForm: TGLLibMaterialPickerForm;
- function GLLibMaterialPickerForm: TGLLibMaterialPickerForm;
- begin
- if not Assigned(vGLLibMaterialPickerForm) then
- vGLLibMaterialPickerForm := TGLLibMaterialPickerForm.Create(nil);
- Result := vGLLibMaterialPickerForm;
- end;
- procedure ReleaseLibMaterialPickerForm;
- begin
- if Assigned(vGLLibMaterialPickerForm) then
- begin
- vGLLibMaterialPickerForm.Free;
- vGLLibMaterialPickerForm := nil;
- end;
- end;
- function TGLLibMaterialPickerForm.Execute(var materialName: TGLLibMaterialName;
- materialLibrary: TGLAbstractMaterialLibrary): Boolean;
- begin
- with LBMaterials do
- begin
- materialLibrary.SetNamesToTStrings(LBMaterials.Items);
- ItemIndex := Items.IndexOf(materialName);
- if (ItemIndex < 0) and (Items.Count > 0) then
- ItemIndex := 0;
- BBOk.Enabled := (Items.Count > 0);
- end;
- LBMaterialsClick(Self);
- Result := (ShowModal = mrOk);
- if Result then
- begin
- with LBMaterials do
- if ItemIndex >= 0 then
- materialName := Items[ItemIndex]
- else
- materialName := '';
- end;
- end;
- procedure TGLLibMaterialPickerForm.LBMaterialsClick(Sender: TObject);
- begin
- with LBMaterials do
- if ItemIndex >= 0 then
- MPPreview.LibMaterial := TGLAbstractLibMaterial(Items.Objects[ItemIndex]);
- end;
- procedure TGLLibMaterialPickerForm.LBMaterialsKeyPress(Sender: TObject;
- var Key: Char);
- begin
- LBMaterialsClick(Sender);
- end;
- procedure TGLLibMaterialPickerForm.LBMaterialsDblClick(Sender: TObject);
- begin
- BBOk.Click;
- end;
- //-----------------------------------------------------------------
- initialization
- //-----------------------------------------------------------------
- finalization
- ReleaseLibMaterialPickerForm;
- end.
|