FmPlugInManagerEditor.pas 6.0 KB

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