BsBuiltinResources.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsPrerequisites.h"
  5. #include "BsGUISkin.h"
  6. #include "BsModule.h"
  7. #include "BsVector2I.h"
  8. #include "BsApplication.h"
  9. namespace BansheeEngine
  10. {
  11. /** @addtogroup Resources-Engine
  12. * @{
  13. */
  14. /** Types of builtin meshes that are always available in the engine. */
  15. enum class BuiltinMesh
  16. {
  17. Box, Sphere, Cone, Quad, Disc
  18. };
  19. /** Types of builtin textures that are always available in the engine. */
  20. enum class BuiltinTexture
  21. {
  22. White, Black, Normal
  23. };
  24. /** Holds references to built-in resources used by the core engine. */
  25. class BS_EXPORT BuiltinResources : public BansheeEngine::Module<BuiltinResources>
  26. {
  27. public:
  28. BuiltinResources();
  29. ~BuiltinResources();
  30. /** Returns the default skin used by engine GUI elements. */
  31. const HGUISkin& getGUISkin() const { return mSkin; }
  32. /** Returns an empty skin used to be used when no other is available. */
  33. const HGUISkin& getEmptyGUISkin() const { return mEmptySkin; }
  34. /** Returns a small entirely white texture. */
  35. const HSpriteTexture& getWhiteSpriteTexture() const { return mWhiteSpriteTexture; }
  36. /** Returns a 2x2 sprite texture that can be used when no other is available. */
  37. const HSpriteTexture& getDummySpriteTexture() const { return mDummySpriteTexture; }
  38. /** Returns a dummy 2x2 texture that may be used when no other is available. Don't modify the returned texture. */
  39. const HTexture& getDummyTexture() const { return mDummyTexture; }
  40. /** Returns image data for an arrow cursor, along with its hotspot. */
  41. const PixelData& getCursorArrow(Vector2I& hotSpot);
  42. /** Returns image data for an arrow with dragged object cursor, along with its hotspot. */
  43. const PixelData& getCursorArrowDrag(Vector2I& hotSpot);
  44. /** Returns image data for a wait cursor, along with its hotspot. */
  45. const PixelData& getCursorWait(Vector2I& hotSpot);
  46. /** Returns image data for an "I" beam cursor, along with its hotspot. */
  47. const PixelData& getCursorIBeam(Vector2I& hotSpot);
  48. /** Returns image data for a NESW resize cursor, along with its hotspot. */
  49. const PixelData& getCursorSizeNESW(Vector2I& hotSpot);
  50. /** Returns image data for a NS resize cursor, along with its hotspot. */
  51. const PixelData& getCursorSizeNS(Vector2I& hotSpot);
  52. /** Returns image data for a NWSE resize cursor, along with its hotspot. */
  53. const PixelData& getCursorSizeNWSE(Vector2I& hotSpot);
  54. /** Returns image data for a WE resize cursor, along with its hotspot. */
  55. const PixelData& getCursorSizeWE(Vector2I& hotSpot);
  56. /** Returns image data for a deny cursor, along with its hotspot. */
  57. const PixelData& getCursorDeny(Vector2I& hotSpot);
  58. /** Returns image data for a move left-right cursor, along with its hotspot. */
  59. const PixelData& getCursorMoveLeftRight(Vector2I& hotSpot);
  60. /** Returns the default application icon. */
  61. const PixelData& getBansheeIcon();
  62. /** Returns a shader used for rendering only a diffuse texture. */
  63. HShader getDiffuseShader() const { return mShaderDiffuse; }
  64. /** Creates material used for textual sprite rendering (for example text in GUI). */
  65. HMaterial createSpriteTextMaterial() const;
  66. /** Creates material used for image sprite rendering (for example images in GUI). */
  67. HMaterial createSpriteImageMaterial() const;
  68. /** Creates material used for non-transparent image sprite rendering (for example images in GUI). */
  69. HMaterial createSpriteNonAlphaImageMaterial() const;
  70. /** Retrieves one of the builtin meshes. */
  71. HMesh getMesh(BuiltinMesh mesh) const;
  72. /**
  73. * Loads a shader at the specified path.
  74. *
  75. * @param[in] path Path relative to the default shader folder with no file extension.
  76. */
  77. HShader getShader(const Path& path);
  78. /** Retrieves one of the builtin textures. */
  79. static HTexture getTexture(BuiltinTexture type);
  80. /** Returns image data the Banshee Engine splash screen. */
  81. static SPtr<PixelData> getSplashScreen();
  82. /** Returns path to the builtin shader include folder, relative to the working directory. */
  83. static Path getShaderIncludeFolder();
  84. /** Returns path to the builtin icons folder, relative to the working directory. */
  85. static Path getIconFolder();
  86. static const WString IconTextureName;
  87. static const String MultiLineLabelStyle;
  88. private:
  89. /**
  90. * Imports all necessary resources and converts them to engine-ready format.
  91. *
  92. * @note
  93. * Normally you only want to use this during development phase and then ship with engine-ready format only.
  94. */
  95. void preprocess();
  96. /** Generates the default engine skin and all GUI element styles. */
  97. SPtr<GUISkin> generateGUISkin();
  98. /** Generates the builtin meshes. */
  99. void generateMeshes();
  100. /** Generates the builtin textures. */
  101. void generateTextures();
  102. /** Loads a GUI skin texture with the specified filename. */
  103. HSpriteTexture getSkinTexture(const WString& name);
  104. /** Loads a cursor texture with the specified filename. */
  105. HTexture getCursorTexture(const WString& name);
  106. HGUISkin mEmptySkin;
  107. HGUISkin mSkin;
  108. SPtr<PixelData> mCursorArrow;
  109. SPtr<PixelData> mCursorArrowDrag;
  110. SPtr<PixelData> mCursorArrowLeftRight;
  111. SPtr<PixelData> mCursorIBeam;
  112. SPtr<PixelData> mCursorDeny;
  113. SPtr<PixelData> mCursorWait;
  114. SPtr<PixelData> mCursorSizeNESW;
  115. SPtr<PixelData> mCursorSizeNS;
  116. SPtr<PixelData> mCursorSizeNWSE;
  117. SPtr<PixelData> mCursorSizeWE;
  118. SPtr<PixelData> mBansheeIcon;
  119. HSpriteTexture mWhiteSpriteTexture;
  120. HSpriteTexture mDummySpriteTexture;
  121. HTexture mDummyTexture;
  122. HShader mShaderSpriteText;
  123. HShader mShaderSpriteImage;
  124. HShader mShaderSpriteNonAlphaImage;
  125. HShader mShaderDiffuse;
  126. SPtr<ResourceManifest> mResourceManifest;
  127. Path mBuiltinRawDataFolder;
  128. Path mEngineRawCursorFolder;
  129. Path mEngineRawIconFolder;
  130. Path mEngineRawShaderFolder;
  131. Path mEngineRawShaderIncludeFolder;
  132. Path mEngineRawSkinFolder;
  133. Path mBuiltinDataFolder;
  134. Path mEngineSkinFolder;
  135. Path mEngineCursorFolder;
  136. Path mEngineIconFolder;
  137. Path mEngineShaderFolder;
  138. Path mEngineShaderIncludeFolder;
  139. Path mEngineMeshFolder;
  140. Path mEngineTextureFolder;
  141. Path ResourceManifestPath;
  142. static const char* CursorFolder;
  143. static const char* IconFolder;
  144. static const char* ShaderFolder;
  145. static const char* ShaderIncludeFolder;
  146. static const char* SkinFolder;
  147. static const char* MeshFolder;
  148. static const char* TextureFolder;
  149. static const WString DefaultFontFilename;
  150. static const UINT32 DefaultFontSize;
  151. static const Color TextNormalColor;
  152. static const Color TextActiveColor;
  153. static const WString GUISkinFile;
  154. static const WString WhiteTex;
  155. static const wchar_t* SplashScreenName;
  156. static const WString ButtonNormalTex;
  157. static const WString ButtonHoverTex;
  158. static const WString ButtonActiveTex;
  159. static const WString ToggleNormalTex;
  160. static const WString ToggleHoverTex;
  161. static const WString ToggleNormalOnTex;
  162. static const WString ToggleHoverOnTex;
  163. static const WString InputBoxNormalTex;
  164. static const WString InputBoxHoverTex;
  165. static const WString InputBoxFocusedTex;
  166. static const WString ScrollBarUpNormalTex;
  167. static const WString ScrollBarUpHoverTex;
  168. static const WString ScrollBarUpActiveTex;
  169. static const WString ScrollBarDownNormalTex;
  170. static const WString ScrollBarDownHoverTex;
  171. static const WString ScrollBarDownActiveTex;
  172. static const WString ScrollBarLeftNormalTex;
  173. static const WString ScrollBarLeftHoverTex;
  174. static const WString ScrollBarLeftActiveTex;
  175. static const WString ScrollBarRightNormalTex;
  176. static const WString ScrollBarRightHoverTex;
  177. static const WString ScrollBarRightActiveTex;
  178. static const WString ScrollBarHandleHorzNormalTex;
  179. static const WString ScrollBarHandleHorzHoverTex;
  180. static const WString ScrollBarHandleHorzActiveTex;
  181. static const WString ScrollBarHandleVertNormalTex;
  182. static const WString ScrollBarHandleVertHoverTex;
  183. static const WString ScrollBarHandleVertActiveTex;
  184. static const WString ScrollBarHBgTex;
  185. static const WString ScrollBarVBgTex;
  186. static const WString DropDownBtnNormalTex;
  187. static const WString DropDownBtnHoverTex;
  188. static const WString DropDownBtnActiveTex;
  189. static const WString DropDownBoxBgTex;
  190. static const WString DropDownBoxSideBgTex;
  191. static const WString DropDownBoxHandleTex;
  192. static const WString DropDownBoxEntryNormalTex;
  193. static const WString DropDownBoxEntryHoverTex;
  194. static const WString DropDownBoxBtnUpNormalTex;
  195. static const WString DropDownBoxBtnUpHoverTex;
  196. static const WString DropDownBoxBtnDownNormalTex;
  197. static const WString DropDownBoxBtnDownHoverTex;
  198. static const WString DropDownBoxEntryExpNormalTex;
  199. static const WString DropDownBoxEntryExpHoverTex;
  200. static const WString DropDownSeparatorTex;
  201. static const WString CursorArrowTex;
  202. static const WString CursorArrowDragTex;
  203. static const WString CursorArrowLeftRightTex;
  204. static const WString CursorIBeamTex;
  205. static const WString CursorDenyTex;
  206. static const WString CursorWaitTex;
  207. static const WString CursorSizeNESWTex;
  208. static const WString CursorSizeNSTex;
  209. static const WString CursorSizeNWSETex;
  210. static const WString CursorSizeWETex;
  211. static const Vector2I CursorArrowHotspot;
  212. static const Vector2I CursorArrowDragHotspot;
  213. static const Vector2I CursorArrowLeftRightHotspot;
  214. static const Vector2I CursorIBeamHotspot;
  215. static const Vector2I CursorDenyHotspot;
  216. static const Vector2I CursorWaitHotspot;
  217. static const Vector2I CursorSizeNESWHotspot;
  218. static const Vector2I CursorSizeNSHotspot;
  219. static const Vector2I CursorSizeNWSEHotspot;
  220. static const Vector2I CursorSizeWEHotspot;
  221. static const WString ShaderSpriteTextFile;
  222. static const WString ShaderSpriteImageAlphaFile;
  223. static const WString ShaderSpriteImageNoAlphaFile;
  224. static const WString ShaderDiffuseFile;
  225. static const WString MeshSphereFile;
  226. static const WString MeshBoxFile;
  227. static const WString MeshConeFile;
  228. static const WString MeshQuadFile;
  229. static const WString MeshDiscFile;
  230. static const WString TextureWhiteFile;
  231. static const WString TextureBlackFile;
  232. static const WString TextureNormalFile;
  233. };
  234. /** @} */
  235. /** @addtogroup Resources-Engine-Internal
  236. * @{
  237. */
  238. /** Provides various methods commonly used for managing builtin resources. */
  239. class BS_EXPORT BuiltinResourcesHelper
  240. {
  241. public:
  242. /**
  243. * Imports all recognized assets in the specified folder and saves them to the specified output folder. All saved
  244. * resources are registered in the provided resource manifest.
  245. */
  246. static void importAssets(const Path& inputFolder, const Path& outputFolder, const SPtr<ResourceManifest>& manifest);
  247. /**
  248. * Imports a font from the specified file. Imported font assets are saved in the output folder. All saved resources
  249. * are registered in the provided resource manifest.
  250. */
  251. static void importFont(const Path& inputFile, const WString& outputName, const Path& outputFolder,
  252. const Vector<UINT32>& fontSizes, bool antialiasing, const SPtr<ResourceManifest>& manifest);
  253. /**
  254. * Generates sprite textures for all texture assets in the specified folder. Results are written in the same folder
  255. * with a "sprite_" prefix. All saved resources are registered in the provided resource manifest.
  256. */
  257. static void generateSpriteTextures(const Path& folder, const SPtr<ResourceManifest>& manifest);
  258. /** Writes a timestamp with the current date and time in the specified file. */
  259. static void writeTimestamp(const Path& file);
  260. /**
  261. * Checks all files in the specified folder for modifications compared to the time stored in the timestamp file.
  262. * Timestamp file must have been saved using writeTimestamp().
  263. */
  264. static bool checkForModifications(const Path& folder, const Path& timeStampFile);
  265. };
  266. /** @} */
  267. }