BsBuiltinResources.cpp 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100
  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, 6);
  120. const Vector2I BuiltinResources::CursorArrowDragHotspot = Vector2I(11, 4);
  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. BuiltinResourcesHelper::importAssets(EngineRawCursorFolder, EngineCursorFolder, mResourceManifest);
  222. BuiltinResourcesHelper::importAssets(EngineRawShaderIncludeFolder, EngineShaderIncludeFolder, mResourceManifest); // Hidden dependency: Includes must be imported before shaders
  223. BuiltinResourcesHelper::importAssets(EngineRawShaderFolder, EngineShaderFolder, mResourceManifest);
  224. BuiltinResourcesHelper::importAssets(EngineRawSkinFolder, EngineSkinFolder, mResourceManifest);
  225. // Import font
  226. BuiltinResourcesHelper::importFont(BuiltinRawDataFolder + DefaultFontFilename, BuiltinDataFolder, DefaultFontSize, false, mResourceManifest);
  227. // Generate & save GUI sprite textures
  228. BuiltinResourcesHelper::generateSpriteTextures(EngineSkinFolder, mResourceManifest);
  229. // Generate & save GUI skin
  230. {
  231. HGUISkin skin = generateGUISkin();
  232. Path outputPath = FileSystem::getWorkingDirectoryPath() + BuiltinDataFolder + (GUISkinFile + L".asset");
  233. Resources::instance().save(skin, outputPath, true);
  234. mResourceManifest->registerResource(skin.getUUID(), outputPath);
  235. }
  236. // Generate & save meshes
  237. generateMeshes();
  238. Resources::instance().unloadAllUnused();
  239. }
  240. HGUISkin BuiltinResources::generateGUISkin()
  241. {
  242. Path fontPath = FileSystem::getWorkingDirectoryPath();
  243. fontPath.append(BuiltinDataFolder);
  244. fontPath.append(DefaultFontFilename + L".asset");
  245. HFont font = gResources().load<Font>(fontPath);
  246. HGUISkin skin = GUISkin::create();
  247. // Label
  248. GUIElementStyle labelStyle;
  249. labelStyle.font = font;
  250. labelStyle.fontSize = DefaultFontSize;
  251. labelStyle.normal.textColor = TextNormalColor;
  252. labelStyle.fixedWidth = false;
  253. labelStyle.fixedHeight = true;
  254. labelStyle.height = 14;
  255. labelStyle.minWidth = 10;
  256. skin->setStyle(GUILabel::getGUITypeName(), labelStyle);
  257. // Button
  258. GUIElementStyle buttonStyle;
  259. buttonStyle.normal.texture = getSkinTexture(ButtonNormalTex);
  260. buttonStyle.hover.texture = getSkinTexture(ButtonHoverTex);
  261. buttonStyle.active.texture = getSkinTexture(ButtonActiveTex);
  262. buttonStyle.normalOn.texture = getSkinTexture(ButtonActiveTex);
  263. buttonStyle.hoverOn.texture = getSkinTexture(ButtonActiveTex);
  264. buttonStyle.activeOn.texture = getSkinTexture(ButtonActiveTex);
  265. buttonStyle.normal.textColor = TextNormalColor;
  266. buttonStyle.hover.textColor = TextNormalColor;
  267. buttonStyle.active.textColor = TextActiveColor;
  268. buttonStyle.normalOn.textColor = TextActiveColor;
  269. buttonStyle.hoverOn.textColor = TextActiveColor;
  270. buttonStyle.activeOn.textColor = TextActiveColor;
  271. buttonStyle.border.left = 2;
  272. buttonStyle.border.right = 2;
  273. buttonStyle.border.top = 2;
  274. buttonStyle.border.bottom = 4;
  275. buttonStyle.contentOffset.top = 2;
  276. buttonStyle.contentOffset.left = 3;
  277. buttonStyle.contentOffset.right = 3;
  278. buttonStyle.margins.bottom = 2;
  279. buttonStyle.fixedHeight = true;
  280. buttonStyle.height = 21;
  281. buttonStyle.minWidth = 20;
  282. buttonStyle.font = font;
  283. buttonStyle.fontSize = DefaultFontSize;
  284. buttonStyle.textHorzAlign = THA_Center;
  285. buttonStyle.textVertAlign = TVA_Center;
  286. skin->setStyle(GUIButton::getGUITypeName(), buttonStyle);
  287. // Toggle
  288. GUIElementStyle toggleStyle;
  289. toggleStyle.normal.texture = getSkinTexture(ToggleNormalTex);
  290. toggleStyle.hover.texture = getSkinTexture(ToggleHoverTex);
  291. toggleStyle.active.texture = toggleStyle.hover.texture;
  292. toggleStyle.normalOn.texture = getSkinTexture(ToggleNormalOnTex);
  293. toggleStyle.hoverOn.texture = getSkinTexture(ToggleHoverOnTex);
  294. toggleStyle.activeOn.texture = toggleStyle.hoverOn.texture;
  295. toggleStyle.fixedHeight = true;
  296. toggleStyle.fixedWidth = true;
  297. toggleStyle.margins.bottom = 2;
  298. toggleStyle.height = 15;
  299. toggleStyle.width = 13;
  300. skin->setStyle(GUIToggle::getGUITypeName(), toggleStyle);
  301. // Input box
  302. GUIElementStyle inputBoxStyle;
  303. inputBoxStyle.normal.texture = getSkinTexture(InputBoxNormalTex);
  304. inputBoxStyle.hover.texture = getSkinTexture(InputBoxHoverTex);
  305. inputBoxStyle.focused.texture = getSkinTexture(InputBoxFocusedTex);
  306. inputBoxStyle.active.texture = inputBoxStyle.normal.texture;
  307. inputBoxStyle.normal.textColor = TextNormalColor;
  308. inputBoxStyle.hover.textColor = TextNormalColor;
  309. inputBoxStyle.focused.textColor = TextNormalColor;
  310. inputBoxStyle.active.textColor = TextNormalColor;
  311. inputBoxStyle.border.left = 4;
  312. inputBoxStyle.border.right = 4;
  313. inputBoxStyle.border.top = 4;
  314. inputBoxStyle.border.bottom = 6;
  315. inputBoxStyle.contentOffset.left = 4;
  316. inputBoxStyle.contentOffset.right = 4;
  317. inputBoxStyle.contentOffset.top = 4;
  318. inputBoxStyle.contentOffset.bottom = 4;
  319. inputBoxStyle.margins.bottom = 2;
  320. inputBoxStyle.fixedHeight = true;
  321. inputBoxStyle.height = 21;
  322. inputBoxStyle.minWidth = 10;
  323. inputBoxStyle.font = font;
  324. inputBoxStyle.fontSize = DefaultFontSize;
  325. inputBoxStyle.textHorzAlign = THA_Left;
  326. inputBoxStyle.textVertAlign = TVA_Top;
  327. skin->setStyle(GUIInputBox::getGUITypeName(), inputBoxStyle);
  328. /************************************************************************/
  329. /* SCROLL BAR */
  330. /************************************************************************/
  331. // Up button
  332. GUIElementStyle scrollUpBtnStyle;
  333. scrollUpBtnStyle.normal.texture = getSkinTexture(ScrollBarUpNormalTex);
  334. scrollUpBtnStyle.hover.texture = getSkinTexture(ScrollBarUpHoverTex);
  335. scrollUpBtnStyle.active.texture = getSkinTexture(ScrollBarUpActiveTex);
  336. scrollUpBtnStyle.fixedHeight = true;
  337. scrollUpBtnStyle.fixedWidth = true;
  338. scrollUpBtnStyle.height = 11;
  339. scrollUpBtnStyle.width = 13;
  340. skin->setStyle("ScrollUpBtn", scrollUpBtnStyle);
  341. // Down button
  342. GUIElementStyle scrollDownBtnStyle;
  343. scrollDownBtnStyle.normal.texture = getSkinTexture(ScrollBarDownNormalTex);
  344. scrollDownBtnStyle.hover.texture = getSkinTexture(ScrollBarDownHoverTex);
  345. scrollDownBtnStyle.active.texture = getSkinTexture(ScrollBarDownActiveTex);
  346. scrollDownBtnStyle.fixedHeight = true;
  347. scrollDownBtnStyle.fixedWidth = true;
  348. scrollDownBtnStyle.height = 11;
  349. scrollDownBtnStyle.width = 13;
  350. skin->setStyle("ScrollDownBtn", scrollDownBtnStyle);
  351. // Left button
  352. GUIElementStyle scrollLeftBtnStyle;
  353. scrollLeftBtnStyle.normal.texture = getSkinTexture(ScrollBarLeftNormalTex);
  354. scrollLeftBtnStyle.hover.texture = getSkinTexture(ScrollBarLeftHoverTex);
  355. scrollLeftBtnStyle.active.texture = getSkinTexture(ScrollBarLeftActiveTex);
  356. scrollLeftBtnStyle.fixedHeight = true;
  357. scrollLeftBtnStyle.fixedWidth = true;
  358. scrollLeftBtnStyle.height = 13;
  359. scrollLeftBtnStyle.width = 11;
  360. skin->setStyle("ScrollLeftBtn", scrollLeftBtnStyle);
  361. // Right button
  362. GUIElementStyle scrollRightBtnStyle;
  363. scrollRightBtnStyle.normal.texture = getSkinTexture(ScrollBarRightNormalTex);
  364. scrollRightBtnStyle.hover.texture = getSkinTexture(ScrollBarRightHoverTex);
  365. scrollRightBtnStyle.active.texture = getSkinTexture(ScrollBarRightActiveTex);
  366. scrollRightBtnStyle.fixedHeight = true;
  367. scrollRightBtnStyle.fixedWidth = true;
  368. scrollRightBtnStyle.height = 13;
  369. scrollRightBtnStyle.width = 11;
  370. skin->setStyle("ScrollRightBtn", scrollRightBtnStyle);
  371. // Horizontal handle
  372. GUIElementStyle scrollBarHorzBtnStyle;
  373. scrollBarHorzBtnStyle.normal.texture = getSkinTexture(ScrollBarHandleHorzNormalTex);
  374. scrollBarHorzBtnStyle.hover.texture = getSkinTexture(ScrollBarHandleHorzHoverTex);
  375. scrollBarHorzBtnStyle.active.texture = getSkinTexture(ScrollBarHandleHorzActiveTex);
  376. scrollBarHorzBtnStyle.fixedHeight = true;
  377. scrollBarHorzBtnStyle.fixedWidth = false;
  378. scrollBarHorzBtnStyle.width = 10;
  379. scrollBarHorzBtnStyle.height = 13;
  380. scrollBarHorzBtnStyle.border.left = 4;
  381. scrollBarHorzBtnStyle.border.right = 4;
  382. skin->setStyle("ScrollBarHorzBtn", scrollBarHorzBtnStyle);
  383. // Vertical handle
  384. GUIElementStyle scrollBarVertBtnStyle;
  385. scrollBarVertBtnStyle.normal.texture = getSkinTexture(ScrollBarHandleVertNormalTex);
  386. scrollBarVertBtnStyle.hover.texture = getSkinTexture(ScrollBarHandleVertHoverTex);
  387. scrollBarVertBtnStyle.active.texture = getSkinTexture(ScrollBarHandleVertActiveTex);
  388. scrollBarVertBtnStyle.fixedHeight = false;
  389. scrollBarVertBtnStyle.fixedWidth = true;
  390. scrollBarVertBtnStyle.width = 13;
  391. scrollBarVertBtnStyle.height = 10;
  392. scrollBarVertBtnStyle.border.top = 4;
  393. scrollBarVertBtnStyle.border.bottom = 4;
  394. skin->setStyle("ScrollBarVertBtn", scrollBarVertBtnStyle);
  395. // Vertical scroll bar
  396. GUIElementStyle vertScrollBarStyle;
  397. vertScrollBarStyle.normal.texture = getSkinTexture(ScrollBarVBgTex);
  398. vertScrollBarStyle.hover.texture = vertScrollBarStyle.normal.texture;
  399. vertScrollBarStyle.active.texture = vertScrollBarStyle.normal.texture;
  400. vertScrollBarStyle.fixedHeight = false;
  401. vertScrollBarStyle.fixedWidth = true;
  402. vertScrollBarStyle.minHeight = 8;
  403. vertScrollBarStyle.width = 16;
  404. skin->setStyle("ScrollBarVert", vertScrollBarStyle);
  405. // Horizontal scroll bar
  406. GUIElementStyle horzScrollBarStyle;
  407. horzScrollBarStyle.normal.texture = getSkinTexture(ScrollBarHBgTex);
  408. horzScrollBarStyle.hover.texture = horzScrollBarStyle.normal.texture;
  409. horzScrollBarStyle.active.texture = horzScrollBarStyle.normal.texture;
  410. horzScrollBarStyle.fixedHeight = true;
  411. horzScrollBarStyle.fixedWidth = false;
  412. horzScrollBarStyle.minWidth = 8;
  413. horzScrollBarStyle.height = 16;
  414. skin->setStyle("ScrollBarHorz", horzScrollBarStyle);
  415. /************************************************************************/
  416. /* DROP DOWN BOX */
  417. /************************************************************************/
  418. // ListBox button
  419. GUIElementStyle dropDownListStyle;
  420. dropDownListStyle.normal.texture = getSkinTexture(DropDownBtnNormalTex);
  421. dropDownListStyle.hover.texture = getSkinTexture(DropDownBtnHoverTex);
  422. dropDownListStyle.active.texture = getSkinTexture(DropDownBtnActiveTex);
  423. dropDownListStyle.normalOn.texture = dropDownListStyle.active.texture;
  424. dropDownListStyle.hoverOn.texture = dropDownListStyle.active.texture;
  425. dropDownListStyle.activeOn.texture = dropDownListStyle.active.texture;
  426. dropDownListStyle.normal.textColor = TextNormalColor;
  427. dropDownListStyle.hover.textColor = TextNormalColor;
  428. dropDownListStyle.active.textColor = TextNormalColor;
  429. dropDownListStyle.normalOn.textColor = TextNormalColor;
  430. dropDownListStyle.hoverOn.textColor = TextNormalColor;
  431. dropDownListStyle.activeOn.textColor = TextNormalColor;
  432. dropDownListStyle.fixedHeight = true;
  433. dropDownListStyle.fixedWidth = false;
  434. dropDownListStyle.height = 21;
  435. dropDownListStyle.minWidth = 20;
  436. dropDownListStyle.contentOffset.left = 3;
  437. dropDownListStyle.contentOffset.right = 18;
  438. dropDownListStyle.contentOffset.top = 2;
  439. dropDownListStyle.contentOffset.bottom = 2;
  440. dropDownListStyle.border.left = 2;
  441. dropDownListStyle.border.right = 16;
  442. dropDownListStyle.border.top = 2;
  443. dropDownListStyle.border.bottom = 4;
  444. dropDownListStyle.margins.bottom = 2;
  445. dropDownListStyle.font = font;
  446. dropDownListStyle.fontSize = DefaultFontSize;
  447. dropDownListStyle.textHorzAlign = THA_Left;
  448. dropDownListStyle.textVertAlign = TVA_Center;
  449. skin->setStyle("ListBox", dropDownListStyle);
  450. // DropDown scroll up button
  451. GUIElementStyle dropDownScrollUpBtnStyle;
  452. dropDownScrollUpBtnStyle.normal.texture = getSkinTexture(DropDownBoxBtnUpNormalTex);
  453. dropDownScrollUpBtnStyle.hover.texture = getSkinTexture(DropDownBoxBtnUpHoverTex);
  454. dropDownScrollUpBtnStyle.active.texture = dropDownScrollUpBtnStyle.hover.texture;
  455. dropDownScrollUpBtnStyle.fixedHeight = true;
  456. dropDownScrollUpBtnStyle.fixedWidth = true;
  457. dropDownScrollUpBtnStyle.width = 8;
  458. dropDownScrollUpBtnStyle.height = 12;
  459. skin->setStyle("ListBoxScrollUpBtn", dropDownScrollUpBtnStyle);
  460. skin->setStyle("MenuBarScrollUpBtn", dropDownScrollUpBtnStyle);
  461. skin->setStyle("ContextMenuScrollUpBtn", dropDownScrollUpBtnStyle);
  462. // DropDown scroll down button
  463. GUIElementStyle dropDownScrollDownBtnStyle;
  464. dropDownScrollDownBtnStyle.normal.texture = getSkinTexture(DropDownBoxBtnDownNormalTex);
  465. dropDownScrollDownBtnStyle.hover.texture = getSkinTexture(DropDownBoxBtnDownHoverTex);
  466. dropDownScrollDownBtnStyle.active.texture = dropDownScrollDownBtnStyle.hover.texture;
  467. dropDownScrollDownBtnStyle.fixedHeight = true;
  468. dropDownScrollDownBtnStyle.fixedWidth = true;
  469. dropDownScrollDownBtnStyle.width = 8;
  470. dropDownScrollDownBtnStyle.height = 12;
  471. skin->setStyle("ListBoxScrollDownBtn", dropDownScrollDownBtnStyle);
  472. skin->setStyle("MenuBarScrollDownBtn", dropDownScrollDownBtnStyle);
  473. skin->setStyle("ContextMenuScrollDownBtn", dropDownScrollDownBtnStyle);
  474. // DropDown handle
  475. GUIElementStyle dropDownScrollHandleStyle;
  476. dropDownScrollHandleStyle.normal.texture = getSkinTexture(DropDownBoxHandleTex);
  477. dropDownScrollHandleStyle.fixedHeight = false;
  478. dropDownScrollHandleStyle.fixedWidth = true;
  479. dropDownScrollHandleStyle.height = 8;
  480. dropDownScrollHandleStyle.width = 8;
  481. skin->setStyle("ListBoxHandle", dropDownScrollHandleStyle);
  482. skin->setStyle("MenuBarHandle", dropDownScrollHandleStyle);
  483. skin->setStyle("ContextMenuHandle", dropDownScrollHandleStyle);
  484. // DropDown sidebar background
  485. GUIElementStyle dropDownSidebarBg;
  486. dropDownSidebarBg.normal.texture = getSkinTexture(DropDownBoxSideBgTex);
  487. dropDownSidebarBg.fixedHeight = false;
  488. dropDownSidebarBg.fixedWidth = true;
  489. dropDownSidebarBg.height = 8;
  490. dropDownSidebarBg.width = 9;
  491. dropDownSidebarBg.border.left = 1;
  492. dropDownSidebarBg.border.top = 1;
  493. dropDownSidebarBg.border.bottom = 1;
  494. skin->setStyle("ListBoxSidebarBg", dropDownSidebarBg);
  495. skin->setStyle("MenuBarSidebarBg", dropDownSidebarBg);
  496. skin->setStyle("ContextMenuSidebarBg", dropDownSidebarBg);
  497. // DropDown entry button
  498. GUIElementStyle dropDownEntryBtnStyle;
  499. dropDownEntryBtnStyle.normal.texture = getSkinTexture(DropDownBoxEntryNormalTex);
  500. dropDownEntryBtnStyle.hover.texture = getSkinTexture(DropDownBoxEntryHoverTex);
  501. dropDownEntryBtnStyle.active.texture = dropDownEntryBtnStyle.hover.texture;
  502. dropDownEntryBtnStyle.normalOn.texture = dropDownEntryBtnStyle.hover.texture;
  503. dropDownEntryBtnStyle.hoverOn.texture = dropDownEntryBtnStyle.hover.texture;
  504. dropDownEntryBtnStyle.activeOn.texture = dropDownEntryBtnStyle.hover.texture;
  505. dropDownEntryBtnStyle.normal.textColor = TextNormalColor;
  506. dropDownEntryBtnStyle.hover.textColor = TextNormalColor;
  507. dropDownEntryBtnStyle.active.textColor = TextNormalColor;
  508. dropDownEntryBtnStyle.normalOn.textColor = TextNormalColor;
  509. dropDownEntryBtnStyle.hoverOn.textColor = TextNormalColor;
  510. dropDownEntryBtnStyle.activeOn.textColor = TextNormalColor;
  511. dropDownEntryBtnStyle.fixedHeight = true;
  512. dropDownEntryBtnStyle.fixedWidth = false;
  513. dropDownEntryBtnStyle.height = 16;
  514. dropDownEntryBtnStyle.width = 30;
  515. dropDownEntryBtnStyle.font = font;
  516. dropDownEntryBtnStyle.fontSize = DefaultFontSize;
  517. dropDownEntryBtnStyle.textHorzAlign = THA_Left;
  518. dropDownEntryBtnStyle.textVertAlign = TVA_Center;
  519. skin->setStyle(GUIDropDownContent::ENTRY_STYLE_TYPE, dropDownEntryBtnStyle);
  520. // DropDown entry button with expand
  521. GUIElementStyle dropDownEntryExpBtnStyle;
  522. dropDownEntryExpBtnStyle.normal.texture = getSkinTexture(DropDownBoxEntryExpNormalTex);
  523. dropDownEntryExpBtnStyle.hover.texture = getSkinTexture(DropDownBoxEntryExpHoverTex);
  524. dropDownEntryExpBtnStyle.active.texture = dropDownEntryExpBtnStyle.hover.texture;
  525. dropDownEntryExpBtnStyle.normalOn.texture = dropDownEntryExpBtnStyle.hover.texture;
  526. dropDownEntryExpBtnStyle.hoverOn.texture = dropDownEntryExpBtnStyle.hover.texture;
  527. dropDownEntryExpBtnStyle.activeOn.texture = dropDownEntryExpBtnStyle.hover.texture;
  528. dropDownEntryExpBtnStyle.normal.textColor = TextNormalColor;
  529. dropDownEntryExpBtnStyle.hover.textColor = TextNormalColor;
  530. dropDownEntryExpBtnStyle.active.textColor = TextNormalColor;
  531. dropDownEntryExpBtnStyle.normalOn.textColor = TextNormalColor;
  532. dropDownEntryExpBtnStyle.hoverOn.textColor = TextNormalColor;
  533. dropDownEntryExpBtnStyle.activeOn.textColor = TextNormalColor;
  534. dropDownEntryExpBtnStyle.fixedHeight = true;
  535. dropDownEntryExpBtnStyle.fixedWidth = false;
  536. dropDownEntryExpBtnStyle.height = 16;
  537. dropDownEntryExpBtnStyle.width = 30;
  538. dropDownEntryExpBtnStyle.border.right = 13;
  539. dropDownEntryExpBtnStyle.font = font;
  540. dropDownEntryExpBtnStyle.fontSize = DefaultFontSize;
  541. dropDownEntryExpBtnStyle.textHorzAlign = THA_Left;
  542. dropDownEntryExpBtnStyle.textVertAlign = TVA_Center;
  543. skin->setStyle(GUIDropDownContent::ENTRY_EXP_STYLE_TYPE, dropDownEntryExpBtnStyle);
  544. // Drop down separator
  545. GUIElementStyle dropDownSeparatorStyle;
  546. dropDownSeparatorStyle.normal.texture = getSkinTexture(DropDownSeparatorTex);
  547. dropDownSeparatorStyle.fixedHeight = true;
  548. dropDownSeparatorStyle.fixedWidth = false;
  549. dropDownSeparatorStyle.height = 3;
  550. dropDownSeparatorStyle.width = 30;
  551. skin->setStyle(GUIDropDownContent::SEPARATOR_STYLE_TYPE, dropDownSeparatorStyle);
  552. // Drop down content
  553. GUIElementStyle dropDownContentStyle;
  554. dropDownContentStyle.minWidth = 50;
  555. dropDownContentStyle.minHeight = 20;
  556. dropDownContentStyle.subStyles[GUIDropDownContent::ENTRY_STYLE_TYPE] = GUIDropDownContent::ENTRY_STYLE_TYPE;
  557. dropDownContentStyle.subStyles[GUIDropDownContent::ENTRY_EXP_STYLE_TYPE] = GUIDropDownContent::ENTRY_EXP_STYLE_TYPE;
  558. dropDownContentStyle.subStyles[GUIDropDownContent::SEPARATOR_STYLE_TYPE] = GUIDropDownContent::SEPARATOR_STYLE_TYPE;
  559. skin->setStyle("ListBoxContent", dropDownContentStyle);
  560. skin->setStyle("MenuBarContent", dropDownContentStyle);
  561. skin->setStyle("ContextMenuContent", dropDownContentStyle);
  562. // DropDown box frame
  563. GUIElementStyle dropDownBoxStyle;
  564. dropDownBoxStyle.normal.texture = getSkinTexture(DropDownBoxBgTex);
  565. dropDownBoxStyle.hover.texture = dropDownBoxStyle.normal.texture;
  566. dropDownBoxStyle.active.texture = dropDownBoxStyle.hover.texture;
  567. dropDownBoxStyle.fixedHeight = false;
  568. dropDownBoxStyle.fixedWidth = false;
  569. dropDownBoxStyle.border.left = 2;
  570. dropDownBoxStyle.border.right = 2;
  571. dropDownBoxStyle.border.top = 2;
  572. dropDownBoxStyle.border.bottom = 4;
  573. dropDownBoxStyle.margins.left = 6;
  574. dropDownBoxStyle.margins.right = 6;
  575. dropDownBoxStyle.margins.top = 4;
  576. dropDownBoxStyle.margins.bottom = 6;
  577. skin->setStyle("ListBoxFrame", dropDownBoxStyle);
  578. skin->setStyle("MenuBarFrame", dropDownBoxStyle);
  579. skin->setStyle("ContextMenuFrame", dropDownBoxStyle);
  580. /************************************************************************/
  581. /* OTHER */
  582. /************************************************************************/
  583. // Right-aligned label
  584. GUIElementStyle rightAlignedLabelStyle;
  585. rightAlignedLabelStyle.font = font;
  586. rightAlignedLabelStyle.fontSize = DefaultFontSize;
  587. rightAlignedLabelStyle.fixedWidth = false;
  588. rightAlignedLabelStyle.fixedHeight = true;
  589. rightAlignedLabelStyle.height = 11;
  590. rightAlignedLabelStyle.minWidth = 10;
  591. rightAlignedLabelStyle.textHorzAlign = THA_Right;
  592. rightAlignedLabelStyle.normal.textColor = TextNormalColor;
  593. skin->setStyle("RightAlignedLabel", rightAlignedLabelStyle);
  594. return skin;
  595. }
  596. void BuiltinResources::generateMeshes()
  597. {
  598. VertexDataDescPtr vertexDesc = bs_shared_ptr_new<VertexDataDesc>();
  599. vertexDesc->addVertElem(VET_FLOAT3, VES_POSITION);
  600. vertexDesc->addVertElem(VET_FLOAT3, VES_NORMAL);
  601. vertexDesc->addVertElem(VET_COLOR, VES_COLOR);
  602. UINT32 boxNumVertices = 0;
  603. UINT32 boxNumIndices = 0;
  604. ShapeMeshes3D::getNumElementsAABox(boxNumVertices, boxNumIndices);
  605. MeshDataPtr boxMeshData = bs_shared_ptr_new<MeshData>(boxNumVertices, boxNumIndices, vertexDesc);
  606. AABox box(Vector3(-0.5f, -0.5f, -0.5f), Vector3(0.5f, 0.5f, 0.5f));
  607. ShapeMeshes3D::solidAABox(box, boxMeshData, 0, 0);
  608. HMesh boxMesh = Mesh::create(boxMeshData);
  609. UINT32 sphereNumVertices = 0;
  610. UINT32 sphereNumIndices = 0;
  611. ShapeMeshes3D::getNumElementsSphere(1, sphereNumVertices, sphereNumIndices);
  612. MeshDataPtr sphereMeshData = bs_shared_ptr_new<MeshData>(sphereNumVertices, sphereNumIndices, vertexDesc);
  613. ShapeMeshes3D::solidSphere(Sphere(Vector3::ZERO, 0.0f), sphereMeshData, 0, 0);
  614. HMesh sphereMesh = Mesh::create(sphereMeshData);
  615. UINT32 coneNumVertices = 0;
  616. UINT32 coneNumIndices = 0;
  617. ShapeMeshes3D::getNumElementsCone(10, coneNumVertices, coneNumIndices);
  618. MeshDataPtr coneMeshData = bs_shared_ptr_new<MeshData>(coneNumVertices, coneNumIndices, vertexDesc);
  619. ShapeMeshes3D::solidCone(Vector3::ZERO, Vector3::UNIT_Y, 1.0f, 1.0f, coneMeshData, 0, 0);
  620. HMesh coneMesh = Mesh::create(coneMeshData);
  621. UINT32 quadNumVertices = 8;
  622. UINT32 quadNumIndices = 12;
  623. ShapeMeshes3D::getNumElementsQuad(quadNumVertices, quadNumIndices);
  624. MeshDataPtr quadMeshData = bs_shared_ptr_new<MeshData>(quadNumVertices, quadNumIndices, vertexDesc);
  625. std::array<Vector3, 2> axes = { Vector3::UNIT_X, Vector3::UNIT_Y };
  626. std::array<float, 2> sizes = { 1.0f, 1.0f };
  627. Rect3 rect(Vector3::ZERO, axes, sizes);
  628. ShapeMeshes3D::solidQuad(rect, quadMeshData, 0, 0);
  629. HMesh quadMesh = Mesh::create(quadMeshData);
  630. UINT32 discNumVertices = 0;
  631. UINT32 discNumIndices = 0;
  632. ShapeMeshes3D::getNumElementsDisc(10, discNumVertices, discNumIndices);
  633. MeshDataPtr discMeshData = bs_shared_ptr_new<MeshData>(discNumVertices, discNumIndices, vertexDesc);
  634. ShapeMeshes3D::solidDisc(Vector3::ZERO, 1.0f, Vector3::UNIT_Y, discMeshData, 0, 0);
  635. HMesh discMesh = Mesh::create(discMeshData);
  636. // Save all meshes
  637. Path outputDir = FileSystem::getWorkingDirectoryPath() + EngineMeshFolder;
  638. Path meshPath = outputDir + MeshBoxFile;
  639. Resources::instance().save(boxMesh, meshPath, true);
  640. mResourceManifest->registerResource(boxMesh.getUUID(), meshPath);
  641. Path spherePath = outputDir + MeshSphereFile;
  642. Resources::instance().save(sphereMesh, spherePath, true);
  643. mResourceManifest->registerResource(sphereMesh.getUUID(), spherePath);
  644. Path conePath = outputDir + MeshConeFile;
  645. Resources::instance().save(coneMesh, conePath, true);
  646. mResourceManifest->registerResource(coneMesh.getUUID(), conePath);
  647. Path quadPath = outputDir + MeshQuadFile;
  648. Resources::instance().save(quadMesh, quadPath, true);
  649. mResourceManifest->registerResource(quadMesh.getUUID(), quadPath);
  650. Path discPath = outputDir + MeshDiscFile;
  651. Resources::instance().save(discMesh, discPath, true);
  652. mResourceManifest->registerResource(discMesh.getUUID(), discPath);
  653. }
  654. HSpriteTexture BuiltinResources::getSkinTexture(const WString& name)
  655. {
  656. Path texturePath = FileSystem::getWorkingDirectoryPath();
  657. texturePath.append(EngineSkinFolder);
  658. texturePath.append(L"sprite_" + name + L".asset");
  659. return gResources().load<SpriteTexture>(texturePath);
  660. }
  661. HShader BuiltinResources::getShader(const Path& path)
  662. {
  663. Path programPath = EngineShaderFolder;
  664. programPath.append(path);
  665. programPath.setExtension(programPath.getExtension() + ".asset");
  666. return gResources().load<Shader>(programPath);
  667. }
  668. HTexture BuiltinResources::getCursorTexture(const WString& name)
  669. {
  670. Path cursorPath = FileSystem::getWorkingDirectoryPath();
  671. cursorPath.append(EngineCursorFolder);
  672. cursorPath.append(name + L".asset");
  673. return gResources().load<Texture>(cursorPath);
  674. }
  675. const PixelData& BuiltinResources::getCursorArrow(Vector2I& hotSpot)
  676. {
  677. hotSpot = CursorArrowHotspot;
  678. return *mCursorArrow.get();
  679. }
  680. const PixelData& BuiltinResources::getCursorArrowDrag(Vector2I& hotSpot)
  681. {
  682. hotSpot = CursorArrowDragHotspot;
  683. return *mCursorArrowDrag.get();
  684. }
  685. const PixelData& BuiltinResources::getCursorWait(Vector2I& hotSpot)
  686. {
  687. hotSpot = CursorWaitHotspot;
  688. return *mCursorWait.get();
  689. }
  690. const PixelData& BuiltinResources::getCursorIBeam(Vector2I& hotSpot)
  691. {
  692. hotSpot = CursorIBeamHotspot;
  693. return *mCursorIBeam.get();
  694. }
  695. const PixelData& BuiltinResources::getCursorSizeNESW(Vector2I& hotSpot)
  696. {
  697. hotSpot = CursorSizeNESWHotspot;
  698. return *mCursorSizeNESW.get();
  699. }
  700. const PixelData& BuiltinResources::getCursorSizeNS(Vector2I& hotSpot)
  701. {
  702. hotSpot = CursorSizeNSHotspot;
  703. return *mCursorSizeNS.get();
  704. }
  705. const PixelData& BuiltinResources::getCursorSizeNWSE(Vector2I& hotSpot)
  706. {
  707. hotSpot = CursorSizeNWSEHotspot;
  708. return *mCursorSizeNWSE.get();
  709. }
  710. const PixelData& BuiltinResources::getCursorSizeWE(Vector2I& hotSpot)
  711. {
  712. hotSpot = CursorSizeWEHotspot;
  713. return *mCursorSizeWE.get();
  714. }
  715. const PixelData& BuiltinResources::getCursorDeny(Vector2I& hotSpot)
  716. {
  717. hotSpot = CursorDenyHotspot;
  718. return *mCursorDeny.get();
  719. }
  720. const PixelData& BuiltinResources::getCursorMoveLeftRight(Vector2I& hotSpot)
  721. {
  722. hotSpot = CursorArrowLeftRightHotspot;
  723. return *mCursorArrowLeftRight.get();
  724. }
  725. HMesh BuiltinResources::getMesh(BuiltinMesh mesh) const
  726. {
  727. Path meshPath = FileSystem::getWorkingDirectoryPath();
  728. meshPath.append(EngineMeshFolder);
  729. switch (mesh)
  730. {
  731. case BuiltinMesh::Box:
  732. meshPath.append(MeshBoxFile);
  733. break;
  734. case BuiltinMesh::Sphere:
  735. meshPath.append(MeshSphereFile);
  736. break;
  737. case BuiltinMesh::Cone:
  738. meshPath.append(MeshConeFile);
  739. break;
  740. case BuiltinMesh::Quad:
  741. meshPath.append(MeshQuadFile);
  742. break;
  743. case BuiltinMesh::Disc:
  744. meshPath.append(MeshDiscFile);
  745. break;
  746. }
  747. return gResources().load<Mesh>(meshPath);
  748. }
  749. GUIMaterialInfo BuiltinResources::createSpriteTextMaterial() const
  750. {
  751. GUIMaterialInfo info;
  752. info.material = Material::create(mShaderSpriteText);
  753. info.mainTexture = info.material->getParamTexture("mainTexture");
  754. info.mainTexSampler = info.material->getParamSamplerState("mainTexSamp");
  755. info.tint = info.material->getParamVec4("tint");
  756. return info;
  757. }
  758. GUIMaterialInfo BuiltinResources::createSpriteImageMaterial() const
  759. {
  760. GUIMaterialInfo info;
  761. info.material = Material::create(mShaderSpriteImage);
  762. info.mainTexture = info.material->getParamTexture("mainTexture");
  763. info.mainTexSampler = info.material->getParamSamplerState("mainTexSamp");
  764. info.tint = info.material->getParamVec4("tint");
  765. return info;
  766. }
  767. GUIMaterialInfo BuiltinResources::createSpriteNonAlphaImageMaterial() const
  768. {
  769. GUIMaterialInfo info;
  770. info.material = Material::create(mShaderSpriteNonAlphaImage);
  771. info.mainTexture = info.material->getParamTexture("mainTexture");
  772. info.mainTexSampler = info.material->getParamSamplerState("mainTexSamp");
  773. info.tint = info.material->getParamVec4("tint");
  774. return info;
  775. }
  776. HMaterial BuiltinResources::createDummyMaterial() const
  777. {
  778. return Material::create(mShaderDummy);
  779. }
  780. void BuiltinResourcesHelper::importAssets(const Path& inputFolder, const Path& outputFolder, const ResourceManifestPtr& manifest)
  781. {
  782. if (!FileSystem::exists(inputFolder))
  783. return;
  784. UnorderedSet<Path> outputAssets;
  785. auto importResource = [&](const Path& filePath)
  786. {
  787. Path relativePath = filePath.getRelative(inputFolder);
  788. relativePath = outputFolder + relativePath;;
  789. relativePath.setFilename(relativePath.getWFilename() + L".asset");
  790. Path outputPath = FileSystem::getWorkingDirectoryPath() + relativePath;
  791. HResource resource;
  792. if (FileSystem::exists(outputPath))
  793. resource = gResources().load(outputPath);
  794. if (resource != nullptr)
  795. gImporter().reimport(resource, filePath);
  796. else
  797. resource = Importer::instance().import(filePath);
  798. if (resource != nullptr)
  799. {
  800. Resources::instance().save(resource, outputPath, true);
  801. manifest->registerResource(resource.getUUID(), outputPath);
  802. outputAssets.insert(relativePath);
  803. }
  804. return true;
  805. };
  806. Vector<Path> obsoleteAssets;
  807. auto gatherObsolete = [&](const Path& filePath)
  808. {
  809. auto iterFind = outputAssets.find(filePath);
  810. if (iterFind == outputAssets.end())
  811. obsoleteAssets.push_back(filePath);
  812. return true;
  813. };
  814. FileSystem::iterate(inputFolder, importResource);
  815. FileSystem::iterate(outputFolder, gatherObsolete);
  816. for (auto& obsoleteAssetPath : obsoleteAssets)
  817. FileSystem::remove(obsoleteAssetPath);
  818. }
  819. void BuiltinResourcesHelper::importFont(const Path& inputFile, const Path& outputFolder,
  820. UINT32 size, bool antialiasing, const ResourceManifestPtr& manifest)
  821. {
  822. ImportOptionsPtr fontImportOptions = Importer::instance().createImportOptions(inputFile);
  823. if (rtti_is_of_type<FontImportOptions>(fontImportOptions))
  824. {
  825. FontImportOptions* importOptions = static_cast<FontImportOptions*>(fontImportOptions.get());
  826. Vector<UINT32> fontSizes;
  827. fontSizes.push_back(size);
  828. importOptions->setFontSizes(fontSizes);
  829. importOptions->setAntialiasing(antialiasing);
  830. }
  831. else
  832. return;
  833. HFont font = Importer::instance().import<Font>(inputFile, fontImportOptions);
  834. WString fontName = inputFile.getWFilename();
  835. Path outputPath = FileSystem::getWorkingDirectoryPath() + outputFolder + fontName;
  836. outputPath.setFilename(outputPath.getWFilename() + L".asset");
  837. Resources::instance().save(font, outputPath, true);
  838. manifest->registerResource(font.getUUID(), outputPath);
  839. // Save font texture pages as well. TODO - Later maybe figure out a more automatic way to do this
  840. SPtr<const FontBitmap> fontData = font->getBitmap(size);
  841. Path texPageOutputPath = FileSystem::getWorkingDirectoryPath() + outputFolder;
  842. UINT32 pageIdx = 0;
  843. for (auto tex : fontData->texturePages)
  844. {
  845. texPageOutputPath.setFilename(fontName + L"_texpage_" + toWString(pageIdx) + L".asset");
  846. Resources::instance().save(tex, texPageOutputPath, true);
  847. manifest->registerResource(tex.getUUID(), texPageOutputPath);
  848. }
  849. }
  850. void BuiltinResourcesHelper::generateSpriteTextures(const Path& folder, const ResourceManifestPtr& manifest)
  851. {
  852. if (!FileSystem::exists(folder))
  853. return;
  854. Vector<Path> filesToProcess;
  855. auto gather = [&](const Path& filePath)
  856. {
  857. filesToProcess.push_back(filePath);
  858. return true;
  859. };
  860. FileSystem::iterate(folder, gather);
  861. for (auto& filePath : filesToProcess)
  862. {
  863. Path outputPath = FileSystem::getWorkingDirectoryPath() + filePath;
  864. outputPath.setFilename(L"sprite_" + outputPath.getWFilename());
  865. HTexture source = gResources().load<Texture>(filePath);
  866. if (source != nullptr)
  867. {
  868. HSpriteTexture spriteTex = SpriteTexture::create(source);
  869. Resources::instance().save(spriteTex, outputPath, true);
  870. manifest->registerResource(spriteTex.getUUID(), outputPath);
  871. }
  872. }
  873. }
  874. void BuiltinResourcesHelper::writeTimestamp(const Path& file)
  875. {
  876. DataStreamPtr fileStream = FileSystem::createAndOpenFile(file);
  877. time_t currentTime = std::time(nullptr);
  878. fileStream->write(&currentTime, sizeof(currentTime));
  879. fileStream->close();
  880. }
  881. bool BuiltinResourcesHelper::checkForModifications(const Path& folder, const Path& timeStampFile)
  882. {
  883. if (!FileSystem::exists(timeStampFile))
  884. return true;
  885. DataStreamPtr fileStream = FileSystem::openFile(timeStampFile);
  886. time_t lastUpdateTime = 0;
  887. fileStream->read(&lastUpdateTime, sizeof(lastUpdateTime));
  888. fileStream->close();
  889. bool upToDate = true;
  890. auto checkUpToDate = [&](const Path& filePath)
  891. {
  892. time_t fileLastModified = FileSystem::getLastModifiedTime(filePath);
  893. if (fileLastModified > lastUpdateTime)
  894. {
  895. upToDate = false;
  896. return false;
  897. }
  898. return true;
  899. };
  900. FileSystem::iterate(folder, checkUpToDate, checkUpToDate);
  901. return !upToDate;
  902. }
  903. }