BsBuiltinResources.h 13 KB

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