2
0

FMxSkinEditor.pas 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. //
  2. // The graphics engine GXScene https://github.com/glscene
  3. //
  4. unit FMxSkinEditor;
  5. (* Editor for skins *)
  6. interface
  7. uses
  8. System.Messaging,
  9. System.SysUtils,
  10. System.Types,
  11. System.UITypes,
  12. System.Classes,
  13. System.Variants,
  14. System.Math.Vectors,
  15. FMX.Types,
  16. FMX.Controls,
  17. FMX.Forms,
  18. FMX.Graphics,
  19. FMX.Dialogs,
  20. FMX.StdCtrls,
  21. FMX.Layouts,
  22. FMX.ListBox,
  23. FMX.Objects,
  24. FMX.Controls.Presentation,
  25. FMX.Edit,
  26. FMX.Controls3D,
  27. GXS.BaseClasses,
  28. GXS.Gui,
  29. GXS.Texture,
  30. GXS.Material;
  31. type
  32. TSkinEditorForm = class(TForm)
  33. PanElements: TPanel;
  34. StatusBar: TStatusBar;
  35. PanBottom: TPanel;
  36. Label1: TLabel;
  37. btnAdd: TButton;
  38. btnDelete: TButton;
  39. LBElements: TListBox;
  40. Label2: TLabel;
  41. ComboBox1: TComboBox;
  42. PanImageProperties: TPanel;
  43. PanZoomImage: TPanel;
  44. SBarHorizontal: TScrollBar;
  45. SBarVertical: TScrollBar;
  46. ImgFull: TImage;
  47. ButtonOK: TButton;
  48. ImageOK: TImage;
  49. ButtonCancel: TButton;
  50. ImageCancel: TImage;
  51. Panel1: TPanel;
  52. ImgPreview: TImage;
  53. Panel2: TPanel;
  54. Label3: TLabel;
  55. CheckBox1: TCheckBox;
  56. Label4: TLabel;
  57. Label5: TLabel;
  58. EditWidth: TEdit;
  59. EditHeight: TEdit;
  60. GLCamera1: TCamera;
  61. GLPanel1: TPanel;
  62. procedure FormCreate(Sender: TObject);
  63. procedure FormDestroy(Sender: TObject);
  64. private
  65. FOriginalWndProc: TWndMethod;
  66. FFocusRect: TRect;
  67. VisibleRect: TRect;
  68. PreviewMousePoint: TPoint;
  69. PreviewWidth,
  70. PreviewHeight: Integer;
  71. FullMousePoint: TPoint;
  72. MouseDown: Boolean;
  73. procedure ImageWndProc(var Message: TMessage);
  74. procedure DrawImageFocusRect(ARect: TRect);
  75. procedure AlignZoomPanel;
  76. procedure UpdateRegionEdits;
  77. procedure SetEditState(Parent: TControl; Enabled: Boolean);
  78. procedure AddElement(Index: Integer);
  79. procedure DrawCrossair(Point: TPoint);
  80. public
  81. TheGuiComponent: TgxGuiElementList;
  82. SelectedElement: TgxGUIElement;
  83. Tex: TgxTexture;
  84. Zoom: Single;
  85. Width: Integer;
  86. Height: Integer;
  87. function Edit(GuiComponent: TgxGuiElementList): Boolean;
  88. procedure Render;
  89. procedure SetMax(Scrollbar: TScrollbar; Val: Integer);
  90. end;
  91. var
  92. SkinEditorForm: TSkinEditorForm;
  93. function GUIComponentDialog(GuiComponent: TgxGuiElementList): Boolean;
  94. //--------------------------------------------------------------------
  95. implementation
  96. //--------------------------------------------------------------------
  97. {$R *.fmx}
  98. function GUIComponentDialog(GuiComponent: TgxGuiElementList): Boolean;
  99. var
  100. Editor: TSkinEditorForm;
  101. begin
  102. Editor := TSkinEditorForm.Create(nil);
  103. Result := Editor.Edit(GuiComponent);
  104. Editor.Free;
  105. end;
  106. procedure TSkinEditorForm.FormCreate(Sender: TObject);
  107. begin
  108. //override original WndProc to capture image mouse leave message
  109. //with FMX tools
  110. (*
  111. FOriginalWndProc := ImgFull.WindowProc;
  112. imgFull.WindowProc := ImageWndProc;
  113. Tex := TgxTexture.Create(Self);
  114. Tex.SetImageClassName('TgxPersistentImage');
  115. GLPanel1.RedrawAtOnce := True;
  116. StatusBar.Panels[0].Text := 'X : 0';
  117. StatusBar.Panels[1].Text := 'Y : 0';
  118. AlignZoomPanel;
  119. UpdateRegionEdits;
  120. DoubleBuffered := True;
  121. FullMousePoint := Point(-1, -1);
  122. //this Delphi bug shows all panels transparent
  123. //the code below is to avoid this bug in XP
  124. panElements.ParentBackground := False;
  125. panElements.ParentBackground := True;
  126. panElements.ParentBackground := False;
  127. panImageProperties.ParentBackground := False;
  128. panImageProperties.ParentBackground := True;
  129. panImageProperties.ParentBackground := False;
  130. panBottom.ParentBackground := False;
  131. panBottom.ParentBackground := True;
  132. panBottom.ParentBackground := False;
  133. panZoomImage.ParentBackground := False;
  134. panZoomImage.ParentBackground := True;
  135. panZoomImage.ParentBackground := False;
  136. *)
  137. end;
  138. procedure TSkinEditorForm.FormDestroy(Sender: TObject);
  139. begin
  140. Tex.Free;
  141. end;
  142. function TSkinEditorForm.Edit(GuiComponent: TgxGuiElementList): Boolean;
  143. var
  144. Mat: TgxMaterial;
  145. GuiLayout: TgxGuiLayout;
  146. XC: Integer;
  147. begin
  148. TheGuiComponent := GuiComponent;
  149. GuiLayout := (GuiComponent.GetOwner as TgxGuiComponent).Owner.GetOwner as
  150. TgxGuiLayout;
  151. Mat := GuiLayout.Material;
  152. GLPanel1.Visible := True;
  153. { TODO : E2003 Undeclared identifier: 'GuiLayout' }
  154. (*
  155. GLPanel1.GuiLayout := GuiLayout;
  156. GLPanel1.GuiLayoutName := (GuiComponent.GetOwner as TGuiComponent).Name;
  157. *)
  158. Zoom := 1.0;
  159. if (Assigned(mat.MaterialLibrary)
  160. and (mat.MaterialLibrary is TgxMaterialLibrary)
  161. and (Mat.LibMaterialName <> '')) then
  162. begin
  163. mat :=
  164. TgxMaterialLibrary(mat.MaterialLibrary).Materials.GetLibMaterialByName(Mat.LibMaterialName).Material;
  165. end;
  166. Width := Mat.Texture.Image.Width;
  167. Height := Mat.Texture.Image.Height;
  168. { TODO : E2003 Undeclared identifier }
  169. (*
  170. WidthEdit.Text := IntToStr(Mat.Texture.Image.Width);
  171. HeightEdit.Text := IntToStr(Mat.Texture.Image.Height);
  172. GLPanel1.GuiLayout.Material.Assign(Mat);
  173. *)
  174. Tex.Assign(mat.Texture);
  175. { TODO : E2003 Undeclared identifier }
  176. (*
  177. imgPreview.Bitmap.Canvas.StretchDraw(imgPreview.ClientRect, (Tex.Image
  178. as TgxPersistentImage).Picture.Bitmap);
  179. PreviewWidth := (Tex.Image as TgxPersistentImage).Picture.Width;
  180. Previewheight := (Tex.Image as TgxPersistentImage).Picture.Height;
  181. *)
  182. lbElements.Clear;
  183. for XC := 0 to TheGuiComponent.Count - 1 do
  184. begin
  185. lbElements.Items.Add(TheGuiComponent.Items[XC].Name);
  186. end;
  187. if TheGuiComponent.Count > 0 then
  188. begin
  189. SelectedElement := TheGuiComponent.Items[0];
  190. lbElements.ItemIndex := 0;
  191. end
  192. else
  193. SelectedElement := nil;
  194. Render;
  195. Result := ShowModal = mrOk;
  196. end;
  197. procedure TSkinEditorForm.AddElement(Index: Integer);
  198. begin
  199. end;
  200. procedure TSkinEditorForm.AlignZoomPanel;
  201. begin
  202. end;
  203. procedure TSkinEditorForm.DrawCrossair(Point: TPoint);
  204. begin
  205. end;
  206. procedure TSkinEditorForm.DrawImageFocusRect(ARect: TRect);
  207. begin
  208. end;
  209. procedure TSkinEditorForm.ImageWndProc(var Message: TMessage);
  210. begin
  211. end;
  212. procedure TSkinEditorForm.Render;
  213. begin
  214. end;
  215. procedure TSkinEditorForm.SetEditState(Parent: TControl; Enabled: Boolean);
  216. begin
  217. end;
  218. procedure TSkinEditorForm.SetMax(Scrollbar: TScrollbar; Val: Integer);
  219. begin
  220. end;
  221. procedure TSkinEditorForm.UpdateRegionEdits;
  222. begin
  223. end;
  224. end.