TextureInspector.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using System.Collections.Generic;
  4. using bs;
  5. namespace bs.Editor
  6. {
  7. /** @addtogroup Inspectors
  8. * @{
  9. */
  10. /// <summary>
  11. /// Renders an inspector for the <see cref="Texture"/> resource.
  12. /// </summary>
  13. [CustomInspector(typeof(Texture))]
  14. internal class TextureInspector : Inspector
  15. {
  16. private GUIEnumField formatField = new GUIEnumField(typeof(PixelFormat), new LocEdString("Format"));
  17. private GUIToggleField generateMipsField = new GUIToggleField(new LocEdString("Generate mipmaps"));
  18. private GUIIntField maximumMipsField = new GUIIntField(new LocEdString("Maximum mipmap level"));
  19. private GUIToggleField srgbField = new GUIToggleField(new LocEdString("Gamma space"));
  20. private GUIToggleField cpuCachedField = new GUIToggleField(new LocEdString("CPU cached"));
  21. private GUIToggleField isCubemapField = new GUIToggleField(new LocEdString("Cubemap"));
  22. private GUIEnumField cubemapSourceTypeField =
  23. new GUIEnumField(typeof(CubemapSourceType), new LocEdString("Cubemap source"));
  24. private GUIReimportButton reimportButton;
  25. private TextureImportOptions importOptions;
  26. /// <inheritdoc/>
  27. protected internal override void Initialize()
  28. {
  29. importOptions = GetImportOptions();
  30. formatField.OnSelectionChanged += x => importOptions.Format = (PixelFormat)x;
  31. generateMipsField.OnChanged += x => importOptions.GenerateMips = x;
  32. maximumMipsField.OnChanged += x => importOptions.MaxMip = x;
  33. srgbField.OnChanged += x => importOptions.SRGB = x;
  34. cpuCachedField.OnChanged += x => importOptions.CpuCached = x;
  35. isCubemapField.OnChanged += x => importOptions.Cubemap = x;
  36. cubemapSourceTypeField.OnSelectionChanged += x => importOptions.CubemapSourceType = (CubemapSourceType)x;
  37. Layout.AddElement(formatField);
  38. Layout.AddElement(generateMipsField);
  39. Layout.AddElement(maximumMipsField);
  40. Layout.AddElement(srgbField);
  41. Layout.AddElement(cpuCachedField);
  42. Layout.AddElement(isCubemapField);
  43. Layout.AddElement(cubemapSourceTypeField);
  44. Layout.AddSpace(10);
  45. reimportButton = new GUIReimportButton(InspectedResourcePath, Layout, () =>
  46. {
  47. ProjectLibrary.Reimport(InspectedResourcePath, importOptions, true);
  48. });
  49. UpdateGUIValues();
  50. }
  51. /// <inheritdoc/>
  52. protected internal override InspectableState Refresh(bool force = false)
  53. {
  54. reimportButton.Update();
  55. return InspectableState.NotModified;
  56. }
  57. /// <summary>
  58. /// Updates the GUI element values from the current import options object.
  59. /// </summary>
  60. private void UpdateGUIValues()
  61. {
  62. formatField.Value = (ulong)importOptions.Format;
  63. generateMipsField.Value = importOptions.GenerateMips;
  64. maximumMipsField.Value = importOptions.MaxMip;
  65. srgbField.Value = importOptions.SRGB;
  66. cpuCachedField.Value = importOptions.CpuCached;
  67. isCubemapField.Value = importOptions.Cubemap;
  68. cubemapSourceTypeField.Value = (ulong) importOptions.CubemapSourceType;
  69. cubemapSourceTypeField.Active = importOptions.Cubemap;
  70. }
  71. /// <summary>
  72. /// Retrieves import options for the texture we're currently inspecting.
  73. /// </summary>
  74. /// <returns>Texture import options object.</returns>
  75. private TextureImportOptions GetImportOptions()
  76. {
  77. TextureImportOptions output = null;
  78. LibraryEntry texEntry = ProjectLibrary.GetEntry(InspectedResourcePath);
  79. if (texEntry != null && texEntry.Type == LibraryEntryType.File)
  80. {
  81. FileEntry texFileEntry = (FileEntry)texEntry;
  82. output = texFileEntry.Options as TextureImportOptions;
  83. }
  84. if (output == null)
  85. {
  86. if (importOptions == null)
  87. output = new TextureImportOptions();
  88. else
  89. output = importOptions;
  90. }
  91. return output;
  92. }
  93. }
  94. /** @} */
  95. }