BsBuiltinResources.cpp 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078
  1. #include "BsBuiltinResources.h"
  2. #include "BsGUIElementStyle.h"
  3. #include "BsGUILabel.h"
  4. #include "BsGUIButton.h"
  5. #include "BsGUIInputBox.h"
  6. #include "BsGUIToggle.h"
  7. #include "BsGUIDropDownContent.h"
  8. #include "BsTextSprite.h"
  9. #include "BsSpriteTexture.h"
  10. #include "BsFont.h"
  11. #include "BsFontImportOptions.h"
  12. #include "BsImporter.h"
  13. #include "BsResources.h"
  14. #include "BsGpuProgram.h"
  15. #include "BsShader.h"
  16. #include "BsShaderInclude.h"
  17. #include "BsTechnique.h"
  18. #include "BsPass.h"
  19. #include "BsMaterial.h"
  20. #include "BsBlendState.h"
  21. #include "BsDepthStencilState.h"
  22. #include "BsRTTIType.h"
  23. #include "BsFileSystem.h"
  24. #include "BsCoreApplication.h"
  25. #include "BsCoreThread.h"
  26. #include "BsApplication.h"
  27. #include "BsDataStream.h"
  28. #include "BsTime.h"
  29. #include "BsResourceManifest.h"
  30. #include "BsVertexDataDesc.h"
  31. #include "BsShapeMeshes3D.h"
  32. #include "BsMesh.h"
  33. namespace BansheeEngine
  34. {
  35. const WString BuiltinResources::DefaultFontFilename = L"arial.ttf";
  36. const UINT32 BuiltinResources::DefaultFontSize = 11;
  37. const Color BuiltinResources::TextNormalColor = Color(0.7f, 0.7f, 0.7f);
  38. const Color BuiltinResources::TextActiveColor = Color(0.0f, 0.0f, 0.0f);
  39. const WString BuiltinResources::GUISkinFile = L"GUISkin";
  40. const Path BuiltinResources::CursorFolder = L"Cursors\\";
  41. const Path BuiltinResources::ShaderFolder = L"Shaders\\";
  42. const Path BuiltinResources::SkinFolder = L"Skin\\";
  43. const Path BuiltinResources::ShaderIncludeFolder = L"Includes\\";
  44. const Path BuiltinResources::MeshFolder = L"Meshes\\";
  45. const Path BuiltinResources::BuiltinRawDataFolder = RUNTIME_DATA_PATH + L"Raw\\Engine\\";
  46. const Path BuiltinResources::EngineRawSkinFolder = BuiltinRawDataFolder + SkinFolder;
  47. const Path BuiltinResources::EngineRawCursorFolder = BuiltinRawDataFolder + CursorFolder;
  48. const Path BuiltinResources::EngineRawShaderFolder = BuiltinRawDataFolder + ShaderFolder;
  49. const Path BuiltinResources::EngineRawShaderIncludeFolder = BuiltinRawDataFolder + ShaderIncludeFolder;
  50. const Path BuiltinResources::BuiltinDataFolder = RUNTIME_DATA_PATH + L"Engine\\";
  51. const Path BuiltinResources::EngineSkinFolder = BuiltinDataFolder + SkinFolder;
  52. const Path BuiltinResources::EngineCursorFolder = BuiltinDataFolder + CursorFolder;
  53. const Path BuiltinResources::EngineShaderFolder = BuiltinDataFolder + ShaderFolder;
  54. const Path BuiltinResources::EngineShaderIncludeFolder = BuiltinDataFolder + ShaderIncludeFolder;
  55. const Path BuiltinResources::EngineMeshFolder = BuiltinDataFolder + MeshFolder;
  56. const Path BuiltinResources::ResourceManifestPath = BuiltinDataFolder + "ResourceManifest.asset";
  57. /************************************************************************/
  58. /* GUI TEXTURES */
  59. /************************************************************************/
  60. const WString BuiltinResources::WhiteTex = L"White.psd";
  61. const WString BuiltinResources::ButtonNormalTex = L"ButtonNormal.png";
  62. const WString BuiltinResources::ButtonHoverTex = L"ButtonHover.png";
  63. const WString BuiltinResources::ButtonActiveTex = L"ButtonActive.png";
  64. const WString BuiltinResources::ToggleNormalTex = L"ToggleNormal.png";
  65. const WString BuiltinResources::ToggleHoverTex = L"ToggleHover.png";
  66. const WString BuiltinResources::ToggleNormalOnTex = L"ToggleNormalOn.png";
  67. const WString BuiltinResources::ToggleHoverOnTex = L"ToggleHoverOn.png";
  68. const WString BuiltinResources::InputBoxNormalTex = L"InputBoxNormal.png";
  69. const WString BuiltinResources::InputBoxHoverTex = L"InputBoxHover.png";
  70. const WString BuiltinResources::InputBoxFocusedTex = L"InputBoxActive.png";
  71. const WString BuiltinResources::ScrollBarUpNormalTex = L"ScrollArrowUpNormal.png";
  72. const WString BuiltinResources::ScrollBarUpHoverTex = L"ScrollArrowUpHover.png";
  73. const WString BuiltinResources::ScrollBarUpActiveTex = L"ScrollArrowUpActive.png";
  74. const WString BuiltinResources::ScrollBarDownNormalTex = L"ScrollArrowDownNormal.png";
  75. const WString BuiltinResources::ScrollBarDownHoverTex = L"ScrollArrowDownHover.png";
  76. const WString BuiltinResources::ScrollBarDownActiveTex = L"ScrollArrowDownActive.png";
  77. const WString BuiltinResources::ScrollBarLeftNormalTex = L"ScrollArrowLeftNormal.png";
  78. const WString BuiltinResources::ScrollBarLeftHoverTex = L"ScrollArrowLeftHover.png";
  79. const WString BuiltinResources::ScrollBarLeftActiveTex = L"ScrollArrowLeftActive.png";
  80. const WString BuiltinResources::ScrollBarRightNormalTex = L"ScrollArrowRightNormal.png";
  81. const WString BuiltinResources::ScrollBarRightHoverTex = L"ScrollArrowRightHover.png";
  82. const WString BuiltinResources::ScrollBarRightActiveTex = L"ScrollArrowRightActive.png";
  83. const WString BuiltinResources::ScrollBarHandleHorzNormalTex = L"ScrollBarHHandleNormal.png";
  84. const WString BuiltinResources::ScrollBarHandleHorzHoverTex = L"ScrollBarHHandleHover.png";
  85. const WString BuiltinResources::ScrollBarHandleHorzActiveTex = L"ScrollBarHHandleActive.png";
  86. const WString BuiltinResources::ScrollBarHandleVertNormalTex = L"ScrollBarVHandleNormal.png";
  87. const WString BuiltinResources::ScrollBarHandleVertHoverTex = L"ScrollBarVHandleHover.png";
  88. const WString BuiltinResources::ScrollBarHandleVertActiveTex = L"ScrollBarVHandleActive.png";
  89. const WString BuiltinResources::ScrollBarHBgTex = L"ScrollBarHBackground.png";
  90. const WString BuiltinResources::ScrollBarVBgTex = L"ScrollBarVBackground.png";
  91. const WString BuiltinResources::DropDownBtnNormalTex = L"DropDownButtonNormal.png";
  92. const WString BuiltinResources::DropDownBtnHoverTex = L"DropDownButtonHover.png";
  93. const WString BuiltinResources::DropDownBtnActiveTex = L"DropDownButtonActive.png";
  94. const WString BuiltinResources::DropDownBoxBgTex = L"DropDownBoxBg.png";
  95. const WString BuiltinResources::DropDownBoxSideBgTex = L"DropDownBoxSideBg.png";
  96. const WString BuiltinResources::DropDownBoxHandleTex = L"DropDownBoxScrollHandle.png";
  97. const WString BuiltinResources::DropDownBoxEntryNormalTex = L"DropDownBoxEntryNormal.png";
  98. const WString BuiltinResources::DropDownBoxEntryHoverTex = L"DropDownBoxEntryHover.png";
  99. const WString BuiltinResources::DropDownBoxBtnUpNormalTex = L"DropDownBoxArrowUpNormal.png";
  100. const WString BuiltinResources::DropDownBoxBtnUpHoverTex = L"DropDownBoxArrowUpHover.png";
  101. const WString BuiltinResources::DropDownBoxBtnDownNormalTex = L"DropDownBoxArrowDownNormal.png";
  102. const WString BuiltinResources::DropDownBoxBtnDownHoverTex = L"DropDownBoxArrowDownHover.png";
  103. const WString BuiltinResources::DropDownBoxEntryExpNormalTex = L"DropDownBoxExpandBtnNormal.png";
  104. const WString BuiltinResources::DropDownBoxEntryExpHoverTex = L"DropDownBoxExpandBtnHover.png";
  105. const WString BuiltinResources::DropDownSeparatorTex = L"DropDownBoxSeparator.png";
  106. /************************************************************************/
  107. /* CURSOR TEXTURES */
  108. /************************************************************************/
  109. const WString BuiltinResources::CursorArrowTex = L"Arrow.psd";
  110. const WString BuiltinResources::CursorArrowDragTex = L"ArrowDrag.psd";
  111. const WString BuiltinResources::CursorArrowLeftRightTex = L"ArrowLeftRight.psd";
  112. const WString BuiltinResources::CursorIBeamTex = L"IBeam.psd";
  113. const WString BuiltinResources::CursorDenyTex = L"Deny.psd";
  114. const WString BuiltinResources::CursorWaitTex = L"Wait.psd";
  115. const WString BuiltinResources::CursorSizeNESWTex = L"SizeNESW.psd";
  116. const WString BuiltinResources::CursorSizeNSTex = L"SizeNS.psd";
  117. const WString BuiltinResources::CursorSizeNWSETex = L"SizeNWSE.psd";
  118. const WString BuiltinResources::CursorSizeWETex = L"SizeWE.psd";
  119. const Vector2I BuiltinResources::CursorArrowHotspot = Vector2I(11, 8);
  120. const Vector2I BuiltinResources::CursorArrowDragHotspot = Vector2I(11, 8);
  121. const Vector2I BuiltinResources::CursorArrowLeftRightHotspot = Vector2I(9, 4);
  122. const Vector2I BuiltinResources::CursorIBeamHotspot = Vector2I(15, 15);
  123. const Vector2I BuiltinResources::CursorDenyHotspot = Vector2I(15, 15);
  124. const Vector2I BuiltinResources::CursorWaitHotspot = Vector2I(15, 15);
  125. const Vector2I BuiltinResources::CursorSizeNESWHotspot = Vector2I(15, 15);
  126. const Vector2I BuiltinResources::CursorSizeNSHotspot = Vector2I(15, 15);
  127. const Vector2I BuiltinResources::CursorSizeNWSEHotspot = Vector2I(15, 15);
  128. const Vector2I BuiltinResources::CursorSizeWEHotspot = Vector2I(15, 15);
  129. /************************************************************************/
  130. /* SHADERS */
  131. /************************************************************************/
  132. const WString BuiltinResources::ShaderSpriteTextFile = L"SpriteText.bsl";
  133. const WString BuiltinResources::ShaderSpriteImageAlphaFile = L"SpriteImageAlpha.bsl";
  134. const WString BuiltinResources::ShaderSpriteImageNoAlphaFile = L"SpriteImageNoAlpha.bsl";
  135. const WString BuiltinResources::ShaderDiffuseFile = L"Diffuse.bsl";
  136. const WString BuiltinResources::ShaderDummyFile = L"Dummy.bsl";
  137. /************************************************************************/
  138. /* MESHES */
  139. /************************************************************************/
  140. const WString BuiltinResources::MeshSphereFile = L"Sphere.asset";
  141. const WString BuiltinResources::MeshBoxFile = L"Box.asset";
  142. const WString BuiltinResources::MeshConeFile = L"Cone.asset";
  143. const WString BuiltinResources::MeshQuadFile = L"Quad.asset";
  144. const WString BuiltinResources::MeshDiscFile = L"Disc.asset";
  145. BuiltinResources::~BuiltinResources()
  146. {
  147. mCursorArrow = nullptr;
  148. mCursorArrowDrag = nullptr;
  149. mCursorArrowLeftRight = nullptr;
  150. mCursorIBeam = nullptr;
  151. mCursorDeny = nullptr;
  152. mCursorWait = nullptr;
  153. mCursorSizeNESW = nullptr;
  154. mCursorSizeNS = nullptr;
  155. mCursorSizeNWSE = nullptr;
  156. mCursorSizeWE = nullptr;
  157. }
  158. BuiltinResources::BuiltinResources()
  159. {
  160. Path absoluteDataPath = FileSystem::getWorkingDirectoryPath();
  161. absoluteDataPath.append(BuiltinDataFolder);
  162. if (FileSystem::exists(ResourceManifestPath))
  163. mResourceManifest = ResourceManifest::load(ResourceManifestPath, absoluteDataPath);
  164. if (mResourceManifest == nullptr)
  165. mResourceManifest = ResourceManifest::create("BuiltinResources");
  166. gResources().registerResourceManifest(mResourceManifest);
  167. #if BS_DEBUG_MODE
  168. if (BuiltinResourcesHelper::checkForModifications(BuiltinRawDataFolder, BuiltinDataFolder + L"Timestamp.asset"))
  169. {
  170. preprocess();
  171. BuiltinResourcesHelper::writeTimestamp(BuiltinDataFolder + L"Timestamp.asset");
  172. Path absoluteDataPath = FileSystem::getWorkingDirectoryPath();
  173. absoluteDataPath.append(BuiltinDataFolder);
  174. ResourceManifest::save(mResourceManifest, ResourceManifestPath, absoluteDataPath);
  175. }
  176. #endif
  177. mShaderSpriteText = getShader(ShaderSpriteTextFile);
  178. mShaderSpriteImage = getShader(ShaderSpriteImageAlphaFile);
  179. mShaderSpriteNonAlphaImage = getShader(ShaderSpriteImageNoAlphaFile);
  180. mShaderDiffuse = getShader(ShaderDiffuseFile);
  181. mShaderDummy = getShader(ShaderDummyFile);
  182. mWhiteSpriteTexture = getSkinTexture(WhiteTex);
  183. mSkin = gResources().load<GUISkin>(BuiltinDataFolder + (GUISkinFile + L".asset"));
  184. /************************************************************************/
  185. /* CURSOR */
  186. /************************************************************************/
  187. HTexture cursorArrowTex = getCursorTexture(CursorArrowTex);
  188. HTexture cursorArrowDragTex = getCursorTexture(CursorArrowDragTex);
  189. HTexture cursorArrowLeftRightTex = getCursorTexture(CursorArrowLeftRightTex);
  190. HTexture cursorIBeamTex = getCursorTexture(CursorIBeamTex);
  191. HTexture cursorDenyTex = getCursorTexture(CursorDenyTex);
  192. HTexture cursorWaitTex = getCursorTexture(CursorWaitTex);
  193. HTexture cursorSizeNESWTex = getCursorTexture(CursorSizeNESWTex);
  194. HTexture cursorSizeNSTex = getCursorTexture(CursorSizeNSTex);
  195. HTexture cursorSizeNWSETex = getCursorTexture(CursorSizeNWSETex);
  196. HTexture cursorSizeWETex = getCursorTexture(CursorSizeWETex);
  197. mCursorArrow = cursorArrowTex->getProperties().allocateSubresourceBuffer(0);
  198. cursorArrowTex->readSubresource(gCoreAccessor(), 0, mCursorArrow);
  199. mCursorArrowDrag = cursorArrowDragTex->getProperties().allocateSubresourceBuffer(0);
  200. cursorArrowDragTex->readSubresource(gCoreAccessor(), 0, mCursorArrowDrag);
  201. mCursorArrowLeftRight = cursorArrowLeftRightTex->getProperties().allocateSubresourceBuffer(0);
  202. cursorArrowLeftRightTex->readSubresource(gCoreAccessor(), 0, mCursorArrowLeftRight);
  203. mCursorIBeam = cursorIBeamTex->getProperties().allocateSubresourceBuffer(0);
  204. cursorIBeamTex->readSubresource(gCoreAccessor(), 0, mCursorIBeam);
  205. mCursorDeny = cursorDenyTex->getProperties().allocateSubresourceBuffer(0);
  206. cursorDenyTex->readSubresource(gCoreAccessor(), 0, mCursorDeny);
  207. mCursorWait = cursorWaitTex->getProperties().allocateSubresourceBuffer(0);
  208. cursorWaitTex->readSubresource(gCoreAccessor(), 0, mCursorWait);
  209. mCursorSizeNESW = cursorSizeNESWTex->getProperties().allocateSubresourceBuffer(0);
  210. cursorSizeNESWTex->readSubresource(gCoreAccessor(), 0, mCursorSizeNESW);
  211. mCursorSizeNS = cursorSizeNSTex->getProperties().allocateSubresourceBuffer(0);
  212. cursorSizeNSTex->readSubresource(gCoreAccessor(), 0, mCursorSizeNS);
  213. mCursorSizeNWSE = cursorSizeNWSETex->getProperties().allocateSubresourceBuffer(0);
  214. cursorSizeNWSETex->readSubresource(gCoreAccessor(), 0, mCursorSizeNWSE);
  215. mCursorSizeWE = cursorSizeWETex->getProperties().allocateSubresourceBuffer(0);
  216. cursorSizeWETex->readSubresource(gCoreAccessor(), 0, mCursorSizeWE);
  217. gCoreAccessor().submitToCoreThread(true);
  218. }
  219. void BuiltinResources::preprocess()
  220. {
  221. FileSystem::remove(EngineCursorFolder);
  222. FileSystem::remove(EngineShaderIncludeFolder);
  223. FileSystem::remove(EngineShaderFolder);
  224. FileSystem::remove(EngineSkinFolder);
  225. FileSystem::remove(EngineMeshFolder);
  226. BuiltinResourcesHelper::importAssets(EngineRawCursorFolder, EngineCursorFolder, mResourceManifest);
  227. BuiltinResourcesHelper::importAssets(EngineRawShaderIncludeFolder, EngineShaderIncludeFolder, mResourceManifest); // Hidden dependency: Includes must be imported before shaders
  228. BuiltinResourcesHelper::importAssets(EngineRawShaderFolder, EngineShaderFolder, mResourceManifest);
  229. BuiltinResourcesHelper::importAssets(EngineRawSkinFolder, EngineSkinFolder, mResourceManifest);
  230. // Import font
  231. BuiltinResourcesHelper::importFont(BuiltinRawDataFolder + DefaultFontFilename, BuiltinDataFolder, DefaultFontSize, false, mResourceManifest);
  232. // Generate & save GUI sprite textures
  233. BuiltinResourcesHelper::generateSpriteTextures(EngineSkinFolder, mResourceManifest);
  234. // Generate & save GUI skin
  235. {
  236. HGUISkin skin = generateGUISkin();
  237. Path outputPath = FileSystem::getWorkingDirectoryPath() + BuiltinDataFolder + (GUISkinFile + L".asset");
  238. Resources::instance().save(skin, outputPath, true);
  239. mResourceManifest->registerResource(skin.getUUID(), outputPath);
  240. }
  241. // Generate & save meshes
  242. generateMeshes();
  243. Resources::instance().unloadAllUnused();
  244. }
  245. HGUISkin BuiltinResources::generateGUISkin()
  246. {
  247. Path fontPath = FileSystem::getWorkingDirectoryPath();
  248. fontPath.append(BuiltinDataFolder);
  249. fontPath.append(DefaultFontFilename + L".asset");
  250. HFont font = Resources::instance().load<Font>(fontPath);
  251. HGUISkin skin = GUISkin::create();
  252. // Label
  253. GUIElementStyle labelStyle;
  254. labelStyle.font = font;
  255. labelStyle.fontSize = DefaultFontSize;
  256. labelStyle.normal.textColor = TextNormalColor;
  257. labelStyle.fixedWidth = false;
  258. labelStyle.fixedHeight = true;
  259. labelStyle.height = 14;
  260. labelStyle.minWidth = 10;
  261. skin->setStyle(GUILabel::getGUITypeName(), labelStyle);
  262. // Button
  263. GUIElementStyle buttonStyle;
  264. buttonStyle.normal.texture = getSkinTexture(ButtonNormalTex);
  265. buttonStyle.hover.texture = getSkinTexture(ButtonHoverTex);
  266. buttonStyle.active.texture = getSkinTexture(ButtonActiveTex);
  267. buttonStyle.normalOn.texture = getSkinTexture(ButtonActiveTex);
  268. buttonStyle.hoverOn.texture = getSkinTexture(ButtonActiveTex);
  269. buttonStyle.activeOn.texture = getSkinTexture(ButtonActiveTex);
  270. buttonStyle.normal.textColor = TextNormalColor;
  271. buttonStyle.hover.textColor = TextNormalColor;
  272. buttonStyle.active.textColor = TextActiveColor;
  273. buttonStyle.normalOn.textColor = TextActiveColor;
  274. buttonStyle.hoverOn.textColor = TextActiveColor;
  275. buttonStyle.activeOn.textColor = TextActiveColor;
  276. buttonStyle.border.left = 2;
  277. buttonStyle.border.right = 2;
  278. buttonStyle.border.top = 2;
  279. buttonStyle.border.bottom = 4;
  280. buttonStyle.contentOffset.top = 2;
  281. buttonStyle.contentOffset.left = 3;
  282. buttonStyle.contentOffset.right = 3;
  283. buttonStyle.margins.bottom = 2;
  284. buttonStyle.fixedHeight = true;
  285. buttonStyle.height = 21;
  286. buttonStyle.minWidth = 20;
  287. buttonStyle.font = font;
  288. buttonStyle.fontSize = DefaultFontSize;
  289. buttonStyle.textHorzAlign = THA_Center;
  290. buttonStyle.textVertAlign = TVA_Center;
  291. skin->setStyle(GUIButton::getGUITypeName(), buttonStyle);
  292. // Toggle
  293. GUIElementStyle toggleStyle;
  294. toggleStyle.normal.texture = getSkinTexture(ToggleNormalTex);
  295. toggleStyle.hover.texture = getSkinTexture(ToggleHoverTex);
  296. toggleStyle.active.texture = toggleStyle.hover.texture;
  297. toggleStyle.normalOn.texture = getSkinTexture(ToggleNormalOnTex);
  298. toggleStyle.hoverOn.texture = getSkinTexture(ToggleHoverOnTex);
  299. toggleStyle.activeOn.texture = toggleStyle.hoverOn.texture;
  300. toggleStyle.fixedHeight = true;
  301. toggleStyle.fixedWidth = true;
  302. toggleStyle.margins.bottom = 2;
  303. toggleStyle.height = 15;
  304. toggleStyle.width = 13;
  305. skin->setStyle(GUIToggle::getGUITypeName(), toggleStyle);
  306. // Input box
  307. GUIElementStyle inputBoxStyle;
  308. inputBoxStyle.normal.texture = getSkinTexture(InputBoxNormalTex);
  309. inputBoxStyle.hover.texture = getSkinTexture(InputBoxHoverTex);
  310. inputBoxStyle.focused.texture = getSkinTexture(InputBoxFocusedTex);
  311. inputBoxStyle.active.texture = inputBoxStyle.normal.texture;
  312. inputBoxStyle.normal.textColor = TextNormalColor;
  313. inputBoxStyle.hover.textColor = TextNormalColor;
  314. inputBoxStyle.focused.textColor = TextNormalColor;
  315. inputBoxStyle.active.textColor = TextNormalColor;
  316. inputBoxStyle.border.left = 4;
  317. inputBoxStyle.border.right = 4;
  318. inputBoxStyle.border.top = 4;
  319. inputBoxStyle.border.bottom = 6;
  320. inputBoxStyle.contentOffset.left = 4;
  321. inputBoxStyle.contentOffset.right = 4;
  322. inputBoxStyle.contentOffset.top = 4;
  323. inputBoxStyle.contentOffset.bottom = 4;
  324. inputBoxStyle.margins.bottom = 2;
  325. inputBoxStyle.fixedHeight = true;
  326. inputBoxStyle.height = 21;
  327. inputBoxStyle.minWidth = 10;
  328. inputBoxStyle.font = font;
  329. inputBoxStyle.fontSize = DefaultFontSize;
  330. inputBoxStyle.textHorzAlign = THA_Left;
  331. inputBoxStyle.textVertAlign = TVA_Top;
  332. skin->setStyle(GUIInputBox::getGUITypeName(), inputBoxStyle);
  333. /************************************************************************/
  334. /* SCROLL BAR */
  335. /************************************************************************/
  336. // Up button
  337. GUIElementStyle scrollUpBtnStyle;
  338. scrollUpBtnStyle.normal.texture = getSkinTexture(ScrollBarUpNormalTex);
  339. scrollUpBtnStyle.hover.texture = getSkinTexture(ScrollBarUpHoverTex);
  340. scrollUpBtnStyle.active.texture = getSkinTexture(ScrollBarUpActiveTex);
  341. scrollUpBtnStyle.fixedHeight = true;
  342. scrollUpBtnStyle.fixedWidth = true;
  343. scrollUpBtnStyle.height = 11;
  344. scrollUpBtnStyle.width = 13;
  345. skin->setStyle("ScrollUpBtn", scrollUpBtnStyle);
  346. // Down button
  347. GUIElementStyle scrollDownBtnStyle;
  348. scrollDownBtnStyle.normal.texture = getSkinTexture(ScrollBarDownNormalTex);
  349. scrollDownBtnStyle.hover.texture = getSkinTexture(ScrollBarDownHoverTex);
  350. scrollDownBtnStyle.active.texture = getSkinTexture(ScrollBarDownActiveTex);
  351. scrollDownBtnStyle.fixedHeight = true;
  352. scrollDownBtnStyle.fixedWidth = true;
  353. scrollDownBtnStyle.height = 11;
  354. scrollDownBtnStyle.width = 13;
  355. skin->setStyle("ScrollDownBtn", scrollDownBtnStyle);
  356. // Left button
  357. GUIElementStyle scrollLeftBtnStyle;
  358. scrollLeftBtnStyle.normal.texture = getSkinTexture(ScrollBarLeftNormalTex);
  359. scrollLeftBtnStyle.hover.texture = getSkinTexture(ScrollBarLeftHoverTex);
  360. scrollLeftBtnStyle.active.texture = getSkinTexture(ScrollBarLeftActiveTex);
  361. scrollLeftBtnStyle.fixedHeight = true;
  362. scrollLeftBtnStyle.fixedWidth = true;
  363. scrollLeftBtnStyle.height = 13;
  364. scrollLeftBtnStyle.width = 11;
  365. skin->setStyle("ScrollLeftBtn", scrollLeftBtnStyle);
  366. // Right button
  367. GUIElementStyle scrollRightBtnStyle;
  368. scrollRightBtnStyle.normal.texture = getSkinTexture(ScrollBarRightNormalTex);
  369. scrollRightBtnStyle.hover.texture = getSkinTexture(ScrollBarRightHoverTex);
  370. scrollRightBtnStyle.active.texture = getSkinTexture(ScrollBarRightActiveTex);
  371. scrollRightBtnStyle.fixedHeight = true;
  372. scrollRightBtnStyle.fixedWidth = true;
  373. scrollRightBtnStyle.height = 13;
  374. scrollRightBtnStyle.width = 11;
  375. skin->setStyle("ScrollRightBtn", scrollRightBtnStyle);
  376. // Horizontal handle
  377. GUIElementStyle scrollBarHorzBtnStyle;
  378. scrollBarHorzBtnStyle.normal.texture = getSkinTexture(ScrollBarHandleHorzNormalTex);
  379. scrollBarHorzBtnStyle.hover.texture = getSkinTexture(ScrollBarHandleHorzHoverTex);
  380. scrollBarHorzBtnStyle.active.texture = getSkinTexture(ScrollBarHandleHorzActiveTex);
  381. scrollBarHorzBtnStyle.fixedHeight = true;
  382. scrollBarHorzBtnStyle.fixedWidth = false;
  383. scrollBarHorzBtnStyle.width = 10;
  384. scrollBarHorzBtnStyle.height = 13;
  385. scrollBarHorzBtnStyle.border.left = 4;
  386. scrollBarHorzBtnStyle.border.right = 4;
  387. skin->setStyle("ScrollBarHorzBtn", scrollBarHorzBtnStyle);
  388. // Vertical handle
  389. GUIElementStyle scrollBarVertBtnStyle;
  390. scrollBarVertBtnStyle.normal.texture = getSkinTexture(ScrollBarHandleVertNormalTex);
  391. scrollBarVertBtnStyle.hover.texture = getSkinTexture(ScrollBarHandleVertHoverTex);
  392. scrollBarVertBtnStyle.active.texture = getSkinTexture(ScrollBarHandleVertActiveTex);
  393. scrollBarVertBtnStyle.fixedHeight = false;
  394. scrollBarVertBtnStyle.fixedWidth = true;
  395. scrollBarVertBtnStyle.width = 13;
  396. scrollBarVertBtnStyle.height = 10;
  397. scrollBarVertBtnStyle.border.top = 4;
  398. scrollBarVertBtnStyle.border.bottom = 4;
  399. skin->setStyle("ScrollBarVertBtn", scrollBarVertBtnStyle);
  400. // Vertical scroll bar
  401. GUIElementStyle vertScrollBarStyle;
  402. vertScrollBarStyle.normal.texture = getSkinTexture(ScrollBarVBgTex);
  403. vertScrollBarStyle.hover.texture = vertScrollBarStyle.normal.texture;
  404. vertScrollBarStyle.active.texture = vertScrollBarStyle.normal.texture;
  405. vertScrollBarStyle.fixedHeight = false;
  406. vertScrollBarStyle.fixedWidth = true;
  407. vertScrollBarStyle.minHeight = 8;
  408. vertScrollBarStyle.width = 16;
  409. skin->setStyle("ScrollBarVert", vertScrollBarStyle);
  410. // Horizontal scroll bar
  411. GUIElementStyle horzScrollBarStyle;
  412. horzScrollBarStyle.normal.texture = getSkinTexture(ScrollBarHBgTex);
  413. horzScrollBarStyle.hover.texture = horzScrollBarStyle.normal.texture;
  414. horzScrollBarStyle.active.texture = horzScrollBarStyle.normal.texture;
  415. horzScrollBarStyle.fixedHeight = true;
  416. horzScrollBarStyle.fixedWidth = false;
  417. horzScrollBarStyle.minWidth = 8;
  418. horzScrollBarStyle.height = 16;
  419. skin->setStyle("ScrollBarHorz", horzScrollBarStyle);
  420. /************************************************************************/
  421. /* DROP DOWN BOX */
  422. /************************************************************************/
  423. // ListBox button
  424. GUIElementStyle dropDownListStyle;
  425. dropDownListStyle.normal.texture = getSkinTexture(DropDownBtnNormalTex);
  426. dropDownListStyle.hover.texture = getSkinTexture(DropDownBtnHoverTex);
  427. dropDownListStyle.active.texture = getSkinTexture(DropDownBtnActiveTex);
  428. dropDownListStyle.normalOn.texture = dropDownListStyle.active.texture;
  429. dropDownListStyle.hoverOn.texture = dropDownListStyle.active.texture;
  430. dropDownListStyle.activeOn.texture = dropDownListStyle.active.texture;
  431. dropDownListStyle.normal.textColor = TextNormalColor;
  432. dropDownListStyle.hover.textColor = TextNormalColor;
  433. dropDownListStyle.active.textColor = TextNormalColor;
  434. dropDownListStyle.normalOn.textColor = TextNormalColor;
  435. dropDownListStyle.hoverOn.textColor = TextNormalColor;
  436. dropDownListStyle.activeOn.textColor = TextNormalColor;
  437. dropDownListStyle.fixedHeight = true;
  438. dropDownListStyle.fixedWidth = false;
  439. dropDownListStyle.height = 21;
  440. dropDownListStyle.minWidth = 20;
  441. dropDownListStyle.contentOffset.left = 3;
  442. dropDownListStyle.contentOffset.right = 18;
  443. dropDownListStyle.contentOffset.top = 2;
  444. dropDownListStyle.contentOffset.bottom = 2;
  445. dropDownListStyle.border.left = 2;
  446. dropDownListStyle.border.right = 16;
  447. dropDownListStyle.border.top = 2;
  448. dropDownListStyle.border.bottom = 4;
  449. dropDownListStyle.margins.bottom = 2;
  450. dropDownListStyle.font = font;
  451. dropDownListStyle.fontSize = DefaultFontSize;
  452. dropDownListStyle.textHorzAlign = THA_Left;
  453. dropDownListStyle.textVertAlign = TVA_Center;
  454. skin->setStyle("ListBox", dropDownListStyle);
  455. // DropDown scroll up button
  456. GUIElementStyle dropDownScrollUpBtnStyle;
  457. dropDownScrollUpBtnStyle.normal.texture = getSkinTexture(DropDownBoxBtnUpNormalTex);
  458. dropDownScrollUpBtnStyle.hover.texture = getSkinTexture(DropDownBoxBtnUpHoverTex);
  459. dropDownScrollUpBtnStyle.active.texture = dropDownScrollUpBtnStyle.hover.texture;
  460. dropDownScrollUpBtnStyle.fixedHeight = true;
  461. dropDownScrollUpBtnStyle.fixedWidth = true;
  462. dropDownScrollUpBtnStyle.width = 8;
  463. dropDownScrollUpBtnStyle.height = 12;
  464. skin->setStyle("ListBoxScrollUpBtn", dropDownScrollUpBtnStyle);
  465. skin->setStyle("MenuBarScrollUpBtn", dropDownScrollUpBtnStyle);
  466. skin->setStyle("ContextMenuScrollUpBtn", dropDownScrollUpBtnStyle);
  467. // DropDown scroll down button
  468. GUIElementStyle dropDownScrollDownBtnStyle;
  469. dropDownScrollDownBtnStyle.normal.texture = getSkinTexture(DropDownBoxBtnDownNormalTex);
  470. dropDownScrollDownBtnStyle.hover.texture = getSkinTexture(DropDownBoxBtnDownHoverTex);
  471. dropDownScrollDownBtnStyle.active.texture = dropDownScrollDownBtnStyle.hover.texture;
  472. dropDownScrollDownBtnStyle.fixedHeight = true;
  473. dropDownScrollDownBtnStyle.fixedWidth = true;
  474. dropDownScrollDownBtnStyle.width = 8;
  475. dropDownScrollDownBtnStyle.height = 12;
  476. skin->setStyle("ListBoxScrollDownBtn", dropDownScrollDownBtnStyle);
  477. skin->setStyle("MenuBarScrollDownBtn", dropDownScrollDownBtnStyle);
  478. skin->setStyle("ContextMenuScrollDownBtn", dropDownScrollDownBtnStyle);
  479. // DropDown handle
  480. GUIElementStyle dropDownScrollHandleStyle;
  481. dropDownScrollHandleStyle.normal.texture = getSkinTexture(DropDownBoxHandleTex);
  482. dropDownScrollHandleStyle.fixedHeight = false;
  483. dropDownScrollHandleStyle.fixedWidth = true;
  484. dropDownScrollHandleStyle.height = 8;
  485. dropDownScrollHandleStyle.width = 8;
  486. skin->setStyle("ListBoxHandle", dropDownScrollHandleStyle);
  487. skin->setStyle("MenuBarHandle", dropDownScrollHandleStyle);
  488. skin->setStyle("ContextMenuHandle", dropDownScrollHandleStyle);
  489. // DropDown sidebar background
  490. GUIElementStyle dropDownSidebarBg;
  491. dropDownSidebarBg.normal.texture = getSkinTexture(DropDownBoxSideBgTex);
  492. dropDownSidebarBg.fixedHeight = false;
  493. dropDownSidebarBg.fixedWidth = true;
  494. dropDownSidebarBg.height = 8;
  495. dropDownSidebarBg.width = 9;
  496. dropDownSidebarBg.border.left = 1;
  497. dropDownSidebarBg.border.top = 1;
  498. dropDownSidebarBg.border.bottom = 1;
  499. skin->setStyle("ListBoxSidebarBg", dropDownSidebarBg);
  500. skin->setStyle("MenuBarSidebarBg", dropDownSidebarBg);
  501. skin->setStyle("ContextMenuSidebarBg", dropDownSidebarBg);
  502. // DropDown entry button
  503. GUIElementStyle dropDownEntryBtnStyle;
  504. dropDownEntryBtnStyle.normal.texture = getSkinTexture(DropDownBoxEntryNormalTex);
  505. dropDownEntryBtnStyle.hover.texture = getSkinTexture(DropDownBoxEntryHoverTex);
  506. dropDownEntryBtnStyle.active.texture = dropDownEntryBtnStyle.hover.texture;
  507. dropDownEntryBtnStyle.normalOn.texture = dropDownEntryBtnStyle.hover.texture;
  508. dropDownEntryBtnStyle.hoverOn.texture = dropDownEntryBtnStyle.hover.texture;
  509. dropDownEntryBtnStyle.activeOn.texture = dropDownEntryBtnStyle.hover.texture;
  510. dropDownEntryBtnStyle.normal.textColor = TextNormalColor;
  511. dropDownEntryBtnStyle.hover.textColor = TextNormalColor;
  512. dropDownEntryBtnStyle.active.textColor = TextNormalColor;
  513. dropDownEntryBtnStyle.normalOn.textColor = TextNormalColor;
  514. dropDownEntryBtnStyle.hoverOn.textColor = TextNormalColor;
  515. dropDownEntryBtnStyle.activeOn.textColor = TextNormalColor;
  516. dropDownEntryBtnStyle.fixedHeight = true;
  517. dropDownEntryBtnStyle.fixedWidth = false;
  518. dropDownEntryBtnStyle.height = 16;
  519. dropDownEntryBtnStyle.width = 30;
  520. dropDownEntryBtnStyle.font = font;
  521. dropDownEntryBtnStyle.fontSize = DefaultFontSize;
  522. dropDownEntryBtnStyle.textHorzAlign = THA_Left;
  523. dropDownEntryBtnStyle.textVertAlign = TVA_Center;
  524. skin->setStyle(GUIDropDownContent::ENTRY_STYLE_TYPE, dropDownEntryBtnStyle);
  525. // DropDown entry button with expand
  526. GUIElementStyle dropDownEntryExpBtnStyle;
  527. dropDownEntryExpBtnStyle.normal.texture = getSkinTexture(DropDownBoxEntryExpNormalTex);
  528. dropDownEntryExpBtnStyle.hover.texture = getSkinTexture(DropDownBoxEntryExpHoverTex);
  529. dropDownEntryExpBtnStyle.active.texture = dropDownEntryExpBtnStyle.hover.texture;
  530. dropDownEntryExpBtnStyle.normalOn.texture = dropDownEntryExpBtnStyle.hover.texture;
  531. dropDownEntryExpBtnStyle.hoverOn.texture = dropDownEntryExpBtnStyle.hover.texture;
  532. dropDownEntryExpBtnStyle.activeOn.texture = dropDownEntryExpBtnStyle.hover.texture;
  533. dropDownEntryExpBtnStyle.normal.textColor = TextNormalColor;
  534. dropDownEntryExpBtnStyle.hover.textColor = TextNormalColor;
  535. dropDownEntryExpBtnStyle.active.textColor = TextNormalColor;
  536. dropDownEntryExpBtnStyle.normalOn.textColor = TextNormalColor;
  537. dropDownEntryExpBtnStyle.hoverOn.textColor = TextNormalColor;
  538. dropDownEntryExpBtnStyle.activeOn.textColor = TextNormalColor;
  539. dropDownEntryExpBtnStyle.fixedHeight = true;
  540. dropDownEntryExpBtnStyle.fixedWidth = false;
  541. dropDownEntryExpBtnStyle.height = 16;
  542. dropDownEntryExpBtnStyle.width = 30;
  543. dropDownEntryExpBtnStyle.border.right = 13;
  544. dropDownEntryExpBtnStyle.font = font;
  545. dropDownEntryExpBtnStyle.fontSize = DefaultFontSize;
  546. dropDownEntryExpBtnStyle.textHorzAlign = THA_Left;
  547. dropDownEntryExpBtnStyle.textVertAlign = TVA_Center;
  548. skin->setStyle(GUIDropDownContent::ENTRY_EXP_STYLE_TYPE, dropDownEntryExpBtnStyle);
  549. // Drop down separator
  550. GUIElementStyle dropDownSeparatorStyle;
  551. dropDownSeparatorStyle.normal.texture = getSkinTexture(DropDownSeparatorTex);
  552. dropDownSeparatorStyle.fixedHeight = true;
  553. dropDownSeparatorStyle.fixedWidth = false;
  554. dropDownSeparatorStyle.height = 3;
  555. dropDownSeparatorStyle.width = 30;
  556. skin->setStyle(GUIDropDownContent::SEPARATOR_STYLE_TYPE, dropDownSeparatorStyle);
  557. // Drop down content
  558. GUIElementStyle dropDownContentStyle;
  559. dropDownContentStyle.minWidth = 50;
  560. dropDownContentStyle.minHeight = 20;
  561. dropDownContentStyle.subStyles[GUIDropDownContent::ENTRY_STYLE_TYPE] = GUIDropDownContent::ENTRY_STYLE_TYPE;
  562. dropDownContentStyle.subStyles[GUIDropDownContent::ENTRY_EXP_STYLE_TYPE] = GUIDropDownContent::ENTRY_EXP_STYLE_TYPE;
  563. dropDownContentStyle.subStyles[GUIDropDownContent::SEPARATOR_STYLE_TYPE] = GUIDropDownContent::SEPARATOR_STYLE_TYPE;
  564. skin->setStyle("ListBoxContent", dropDownContentStyle);
  565. skin->setStyle("MenuBarContent", dropDownContentStyle);
  566. skin->setStyle("ContextMenuContent", dropDownContentStyle);
  567. // DropDown box frame
  568. GUIElementStyle dropDownBoxStyle;
  569. dropDownBoxStyle.normal.texture = getSkinTexture(DropDownBoxBgTex);
  570. dropDownBoxStyle.hover.texture = dropDownBoxStyle.normal.texture;
  571. dropDownBoxStyle.active.texture = dropDownBoxStyle.hover.texture;
  572. dropDownBoxStyle.fixedHeight = false;
  573. dropDownBoxStyle.fixedWidth = false;
  574. dropDownBoxStyle.border.left = 2;
  575. dropDownBoxStyle.border.right = 2;
  576. dropDownBoxStyle.border.top = 2;
  577. dropDownBoxStyle.border.bottom = 4;
  578. dropDownBoxStyle.margins.left = 6;
  579. dropDownBoxStyle.margins.right = 6;
  580. dropDownBoxStyle.margins.top = 4;
  581. dropDownBoxStyle.margins.bottom = 6;
  582. skin->setStyle("ListBoxFrame", dropDownBoxStyle);
  583. skin->setStyle("MenuBarFrame", dropDownBoxStyle);
  584. skin->setStyle("ContextMenuFrame", dropDownBoxStyle);
  585. /************************************************************************/
  586. /* OTHER */
  587. /************************************************************************/
  588. // Right-aligned label
  589. GUIElementStyle rightAlignedLabelStyle;
  590. rightAlignedLabelStyle.font = font;
  591. rightAlignedLabelStyle.fontSize = DefaultFontSize;
  592. rightAlignedLabelStyle.fixedWidth = false;
  593. rightAlignedLabelStyle.fixedHeight = true;
  594. rightAlignedLabelStyle.height = 11;
  595. rightAlignedLabelStyle.minWidth = 10;
  596. rightAlignedLabelStyle.textHorzAlign = THA_Right;
  597. rightAlignedLabelStyle.normal.textColor = TextNormalColor;
  598. skin->setStyle("RightAlignedLabel", rightAlignedLabelStyle);
  599. return skin;
  600. }
  601. void BuiltinResources::generateMeshes()
  602. {
  603. VertexDataDescPtr vertexDesc = bs_shared_ptr_new<VertexDataDesc>();
  604. vertexDesc->addVertElem(VET_FLOAT3, VES_POSITION);
  605. vertexDesc->addVertElem(VET_FLOAT3, VES_NORMAL);
  606. vertexDesc->addVertElem(VET_COLOR, VES_COLOR);
  607. UINT32 boxNumVertices = 0;
  608. UINT32 boxNumIndices = 0;
  609. ShapeMeshes3D::getNumElementsAABox(boxNumVertices, boxNumIndices);
  610. MeshDataPtr boxMeshData = bs_shared_ptr_new<MeshData>(boxNumVertices, boxNumIndices, vertexDesc);
  611. AABox box(Vector3(-0.5f, -0.5f, -0.5f), Vector3(0.5f, 0.5f, 0.5f));
  612. ShapeMeshes3D::solidAABox(box, boxMeshData, 0, 0);
  613. HMesh boxMesh = Mesh::create(boxMeshData);
  614. UINT32 sphereNumVertices = 0;
  615. UINT32 sphereNumIndices = 0;
  616. ShapeMeshes3D::getNumElementsSphere(1, sphereNumVertices, sphereNumIndices);
  617. MeshDataPtr sphereMeshData = bs_shared_ptr_new<MeshData>(sphereNumVertices, sphereNumIndices, vertexDesc);
  618. ShapeMeshes3D::solidSphere(Sphere(Vector3::ZERO, 0.0f), sphereMeshData, 0, 0);
  619. HMesh sphereMesh = Mesh::create(sphereMeshData);
  620. UINT32 coneNumVertices = 0;
  621. UINT32 coneNumIndices = 0;
  622. ShapeMeshes3D::getNumElementsCone(10, coneNumVertices, coneNumIndices);
  623. MeshDataPtr coneMeshData = bs_shared_ptr_new<MeshData>(coneNumVertices, coneNumIndices, vertexDesc);
  624. ShapeMeshes3D::solidCone(Vector3::ZERO, Vector3::UNIT_Y, 1.0f, 1.0f, coneMeshData, 0, 0);
  625. HMesh coneMesh = Mesh::create(coneMeshData);
  626. UINT32 quadNumVertices = 8;
  627. UINT32 quadNumIndices = 12;
  628. ShapeMeshes3D::getNumElementsQuad(quadNumVertices, quadNumIndices);
  629. MeshDataPtr quadMeshData = bs_shared_ptr_new<MeshData>(quadNumVertices, quadNumIndices, vertexDesc);
  630. std::array<Vector3, 2> axes = { Vector3::UNIT_X, Vector3::UNIT_Y };
  631. std::array<float, 2> sizes = { 1.0f, 1.0f };
  632. Rect3 rect(Vector3::ZERO, axes, sizes);
  633. ShapeMeshes3D::solidQuad(rect, quadMeshData, 0, 0);
  634. HMesh quadMesh = Mesh::create(quadMeshData);
  635. UINT32 discNumVertices = 0;
  636. UINT32 discNumIndices = 0;
  637. ShapeMeshes3D::getNumElementsDisc(10, discNumVertices, discNumIndices);
  638. MeshDataPtr discMeshData = bs_shared_ptr_new<MeshData>(discNumVertices, discNumIndices, vertexDesc);
  639. ShapeMeshes3D::solidDisc(Vector3::ZERO, 1.0f, Vector3::UNIT_Y, discMeshData, 0, 0);
  640. HMesh discMesh = Mesh::create(discMeshData);
  641. // Save all meshes
  642. Path outputDir = FileSystem::getWorkingDirectoryPath() + EngineMeshFolder;
  643. Path meshPath = outputDir + MeshBoxFile;
  644. Resources::instance().save(boxMesh, meshPath, true);
  645. mResourceManifest->registerResource(boxMesh.getUUID(), meshPath);
  646. Path spherePath = outputDir + MeshSphereFile;
  647. Resources::instance().save(sphereMesh, spherePath, true);
  648. mResourceManifest->registerResource(sphereMesh.getUUID(), spherePath);
  649. Path conePath = outputDir + MeshConeFile;
  650. Resources::instance().save(coneMesh, conePath, true);
  651. mResourceManifest->registerResource(coneMesh.getUUID(), conePath);
  652. Path quadPath = outputDir + MeshQuadFile;
  653. Resources::instance().save(quadMesh, quadPath, true);
  654. mResourceManifest->registerResource(quadMesh.getUUID(), quadPath);
  655. Path discPath = outputDir + MeshDiscFile;
  656. Resources::instance().save(discMesh, discPath, true);
  657. mResourceManifest->registerResource(discMesh.getUUID(), discPath);
  658. }
  659. HSpriteTexture BuiltinResources::getSkinTexture(const WString& name)
  660. {
  661. Path texturePath = FileSystem::getWorkingDirectoryPath();
  662. texturePath.append(EngineSkinFolder);
  663. texturePath.append(L"sprite_" + name + L".asset");
  664. return Resources::instance().load<SpriteTexture>(texturePath);
  665. }
  666. HShader BuiltinResources::getShader(const WString& name)
  667. {
  668. Path programPath = EngineShaderFolder;
  669. programPath.append(name + L".asset");
  670. return gResources().load<Shader>(programPath);
  671. }
  672. HTexture BuiltinResources::getCursorTexture(const WString& name)
  673. {
  674. Path cursorPath = FileSystem::getWorkingDirectoryPath();
  675. cursorPath.append(EngineCursorFolder);
  676. cursorPath.append(name + L".asset");
  677. return Resources::instance().load<Texture>(cursorPath);
  678. }
  679. const PixelData& BuiltinResources::getCursorArrow(Vector2I& hotSpot)
  680. {
  681. hotSpot = CursorArrowHotspot;
  682. return *mCursorArrow.get();
  683. }
  684. const PixelData& BuiltinResources::getCursorArrowDrag(Vector2I& hotSpot)
  685. {
  686. hotSpot = CursorArrowDragHotspot;
  687. return *mCursorArrowDrag.get();
  688. }
  689. const PixelData& BuiltinResources::getCursorWait(Vector2I& hotSpot)
  690. {
  691. hotSpot = CursorWaitHotspot;
  692. return *mCursorWait.get();
  693. }
  694. const PixelData& BuiltinResources::getCursorIBeam(Vector2I& hotSpot)
  695. {
  696. hotSpot = CursorIBeamHotspot;
  697. return *mCursorIBeam.get();
  698. }
  699. const PixelData& BuiltinResources::getCursorSizeNESW(Vector2I& hotSpot)
  700. {
  701. hotSpot = CursorSizeNESWHotspot;
  702. return *mCursorSizeNESW.get();
  703. }
  704. const PixelData& BuiltinResources::getCursorSizeNS(Vector2I& hotSpot)
  705. {
  706. hotSpot = CursorSizeNSHotspot;
  707. return *mCursorSizeNS.get();
  708. }
  709. const PixelData& BuiltinResources::getCursorSizeNWSE(Vector2I& hotSpot)
  710. {
  711. hotSpot = CursorSizeNWSEHotspot;
  712. return *mCursorSizeNWSE.get();
  713. }
  714. const PixelData& BuiltinResources::getCursorSizeWE(Vector2I& hotSpot)
  715. {
  716. hotSpot = CursorSizeWEHotspot;
  717. return *mCursorSizeWE.get();
  718. }
  719. const PixelData& BuiltinResources::getCursorDeny(Vector2I& hotSpot)
  720. {
  721. hotSpot = CursorDenyHotspot;
  722. return *mCursorDeny.get();
  723. }
  724. const PixelData& BuiltinResources::getCursorMoveLeftRight(Vector2I& hotSpot)
  725. {
  726. hotSpot = CursorArrowLeftRightHotspot;
  727. return *mCursorArrowLeftRight.get();
  728. }
  729. HMesh BuiltinResources::getMesh(BuiltinMesh mesh) const
  730. {
  731. Path meshPath = FileSystem::getWorkingDirectoryPath();
  732. meshPath.append(EngineMeshFolder);
  733. switch (mesh)
  734. {
  735. case BuiltinMesh::Box:
  736. meshPath.append(MeshBoxFile);
  737. break;
  738. case BuiltinMesh::Sphere:
  739. meshPath.append(MeshSphereFile);
  740. break;
  741. case BuiltinMesh::Cone:
  742. meshPath.append(MeshConeFile);
  743. break;
  744. case BuiltinMesh::Quad:
  745. meshPath.append(MeshQuadFile);
  746. break;
  747. case BuiltinMesh::Disc:
  748. meshPath.append(MeshDiscFile);
  749. break;
  750. }
  751. return Resources::instance().load<Mesh>(meshPath);
  752. }
  753. GUIMaterialInfo BuiltinResources::createSpriteTextMaterial() const
  754. {
  755. GUIMaterialInfo info;
  756. info.material = Material::create(mShaderSpriteText);
  757. info.mainTexture = info.material->getParamTexture("mainTexture");
  758. info.mainTexSampler = info.material->getParamSamplerState("mainTexSamp");
  759. info.tint = info.material->getParamVec4("tint");
  760. return info;
  761. }
  762. GUIMaterialInfo BuiltinResources::createSpriteImageMaterial() const
  763. {
  764. GUIMaterialInfo info;
  765. info.material = Material::create(mShaderSpriteImage);
  766. info.mainTexture = info.material->getParamTexture("mainTexture");
  767. info.mainTexSampler = info.material->getParamSamplerState("mainTexSamp");
  768. info.tint = info.material->getParamVec4("tint");
  769. return info;
  770. }
  771. GUIMaterialInfo BuiltinResources::createSpriteNonAlphaImageMaterial() const
  772. {
  773. GUIMaterialInfo info;
  774. info.material = Material::create(mShaderSpriteNonAlphaImage);
  775. info.mainTexture = info.material->getParamTexture("mainTexture");
  776. info.mainTexSampler = info.material->getParamSamplerState("mainTexSamp");
  777. info.tint = info.material->getParamVec4("tint");
  778. return info;
  779. }
  780. HMaterial BuiltinResources::createDummyMaterial() const
  781. {
  782. return Material::create(mShaderDummy);
  783. }
  784. void BuiltinResourcesHelper::importAssets(const Path& inputFolder, const Path& outputFolder, const ResourceManifestPtr& manifest)
  785. {
  786. if (!FileSystem::exists(inputFolder))
  787. return;
  788. auto importResource = [&](const Path& filePath)
  789. {
  790. Path relativePath = filePath.getRelative(inputFolder);
  791. Path outputPath = FileSystem::getWorkingDirectoryPath() + outputFolder + relativePath;
  792. outputPath.setFilename(outputPath.getWFilename() + L".asset");
  793. HResource resource = Importer::instance().import(filePath);
  794. if (resource != nullptr)
  795. {
  796. Resources::instance().save(resource, outputPath, true);
  797. manifest->registerResource(resource.getUUID(), outputPath);
  798. }
  799. return true;
  800. };
  801. FileSystem::iterate(inputFolder, importResource);
  802. }
  803. void BuiltinResourcesHelper::importFont(const Path& inputFile, const Path& outputFolder,
  804. UINT32 size, bool antialiasing, const ResourceManifestPtr& manifest)
  805. {
  806. ImportOptionsPtr fontImportOptions = Importer::instance().createImportOptions(inputFile);
  807. if (rtti_is_of_type<FontImportOptions>(fontImportOptions))
  808. {
  809. FontImportOptions* importOptions = static_cast<FontImportOptions*>(fontImportOptions.get());
  810. Vector<UINT32> fontSizes;
  811. fontSizes.push_back(size);
  812. importOptions->setFontSizes(fontSizes);
  813. importOptions->setAntialiasing(antialiasing);
  814. }
  815. else
  816. return;
  817. HFont font = Importer::instance().import<Font>(inputFile, fontImportOptions);
  818. WString fontName = inputFile.getWFilename();
  819. Path outputPath = FileSystem::getWorkingDirectoryPath() + outputFolder + fontName;
  820. outputPath.setFilename(outputPath.getWFilename() + L".asset");
  821. Resources::instance().save(font, outputPath, true);
  822. manifest->registerResource(font.getUUID(), outputPath);
  823. // Save font texture pages as well. TODO - Later maybe figure out a more automatic way to do this
  824. const FontData* fontData = font->getFontDataForSize(size);
  825. Path texPageOutputPath = FileSystem::getWorkingDirectoryPath() + outputFolder;
  826. UINT32 pageIdx = 0;
  827. for (auto tex : fontData->texturePages)
  828. {
  829. texPageOutputPath.setFilename(fontName + L"_texpage_" + toWString(pageIdx) + L".asset");
  830. Resources::instance().save(tex, texPageOutputPath, true);
  831. manifest->registerResource(tex.getUUID(), texPageOutputPath);
  832. }
  833. }
  834. void BuiltinResourcesHelper::generateSpriteTextures(const Path& folder, const ResourceManifestPtr& manifest)
  835. {
  836. if (!FileSystem::exists(folder))
  837. return;
  838. Vector<Path> filesToProcess;
  839. auto gather = [&](const Path& filePath)
  840. {
  841. filesToProcess.push_back(filePath);
  842. return true;
  843. };
  844. FileSystem::iterate(folder, gather);
  845. for (auto& filePath : filesToProcess)
  846. {
  847. Path outputPath = FileSystem::getWorkingDirectoryPath() + filePath;
  848. outputPath.setFilename(L"sprite_" + outputPath.getWFilename());
  849. HTexture source = gResources().load<Texture>(filePath);
  850. if (source != nullptr)
  851. {
  852. HSpriteTexture spriteTex = SpriteTexture::create(source);
  853. Resources::instance().save(spriteTex, outputPath, true);
  854. manifest->registerResource(spriteTex.getUUID(), outputPath);
  855. }
  856. }
  857. }
  858. void BuiltinResourcesHelper::writeTimestamp(const Path& file)
  859. {
  860. DataStreamPtr fileStream = FileSystem::createAndOpenFile(file);
  861. time_t currentTime = std::time(nullptr);
  862. fileStream->write(&currentTime, sizeof(currentTime));
  863. fileStream->close();
  864. }
  865. bool BuiltinResourcesHelper::checkForModifications(const Path& folder, const Path& timeStampFile)
  866. {
  867. if (!FileSystem::exists(timeStampFile))
  868. return true;
  869. DataStreamPtr fileStream = FileSystem::openFile(timeStampFile);
  870. time_t lastUpdateTime = 0;
  871. fileStream->read(&lastUpdateTime, sizeof(lastUpdateTime));
  872. fileStream->close();
  873. bool upToDate = true;
  874. auto checkUpToDate = [&](const Path& filePath)
  875. {
  876. time_t fileLastModified = FileSystem::getLastModifiedTime(filePath);
  877. if (fileLastModified > lastUpdateTime)
  878. {
  879. upToDate = false;
  880. return false;
  881. }
  882. return true;
  883. };
  884. FileSystem::iterate(folder, checkUpToDate, checkUpToDate);
  885. return !upToDate;
  886. }
  887. }