FMaterialEditorForm.pas 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. //
  2. // This unit is part of the GLScene Engine, http://glscene.org
  3. //
  4. {
  5. Editor window for a material (with preview).
  6. }
  7. unit FMaterialEditorForm;
  8. interface
  9. {$I GLScene.inc}
  10. uses
  11. Winapi.Windows,
  12. System.Classes,
  13. System.TypInfo,
  14. VCL.Forms,
  15. VCL.ComCtrls,
  16. VCL.StdCtrls,
  17. VCL.Controls,
  18. VCL.Buttons,
  19. GLWin32Viewer,
  20. GLState,
  21. GLMaterial,
  22. GLTexture,
  23. FRMaterialPreview,
  24. FRColorEditor,
  25. FRFaceEditor,
  26. FRTextureEdit;
  27. type
  28. TGLMaterialEditorForm = class(TForm)
  29. PageControl1: TPageControl;
  30. TSFront: TTabSheet;
  31. TSBack: TTabSheet;
  32. TSTexture: TTabSheet;
  33. FEFront: TRFaceEditor;
  34. FEBack: TRFaceEditor;
  35. GroupBox1: TGroupBox;
  36. MPPreview: TRMaterialPreview;
  37. BBOk: TBitBtn;
  38. BBCancel: TBitBtn;
  39. RTextureEdit: TRTextureEdit;
  40. CBBlending: TComboBox;
  41. Label1: TLabel;
  42. Label2: TLabel;
  43. CBPolygonMode: TComboBox;
  44. procedure OnMaterialChanged(Sender: TObject);
  45. private
  46. public
  47. constructor Create(AOwner: TComponent); override;
  48. function Execute(AMaterial: TGLMaterial): Boolean;
  49. end;
  50. function GLMaterialEditorForm: TGLMaterialEditorForm;
  51. procedure ReleaseMaterialEditorForm;
  52. //----------------------------------------------
  53. implementation
  54. //----------------------------------------------
  55. {$R *.dfm}
  56. var
  57. vGLMaterialEditorForm: TGLMaterialEditorForm;
  58. function GLMaterialEditorForm: TGLMaterialEditorForm;
  59. begin
  60. if not Assigned(vGLMaterialEditorForm) then
  61. vGLMaterialEditorForm := TGLMaterialEditorForm.Create(nil);
  62. Result := vGLMaterialEditorForm;
  63. end;
  64. procedure ReleaseMaterialEditorForm;
  65. begin
  66. if Assigned(vGLMaterialEditorForm) then
  67. begin
  68. vGLMaterialEditorForm.Free;
  69. vGLMaterialEditorForm := nil;
  70. end;
  71. end;
  72. constructor TGLMaterialEditorForm.Create(AOwner: TComponent);
  73. var
  74. I: Integer;
  75. begin
  76. inherited;
  77. for i := 0 to Integer(High(TGLBlendingMode)) do
  78. CBBlending.Items.Add(GetEnumName(TypeInfo(TGLBlendingMode), i));
  79. for i := 0 to Integer(High(TGLPolygonMode)) do
  80. CBPolygonMode.Items.Add(GetEnumName(TypeInfo(TGLPolygonMode), i));
  81. FEFront.OnChange := OnMaterialChanged;
  82. FEBack.OnChange := OnMaterialChanged;
  83. RTextureEdit.OnChange := OnMaterialChanged;
  84. end;
  85. // Execute
  86. //
  87. function TGLMaterialEditorForm.Execute(AMaterial: TGLMaterial): Boolean;
  88. begin
  89. with AMaterial.GetActualPrimaryMaterial do
  90. begin
  91. FEFront.FaceProperties := FrontProperties;
  92. FEBack.FaceProperties := BackProperties;
  93. RTextureEdit.Texture := Texture;
  94. CBPolygonMode.ItemIndex:=Integer(PolygonMode);
  95. CBBlending.ItemIndex := Integer(BlendingMode);
  96. end;
  97. MPPreview.Material := AMaterial;
  98. Result := (ShowModal = mrOk);
  99. if Result then
  100. with AMaterial.GetActualPrimaryMaterial do
  101. begin
  102. FrontProperties := FEFront.FaceProperties;
  103. BackProperties := FEBack.FaceProperties;
  104. Texture := RTextureEdit.Texture;
  105. BlendingMode := TGLBlendingMode(CBBlending.ItemIndex);
  106. PolygonMode := TGLPolygonMode(CBPolygonMode.ItemIndex);
  107. end;
  108. end;
  109. // OnMaterialChanged
  110. //
  111. procedure TGLMaterialEditorForm.OnMaterialChanged(Sender: TObject);
  112. begin
  113. with MPPreview.Material do
  114. begin
  115. FrontProperties := FEFront.FaceProperties;
  116. BackProperties := FEBack.FaceProperties;
  117. Texture := RTextureEdit.Texture;
  118. BlendingMode := TGLBlendingMode(CBBlending.ItemIndex);
  119. PolygonMode := TGLPolygonMode(CBPolygonMode.ItemIndex);
  120. end;
  121. MPPreview.GLSceneViewer.Invalidate;
  122. end;
  123. // ------------------------------------------------------------------
  124. initialization
  125. // ------------------------------------------------------------------
  126. finalization
  127. ReleaseMaterialEditorForm;
  128. end.