BsBuiltinResources.cpp 46 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 "BsGpuProgramImportOptions.h"
  13. #include "BsImporter.h"
  14. #include "BsResources.h"
  15. #include "BsGpuProgram.h"
  16. #include "BsShader.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. namespace BansheeEngine
  28. {
  29. const WString BuiltinResources::DefaultFontFilename = L"arial.ttf";
  30. const UINT32 BuiltinResources::DefaultFontSize = 10;
  31. const Path BuiltinResources::DefaultSkinFolderRaw = L"..\\..\\..\\..\\Data\\Raw\\Engine\\Skin\\";
  32. const Path BuiltinResources::DefaultCursorFolderRaw = L"..\\..\\..\\..\\Data\\Raw\\Engine\\Cursors\\";
  33. const Path BuiltinResources::DefaultShaderFolderRaw = L"..\\..\\..\\..\\Data\\Raw\\Engine\\Shaders\\";
  34. const Path BuiltinResources::DefaultSkinFolder = L"..\\..\\..\\..\\Data\\Engine\\Skin\\";
  35. const Path BuiltinResources::DefaultCursorFolder = L"..\\..\\..\\..\\Data\\Engine\\Cursors\\";
  36. const Path BuiltinResources::DefaultShaderFolder = L"..\\..\\..\\..\\Data\\Engine\\Shaders\\";
  37. const WString BuiltinResources::HLSL11ShaderSubFolder = L"HLSL11/";
  38. const WString BuiltinResources::HLSL9ShaderSubFolder = L"HLSL9/";
  39. const WString BuiltinResources::GLSLShaderSubFolder = L"GLSL/";
  40. /************************************************************************/
  41. /* GUI TEXTURES */
  42. /************************************************************************/
  43. const WString BuiltinResources::WhiteTex = L"White.psd";
  44. const WString BuiltinResources::ButtonNormalTex = L"ButtonNormal.psd";
  45. const WString BuiltinResources::ButtonHoverTex = L"ButtonHover.psd";
  46. const WString BuiltinResources::ButtonActiveTex = L"ButtonActive.psd";
  47. const WString BuiltinResources::ToggleNormalTex = L"ToggleNormal.psd";
  48. const WString BuiltinResources::ToggleHoverTex = L"ToggleHover.psd";
  49. const WString BuiltinResources::ToggleActiveTex = L"ToggleActive.psd";
  50. const WString BuiltinResources::ToggleNormalOnTex = L"ToggleOnNormal.psd";
  51. const WString BuiltinResources::ToggleHoverOnTex = L"ToggleOnHover.psd";
  52. const WString BuiltinResources::ToggleActiveOnTex = L"ToggleOnActive.psd";
  53. const WString BuiltinResources::InputBoxNormalTex = L"InputBoxNormal.psd";
  54. const WString BuiltinResources::InputBoxHoverTex = L"InputBoxHover.psd";
  55. const WString BuiltinResources::InputBoxFocusedTex = L"InputBoxFocused.psd";
  56. const WString BuiltinResources::ScrollBarUpNormalTex = L"ScrollBarUpNormal.psd";
  57. const WString BuiltinResources::ScrollBarUpHoverTex = L"ScrollBarUpHover.psd";
  58. const WString BuiltinResources::ScrollBarUpActiveTex = L"ScrollBarUpActive.psd";
  59. const WString BuiltinResources::ScrollBarDownNormalTex = L"ScrollBarDownNormal.psd";
  60. const WString BuiltinResources::ScrollBarDownHoverTex = L"ScrollBarDownHover.psd";
  61. const WString BuiltinResources::ScrollBarDownActiveTex = L"ScrollBarDownActive.psd";
  62. const WString BuiltinResources::ScrollBarLeftNormalTex = L"ScrollBarLeftNormal.psd";
  63. const WString BuiltinResources::ScrollBarLeftHoverTex = L"ScrollBarLeftHover.psd";
  64. const WString BuiltinResources::ScrollBarLeftActiveTex = L"ScrollBarLeftActive.psd";
  65. const WString BuiltinResources::ScrollBarRightNormalTex = L"ScrollBarRightNormal.psd";
  66. const WString BuiltinResources::ScrollBarRightHoverTex = L"ScrollBarRightHover.psd";
  67. const WString BuiltinResources::ScrollBarRightActiveTex = L"ScrollBarRightActive.psd";
  68. const WString BuiltinResources::ScrollBarHandleHorzNormalTex = L"ScrollBarHorzHandleNormal.psd";
  69. const WString BuiltinResources::ScrollBarHandleHorzHoverTex = L"ScrollBarHorzHandleHover.psd";
  70. const WString BuiltinResources::ScrollBarHandleHorzActiveTex = L"ScrollBarHorzHandleActive.psd";
  71. const WString BuiltinResources::ScrollBarHandleVertNormalTex = L"ScrollBarVertHandleNormal.psd";
  72. const WString BuiltinResources::ScrollBarHandleVertHoverTex = L"ScrollBarVertHandleHover.psd";
  73. const WString BuiltinResources::ScrollBarHandleVertActiveTex = L"ScrollBarVertHandleActive.psd";
  74. const WString BuiltinResources::DropDownBtnNormalTex = L"DropDownNormal.psd";
  75. const WString BuiltinResources::DropDownBtnHoverTex = L"DropDownHover.psd";
  76. const WString BuiltinResources::DropDownBoxBgTex = L"DropDownBoxBg.psd";
  77. const WString BuiltinResources::DropDownBoxEntryNormalTex = L"DropDownButtonNormal.psd";
  78. const WString BuiltinResources::DropDownBoxEntryHoverTex = L"DropDownButtonHover.psd";
  79. const WString BuiltinResources::DropDownBoxBtnUpNormalTex = L"DropDownBoxBtnUpNormal.psd";
  80. const WString BuiltinResources::DropDownBoxBtnUpHoverTex = L"DropDownBoxBtnUpHover.psd";
  81. const WString BuiltinResources::DropDownBoxBtnDownNormalTex = L"DropDownBoxBtnDownNormal.psd";
  82. const WString BuiltinResources::DropDownBoxBtnDownHoverTex = L"DropDownBoxBtnDownHover.psd";
  83. const WString BuiltinResources::DropDownBoxEntryExpNormalTex = L"DropDownExpNormal.psd";
  84. const WString BuiltinResources::DropDownBoxEntryExpHoverTex = L"DropDownExpHover.psd";
  85. const WString BuiltinResources::DropDownSeparatorTex = L"DropDownSeparator.psd";
  86. const WString BuiltinResources::DropDownBoxBtnUpArrowTex = L"DropDownBoxBtnUpArrow.psd";
  87. const WString BuiltinResources::DropDownBoxBtnDownArrowTex = L"DropDownBoxBtnDownArrow.psd";
  88. const WString BuiltinResources::ScrollBarBgTex = L"ScrollBarBg.psd";
  89. /************************************************************************/
  90. /* CURSOR TEXTURES */
  91. /************************************************************************/
  92. const WString BuiltinResources::CursorArrowTex = L"Arrow.psd";
  93. const WString BuiltinResources::CursorArrowDragTex = L"ArrowDrag.psd";
  94. const WString BuiltinResources::CursorArrowLeftRightTex = L"ArrowLeftRight.psd";
  95. const WString BuiltinResources::CursorIBeamTex = L"IBeam.psd";
  96. const WString BuiltinResources::CursorDenyTex = L"Deny.psd";
  97. const WString BuiltinResources::CursorWaitTex = L"Wait.psd";
  98. const WString BuiltinResources::CursorSizeNESWTex = L"SizeNESW.psd";
  99. const WString BuiltinResources::CursorSizeNSTex = L"SizeNS.psd";
  100. const WString BuiltinResources::CursorSizeNWSETex = L"SizeNWSE.psd";
  101. const WString BuiltinResources::CursorSizeWETex = L"SizeWE.psd";
  102. const Vector2I BuiltinResources::CursorArrowHotspot = Vector2I(11, 8);
  103. const Vector2I BuiltinResources::CursorArrowDragHotspot = Vector2I(11, 8);
  104. const Vector2I BuiltinResources::CursorArrowLeftRightHotspot = Vector2I(9, 4);
  105. const Vector2I BuiltinResources::CursorIBeamHotspot = Vector2I(15, 15);
  106. const Vector2I BuiltinResources::CursorDenyHotspot = Vector2I(15, 15);
  107. const Vector2I BuiltinResources::CursorWaitHotspot = Vector2I(15, 15);
  108. const Vector2I BuiltinResources::CursorSizeNESWHotspot = Vector2I(15, 15);
  109. const Vector2I BuiltinResources::CursorSizeNSHotspot = Vector2I(15, 15);
  110. const Vector2I BuiltinResources::CursorSizeNWSEHotspot = Vector2I(15, 15);
  111. const Vector2I BuiltinResources::CursorSizeWEHotspot = Vector2I(15, 15);
  112. /************************************************************************/
  113. /* SHADERS */
  114. /************************************************************************/
  115. struct GpuProgramImportData
  116. {
  117. WString filename;
  118. String entryPoint;
  119. GpuProgramType type;
  120. GpuProgramProfile profile;
  121. String language;
  122. WString folder;
  123. };
  124. const WString BuiltinResources::ShaderSpriteTextVSFile = L"spriteTextVS.gpuprog";
  125. const WString BuiltinResources::ShaderSpriteTextPSFile = L"spriteTextPS.gpuprog";
  126. const WString BuiltinResources::ShaderSpriteImageVSFile = L"spriteImageVS.gpuprog";
  127. const WString BuiltinResources::ShaderSpriteImagePSFile = L"spriteImagePS.gpuprog";
  128. const WString BuiltinResources::ShaderDockOverlayVSFile = L"dockDropOverlayVS.gpuprog";
  129. const WString BuiltinResources::ShaderDockOverlayPSFile = L"dockDropOverlayPS.gpuprog";
  130. const WString BuiltinResources::ShaderDummyVSFile = L"dummyVS.gpuprog";
  131. const WString BuiltinResources::ShaderDummyPSFile = L"dummyPS.gpuprog";
  132. BuiltinResources::~BuiltinResources()
  133. {
  134. mCursorArrow = nullptr;
  135. mCursorArrowDrag = nullptr;
  136. mCursorArrowLeftRight = nullptr;
  137. mCursorIBeam = nullptr;
  138. mCursorDeny = nullptr;
  139. mCursorWait = nullptr;
  140. mCursorSizeNESW = nullptr;
  141. mCursorSizeNS = nullptr;
  142. mCursorSizeNWSE = nullptr;
  143. mCursorSizeWE = nullptr;
  144. }
  145. BuiltinResources::BuiltinResources(RenderSystemPlugin activeRSPlugin)
  146. :mRenderSystemPlugin(activeRSPlugin)
  147. {
  148. switch (activeRSPlugin)
  149. {
  150. case RenderSystemPlugin::DX11:
  151. mActiveShaderSubFolder = HLSL11ShaderSubFolder;
  152. mActiveRenderSystem = RenderAPIDX11;
  153. break;
  154. case RenderSystemPlugin::DX9:
  155. mActiveShaderSubFolder = HLSL9ShaderSubFolder;
  156. mActiveRenderSystem = RenderAPIDX9;
  157. break;
  158. case RenderSystemPlugin::OpenGL:
  159. mActiveShaderSubFolder = GLSLShaderSubFolder;
  160. mActiveRenderSystem = RenderAPIOpenGL;
  161. break;
  162. }
  163. preprocess();
  164. initSpriteTextShader();
  165. initSpriteImageShader();
  166. initSpriteNonAlphaImageShader();
  167. initDummyShader();
  168. mWhiteSpriteTexture = getSkinTexture(WhiteTex);
  169. /************************************************************************/
  170. /* CURSOR */
  171. /************************************************************************/
  172. HTexture cursorArrowTex = getCursorTexture(CursorArrowTex);
  173. HTexture cursorArrowDragTex = getCursorTexture(CursorArrowDragTex);
  174. HTexture cursorArrowLeftRightTex = getCursorTexture(CursorArrowLeftRightTex);
  175. HTexture cursorIBeamTex = getCursorTexture(CursorIBeamTex);
  176. HTexture cursorDenyTex = getCursorTexture(CursorDenyTex);
  177. HTexture cursorWaitTex = getCursorTexture(CursorWaitTex);
  178. HTexture cursorSizeNESWTex = getCursorTexture(CursorSizeNESWTex);
  179. HTexture cursorSizeNSTex = getCursorTexture(CursorSizeNSTex);
  180. HTexture cursorSizeNWSETex = getCursorTexture(CursorSizeNWSETex);
  181. HTexture cursorSizeWETex = getCursorTexture(CursorSizeWETex);
  182. mCursorArrow = cursorArrowTex->getProperties().allocateSubresourceBuffer(0);
  183. cursorArrowTex->readSubresource(gCoreAccessor(), 0, mCursorArrow);
  184. mCursorArrowDrag = cursorArrowDragTex->getProperties().allocateSubresourceBuffer(0);
  185. cursorArrowDragTex->readSubresource(gCoreAccessor(), 0, mCursorArrowDrag);
  186. mCursorArrowLeftRight = cursorArrowLeftRightTex->getProperties().allocateSubresourceBuffer(0);
  187. cursorArrowLeftRightTex->readSubresource(gCoreAccessor(), 0, mCursorArrowLeftRight);
  188. mCursorIBeam = cursorIBeamTex->getProperties().allocateSubresourceBuffer(0);
  189. cursorIBeamTex->readSubresource(gCoreAccessor(), 0, mCursorIBeam);
  190. mCursorDeny = cursorDenyTex->getProperties().allocateSubresourceBuffer(0);
  191. cursorDenyTex->readSubresource(gCoreAccessor(), 0, mCursorDeny);
  192. mCursorWait = cursorWaitTex->getProperties().allocateSubresourceBuffer(0);
  193. cursorWaitTex->readSubresource(gCoreAccessor(), 0, mCursorWait);
  194. mCursorSizeNESW = cursorSizeNESWTex->getProperties().allocateSubresourceBuffer(0);
  195. cursorSizeNESWTex->readSubresource(gCoreAccessor(), 0, mCursorSizeNESW);
  196. mCursorSizeNS = cursorSizeNSTex->getProperties().allocateSubresourceBuffer(0);
  197. cursorSizeNSTex->readSubresource(gCoreAccessor(), 0, mCursorSizeNS);
  198. mCursorSizeNWSE = cursorSizeNWSETex->getProperties().allocateSubresourceBuffer(0);
  199. cursorSizeNWSETex->readSubresource(gCoreAccessor(), 0, mCursorSizeNWSE);
  200. mCursorSizeWE = cursorSizeWETex->getProperties().allocateSubresourceBuffer(0);
  201. cursorSizeWETex->readSubresource(gCoreAccessor(), 0, mCursorSizeWE);
  202. gCoreAccessor().submitToCoreThread(true);
  203. Path fontPath = FileSystem::getWorkingDirectoryPath();
  204. fontPath.append(DefaultSkinFolder);
  205. fontPath.append(DefaultFontFilename + L".asset");
  206. HFont font = Resources::instance().load<Font>(fontPath);
  207. // Label
  208. GUIElementStyle labelStyle;
  209. labelStyle.font = font;
  210. labelStyle.fontSize = DefaultFontSize;
  211. labelStyle.fixedWidth = false;
  212. labelStyle.fixedHeight = true;
  213. labelStyle.height = 11;
  214. labelStyle.minWidth = 10;
  215. mSkin.setStyle(GUILabel::getGUITypeName(), labelStyle);
  216. // Button
  217. GUIElementStyle buttonStyle;
  218. buttonStyle.normal.texture = getSkinTexture(ButtonNormalTex);
  219. buttonStyle.hover.texture = getSkinTexture(ButtonHoverTex);
  220. buttonStyle.active.texture = getSkinTexture(ButtonActiveTex);
  221. buttonStyle.border.left = 6;
  222. buttonStyle.border.right = 6;
  223. buttonStyle.border.top = 6;
  224. buttonStyle.border.bottom = 6;
  225. buttonStyle.contentOffset.left = 3;
  226. buttonStyle.contentOffset.right = 3;
  227. buttonStyle.fixedHeight = true;
  228. buttonStyle.height = 15;
  229. buttonStyle.minWidth = 50;
  230. buttonStyle.font = font;
  231. buttonStyle.fontSize = DefaultFontSize;
  232. buttonStyle.textHorzAlign = THA_Center;
  233. buttonStyle.textVertAlign = TVA_Center;
  234. mSkin.setStyle(GUIButton::getGUITypeName(), buttonStyle);
  235. // Toggle
  236. GUIElementStyle toggleStyle;
  237. toggleStyle.normal.texture = getSkinTexture(ToggleNormalTex);
  238. toggleStyle.hover.texture = getSkinTexture(ToggleHoverTex);
  239. toggleStyle.active.texture = getSkinTexture(ToggleActiveTex);
  240. toggleStyle.normalOn.texture = getSkinTexture(ToggleNormalOnTex);
  241. toggleStyle.hoverOn.texture = getSkinTexture(ToggleHoverOnTex);
  242. toggleStyle.activeOn.texture = getSkinTexture(ToggleActiveOnTex);
  243. toggleStyle.fixedHeight = true;
  244. toggleStyle.fixedWidth = true;
  245. toggleStyle.height = 15;
  246. toggleStyle.width = 15;
  247. mSkin.setStyle(GUIToggle::getGUITypeName(), toggleStyle);
  248. // Input box
  249. GUIElementStyle inputBoxStyle;
  250. inputBoxStyle.normal.texture = getSkinTexture(InputBoxNormalTex);
  251. inputBoxStyle.hover.texture = getSkinTexture(InputBoxHoverTex);
  252. inputBoxStyle.focused.texture = getSkinTexture(InputBoxFocusedTex);
  253. inputBoxStyle.active.texture = inputBoxStyle.normal.texture;
  254. inputBoxStyle.border.left = 1;
  255. inputBoxStyle.border.right = 1;
  256. inputBoxStyle.border.top = 1;
  257. inputBoxStyle.border.bottom = 1;
  258. inputBoxStyle.contentOffset.left = 3;
  259. inputBoxStyle.contentOffset.right = 3;
  260. inputBoxStyle.contentOffset.top = 2;
  261. inputBoxStyle.contentOffset.bottom = 2;
  262. inputBoxStyle.fixedHeight = true;
  263. inputBoxStyle.height = 15;
  264. inputBoxStyle.minWidth = 10;
  265. inputBoxStyle.font = font;
  266. inputBoxStyle.fontSize = DefaultFontSize;
  267. inputBoxStyle.textHorzAlign = THA_Left;
  268. inputBoxStyle.textVertAlign = TVA_Top;
  269. mSkin.setStyle(GUIInputBox::getGUITypeName(), inputBoxStyle);
  270. /************************************************************************/
  271. /* SCROLL BAR */
  272. /************************************************************************/
  273. // Up button
  274. GUIElementStyle scrollUpBtnStyle;
  275. scrollUpBtnStyle.normal.texture = getSkinTexture(ScrollBarUpNormalTex);
  276. scrollUpBtnStyle.hover.texture = getSkinTexture(ScrollBarUpHoverTex);
  277. scrollUpBtnStyle.active.texture = getSkinTexture(ScrollBarUpActiveTex);
  278. scrollUpBtnStyle.fixedHeight = true;
  279. scrollUpBtnStyle.fixedWidth = true;
  280. scrollUpBtnStyle.height = 4;
  281. scrollUpBtnStyle.width = 8;
  282. mSkin.setStyle("ScrollUpBtn", scrollUpBtnStyle);
  283. // Down button
  284. GUIElementStyle scrollDownBtnStyle;
  285. scrollDownBtnStyle.normal.texture = getSkinTexture(ScrollBarDownNormalTex);
  286. scrollDownBtnStyle.hover.texture = getSkinTexture(ScrollBarDownHoverTex);
  287. scrollDownBtnStyle.active.texture = getSkinTexture(ScrollBarDownActiveTex);
  288. scrollDownBtnStyle.fixedHeight = true;
  289. scrollDownBtnStyle.fixedWidth = true;
  290. scrollDownBtnStyle.height = 4;
  291. scrollDownBtnStyle.width = 8;
  292. mSkin.setStyle("ScrollDownBtn", scrollDownBtnStyle);
  293. // Left button
  294. GUIElementStyle scrollLeftBtnStyle;
  295. scrollLeftBtnStyle.normal.texture = getSkinTexture(ScrollBarLeftNormalTex);
  296. scrollLeftBtnStyle.hover.texture = getSkinTexture(ScrollBarLeftHoverTex);
  297. scrollLeftBtnStyle.active.texture = getSkinTexture(ScrollBarLeftActiveTex);
  298. scrollLeftBtnStyle.fixedHeight = true;
  299. scrollLeftBtnStyle.fixedWidth = true;
  300. scrollLeftBtnStyle.height = 8;
  301. scrollLeftBtnStyle.width = 4;
  302. mSkin.setStyle("ScrollLeftBtn", scrollLeftBtnStyle);
  303. // Right button
  304. GUIElementStyle scrollRightBtnStyle;
  305. scrollRightBtnStyle.normal.texture = getSkinTexture(ScrollBarRightNormalTex);
  306. scrollRightBtnStyle.hover.texture = getSkinTexture(ScrollBarRightHoverTex);
  307. scrollRightBtnStyle.active.texture = getSkinTexture(ScrollBarRightActiveTex);
  308. scrollRightBtnStyle.fixedHeight = true;
  309. scrollRightBtnStyle.fixedWidth = true;
  310. scrollRightBtnStyle.height = 8;
  311. scrollRightBtnStyle.width = 4;
  312. mSkin.setStyle("ScrollRightBtn", scrollRightBtnStyle);
  313. // Horizontal handle
  314. GUIElementStyle scrollBarHorzBtnStyle;
  315. scrollBarHorzBtnStyle.normal.texture = getSkinTexture(ScrollBarHandleHorzNormalTex);
  316. scrollBarHorzBtnStyle.hover.texture = getSkinTexture(ScrollBarHandleHorzHoverTex);
  317. scrollBarHorzBtnStyle.active.texture = getSkinTexture(ScrollBarHandleHorzActiveTex);
  318. scrollBarHorzBtnStyle.fixedHeight = true;
  319. scrollBarHorzBtnStyle.fixedWidth = true;
  320. scrollBarHorzBtnStyle.height = 6;
  321. scrollBarHorzBtnStyle.width = 4;
  322. mSkin.setStyle("ScrollBarHorzBtn", scrollBarHorzBtnStyle);
  323. // Vertical handle
  324. GUIElementStyle scrollBarVertBtnStyle;
  325. scrollBarVertBtnStyle.normal.texture = getSkinTexture(ScrollBarHandleVertNormalTex);
  326. scrollBarVertBtnStyle.hover.texture = getSkinTexture(ScrollBarHandleVertHoverTex);
  327. scrollBarVertBtnStyle.active.texture = getSkinTexture(ScrollBarHandleVertActiveTex);
  328. scrollBarVertBtnStyle.fixedHeight = true;
  329. scrollBarVertBtnStyle.fixedWidth = true;
  330. scrollBarVertBtnStyle.height = 4;
  331. scrollBarVertBtnStyle.width = 6;
  332. mSkin.setStyle("ScrollBarVertBtn", scrollBarVertBtnStyle);
  333. HSpriteTexture scrollBarBgPtr = getSkinTexture(ScrollBarBgTex);
  334. // Vertical scroll bar
  335. GUIElementStyle vertScrollBarStyle;
  336. vertScrollBarStyle.normal.texture = scrollBarBgPtr;
  337. vertScrollBarStyle.hover.texture = scrollBarBgPtr;
  338. vertScrollBarStyle.active.texture = scrollBarBgPtr;
  339. vertScrollBarStyle.fixedHeight = false;
  340. vertScrollBarStyle.fixedWidth = true;
  341. vertScrollBarStyle.minHeight = 16;
  342. vertScrollBarStyle.width = 8;
  343. mSkin.setStyle("ScrollBarVert", vertScrollBarStyle);
  344. // Horizontal scroll bar
  345. GUIElementStyle horzScrollBarStyle;
  346. horzScrollBarStyle.normal.texture = scrollBarBgPtr;
  347. horzScrollBarStyle.hover.texture = scrollBarBgPtr;
  348. horzScrollBarStyle.active.texture = scrollBarBgPtr;
  349. horzScrollBarStyle.fixedHeight = true;
  350. horzScrollBarStyle.fixedWidth = false;
  351. horzScrollBarStyle.minWidth = 16;
  352. horzScrollBarStyle.height = 8;
  353. mSkin.setStyle("ScrollBarHorz", horzScrollBarStyle);
  354. /************************************************************************/
  355. /* DROP DOWN BOX */
  356. /************************************************************************/
  357. // ListBox button
  358. GUIElementStyle dropDownListStyle;
  359. dropDownListStyle.normal.texture = getSkinTexture(DropDownBtnNormalTex);
  360. dropDownListStyle.hover.texture = getSkinTexture(DropDownBtnHoverTex);
  361. dropDownListStyle.active.texture = dropDownListStyle.hover.texture;
  362. dropDownListStyle.normalOn.texture = dropDownListStyle.hover.texture;
  363. dropDownListStyle.hoverOn.texture = dropDownListStyle.hover.texture;
  364. dropDownListStyle.activeOn.texture = dropDownListStyle.hover.texture;
  365. dropDownListStyle.fixedHeight = true;
  366. dropDownListStyle.fixedWidth = false;
  367. dropDownListStyle.height = 13;
  368. dropDownListStyle.width = 30;
  369. dropDownListStyle.contentOffset.left = 3;
  370. dropDownListStyle.contentOffset.right = 11;
  371. dropDownListStyle.contentOffset.top = 1;
  372. dropDownListStyle.contentOffset.bottom = 1;
  373. dropDownListStyle.border.left = 1;
  374. dropDownListStyle.border.right = 10;
  375. dropDownListStyle.border.top = 1;
  376. dropDownListStyle.border.bottom = 1;
  377. dropDownListStyle.font = font;
  378. dropDownListStyle.fontSize = DefaultFontSize;
  379. dropDownListStyle.textHorzAlign = THA_Left;
  380. dropDownListStyle.textVertAlign = TVA_Top;
  381. mSkin.setStyle("ListBox", dropDownListStyle);
  382. // DropDown scroll up button arrow
  383. GUIElementStyle dropDownScrollUpBtnArrowStyle;
  384. dropDownScrollUpBtnArrowStyle.normal.texture = getSkinTexture(DropDownBoxBtnUpArrowTex);
  385. dropDownScrollUpBtnArrowStyle.hover.texture = dropDownScrollUpBtnArrowStyle.normal.texture;
  386. dropDownScrollUpBtnArrowStyle.active.texture = dropDownScrollUpBtnArrowStyle.hover.texture;
  387. dropDownScrollUpBtnArrowStyle.fixedHeight = true;
  388. dropDownScrollUpBtnArrowStyle.fixedWidth = false;
  389. dropDownScrollUpBtnArrowStyle.height = 7;
  390. dropDownScrollUpBtnArrowStyle.width = 30;
  391. dropDownScrollUpBtnArrowStyle.border.left = 1;
  392. dropDownScrollUpBtnArrowStyle.border.right = 1;
  393. dropDownScrollUpBtnArrowStyle.border.top = 1;
  394. dropDownScrollUpBtnArrowStyle.border.bottom = 1;
  395. mSkin.setStyle("ListBoxScrollUpBtnArrow", dropDownScrollUpBtnArrowStyle);
  396. mSkin.setStyle("MenuBarScrollUpBtnArrow", dropDownScrollUpBtnArrowStyle);
  397. mSkin.setStyle("ContextMenuScrollUpBtnArrow", dropDownScrollUpBtnArrowStyle);
  398. // DropDown scroll up button
  399. GUIElementStyle dropDownScrollUpBtnStyle;
  400. dropDownScrollUpBtnStyle.normal.texture = getSkinTexture(DropDownBoxBtnUpNormalTex);
  401. dropDownScrollUpBtnStyle.hover.texture = getSkinTexture(DropDownBoxBtnUpHoverTex);
  402. dropDownScrollUpBtnStyle.active.texture = dropDownScrollUpBtnStyle.hover.texture;
  403. dropDownScrollUpBtnStyle.fixedHeight = true;
  404. dropDownScrollUpBtnStyle.fixedWidth = false;
  405. dropDownScrollUpBtnStyle.height = 7;
  406. dropDownScrollUpBtnStyle.width = 30;
  407. dropDownScrollUpBtnStyle.border.left = 1;
  408. dropDownScrollUpBtnStyle.border.right = 1;
  409. dropDownScrollUpBtnStyle.border.top = 1;
  410. dropDownScrollUpBtnStyle.border.bottom = 1;
  411. mSkin.setStyle("ListBoxScrollUpBtn", dropDownScrollUpBtnStyle);
  412. mSkin.setStyle("MenuBarScrollUpBtn", dropDownScrollUpBtnStyle);
  413. mSkin.setStyle("ContextMenuScrollUpBtn", dropDownScrollUpBtnStyle);
  414. // DropDown scroll down button arrow
  415. GUIElementStyle dropDownScrollDownBtnArrowStyle;
  416. dropDownScrollDownBtnArrowStyle.normal.texture = getSkinTexture(DropDownBoxBtnDownArrowTex);
  417. dropDownScrollDownBtnArrowStyle.hover.texture = dropDownScrollDownBtnArrowStyle.normal.texture;
  418. dropDownScrollDownBtnArrowStyle.active.texture = dropDownScrollDownBtnArrowStyle.hover.texture;
  419. dropDownScrollDownBtnArrowStyle.fixedHeight = true;
  420. dropDownScrollDownBtnArrowStyle.fixedWidth = false;
  421. dropDownScrollDownBtnArrowStyle.height = 7;
  422. dropDownScrollDownBtnArrowStyle.width = 30;
  423. dropDownScrollDownBtnArrowStyle.border.left = 1;
  424. dropDownScrollDownBtnArrowStyle.border.right = 1;
  425. dropDownScrollDownBtnArrowStyle.border.top = 1;
  426. dropDownScrollDownBtnArrowStyle.border.bottom = 1;
  427. mSkin.setStyle("ListBoxScrollDownBtnArrow", dropDownScrollDownBtnArrowStyle);
  428. mSkin.setStyle("MenuBarScrollDownBtnArrow", dropDownScrollDownBtnArrowStyle);
  429. mSkin.setStyle("ContextMenuScrollDownBtnArrow", dropDownScrollDownBtnArrowStyle);
  430. // DropDown scroll down button
  431. GUIElementStyle dropDownScrollDownBtnStyle;
  432. dropDownScrollDownBtnStyle.normal.texture = getSkinTexture(DropDownBoxBtnDownNormalTex);
  433. dropDownScrollDownBtnStyle.hover.texture = getSkinTexture(DropDownBoxBtnDownHoverTex);
  434. dropDownScrollDownBtnStyle.active.texture = dropDownScrollDownBtnStyle.hover.texture;
  435. dropDownScrollDownBtnStyle.fixedHeight = true;
  436. dropDownScrollDownBtnStyle.fixedWidth = false;
  437. dropDownScrollDownBtnStyle.height = 7;
  438. dropDownScrollDownBtnStyle.width = 30;
  439. dropDownScrollDownBtnStyle.border.left = 1;
  440. dropDownScrollDownBtnStyle.border.right = 1;
  441. dropDownScrollDownBtnStyle.border.top = 1;
  442. dropDownScrollDownBtnStyle.border.bottom = 1;
  443. mSkin.setStyle("ListBoxScrollDownBtn", dropDownScrollDownBtnStyle);
  444. mSkin.setStyle("MenuBarScrollDownBtn", dropDownScrollDownBtnStyle);
  445. mSkin.setStyle("ContextMenuScrollDownBtn", dropDownScrollDownBtnStyle);
  446. // DropDown entry button
  447. GUIElementStyle dropDownEntryBtnStyle;
  448. dropDownEntryBtnStyle.normal.texture = getSkinTexture(DropDownBoxEntryNormalTex);
  449. dropDownEntryBtnStyle.hover.texture = getSkinTexture(DropDownBoxEntryHoverTex);
  450. dropDownEntryBtnStyle.active.texture = dropDownEntryBtnStyle.hover.texture;
  451. dropDownEntryBtnStyle.normalOn.texture = dropDownEntryBtnStyle.hover.texture;
  452. dropDownEntryBtnStyle.hoverOn.texture = dropDownEntryBtnStyle.hover.texture;
  453. dropDownEntryBtnStyle.activeOn.texture = dropDownEntryBtnStyle.hover.texture;
  454. dropDownEntryBtnStyle.fixedHeight = true;
  455. dropDownEntryBtnStyle.fixedWidth = false;
  456. dropDownEntryBtnStyle.height = 14;
  457. dropDownEntryBtnStyle.width = 30;
  458. dropDownEntryBtnStyle.border.left = 1;
  459. dropDownEntryBtnStyle.border.right = 1;
  460. dropDownEntryBtnStyle.border.top = 1;
  461. dropDownEntryBtnStyle.border.bottom = 1;
  462. dropDownEntryBtnStyle.font = font;
  463. dropDownEntryBtnStyle.fontSize = DefaultFontSize;
  464. dropDownEntryBtnStyle.textHorzAlign = THA_Left;
  465. dropDownEntryBtnStyle.textVertAlign = TVA_Top;
  466. mSkin.setStyle(GUIDropDownContent::ENTRY_STYLE_TYPE, dropDownEntryBtnStyle);
  467. // DropDown entry button with expand
  468. GUIElementStyle dropDownEntryExpBtnStyle;
  469. dropDownEntryExpBtnStyle.normal.texture = getSkinTexture(DropDownBoxEntryExpNormalTex);
  470. dropDownEntryExpBtnStyle.hover.texture = getSkinTexture(DropDownBoxEntryExpHoverTex);
  471. dropDownEntryExpBtnStyle.active.texture = dropDownEntryExpBtnStyle.hover.texture;
  472. dropDownEntryExpBtnStyle.normalOn.texture = dropDownEntryExpBtnStyle.hover.texture;
  473. dropDownEntryExpBtnStyle.hoverOn.texture = dropDownEntryExpBtnStyle.hover.texture;
  474. dropDownEntryExpBtnStyle.activeOn.texture = dropDownEntryExpBtnStyle.hover.texture;
  475. dropDownEntryExpBtnStyle.fixedHeight = true;
  476. dropDownEntryExpBtnStyle.fixedWidth = false;
  477. dropDownEntryExpBtnStyle.height = 14;
  478. dropDownEntryExpBtnStyle.width = 30;
  479. dropDownEntryExpBtnStyle.border.left = 1;
  480. dropDownEntryExpBtnStyle.border.right = 6;
  481. dropDownEntryExpBtnStyle.border.top = 1;
  482. dropDownEntryExpBtnStyle.border.bottom = 1;
  483. dropDownEntryExpBtnStyle.font = font;
  484. dropDownEntryExpBtnStyle.fontSize = DefaultFontSize;
  485. dropDownEntryExpBtnStyle.textHorzAlign = THA_Left;
  486. dropDownEntryExpBtnStyle.textVertAlign = TVA_Top;
  487. mSkin.setStyle(GUIDropDownContent::ENTRY_EXP_STYLE_TYPE, dropDownEntryExpBtnStyle);
  488. // Drop down separator
  489. GUIElementStyle dropDownSeparatorStyle;
  490. dropDownSeparatorStyle.normal.texture = getSkinTexture(DropDownSeparatorTex);
  491. dropDownSeparatorStyle.fixedHeight = true;
  492. dropDownSeparatorStyle.fixedWidth = false;
  493. dropDownSeparatorStyle.height = 3;
  494. dropDownSeparatorStyle.width = 30;
  495. dropDownSeparatorStyle.border.left = 1;
  496. dropDownSeparatorStyle.border.right = 1;
  497. dropDownSeparatorStyle.border.top = 1;
  498. dropDownSeparatorStyle.border.bottom = 1;
  499. mSkin.setStyle(GUIDropDownContent::SEPARATOR_STYLE_TYPE, dropDownSeparatorStyle);
  500. // Drop down content
  501. GUIElementStyle dropDownContentStyle;
  502. dropDownContentStyle.minWidth = 50;
  503. dropDownContentStyle.minHeight = 20;
  504. dropDownContentStyle.subStyles[GUIDropDownContent::ENTRY_STYLE_TYPE] = GUIDropDownContent::ENTRY_STYLE_TYPE;
  505. dropDownContentStyle.subStyles[GUIDropDownContent::ENTRY_EXP_STYLE_TYPE] = GUIDropDownContent::ENTRY_EXP_STYLE_TYPE;
  506. dropDownContentStyle.subStyles[GUIDropDownContent::SEPARATOR_STYLE_TYPE] = GUIDropDownContent::SEPARATOR_STYLE_TYPE;
  507. mSkin.setStyle("ListBoxContent", dropDownContentStyle);
  508. mSkin.setStyle("MenuBarContent", dropDownContentStyle);
  509. mSkin.setStyle("ContextMenuContent", dropDownContentStyle);
  510. // DropDown box frame
  511. GUIElementStyle dropDownBoxStyle;
  512. dropDownBoxStyle.normal.texture = getSkinTexture(DropDownBoxBgTex);
  513. dropDownBoxStyle.hover.texture = dropDownEntryBtnStyle.normal.texture;
  514. dropDownBoxStyle.active.texture = dropDownEntryBtnStyle.hover.texture;
  515. dropDownBoxStyle.fixedHeight = false;
  516. dropDownBoxStyle.fixedWidth = false;
  517. dropDownBoxStyle.border.left = 1;
  518. dropDownBoxStyle.border.right = 1;
  519. dropDownBoxStyle.border.top = 1;
  520. dropDownBoxStyle.border.bottom = 1;
  521. dropDownBoxStyle.margins.left = 1;
  522. dropDownBoxStyle.margins.right = 1;
  523. dropDownBoxStyle.margins.top = 1;
  524. dropDownBoxStyle.margins.bottom = 1;
  525. mSkin.setStyle("ListBoxFrame", dropDownBoxStyle);
  526. mSkin.setStyle("MenuBarFrame", dropDownBoxStyle);
  527. mSkin.setStyle("ContextMenuFrame", dropDownBoxStyle);
  528. /************************************************************************/
  529. /* OTHER */
  530. /************************************************************************/
  531. // Right-aligned label
  532. GUIElementStyle rightAlignedLabelStyle;
  533. rightAlignedLabelStyle.font = font;
  534. rightAlignedLabelStyle.fontSize = DefaultFontSize;
  535. rightAlignedLabelStyle.fixedWidth = false;
  536. rightAlignedLabelStyle.fixedHeight = true;
  537. rightAlignedLabelStyle.height = 11;
  538. rightAlignedLabelStyle.minWidth = 10;
  539. rightAlignedLabelStyle.textHorzAlign = THA_Right;
  540. mSkin.setStyle("RightAlignedLabel", rightAlignedLabelStyle);
  541. }
  542. void BuiltinResources::preprocess()
  543. {
  544. static const WString GUI_TEXTURES[] = { WhiteTex, ButtonNormalTex, ButtonHoverTex, ButtonActiveTex, ToggleNormalTex,
  545. ToggleHoverTex, ToggleActiveTex, ToggleNormalOnTex, ToggleHoverOnTex, ToggleActiveOnTex, InputBoxNormalTex,
  546. InputBoxHoverTex, InputBoxFocusedTex, ScrollBarUpNormalTex, ScrollBarUpHoverTex, ScrollBarUpActiveTex,
  547. ScrollBarDownNormalTex, ScrollBarDownHoverTex, ScrollBarDownActiveTex, ScrollBarLeftNormalTex,
  548. ScrollBarLeftHoverTex, ScrollBarLeftActiveTex, ScrollBarRightNormalTex, ScrollBarRightHoverTex,
  549. ScrollBarRightActiveTex, ScrollBarHandleHorzNormalTex, ScrollBarHandleHorzHoverTex, ScrollBarHandleHorzActiveTex,
  550. ScrollBarHandleVertNormalTex, ScrollBarHandleVertHoverTex, ScrollBarHandleVertActiveTex, DropDownBtnNormalTex,
  551. DropDownBtnHoverTex, DropDownBoxBgTex, DropDownBoxEntryNormalTex, DropDownBoxEntryHoverTex, DropDownBoxBtnUpNormalTex,
  552. DropDownBoxBtnUpHoverTex, DropDownBoxBtnDownNormalTex, DropDownBoxBtnDownHoverTex, DropDownBoxEntryExpNormalTex, DropDownBoxEntryExpHoverTex,
  553. DropDownSeparatorTex, DropDownBoxBtnUpArrowTex, DropDownBoxBtnDownArrowTex };
  554. static const WString CURSOR_TEXTURES[] = { CursorArrowTex, CursorArrowDragTex, CursorArrowLeftRightTex, CursorIBeamTex,
  555. CursorDenyTex, CursorWaitTex, CursorSizeNESWTex, CursorSizeNSTex, CursorSizeNWSETex, CursorSizeWETex };
  556. static const GpuProgramImportData GPU_PROGRAM_IMPORT_DATA[] =
  557. {
  558. { ShaderSpriteTextVSFile, "vs_main", GPT_VERTEX_PROGRAM, GPP_VS_4_0, "hlsl", HLSL11ShaderSubFolder},
  559. { ShaderSpriteTextPSFile, "ps_main", GPT_FRAGMENT_PROGRAM, GPP_FS_4_0, "hlsl", HLSL11ShaderSubFolder },
  560. { ShaderSpriteImageVSFile, "vs_main", GPT_VERTEX_PROGRAM, GPP_VS_4_0, "hlsl", HLSL11ShaderSubFolder },
  561. { ShaderSpriteImagePSFile, "ps_main", GPT_FRAGMENT_PROGRAM, GPP_FS_4_0, "hlsl", HLSL11ShaderSubFolder },
  562. { ShaderDummyVSFile, "vs_main", GPT_VERTEX_PROGRAM, GPP_VS_4_0, "hlsl", HLSL11ShaderSubFolder },
  563. { ShaderDummyPSFile, "ps_main", GPT_FRAGMENT_PROGRAM, GPP_FS_4_0, "hlsl", HLSL11ShaderSubFolder },
  564. { ShaderSpriteTextVSFile, "vs_main", GPT_VERTEX_PROGRAM, GPP_VS_2_0, "hlsl", HLSL9ShaderSubFolder },
  565. { ShaderSpriteTextPSFile, "ps_main", GPT_FRAGMENT_PROGRAM, GPP_FS_2_0, "hlsl", HLSL9ShaderSubFolder },
  566. { ShaderSpriteImageVSFile, "vs_main", GPT_VERTEX_PROGRAM, GPP_VS_2_0, "hlsl", HLSL9ShaderSubFolder },
  567. { ShaderSpriteImagePSFile, "ps_main", GPT_FRAGMENT_PROGRAM, GPP_FS_2_0, "hlsl", HLSL9ShaderSubFolder },
  568. { ShaderDummyVSFile, "vs_main", GPT_VERTEX_PROGRAM, GPP_VS_2_0, "hlsl", HLSL9ShaderSubFolder },
  569. { ShaderDummyPSFile, "ps_main", GPT_FRAGMENT_PROGRAM, GPP_FS_2_0, "hlsl", HLSL9ShaderSubFolder },
  570. { ShaderSpriteTextVSFile, "main", GPT_VERTEX_PROGRAM, GPP_VS_4_0, "glsl", GLSLShaderSubFolder },
  571. { ShaderSpriteTextPSFile, "main", GPT_FRAGMENT_PROGRAM, GPP_FS_4_0, "glsl", GLSLShaderSubFolder },
  572. { ShaderSpriteImageVSFile, "main", GPT_VERTEX_PROGRAM, GPP_VS_4_0, "glsl", GLSLShaderSubFolder },
  573. { ShaderSpriteImagePSFile, "main", GPT_FRAGMENT_PROGRAM, GPP_FS_4_0, "glsl", GLSLShaderSubFolder },
  574. { ShaderDummyVSFile, "main", GPT_VERTEX_PROGRAM, GPP_VS_4_0, "glsl", GLSLShaderSubFolder },
  575. { ShaderDummyPSFile, "main", GPT_FRAGMENT_PROGRAM, GPP_FS_4_0, "glsl", GLSLShaderSubFolder },
  576. };
  577. if (FileSystem::exists(DefaultCursorFolderRaw))
  578. {
  579. FileSystem::remove(DefaultCursorFolder);
  580. for (auto& tex : CURSOR_TEXTURES)
  581. importCursorTexture(tex);
  582. }
  583. if (FileSystem::exists(DefaultSkinFolderRaw))
  584. {
  585. FileSystem::remove(DefaultSkinFolder);
  586. for (auto& tex : GUI_TEXTURES)
  587. importSkinTexture(tex);
  588. {
  589. Path fontPath = FileSystem::getWorkingDirectoryPath();
  590. fontPath.append(DefaultSkinFolderRaw);
  591. fontPath.append(DefaultFontFilename);
  592. ImportOptionsPtr fontImportOptions = Importer::instance().createImportOptions(fontPath);
  593. if (rtti_is_of_type<FontImportOptions>(fontImportOptions))
  594. {
  595. FontImportOptions* importOptions = static_cast<FontImportOptions*>(fontImportOptions.get());
  596. Vector<UINT32> fontSizes;
  597. fontSizes.push_back(DefaultFontSize);
  598. importOptions->setFontSizes(fontSizes);
  599. importOptions->setAntialiasing(false);
  600. }
  601. HFont font = Importer::instance().import<Font>(fontPath, fontImportOptions);
  602. Path outputPath = FileSystem::getWorkingDirectoryPath();
  603. outputPath.append(DefaultSkinFolder);
  604. outputPath.append(DefaultFontFilename + L".asset");
  605. Resources::instance().save(font, outputPath, true);
  606. // Save font texture pages as well. TODO - Later maybe figure out a more automatic way to do this
  607. const FontData* fontData = font->getFontDataForSize(DefaultFontSize);
  608. Path texPageOutputPath = FileSystem::getWorkingDirectoryPath();
  609. texPageOutputPath.append(DefaultSkinFolder);
  610. UINT32 pageIdx = 0;
  611. for (auto tex : fontData->texturePages)
  612. {
  613. texPageOutputPath.setFilename(DefaultFontFilename + L"_texpage_" + toWString(pageIdx) + L".asset");
  614. Resources::instance().save(tex, texPageOutputPath, true);
  615. }
  616. }
  617. }
  618. if (FileSystem::exists(DefaultShaderFolderRaw))
  619. {
  620. Path shaderFolder = DefaultShaderFolder;
  621. shaderFolder.append(mActiveShaderSubFolder);
  622. FileSystem::remove(shaderFolder);
  623. for (auto& importData : GPU_PROGRAM_IMPORT_DATA)
  624. {
  625. if (importData.folder != mActiveShaderSubFolder)
  626. continue;
  627. Path gpuProgInputLoc = DefaultShaderFolderRaw;
  628. gpuProgInputLoc.append(importData.folder);
  629. gpuProgInputLoc.append(importData.filename);
  630. Path gpuProgOutputLoc = DefaultShaderFolder;
  631. gpuProgOutputLoc.append(importData.folder);
  632. gpuProgOutputLoc.append(importData.filename + L".asset");
  633. ImportOptionsPtr gpuProgImportOptions = Importer::instance().createImportOptions(gpuProgInputLoc);
  634. if (rtti_is_of_type<GpuProgramImportOptions>(gpuProgImportOptions))
  635. {
  636. GpuProgramImportOptions* importOptions = static_cast<GpuProgramImportOptions*>(gpuProgImportOptions.get());
  637. importOptions->setEntryPoint(importData.entryPoint);
  638. importOptions->setLanguage(importData.language);
  639. importOptions->setProfile(importData.profile);
  640. importOptions->setType(importData.type);
  641. }
  642. HGpuProgram gpuProgram = Importer::instance().import<GpuProgram>(gpuProgInputLoc, gpuProgImportOptions);
  643. Resources::instance().save(gpuProgram, gpuProgOutputLoc, true);
  644. }
  645. }
  646. Resources::instance().unloadAllUnused();
  647. }
  648. HSpriteTexture BuiltinResources::getSkinTexture(const WString& name)
  649. {
  650. Path texturePath = FileSystem::getWorkingDirectoryPath();
  651. texturePath.append(DefaultSkinFolder);
  652. texturePath.append(L"sprite_" + name + L".asset");
  653. return Resources::instance().load<SpriteTexture>(texturePath);
  654. }
  655. HTexture BuiltinResources::getCursorTexture(const WString& name)
  656. {
  657. Path cursorPath = FileSystem::getWorkingDirectoryPath();
  658. cursorPath.append(DefaultCursorFolder);
  659. cursorPath.append(name + L".asset");
  660. return Resources::instance().load<Texture>(cursorPath);
  661. }
  662. HGpuProgram BuiltinResources::getGpuProgram(const WString& name)
  663. {
  664. Path programPath = DefaultShaderFolder;
  665. programPath.append(mActiveShaderSubFolder);
  666. programPath.append(name + L".asset");
  667. return gResources().load<GpuProgram>(programPath);
  668. }
  669. void BuiltinResources::importSkinTexture(const WString& name)
  670. {
  671. Path texturePath = FileSystem::getWorkingDirectoryPath();
  672. texturePath.append(DefaultSkinFolderRaw);
  673. texturePath.append(name);
  674. Path texOutputPath = FileSystem::getWorkingDirectoryPath();
  675. texOutputPath.append(DefaultSkinFolder);
  676. Path spriteTexOutputPath = texOutputPath;
  677. texOutputPath.append(name + L".asset");
  678. spriteTexOutputPath.append(L"sprite_" + name + L".asset");
  679. HTexture tex = Importer::instance().import<Texture>(texturePath);
  680. Resources::instance().save(tex, texOutputPath, true);
  681. HSpriteTexture spriteTex = SpriteTexture::create(tex);
  682. Resources::instance().save(spriteTex, spriteTexOutputPath, true);
  683. }
  684. void BuiltinResources::importCursorTexture(const WString& name)
  685. {
  686. Path inputPath = FileSystem::getWorkingDirectoryPath();
  687. inputPath.append(DefaultCursorFolderRaw);
  688. inputPath.append(name);
  689. Path ouputPath = FileSystem::getWorkingDirectoryPath();
  690. ouputPath.append(DefaultCursorFolder);
  691. ouputPath.append(name + L".asset");
  692. HTexture tex = Importer::instance().import<Texture>(inputPath);
  693. Resources::instance().save(tex, ouputPath, true);
  694. }
  695. void BuiltinResources::initSpriteTextShader()
  696. {
  697. HGpuProgram vsProgram = getGpuProgram(ShaderSpriteTextVSFile);
  698. HGpuProgram psProgram = getGpuProgram(ShaderSpriteTextPSFile);
  699. BLEND_STATE_DESC desc;
  700. desc.renderTargetDesc[0].blendEnable = true;
  701. desc.renderTargetDesc[0].srcBlend = BF_SOURCE_ALPHA;
  702. desc.renderTargetDesc[0].dstBlend = BF_INV_SOURCE_ALPHA;
  703. desc.renderTargetDesc[0].blendOp = BO_ADD;
  704. desc.renderTargetDesc[0].renderTargetWriteMask = 0x7; // Don't write to alpha
  705. HBlendState blendState = BlendState::create(desc);
  706. DEPTH_STENCIL_STATE_DESC depthStateDesc;
  707. depthStateDesc.depthReadEnable = false;
  708. depthStateDesc.depthWriteEnable = false;
  709. HDepthStencilState depthState = DepthStencilState::create(depthStateDesc);
  710. PASS_DESC passDesc;
  711. passDesc.vertexProgram = vsProgram;
  712. passDesc.fragmentProgram = psProgram;
  713. passDesc.blendState = blendState;
  714. passDesc.depthStencilState = depthState;
  715. PassPtr newPass = Pass::create(passDesc);
  716. TechniquePtr newTechnique = Technique::create(mActiveRenderSystem, RendererAny, { newPass });
  717. SHADER_DESC shaderDesc;
  718. shaderDesc.addParameter("worldTransform", "worldTransform", GPDT_MATRIX_4X4);
  719. shaderDesc.addParameter("invViewportWidth", "invViewportWidth", GPDT_FLOAT1);
  720. shaderDesc.addParameter("invViewportHeight", "invViewportHeight", GPDT_FLOAT1);
  721. shaderDesc.addParameter("mainTexSamp", "mainTexSamp", GPOT_SAMPLER2D);
  722. shaderDesc.addParameter("mainTexSamp", "mainTexture", GPOT_SAMPLER2D);
  723. shaderDesc.addParameter("mainTexture", "mainTexture", GPOT_TEXTURE2D);
  724. shaderDesc.addParameter("tint", "tint", GPDT_FLOAT4);
  725. mShaderSpriteText = Shader::create("TextSpriteShader", shaderDesc, { newTechnique });
  726. }
  727. void BuiltinResources::initSpriteImageShader()
  728. {
  729. HGpuProgram vsProgram = getGpuProgram(ShaderSpriteImageVSFile);
  730. HGpuProgram psProgram = getGpuProgram(ShaderSpriteImagePSFile);
  731. BLEND_STATE_DESC desc;
  732. desc.renderTargetDesc[0].blendEnable = true;
  733. desc.renderTargetDesc[0].srcBlend = BF_SOURCE_ALPHA;
  734. desc.renderTargetDesc[0].dstBlend = BF_INV_SOURCE_ALPHA;
  735. desc.renderTargetDesc[0].blendOp = BO_ADD;
  736. desc.renderTargetDesc[0].renderTargetWriteMask = 0x7; // Don't write to alpha
  737. HBlendState blendState = BlendState::create(desc);
  738. DEPTH_STENCIL_STATE_DESC depthStateDesc;
  739. depthStateDesc.depthReadEnable = false;
  740. depthStateDesc.depthWriteEnable = false;
  741. HDepthStencilState depthState = DepthStencilState::create(depthStateDesc);
  742. PASS_DESC passDesc;
  743. passDesc.vertexProgram = vsProgram;
  744. passDesc.fragmentProgram = psProgram;
  745. passDesc.blendState = blendState;
  746. passDesc.depthStencilState = depthState;
  747. PassPtr newPass = Pass::create(passDesc);
  748. TechniquePtr newTechnique = Technique::create(mActiveRenderSystem, RendererAny, { newPass });
  749. SHADER_DESC shaderDesc;
  750. shaderDesc.addParameter("worldTransform", "worldTransform", GPDT_MATRIX_4X4);
  751. shaderDesc.addParameter("invViewportWidth", "invViewportWidth", GPDT_FLOAT1);
  752. shaderDesc.addParameter("invViewportHeight", "invViewportHeight", GPDT_FLOAT1);
  753. shaderDesc.addParameter("mainTexSamp", "mainTexSamp", GPOT_SAMPLER2D);
  754. shaderDesc.addParameter("mainTexSamp", "mainTexture", GPOT_SAMPLER2D);
  755. shaderDesc.addParameter("mainTexture", "mainTexture", GPOT_TEXTURE2D);
  756. shaderDesc.addParameter("tint", "tint", GPDT_FLOAT4);
  757. mShaderSpriteImage = Shader::create("ImageSpriteShader", shaderDesc, { newTechnique });
  758. }
  759. void BuiltinResources::initSpriteNonAlphaImageShader()
  760. {
  761. HGpuProgram vsProgram = getGpuProgram(ShaderSpriteImageVSFile);
  762. HGpuProgram psProgram = getGpuProgram(ShaderSpriteImagePSFile);
  763. DEPTH_STENCIL_STATE_DESC depthStateDesc;
  764. depthStateDesc.depthReadEnable = false;
  765. depthStateDesc.depthWriteEnable = false;
  766. HDepthStencilState depthState = DepthStencilState::create(depthStateDesc);
  767. PASS_DESC passDesc;
  768. passDesc.vertexProgram = vsProgram;
  769. passDesc.fragmentProgram = psProgram;
  770. passDesc.depthStencilState = depthState;
  771. PassPtr newPass = Pass::create(passDesc);
  772. TechniquePtr newTechnique = Technique::create(mActiveRenderSystem, RendererAny, { newPass });
  773. SHADER_DESC shaderDesc;
  774. shaderDesc.addParameter("worldTransform", "worldTransform", GPDT_MATRIX_4X4);
  775. shaderDesc.addParameter("invViewportWidth", "invViewportWidth", GPDT_FLOAT1);
  776. shaderDesc.addParameter("invViewportHeight", "invViewportHeight", GPDT_FLOAT1);
  777. shaderDesc.addParameter("mainTexSamp", "mainTexSamp", GPOT_SAMPLER2D);
  778. shaderDesc.addParameter("mainTexSamp", "mainTexture", GPOT_SAMPLER2D);
  779. shaderDesc.addParameter("mainTexture", "mainTexture", GPOT_TEXTURE2D);
  780. shaderDesc.addParameter("tint", "tint", GPDT_FLOAT4);
  781. mShaderSpriteNonAlphaImage = Shader::create("NonAlphaImageSpriteShader", shaderDesc, { newTechnique });
  782. }
  783. void BuiltinResources::initDummyShader()
  784. {
  785. HGpuProgram vsProgram = getGpuProgram(ShaderDummyVSFile);
  786. HGpuProgram psProgram = getGpuProgram(ShaderDummyPSFile);
  787. PASS_DESC passDesc;
  788. passDesc.vertexProgram = vsProgram;
  789. passDesc.fragmentProgram = psProgram;
  790. PassPtr newPass = Pass::create(passDesc);
  791. TechniquePtr newTechnique = Technique::create(mActiveRenderSystem, RendererAny, { newPass });
  792. SHADER_DESC shaderDesc;
  793. shaderDesc.addParameter("matWorldViewProj", "matWorldViewProj", GPDT_MATRIX_4X4);
  794. mShaderDummy = Shader::create("DummyShader", shaderDesc, { newTechnique });
  795. }
  796. const PixelData& BuiltinResources::getCursorArrow(Vector2I& hotSpot)
  797. {
  798. hotSpot = CursorArrowHotspot;
  799. return *mCursorArrow.get();
  800. }
  801. const PixelData& BuiltinResources::getCursorArrowDrag(Vector2I& hotSpot)
  802. {
  803. hotSpot = CursorArrowDragHotspot;
  804. return *mCursorArrowDrag.get();
  805. }
  806. const PixelData& BuiltinResources::getCursorWait(Vector2I& hotSpot)
  807. {
  808. hotSpot = CursorWaitHotspot;
  809. return *mCursorWait.get();
  810. }
  811. const PixelData& BuiltinResources::getCursorIBeam(Vector2I& hotSpot)
  812. {
  813. hotSpot = CursorIBeamHotspot;
  814. return *mCursorIBeam.get();
  815. }
  816. const PixelData& BuiltinResources::getCursorSizeNESW(Vector2I& hotSpot)
  817. {
  818. hotSpot = CursorSizeNESWHotspot;
  819. return *mCursorSizeNESW.get();
  820. }
  821. const PixelData& BuiltinResources::getCursorSizeNS(Vector2I& hotSpot)
  822. {
  823. hotSpot = CursorSizeNSHotspot;
  824. return *mCursorSizeNS.get();
  825. }
  826. const PixelData& BuiltinResources::getCursorSizeNWSE(Vector2I& hotSpot)
  827. {
  828. hotSpot = CursorSizeNWSEHotspot;
  829. return *mCursorSizeNWSE.get();
  830. }
  831. const PixelData& BuiltinResources::getCursorSizeWE(Vector2I& hotSpot)
  832. {
  833. hotSpot = CursorSizeWEHotspot;
  834. return *mCursorSizeWE.get();
  835. }
  836. const PixelData& BuiltinResources::getCursorDeny(Vector2I& hotSpot)
  837. {
  838. hotSpot = CursorDenyHotspot;
  839. return *mCursorDeny.get();
  840. }
  841. const PixelData& BuiltinResources::getCursorMoveLeftRight(Vector2I& hotSpot)
  842. {
  843. hotSpot = CursorArrowLeftRightHotspot;
  844. return *mCursorArrowLeftRight.get();
  845. }
  846. GUIMaterialInfo BuiltinResources::createSpriteTextMaterial() const
  847. {
  848. GUIMaterialInfo info;
  849. info.material = Material::create(mShaderSpriteText);
  850. info.invViewportWidth = info.material->getParamFloat("invViewportWidth");
  851. info.invViewportHeight = info.material->getParamFloat("invViewportHeight");
  852. info.worldTransform = info.material->getParamMat4("worldTransform");
  853. info.mainTexture = info.material->getParamTexture("mainTexture");
  854. info.mainTexSampler = info.material->getParamSamplerState("mainTexSamp");
  855. info.tint = info.material->getParamVec4("tint");
  856. return info;
  857. }
  858. GUIMaterialInfo BuiltinResources::createSpriteImageMaterial() const
  859. {
  860. GUIMaterialInfo info;
  861. info.material = Material::create(mShaderSpriteImage);
  862. info.invViewportWidth = info.material->getParamFloat("invViewportWidth");
  863. info.invViewportHeight = info.material->getParamFloat("invViewportHeight");
  864. info.worldTransform = info.material->getParamMat4("worldTransform");
  865. info.mainTexture = info.material->getParamTexture("mainTexture");
  866. info.mainTexSampler = info.material->getParamSamplerState("mainTexSamp");
  867. info.tint = info.material->getParamVec4("tint");
  868. return info;
  869. }
  870. GUIMaterialInfo BuiltinResources::createSpriteNonAlphaImageMaterial() const
  871. {
  872. GUIMaterialInfo info;
  873. info.material = Material::create(mShaderSpriteNonAlphaImage);
  874. info.invViewportWidth = info.material->getParamFloat("invViewportWidth");
  875. info.invViewportHeight = info.material->getParamFloat("invViewportHeight");
  876. info.worldTransform = info.material->getParamMat4("worldTransform");
  877. info.mainTexture = info.material->getParamTexture("mainTexture");
  878. info.mainTexSampler = info.material->getParamSamplerState("mainTexSamp");
  879. info.tint = info.material->getParamVec4("tint");
  880. return info;
  881. }
  882. HMaterial BuiltinResources::createDummyMaterial() const
  883. {
  884. return Material::create(mShaderDummy);
  885. }
  886. }