FPlugInManagerEditor.pas 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. //
  2. // This unit is part of the GLScene Engine, http://glscene.org
  3. //
  4. {
  5. Need a short description of what it does here.
  6. }
  7. unit FPlugInManagerEditor;
  8. interface
  9. {$I GLScene.inc}
  10. uses
  11. System.Classes,
  12. System.SysUtils,
  13. System.ImageList,
  14. VCL.Forms,
  15. VCL.Dialogs,
  16. VCL.StdCtrls,
  17. VCL.Controls,
  18. VCL.Buttons,
  19. Vcl.ExtCtrls,
  20. Vcl.ImgList,
  21. Vcl.ComCtrls,
  22. Vcl.ToolWin,
  23. GLPlugInIntf,
  24. GLPlugInManager;
  25. type
  26. TGLPlugInManagerEditorForm = class(TForm)
  27. OpenDialog: TOpenDialog;
  28. ListBox: TListBox;
  29. Label1: TLabel;
  30. GroupBox: TGroupBox;
  31. DescriptionMemo: TMemo;
  32. Label2: TLabel;
  33. Label3: TLabel;
  34. DateLabel: TLabel;
  35. SizeLabel: TLabel;
  36. Label4: TLabel;
  37. Label5: TLabel;
  38. ServiceBox: TComboBox;
  39. NameBox: TComboBox;
  40. ToolBar1: TToolBar;
  41. ToolButton1: TToolButton;
  42. ToolButton2: TToolButton;
  43. ToolButton3: TToolButton;
  44. ImageList: TImageList;
  45. procedure OKButtonClick(Sender: TObject);
  46. procedure LoadButtonClick(Sender: TObject);
  47. procedure ListBoxClick(Sender: TObject);
  48. procedure UnloadButtonClick(Sender: TObject);
  49. procedure ServiceBoxChange(Sender: TObject);
  50. private
  51. FManager: TGLPlugInManager;
  52. public
  53. class procedure EditPlugIns(AManager: TGLPlugInManager);
  54. end;
  55. // ------------------------------------------------------------------------------
  56. implementation
  57. // ------------------------------------------------------------------------------
  58. {$R *.DFM}
  59. var
  60. vGLPlugInManagerEditor: TGLPlugInManagerEditorForm;
  61. procedure TGLPlugInManagerEditorForm.OKButtonClick(Sender: TObject);
  62. begin
  63. Close;
  64. end;
  65. // ------------------------------------------------------------------------------
  66. procedure TGLPlugInManagerEditorForm.LoadButtonClick(Sender: TObject);
  67. var
  68. I, Index: Integer;
  69. begin
  70. with OpenDialog do
  71. if Execute then
  72. for I := 0 to Files.Count - 1 do
  73. begin
  74. Index := FManager.AddPlugIn(Files[I]);
  75. if Index > -1 then
  76. if Index >= ListBox.Items.Count then
  77. begin
  78. FManager.PlugIns.Objects[Index];
  79. ListBox.Items.Add(FManager.PlugIns.Strings[I]);
  80. end
  81. else
  82. else
  83. MessageDlg(Format('Error while loading %s' + #13 +
  84. 'not a valid GLScene plug-in', [Files[I]]), mtError, [mbOK], 0);
  85. end;
  86. end;
  87. // ------------------------------------------------------------------------------
  88. class procedure TGLPlugInManagerEditorForm.EditPlugIns(AManager: TGLPlugInManager);
  89. begin
  90. // ensure only one instance
  91. if Assigned(vGLPlugInManagerEditor) then
  92. vGLPlugInManagerEditor.Free;
  93. vGLPlugInManagerEditor := TGLPlugInManagerEditorForm.Create(Application);
  94. with vGLPlugInManagerEditor do
  95. begin
  96. ListBox.Items := AManager.PlugIns;
  97. FManager := AManager;
  98. ShowModal;
  99. Free;
  100. end;
  101. vGLPlugInManagerEditor := nil;
  102. end;
  103. // ------------------------------------------------------------------------------
  104. procedure TGLPlugInManagerEditorForm.ListBoxClick(Sender: TObject);
  105. var
  106. Entry: Integer;
  107. Service: TPIServiceType;
  108. Services: TPIServices;
  109. begin
  110. Entry := ListBox.ItemIndex;
  111. if Entry > -1 then
  112. begin
  113. SizeLabel.Caption := Format('%n KB',
  114. [FManager.PlugIns[Entry].FileSize / 1000]);
  115. SizeLabel.Enabled := True;
  116. DateLabel.Caption := DateToStr(FManager.PlugIns[Entry].FileDate);
  117. DateLabel.Enabled := True;
  118. DescriptionMemo.Lines.Text :=
  119. string(FManager.PlugIns[Entry].GetDescription);
  120. ServiceBox.Items.Clear;
  121. ServiceBox.Enabled := True;
  122. Services := FManager.PlugIns[Entry].GetServices;
  123. for Service := Low(TPIServiceType) to High(TPIServiceType) do
  124. if Service in Services then
  125. case Service of
  126. stRaw:
  127. begin
  128. Entry := ServiceBox.Items.Add('Raw');
  129. ServiceBox.Items.Objects[Entry] := Pointer(stRaw);
  130. end;
  131. stObject:
  132. begin
  133. Entry := ServiceBox.Items.Add('Object');
  134. ServiceBox.Items.Objects[Entry] := Pointer(stObject);
  135. end;
  136. stBitmap:
  137. begin
  138. Entry := ServiceBox.Items.Add('Bitmap');
  139. ServiceBox.Items.Objects[Entry] := Pointer(stBitmap);
  140. end;
  141. stTexture:
  142. begin
  143. Entry := ServiceBox.Items.Add('Texture');
  144. ServiceBox.Items.Objects[Entry] := Pointer(stTexture);
  145. end;
  146. stImport:
  147. begin
  148. Entry := ServiceBox.Items.Add('Import');
  149. ServiceBox.Items.Objects[Entry] := Pointer(stImport);
  150. end;
  151. stExport:
  152. begin
  153. Entry := ServiceBox.Items.Add('Export');
  154. ServiceBox.Items.Objects[Entry] := Pointer(stExport);
  155. end;
  156. end;
  157. ServiceBox.ItemIndex := 0;
  158. ServiceBox.OnChange(ServiceBox);
  159. end;
  160. end;
  161. // ------------------------------------------------------------------------------
  162. procedure TGLPlugInManagerEditorForm.UnloadButtonClick(Sender: TObject);
  163. var
  164. I: Integer;
  165. begin
  166. for I := 0 to ListBox.Items.Count - 1 do
  167. if ListBox.Selected[I] then
  168. begin
  169. FManager.RemovePlugIn(I);
  170. ListBox.Items.Delete(I);
  171. end;
  172. DescriptionMemo.Clear;
  173. DateLabel.Caption := '???';
  174. DateLabel.Enabled := False;
  175. SizeLabel.Caption := '???';
  176. SizeLabel.Enabled := False;
  177. ServiceBox.ItemIndex := -1;
  178. ServiceBox.Enabled := False;
  179. NameBox.ItemIndex := -1;
  180. NameBox.Enabled := False;
  181. end;
  182. // ------------------------------------------------------------------------------
  183. procedure NameCallback(Name: PAnsiChar); stdcall;
  184. begin
  185. vGLPlugInManagerEditor.NameBox.Items.Add(String(Name));
  186. end;
  187. // ------------------------------------------------------------------------------
  188. procedure TGLPlugInManagerEditorForm.ServiceBoxChange(Sender: TObject);
  189. begin
  190. NameBox.Items.Clear;
  191. with ServiceBox, Items do
  192. FManager.PlugIns[ListBox.ItemIndex].EnumResourceNames
  193. (TPIServiceType(Objects[ItemIndex]), NameCallback);
  194. NameBox.ItemIndex := 0;
  195. NameBox.Enabled := True;
  196. end;
  197. // ------------------------------------------------------------------------------
  198. end.