TextureInspector.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 =>
  36. {
  37. importOptions.Cubemap = x;
  38. cubemapSourceTypeField.Active = x;
  39. };
  40. cubemapSourceTypeField.OnSelectionChanged += x => importOptions.CubemapSourceType = (CubemapSourceType)x;
  41. Layout.AddElement(formatField);
  42. Layout.AddElement(generateMipsField);
  43. Layout.AddElement(maximumMipsField);
  44. Layout.AddElement(srgbField);
  45. Layout.AddElement(cpuCachedField);
  46. Layout.AddElement(isCubemapField);
  47. Layout.AddElement(cubemapSourceTypeField);
  48. Layout.AddSpace(10);
  49. reimportButton = new GUIReimportButton(InspectedResourcePath, Layout, () =>
  50. {
  51. ProjectLibrary.Reimport(InspectedResourcePath, importOptions, true);
  52. });
  53. UpdateGUIValues();
  54. }
  55. /// <inheritdoc/>
  56. protected internal override InspectableState Refresh(bool force = false)
  57. {
  58. reimportButton.Update();
  59. return InspectableState.NotModified;
  60. }
  61. /// <summary>
  62. /// Updates the GUI element values from the current import options object.
  63. /// </summary>
  64. private void UpdateGUIValues()
  65. {
  66. formatField.Value = (ulong)importOptions.Format;
  67. generateMipsField.Value = importOptions.GenerateMips;
  68. maximumMipsField.Value = importOptions.MaxMip;
  69. srgbField.Value = importOptions.SRGB;
  70. cpuCachedField.Value = importOptions.CpuCached;
  71. isCubemapField.Value = importOptions.Cubemap;
  72. cubemapSourceTypeField.Value = (ulong) importOptions.CubemapSourceType;
  73. cubemapSourceTypeField.Active = importOptions.Cubemap;
  74. }
  75. /// <summary>
  76. /// Retrieves import options for the texture we're currently inspecting.
  77. /// </summary>
  78. /// <returns>Texture import options object.</returns>
  79. private TextureImportOptions GetImportOptions()
  80. {
  81. TextureImportOptions output = null;
  82. LibraryEntry texEntry = ProjectLibrary.GetEntry(InspectedResourcePath);
  83. if (texEntry != null && texEntry.Type == LibraryEntryType.File)
  84. {
  85. FileEntry texFileEntry = (FileEntry)texEntry;
  86. output = texFileEntry.Options as TextureImportOptions;
  87. }
  88. if (output == null)
  89. {
  90. if (importOptions == null)
  91. output = new TextureImportOptions();
  92. else
  93. output = importOptions;
  94. }
  95. return output;
  96. }
  97. }
  98. /** @} */
  99. }